Hi, I tried the nice example in the p5js.org examples page (examples | p5.js), though with my own sounds and reverb files.
My goal is to make a convolution of an original signal with the impulse response of a filter which changes both the frequency and the amplitude of the signal. An example if a low-pass filter and an attenuation of 20 dB. I can hear the low-pass filtering but not the 20dB decrease. it seems that the processed file plays back with maximum dynamic range, therefore no attenuation can be heard.
Any similar experience or advice from your side is more than welcome!
Thanks, Fred
Does a gain node work?
https://p5js.org/reference/#/p5.Gain
Note that p5.Sound does a lot behind the scenes (it’s likely that the impulse response is normalized) and if you want to go deeper I highly recommend to use tone.js or native web audio API
Hi and thanks for you quick feedback! I am pretty new at javascript and P5, come from Matlab programming environment. You thought about normalization of the signal seems interesting, I would really like to find the detailed documentation about what createConvolver does, as well as process().
To tackle this, I would need to use gain as you said in order to compensate for the normalization. The question if there is a p5.sound settings telling to not normalize.
The whole purpose of my application is that frequency content and attenuation (gain) is preserved. I want to demonstrate the sound attenuation of walls and facades in building.
I would look into tone.js
I looked into the code and it seems not p5.sound but Web Audio handles normalization. Under the hood, p5.js simply wraps createConvolver
of Web Audio API (as p5.Convolver extends p5.Reverb)
and in Web Audio API, there is a flag normalize
for normalization. It’s strange that they don’t provide the default state, but I’m guessing it’s true
because in their example they explicitly set false
before setting a buffer:
https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode/normalize
As you can see, p5.sound is simply a wrapper of Web Audio API (and the same for tone.js) which simplifies things a lot (e.g., normally you need to explicitly connect the sample to master out, but p5.sound automatically does it so that something “sounds” as the first step for learners) but if you are into signal processing on web, it’s good to invest time to learn Web Audio API, as it’s the fundamental of p5.sound, tone.js or whatever javascript library for sound (except those use webassembly for synthesis).
Thanks again, a lot of new things for me since I am only starting coding with P5. I think I would need some more time to understand the web audio API, but I will, it seems powerful.
I thought I could solve my issue by measuring the original peak value of my impulse response (imagine it would be 0.15). Then when it is time to play back through the Impulse response I could just set the amplitude of the playback to 0.15. However, I do not understand how to get this peak value in a first place. I though the getPeaks() would work but I don’t know how to use it. any advice?
// play the sound through the impulse
sound.amp(.15);
sound.play();
I thought about the normalize capability of the convolverNode. Isn’t it something I could specify even within my P5 coding in my editor? While looking at my variable cVerb (cVerb=createConvolver(’/FilterFiles/dirac_44kHz.mp3’) ; ) in the developer environment in my browser, I can see that cVerb.convolverNode.normalize equals true. Is there a code line to say it should be false prior to starting the convolution process? That would ease a lot.
I am thinking about, but it always get back to true. getting close, I think…
cVerb = createConvolver(’/FilterFiles/dirac_44kHz.mp3’);
cVerb.convolverNode.normalize=false;
console.log(cVerb.convolverNode.normalize);
cVerb.addImpulse(’/FilterFiles/TimbreFacade_44kHz.mp3’);
console.log(cVerb.convolverNode.normalize)
Hello,
Sorry for the late feedback, but I tested your code and it works really fine, thank you so much. I implemented your solution and can now combine several sound files playing when clicking on a button and changing the IR function by clicking on the corresponding filter button. Great!
I think I would like to propose an enhancement of the P5 function to include the choice of normalizing or not the IR function, also I will definitely check Web Audio API.
Best Regards, Frédéric