Re: Stopping a looping source when an envelope cycle has ended

First, what Paul said:  File a bug with the browser.

However, it seems to me that if you have a looping source, it can never be
stopped (unless you stop or disconnect it).  Everything it's connected to
must continue to process.

In chrome, we do take some shortcuts if the gain is 0, but probably not
when you have automations on the gain.  This would be an optimization that
we need to do.

On Thu, May 5, 2016 at 2:20 PM, Marcus Geelnard <marcus.geelnard@gmail.com>
wrote:

> Hi all!
>
> I just recently started doing some (almost) serious work with Web Audio,
> and I'm glad to find that the API and the implementations are moving along
> nicely!
>
> One of the things I have not been able to find a nice solution to yet,
> though, is a situation that leaks memory and CPU cycles... (I'm sure
> there's a solution that I have missed)
>
> I'm playing an AudioBuffer using a looping AudioBufferSourceNode, followed
> by a GainNode that acts as an envelope modulator.
>
> Now, one AudioBufferSourceNode + GainNode is created and start():ed for
> each note that I play, and all JS references to the nodes are dropped.
> Eventually the GainNode will reach zero (when the envelope cycle has
> ended), but as far as I can tell, the AudioBufferSourceNode will continue
> sampling and eat CPU cycles.
>
> I think that this is correct behavior (the AudioBufferSourceNode has the
> playing state set, so it will not be GC:ed), although there seems to be a
> difference between Blink & Gecko w.r.t how much CPU is consumed by all the
> silent nodes.
>
> Question: What is the best method for stopping / disconnecting a looping
> source node at a predefined AudioContext time (i.e. when the GainNode has
> finished all the automation events)? I would like to avoid keeping track of
> all the active nodes myself (e.g. array of active source nodes + polling &
> checking against currentTime)..
>
> /Marcus
>
>

Received on Monday, 9 May 2016 17:27:37 UTC