Hi! How can I put a threshold on microphone input signal and modify the oscillator’s amplitude (with this new range)? I use “p5.Oscillator” to make sound and “p5.AudioIn()” to catch the microphone signal.
This example doesn’t solve my question: https://p5js.org/examples/sound-mic-threshold.html
Hello @Sven ! Thanks for the help.
I need to put a threshold on microphone input signal (like a noise gate) and modify the oscillator’s amplitude (with this new range).
Thanks! It’s looks like you’re pretty close to me.
var volume = mic.getLevel(0.005) * 0.5; // tiempo que tarda en
// [...]
let amp1 = map(volume, 0, 1, 0, 0.8);
// [...]
sonido1.amp(amp1);
The code sets the variable volume by calling mic.getLevel() using smoothing value of 0.005 and multiplying the result with 0.5. That will return a value in the range 0–0.5. Is that what you want? If so, you should update the map call to reflect that: map(volume, 0, 0.5, 0, 0.8).
If you want to apply a noise gate/threshold on the signal, the logic should be like if volume is less than YOUR_THRESHOLD_VALUE set volume to 0. Now, how to implement that in code? The example you’re linking to shows that, in the first few lines of the draw function.
Hi! Thanks!
The code is designed to run on a mobile device. Therefore, I need to apply the noise gate/threshold to get the signal only above a threshold, because mobile devices microphones are too sensitive. The problem of the example in the first post is that I don’t know how to put the amplitude of the oscillator inside of the conditional: