mardi 28 avril 2020

WEB AUDIO API creating rain crackling noises

I'm trying to create rain in the javascript Web Audio API. So far I've created a low frequency rumbling noise for the background and I'm working on a high frequency noise which will imitate the sound of rain droplets. However, right now the high-frequency noise is very much like white noise and too intense to be individual droplets. Does anyone know how to "separate" the sound a little so it almost sounds like crackling. Here is a link to what I would like the high-frequency noise to sound like if you increase the last slider (violet) you can hear it.

And here is my HTML code so far

<script>
let context= new AudioContext();
let context2= new AudioContext();

let lowpass = context.createBiquadFilter();
  lowpass.type = 'lowpass';
  //lowpass.Q.value = -7.01;
  lowpass.frequency.setValueAtTime(80, context2.currentTime);

let gain = new GainNode(context);
  gain.gain.value= 0.4;

let gain2 = new GainNode(context2);
  gain2.gain.value= 0.02;

let highpass=context2.createBiquadFilter();
  highpass.type = 'highpass';
  highpass.Q.value = 2;
  //highpass.frequency.setValueAtTime(6000, context2.currentTime);

let distortion = context2.createWaveShaper();

let delay = context2.createDelay(90.0);




function StartAudio() {context.resume()};
context.audioWorklet.addModule('basicnoise.js').then(() => {
  let myNoise = new AudioWorkletNode(context,'noise-generator');

  myNoise.connect(lowpass);
  lowpass.connect(gain);
  gain.connect(context.destination);
});

function StartAudio2() {context2.resume()};
context2.audioWorklet.addModule('basicnoise.js').then(() => {
  let myNoise2 = new AudioWorkletNode(context2,'noise-generator');

  myNoise2.connect(highpass);
  highpass.connect(gain2);
  gain2.connect(delay);
  delay.connect(context2.destination);
});

I've been playing around with different functions, some of them didn't do much or I simply am not using them correctly as I am very new to the audio API scene. Any help is appreciated as this is for a school project and I know some other students want to make fire sounds and could also benefit from the crackling noise !! Thank you !!




Aucun commentaire:

Enregistrer un commentaire