- From: Chris Wilson <cwilso@google.com>
- Date: Mon, 16 Jul 2012 09:47:43 -0700
- To: Marcus Geelnard <mage@opera.com>
- Cc: Matt Diamond <mdiamond@jhu.edu>, public-audio@w3.org
- Message-ID: <CAJK2wqVHWH6T7YxdQHLqPzK_eW4g0V5tGjHz2VF42r-OFZvznA@mail.gmail.com>
Actually, no, I didn't mean that Math.random was a bottleneck; just that this approach was probably more costly than it needs to be. Having to generate samples from Math.random() and write them into the output buffer in a JSnode (plus the cost of calling the JSnode) would be, I expect, more costly than just looping a precalculated buffer. But it was just a side comment. On Mon, Jul 16, 2012 at 12:10 AM, Marcus Geelnard <mage@opera.com> wrote: > 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<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 16:48:15 UTC