<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>17327</bug_id>
          
          <creation_ts>2012-06-05 11:19:28 +0000</creation_ts>
          <short_desc>(ScriptStateInteraction): Script interaction (setting and reading) of most state is underdefined</short_desc>
          <delta_ts>2014-10-28 17:16:28 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>AudioWG</product>
          <component>Web Audio API</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>TBD</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Philip Jägenstedt">philipj</reporter>
          <assigned_to name="Chris Rogers">crogers</assigned_to>
          <cc>mage</cc>
    
    <cc>olivier.thereaux</cc>
    
    <cc>public-audio</cc>
          
          <qa_contact name="This bug has no owner yet - up for the taking">dave.null</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>68637</commentid>
    <comment_count>0</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2012-06-05 11:19:28 +0000</bug_when>
    <thetext>Audio-ISSUE-28 (ScriptStateInteraction): Script interaction (setting and reading) of most state is underdefined [Web Audio API]

http://www.w3.org/2011/audio/track/issues/28

Raised by: Philip Jägenstedt
On product: Web Audio API

How scripts observe and modify the state of the audio graph has big consequences for both implementation complexity and ease of use for Web authors.

Observing:

Can long-running scripts busy-wait and monitor changes to AudioContext.currentTime, AudioBufferSourceNode.playbackState, Oscillator.playbackState and AudioParam.value? (HTMLMediaElement.currentTime is held stable during script execution.)

Modifying:

When modification are made to the graph, when do they take effect? Should conforming implementations work with long-running scripts that continuously modify some state, or should all modifications made be applied atomically after the script thread has finished.

Recommendations:

For observing, it&apos;s not clear what is the best solution. Showing scripts a stable state is probably simpler to specify, simpler to write a test suite for (since otherwise state may at any time be inconsistent, a big problem in testing HTMLMediaElement) but hard to implement as an after-thought.

For modifications, it seems wise to apply all changes as a single &quot;transaction&quot; after the script has finished running. Otherwise, intermediary states could cause audible glitches if GC is run for even a few milliseconds between the two setters. An example would be changing ConvolverNode.buffer and normalize. If the change to normalize takes effect some time after the change to buffer, one could hear a loud pop or gap of silence generated from the inconsistent combination of the new buffer and old normalize value.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68833</commentid>
    <comment_count>1</comment_count>
    <who name="Olivier Thereaux">olivier.thereaux</who>
    <bug_when>2012-06-07 15:55:44 +0000</bug_when>
    <thetext>Comment from Chris Rogers, 18 May 2012


I&apos;ll need to add more detail into the spec. Here&apos;s my thinking:

Observing: the states MAY change during script execution. We believe we have good automated test methods for testing things such as .playbackState, and already test them today.

Modifying: I believe it&apos;s critical to have modifications to the graph state happen immediately due to the real-time nature of audio (think real-time synthesis where we have a MIDI API, playing notes in real-time). We need to respond to the &quot;command&quot; noteOn() (or start() given a better naming) right away as soon as we know for sure that this is what we want to happen. Any delays caused by waiting for the script thread to finish, gc, etc. will adversely affect this model and would be highly undesirable.

That said, there could be some advanced uses cases (not yet required or demanded by any Web Audio developers) where more complex and atomic changes to the graph will be necessary. For this, I propose something along the lines of:

context.beginAtomicChanges();
...
context.endAtomicChanges();

Once again, I believe I can demonstrate that these atomic changes will be rarely needed so won&apos;t overly complicate the JS code for developers in nearly all cases.
But we should support them for certain advanced cases, and will need to work out exactly the details...

Regarding your example of ConvolverNode -- I don&apos;t believe this specific example will be a problem, but I can understand your confusion because I haven&apos;t fully explained how these work. Give me some time...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68974</commentid>
    <comment_count>2</comment_count>
    <who name="Marcus Geelnard (Opera)">mage</who>
    <bug_when>2012-06-12 13:03:21 +0000</bug_when>
    <thetext>More comments from the mailing list...

Robert O&apos;Callahan, http://lists.w3.org/Archives/Public/public-audio/2012AprJun/0453.html

&quot;
Chris wrote:

&gt; Observing: the states MAY change during script execution. We believe we
&gt; have good automated test methods for testing things such as .playbackState,
&gt; and already test them today.
&gt;

It&apos;s generally simpler for Web authors if states don&apos;t change during script
execution (except for changes explicitly made by the script), in particular
if scripts always see a consistent snapshot of the state of the graph.
That&apos;s what MSP does. If we&apos;re not going to do this, I think we need a
strong argument for not doing it, we&apos;ll need a careful description of which
states can change asynchronously and how, and we&apos;ll need to make sure that
scripts can actually safely read and do something with that state (which is
often not the case for state that can change asynchronously).

Modifying: I believe it&apos;s critical to have modifications to the graph state
&gt; happen immediately due to the real-time nature of audio (think real-time
&gt; synthesis where we have a MIDI API, playing notes in real-time). We need to
&gt; respond to the &quot;command&quot; noteOn() (or start() given a better naming) right
&gt; away as soon as we know for sure that this is what we want to happen. Any
&gt; delays caused by waiting for the script thread to finish, gc, etc. will
&gt; adversely affect this model and would be highly undesirable.
&gt;

I think that deferring changes to happen atomically at the next stable
state (in HTML5 terms) makes sense. That&apos;s what MSP does. That makes it
very simple for Web authors to avoid glitches due to unintended
intermediate states, without needing to introduce new atomicity constructs
and educate authors to use them correctly. I don&apos;t think Chris&apos; objections
apply. Authors cannot and should not rely on their API calls happening at
particular moments in real time. A GC or other pause happening after
noteOn() and before the next stable state could just as easily have
happened before the noteOn(). As a matter of general Web application
design, scripts should not run long between stable states since that
adversely affects almost everything in the page (including rendering etc),
so any delays introduced by deferring to the next stable state should be
very short.

If deferring changes to happen atomically at the next stable state is still
considered harmful, I&apos;d like to see more detailed examples of scripts that
would be adversely affected.
&quot;

Philip Jägenstedt, http://lists.w3.org/Archives/Public/public-audio/2012AprJun/0486.html

&quot;
We strongly agree with Robert. We have negative experiences with race  
conditions in the HTMLMediaElement API and do not want to implement  
something that we know will cause subtle and hard-to-reproduce bugs. The  
specification will require a lot more detail if state changes are  
reflected immediately, e.g. as in the ConvolverNode example we&apos;ve given.

We suggest defining state modification (both by scripts and the audio  
graph) in terms of tasks [1] such that e.g. modifying the ConvolverNode  
properties will queue a task to atomically apply the changes to the  
underlying audio graph.

[1]  
http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#task-source
&quot;

Robert O&apos;Callahan, http://lists.w3.org/Archives/Public/public-audio/2012AprJun/0490.html

&quot;
I suggest batching all changes between each stable state and then applying
them atomically.
&quot;

Philip Jägenstedt, http://lists.w3.org/Archives/Public/public-audio/2012AprJun/0494.html

&quot;
I think we mean exactly the same thing, did I use the wrong terminology?
&quot;

Robert O&apos;Callahan, http://lists.w3.org/Archives/Public/public-audio/2012AprJun/0536.html

&quot;
Queuing a task to perform an action is rather different to performing the
action at the next stable state.
&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68985</commentid>
    <comment_count>3</comment_count>
    <who name="Philip Jägenstedt">philipj</who>
    <bug_when>2012-06-12 14:41:48 +0000</bug_when>
    <thetext>Robert is correct, queuing a task doesn&apos;t guarantee that the steps will be run before any more scripts are run, awaiting a stable state is better. That concept is defined in http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#await-a-stable-state</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113848</commentid>
    <comment_count>4</comment_count>
    <who name="Olivier Thereaux">olivier.thereaux</who>
    <bug_when>2014-10-28 17:13:32 +0000</bug_when>
    <thetext>Web Audio API issues have been migrated to Github. 
See https://github.com/WebAudio/web-audio-api/issues</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113991</commentid>
    <comment_count>5</comment_count>
    <who name="Olivier Thereaux">olivier.thereaux</who>
    <bug_when>2014-10-28 17:16:28 +0000</bug_when>
    <thetext>Closing. See https://github.com/WebAudio/web-audio-api/issues for up to date list of issues for the Web Audio API.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>