1 var toneLengthSeconds = 1;
3 // Create a buffer with multiple channels.
4 // The signal frequency in each channel is the multiple of that in the first channel.
5 function createToneBuffer(context, frequency, duration, numberOfChannels) {
6 var sampleRate = context.sampleRate;
7 var sampleFrameLength = duration * sampleRate;
9 var audioBuffer = context.createBuffer(numberOfChannels, sampleFrameLength, sampleRate);
11 var n = audioBuffer.length;
13 for (var k = 0; k < numberOfChannels; ++k)
15 var data = audioBuffer.getChannelData(k);
17 for (var i = 0; i < n; ++i)
18 data[i] = Math.sin(frequency * (k + 1) * 2.0*Math.PI * i / sampleRate);