pistacchio
pistacchio

Reputation: 58863

WebAudio sounds from wave point

Suppose that I make a simple canvas drawing app like this:

enter image description here

I now have a series of points. How can I feed them to some of the WebAudio objects (an oscillator or a sound make from a byte array or something) to actually generate and play a wave out of them (in this case a sine-like wave)? What is the theory behind it?

Upvotes: 0

Views: 51

Answers (1)

Raymond Toy
Raymond Toy

Reputation: 6048

If you have the data from your graph in an array, y, you can do something like

var buffer = context.createBuffer(1, y.length, context.sampleRate);
buffer.copyToChannel(y);
var src = context.createBufferSource();
src.buffer = buffer;
src.start()

You may need to set the sample rate in context.createBuffer to something other than context.sampleRate, depending on the data from your graph.

Upvotes: 2

Related Questions