Re: setValueFunctionAtTime for AudioParam

B, fire the same callback many times (maybe even with a user specified granularity: small granularity/large buffers cache more data)

As I see it case A could easily be achieved by setValueCurveAtTime and a auxiliary function that renders the callback function into an Float Array.

Hiere a quick callback function I had in mind which would introduce difficulties with the current API (it actually would be possible but would require the user to regularly "push" values to the AudioParam). Off course it's a bit naive (and bad names for args and method names) but I hope you're getting my intentions (also code not tested …).

var lfo = function(frequency, min, max) {
	var phase = 0;
	var delta = 1 / SAMPLERATE * 2 * Math.PI;
	
	return function (buffer, time) {
		for(var i = 0; i < buffer.length; i++) {
			buffer[i] = (Math.sin(phase) + 1.0) * (max - min) + min;
			
			phase += delta;
			if(phase >= (Math.PI * 2) {
				phase -= (Math.PI * 2);
			}
		}
	}
}

filter.frequency.setValueFunction(lfo(1, 500, 2000));


Now the filter (a BiquadFilterNode) has a LFO running at 1Hz attached to its frequency, ranging from 500Hz to 2000Hz.


Patrick


Am 27.03.2012 um 19:26 schrieb Alistair MacDonald:

> Hi Patrick,
> 
> I have been thinking about your use-case over the last day or so and have a further question.
> 
> Did you want to:
> 
>     A) Fire a callback, once, at an exact time?
> 
>     B) Fire the same callback many times?
> 
> 
> Al

Received on Tuesday, 27 March 2012 18:26:21 UTC