- From: Marcus Geelnard <mage@opera.com>
- Date: Mon, 16 Jul 2012 09:10:38 +0200
- To: "Matt Diamond" <mdiamond@jhu.edu>, "Chris Wilson" <cwilso@google.com>
- Cc: public-audio@w3.org
Den 2012-07-15 17:03:08 skrev Chris Wilson <cwilso@google.com>: > On Sat, Jul 14, 2012 at 12:26 PM, Matt Diamond <mdiamond@jhu.edu> wrote: > >> Hey all, >> >> Put together a little experiment in synthesizing an ambient sound >> texture >> using the Web Audio API: >> >> http://matt-diamond.com/drone.html >> >> Matt Matt, nice demo! > Hey Matt- > > Neat! I like the apparent pitch generated by bandpass filter. > > One comment - instead of continually generating noise via > JavaScriptAudioNodes, you'd probably find it much more performant to > pre-generate a couple of seconds (to avoid any detectable periodicity) of > noise in a Buffer and playing it as an AudioNode. That would probably > be a > bit more performant than continually calling Math.random for each sample. > > var lengthInSamples = 2 * audioContext.sampleRate; > var noiseBuffer = audioContext.createBuffer(1, lengthInSamples, > audioContext.sampleRate); > var bufferData = noiseBuffer.getChannelData(0); > for (var i = 0; i < lengthInSamples; ++i) { > bufferData[i] = (2*Math.random() - 1); > } Surely, Math.random() can't be the bottleneck here. On my computer Math.random() can generate 48000 samples in less than one millisecond. In other words, it should consume less than 4% CPU if 40 such sources are used - yet Chrome consumes 45% CPU when running the demo. /Marcus -- Marcus Geelnard Core Graphics Developer Opera Software ASA
Received on Monday, 16 July 2012 07:11:16 UTC