[tw5] WebAudio API multi-voice experimentation

Put the following in a new tiddler:

<iframe srcdoc="
<script>
context = new AudioContext();

var merger = context.createChannelMerger(3);
merger.connect(context.destination);

oscillatorNode1 = context.createOscillator();
oscillatorNode1.type = 'sine';
oscillatorNode1.frequency.value = 220;

oscillatorNode2 = context.createOscillator();
oscillatorNode2.type = 'sine';
oscillatorNode2.frequency.value = 293.6648;

oscillatorNode3 = context.createOscillator();
oscillatorNode3.type = 'triangle';
oscillatorNode3.frequency.value = 783.9909;

oscillatorNode1.connect(merger, 0, 0);
oscillatorNode1.start();

oscillatorNode2.connect(merger, 0, 1);
oscillatorNode2.start();

oscillatorNode3.connect(merger, 0, 2);
oscillatorNode3.start();
</script>">
</iframe>

1 Like

Here’s something interesting.

Although the first and second oscillators are playing, the third oscillator is not.

I tested by, one at a time, changing one oscillator’s frequency to 1000. That note plays only for the first two oscillators, but not the third.

So I tried this for the giggles:

var merger = context.createChannelMerger(**4**)

After that change, the three oscillators play A-1.

Change it to 5, and the third oscillator does not play. Change it to 6, and the notes play, but the sound is horrible.

I do not know if this behaviour applies to only the Chrome browser or to many browsers.