We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm starting to play with the p5.sound lib from p5.js. I'm trying to simply modulate a noise with an oscillator, so I'm trying this :
noise = new p5.Noise();
noise.start();
osc = new p5.Oscillator('sine');
osc.disconnect();
osc.amp(1);
osc.freq(0.2);
osc.start();
noise.amp(osc,0,0);
Normally this should do the trick but I get an error : " Uncaught InvalidStateError: Failed to execute 'linearRampToValueAtTime' on 'AudioParam': Target value must be a finite number: NaN "
I took example from this code, where the modulation is on the frequency of the signal, and of course it works : http://p5js.org/reference/#/p5.Signal
I played around with other stuff from the lib (which looks amazing btw) with no issues , but I can't seem to find a way around this. If somebody could help it would be great !
Answers
Perhaps your disconnect() might be the cause? :-?
What exactly does it do? I bet it closes the whole p5.Oscillator! >-)
Thinking it over, my new guess is that p5.Noise doesn't have a proper amp() method or something! 3:-O
According to p5.Oscillator's amp(): http://p5js.org/reference/#/p5.Oscillator/amp,
All 3 arguments gotta be numbers! :-@
I think disconnect() is used to create an oscillator but not hearing it in the main mix.
the p5.Noise method does exist ! if you do that it works :)
On the third comment, yes I agree, but it doesn't seem to change that much, the other values are just interpolation param. If you check the ref of freq() : http://p5js.org/reference/#/p5.Oscillator/freq
it states the same thing but the first example I mentionned (i.e. : http://p5js.org/reference/#/p5.Signal) uses this trick to modulate. So I thought it would work, but it doesn't.
One thing would be to have a node to multiply two signals together somthing like
result = mult(osc,noise);
Maybe it's just conceptual, and I am not suposed to do this that way ?
After a discusion with @therewasaguy it seems that it's probably due to a samplerate mismatch.
It's now a filed issue on github : https://github.com/therewasaguy/p5.sound/issues/25
This issue has been resolved in Chrome, Safari and Opera. However, there is lingering bug with amplitude modulation in Firefox. Hope to figure that out soon.
Also, updating the reference pages—good call on that, @GoToLoop!