W3C home > Mailing lists > Public > public-audio@w3.org > January to March 2012

Re: replay AudioBufferSourceNode ?

From: Jerome Etienne <jerome.etienne@gmail.com>
Date: Wed, 21 Mar 2012 17:50:55 +0100
Message-ID: <CAN_PVv5_A6LLMJ+CNEckXHwUya3wkU79eO=g2J+vhSkhMpodRw@mail.gmail.com>
To: Chris Wilson <cwilso@google.com>
Cc: "Wei, James" <james.wei@intel.com>, Chris Rogers <crogers@google.com>, "public-audio@w3.org" <public-audio@w3.org>
Ok i think i start to understand the spirit behind it. Thanks for your help

On Wed, Mar 21, 2012 at 5:34 PM, Chris Wilson <cwilso@google.com> wrote:
> Jerome, the key to the answer to your question - how do I play a sound
> several times - is that an AudioBuffer can be reused many times.  You can
> create multiple AudioBufferSourceNodes, even playing simultaneously, that
> have their .buffer properties pointing to the same AudioBuffer instance.
>  The actual AudioBufferSourceNode doesn't contain that much independent of
> the buffer - the playbackRate and the loop boolean - so they are pretty
> lightweight.
>
> My initial take on looking at PlaySound() in the previous example was "Wow,
> that seems like you're throwing away a lot" - but you're really not.  You
> don't need to create (and load data into) a new buffer for each call to
> PlaySound() in that example.
>
>
> On Tue, Mar 20, 2012 at 11:18 PM, Wei, James <james.wei@intel.com> wrote:
>>
>> I think your confusion comes from the feature of dynamic lifetime of
>> AudioBufferSourceNode.
>>
>> >From the spec:
>> "The audio system automatically deals with tearing-down the part of the
>> routing graph for individual "note" events. A "note" is represented by an
>> AudioBufferSourceNode, which can be directly connected to other processing
>> nodes. When the note has finished playing, the context will automatically
>> release the reference to the AudioBufferSourceNode, which in turn will
>> release references to any nodes it is connected to, and so on. The nodes
>> will automatically get disconnected from the graph and will be deleted when
>> they have no more references. Nodes in the graph which are long-lived and
>> shared between dynamic voices can be managed explicitly. Although it sounds
>> complicated, this all happens automatically with no extra JavaScript
>> handling required."
>>
>> As stated in the spec: Although it sounds complicated, this all happens
>> automatically with no extra JavaScript handling required.
>>
>> Best Regards
>>
>> James
>>
>>
>>
>> -----Original Message-----
>> From: Jerome Etienne [mailto:jerome.etienne@gmail.com]
>> Sent: Wednesday, March 21, 2012 12:31 PM
>> To: Chris Rogers
>> Cc: public-audio@w3.org
>> Subject: Re: replay AudioBufferSourceNode ?
>>
>> On Tue, Mar 20, 2012 at 8:34 PM, Chris Rogers <crogers@google.com> wrote:
>> > On Tue, Mar 20, 2012 at 12:29 AM, Jerome Etienne
>> > <jerome.etienne@gmail.com>
>> >> Nevertheless in a game, a sound is played many-many times. So
>> >> BufferSource javascript object needs to be recreated, fully
>> >> reconfigured and reconnect every time you play it. This is rather
>> >> cumbersome for the developer. How can i clone an existing
>> >> BufferSource ? maybe somebody did a javascript function on top of the
>> >> spec ?
>> >
>> >
>> > Although it may seem strange at first, I think it's straight-forward
>> > and works quite well.  There are a few tutorials/blogs explaining how
>> > this works, for example:
>> >
>> > Please see the playSound() function here:
>> > http://www.html5rocks.com/en/tutorials/webaudio/intro/
>>
>> i read this tutorial. in fact i read all tutorials about webaudio i could
>> find on html5rock. i failed to find one which explain how to
>> *clone* a buffersource, aka copy an existing buffersource. i only found
>> how to *create* one. did i miss it ?
>>
>> > It's only a few lines of JavaScript which is wrapped up in a function
>> > which is simple to call each time a particular sound needs to be played.
>>
>> I asuppose i want to play a sound several time ? how can i do that ?
>> what is the recommended way ?
>>
>> Is it to create a function which init the buffersource node, and call it
>> to recreate the node at every occurance ? how to do that efficiently ?
>>
>>
>
Received on Wednesday, 21 March 2012 16:51:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 21 March 2012 16:51:29 GMT