Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modulate an AudioParam with a LFO in Web Audio API

How can i modulate any of the AudioParams in Web Audio API, for example gain value of the GainNode using a Low Frequency Oscillator ?

like image 350
zya Avatar asked Sep 03 '25 06:09

zya


2 Answers

https://coderwall.com/p/h1jnmg

var saw = context.createOscillator(),
      sine = context.createOscillator(),
      sineGain = context.createGainNode();

//set up our oscillator types
saw.type = saw.SAWTOOTH;
sine.type = sine.SINE;

//set the amplitude of the modulation
sineGain.gain.value = 10;

//connect the dots
sine.connect(sineGain);
sineGain.connect(saw.frequency);
like image 106
Kevin Ennis Avatar answered Sep 04 '25 19:09

Kevin Ennis


You're not saving your actual nodes, just the value - so when you try to connect to oscillator.frequency, you're passing an integer value (400 - the frequency you saved in the node). Try http://jsfiddle.net/GCSEq/6/ - this stores the nodes, and properly routes to the AudioParam.

this.oscillator = context.createOscillator();
this.gain = context.createGainNode();

and osctest2.play(osctest.oscillator.frequency , 1000);

(You were getting an error in the console.)

like image 27
cwilso Avatar answered Sep 04 '25 19:09

cwilso