Closed Bug 1252988 Opened 8 years ago Closed 8 years ago

Web Audio API OscillatorNode onended callback fires even if oscillator does not play

Categories

(Core :: Web Audio, defect)

47 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: steve, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36

Steps to reproduce:

Using latest nightly build (v47.0a1) on Windows, 64 bit. Build ID 20160302030209.
Also occurs in v44.0.2, Windows, 64 bit. Build ID 20160210153822.

Create a new AudioContext.
Create an OscillatorNode and connect it to the AudioContext.
Set an onended callback on the OscillatorNode.
Set the start time of the OscillatorNode to 1 second from now and the end time to 1.2s from now.
Disconnect the OscillatorNode from the AudioContext.

Fiddle here:
https://jsfiddle.net/scp93ch/m9m3wxnv/


Actual results:

Sound does not play (correct).
Callback still fires (possibly not correct).


Expected results:

I did not expect the callback to fire: I expect the callback to fire when the oscillator ends. In this case, the oscillator does not start. Once it is disconnected from the AudioContext it could quite legitimately be garbage collected. Instead the callback fires.

The behaviour in Chrome is for the callback NOT to fire.

The documentation in the standard is not clear either way.

Web Audio API spec 2.30.1 (http://webaudio.github.io/web-audio-api/#idl-def-OscillatorNode) says:

onended of type EventHandler
    A property used to set the EventHandler (described in HTML[HTML]) for the ended event that is dispatched to OscillatorNode node types. When the OscillatorNode has finished playing (i.e. its stop time has been reached), an event of type Event (described in HTML[HTML]) will be dispatched to the event handler. 

In Firefox, the callback executes though the OscillatorNode has not "finished playing" as it never starts. However, you could argue that "its stop time has been reached".
OS: Unspecified → Windows 7
Hardware: Unspecified → x86_64
Component: Untriaged → Web Audio
Product: Firefox → Core
Thanks for the nice description.

The OscillatorNode does play, but it is not connected to anything else that notices.  Connecting a ScriptProcessorNode or an AnalyserNode would also notice that the OscillatorNode plays, regardless of whether indirectly connected to a destination.  If there is an ended event listener, then the OscillatorNode can't be GC'd until after the event dispatch.

IIRC Chrome does not play nodes that are not connected (directly or indirectly) to the destination node.  Such behavior is not indicated in the spec and would make no sense wrt "All scheduled times in the Web Audio API are relative to the value of currentTime."
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.