- From: Matt Diamond <mdiamond@jhu.edu>
- Date: Wed, 19 Sep 2012 16:20:52 -0700
- To: public-audio@w3.org
Hey all - Just wondering if anyone else has been working on code to generate impulses on-the-fly for use in convolution nodes... I noticed that a lot of examples involve downloading pre-recorded impulses, but I figure if you're in need of some quick-and-dirty reverb, you probably don't need to rope in additional audio file dependencies. For example, the code below will generate a basic reverb node: function ReverbNodeFactory(context, seconds, options){ options = options || {}; var sampleRate = context.sampleRate; var length = sampleRate * seconds; var impulse = context.createBuffer(2, length, sampleRate); var impulseL = impulse.getChannelData(0); var impulseR = impulse.getChannelData(1); var decay = options.decay || 2; for (var i = 0; i < length; i++){ var n = options.reverse ? length - i : i; impulseL[i] = (Math.random() * 2 - 1) * Math.pow(1 - n / length, decay); impulseR[i] = (Math.random() * 2 - 1) * Math.pow(1 - n / length, decay); } var convolver = context.createConvolver(); convolver.buffer = impulse; return convolver; } The "options" here are just "reverse" and "decay", and the result is a pretty basic but adequate reverb effect. Has anyone else played around with a strategy like this? Matt
Received on Wednesday, 19 September 2012 23:21:20 UTC