Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web audio api: multiply waves

The Web Audio API lets me create a constant sine wave in a specified frequence signal like this:

var actx = new AudioContext();
var osc = actx.createOscillator();

osc.frequency.value = 500;
osc.connect(actx.destination);
osc.start();

How can I multiply this wave by another wave in order to "shape" it. For example how could I multiply it by another sine wave of 200 Hz.

Like so:

enter image description here

like image 863
Anton Harald Avatar asked Mar 13 '23 08:03

Anton Harald


1 Answers

Try something like

var osc1 = context.createOscillator();
var osc2 = context.createOscillator();
var gain = context.createGain();

osc1.frequency.value = 500;
osc2.frequency.value = 20;

osc1.connect(gain);
osc2.connect(gain.gain);

gain.connect(context.destination);

osc1.start();
osc2.start();
like image 93
Raymond Toy Avatar answered Mar 27 '23 13:03

Raymond Toy