p5.sound modulate a noise with an osc

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! >-)

  • Answer ✓

    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! :-@

  • edited December 2014

    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 :)

    function setup() {
      // put setup code here
      createCanvas(windowWidth, windowHeight);
    
      // sound
      noise = new p5.Noise();
      noise.start();
    
    }
    
    function draw() {
      noise.pan(map(mouseX,0,width,-1,1));
      noise.amp(map(mouseY,0,height,0,1));
    }
    

    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!

Sign In or Register to comment.