Re: AudioParam constructor

On Mon, Jun 6, 2011 at 1:48 PM, Jussi Kalliokoski <> wrote:

> Yeah, that being the main case and also that of abstraction layers, such as
> if someone wrote, for instance something called a MixerNode, that uses gain
> nodes to take multiple inputs and such, maybe AUXes or whatever. Also, now
> that I think of it, it would be pretty handy if AudioParam was an instance
> of EventTarget, so you could add listener hooks to such things as onChange
> or onAutomationEnd (I don't know about this one), don't you think? It might
> complicate the thing a bit, but at the benefit of hackability, and that's
> always a good thing if you want to attract developers.

Hi Jussi, with automation the AudioParam value can change for every single
sample-frame, so I think it would be pretty dramatic to have an
EventListener get called thousands of times a second!  Instead, I think it
should be possible to query the AudioParam for its value at any exact time.

> Also, now that I'm asking, can you dereference AudioParams? For example,
> make two separate AudioGainNodes and make them share the AudioParam for
> .gain? As here:
> var gain1 = ctx.createGainNode();
> var gain2 = ctx.createGainNode();
> gain1.gain = gain2.gain;
> gain1.gain.value = 0.5;

> And that would change the value of both? I could've just tried, but quite
> honestly I'm pretty ill and tired, so I'll just ask. :)

I believe this should work.

> I think that would be a useful feature to have, if it's not that way. After
> all, it only follows the same logic as do most things in javascript, for
> example being able to do, 1); sorta
> things.
> I realize these things have many complicating effects, implementation-wise,
> but I'm just throwing things at you and the rest of us, to see whether you
> think they're good ideas or not.
> Another thing about AudioParam on my mind may be completely absurd, the
> fever talking and impossible to implement (I'm not sure if V8 for instance
> allows that, without changing the toString), but what if the primitive of
> AudioParam was the value of it? That way one could use normal number values
> in stead of AudioParams, if one pleases, and yet not making horrible
> performance sacrifices in checking whether it's an audio param or not on
> every sample, for example:
> sample = sample * myGainlikeEffect.gain;
> versus
> sample = sample * (isNaN(myGainlikeEffect.gain) ?
> myGainlikeEffect.gain.value : myGainlikeEffect.gain.value);
> This would be similar to behaviour of Date(), as +new Date does the same
> trick as (new Date).getTime().

I'll have to think about this one, but I'm not sure I understand your
example here.  If you want to use the time-varying AudioParam values over a
time-range,then I think it might be better to have a method to get the
values into a Float32Array, then work from there.

> I'm sorry not having brought up these things earlier, but such things come
> to mind only when you have a working prototype to play with.
> Jussi
> On Mon, Jun 6, 2011 at 9:33 PM, Chris Rogers <> wrote:
>> Hmmm, that's an interesting idea.  I assume you're talking in the context
>> of a JavaScriptAudioNode?  In this case, I can see where it might be useful
>> to add your own AudioParams to the JavaScriptAudioNode, then they could be
>> automated (envelope, fade-in/out, LFO, etc.) just like any other parameter.
>>  If you wanted to get sample-accurate parameter data then we'd have to add
>> another method (something like requesting to fill a Float32Array for a given
>> time range) from AudioParam, so custom DSP code can do useful things with
>> it...
>> Chris
>> On Mon, Jun 6, 2011 at 10:26 AM, Jussi Kalliokoski <
>>> wrote:
>>> Hello Chris, others,
>>> Is there a way to create an AudioParam from your code, I've tried several
>>> things in the fashion of
>>> new (new webkitAudioContext).createGainNode().gain.constructor
>>> but I keep getting errors, like Illegal constructor. Is it possible to
>>> do? Would be pretty handy when crafting your own effects.
>>> Jussi

Received on Tuesday, 7 June 2011 17:27:37 UTC