diff --git a/index.bs b/index.bs index d171a1232..dc3bdf605 100644 --- a/index.bs +++ b/index.bs @@ -2500,9 +2500,10 @@ returned promise with the rendered result as an interface OfflineAudioContext : BaseAudioContext { constructor(OfflineAudioContextOptions contextOptions); constructor(unsigned long numberOfChannels, unsigned long length, float sampleRate); - Promise startRendering(); + Promise startRendering(optional unsigned long chunkSize); Promise resume(); Promise suspend(double suspendTime); + Promise close(); readonly attribute unsigned long length; attribute EventHandler oncomplete; }; @@ -2596,7 +2597,7 @@ Constructors
         numberOfChannels: Determines how many channels the buffer will have. See {{BaseAudioContext/createBuffer()}} for the supported number of channels.
-        length: Determines the size of the buffer in sample-frames.
+        length: Determines the total size of the audio render in sample-frames.
         sampleRate: Describes the sample-rate of the [=linear PCM=] audio data in the buffer in sample-frames per second. See [[#sample-rates]] for the required supported range.
         
@@ -2607,8 +2608,11 @@ Attributes
: length :: - The size of the buffer in sample-frames. This is the same as the - value of the length parameter for the constructor. + The total size of the audio render in sample-frames. This is the same + as the value of the length parameter for the constructor. + + For undefined-length rendering, this attribute SHOULD be set to + null. : oncomplete :: @@ -2621,7 +2625,7 @@ Attributes Methods
- : startRendering() + : startRendering(chunkSize) :: Given the current connections and scheduled changes, starts rendering audio. @@ -2640,21 +2644,41 @@ Methods
  1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=fully active=] then return [=a promise rejected with=] "{{InvalidStateError}}" {{DOMException}}. -
  2. If the {{[[rendering started]]}} slot on the - {{OfflineAudioContext}} is true, return a rejected - promise with {{InvalidStateError}}, and abort these - steps. -
  3. Set the {{[[rendering started]]}} slot of the {{OfflineAudioContext}} to true.
  4. Let promise be a new promise. +
  5. Let bufferLength be a number initialized to the + value of {{OfflineAudioContext/length}}. + +
      +
    1. If {{OfflineAudioContext/startRendering(chunkSize)/chunkSize}} + is provided: +
        +
      1. Let renderedFrames be the number of + sample-frames already rendered by the + {{OfflineAudioContext}}. +
      2. If renderedFrames + + {{OfflineAudioContext/startRendering(chunkSize)/chunkSize}} + is less than or equal to {{OfflineAudioContext/length}}, + set bufferLength to + {{OfflineAudioContext/startRendering(chunkSize)/chunkSize}}. +
      3. Otherwise, set bufferLength to + {{OfflineAudioContext/length}} - + renderedFrames. +
      +
    2. Otherwise, if {{OfflineAudioContext/length}} is + null, set bufferLength to the + render quantum size. +
    +
  6. Create a new {{AudioBuffer}}, with a number of - channels, length and sample rate equal respectively to the - numberOfChannels, length and + channels and sample rate equal respectively to the + numberOfChannels and sampleRate values passed to this instance's - constructor in the contextOptions parameter. + constructor in the contextOptions parameter; + and length equal to bufferLength. Assign this buffer to an internal slot [[rendered buffer]] in the {{OfflineAudioContext}}. @@ -2677,9 +2701,12 @@ Methods occasion.
      +
    1. Let numberOfFrames be a number initialized to + the value of the length of {{[[rendered buffer]]}}. +
    2. Given the current connections and scheduled changes, start - rendering length sample-frames of audio into - {{[[rendered buffer]]}} + rendering numberOfFrames sample-frames of audio into + {{[[rendered buffer]]}}.
    3. For every render quantum, check and {{OfflineAudioContext/suspend()|suspend}} @@ -2696,19 +2723,21 @@ Methods
    4. Resolve the promise created by {{startRendering()}} with {{[[rendered buffer]]}}. -
    5. [=Queue a media element task=] to [=fire an event=] named - {{OfflineAudioContext/complete}} at the {{OfflineAudioContext}} using - {{OfflineAudioCompletionEvent}} whose `renderedBuffer` property is set to - {{[[rendered buffer]]}}. +
    6. If {{OfflineAudioContext/length}} is not + null, [=Queue a media element task=] to + [=fire an event=] named {{OfflineAudioContext/complete}} + at the {{OfflineAudioContext}} using + {{OfflineAudioCompletionEvent}} whose `renderedBuffer` + property is set to {{[[rendered buffer]]}}.
-
- No parameters. -
+
+            chunkSize: The number of sample-frames to render during this call.
+        
Return type: {{Promise}}<{{AudioBuffer}}>
@@ -2803,6 +2832,71 @@ Methods
Return type: {{Promise}}<{{undefined}}>
+ + : close() + :: + Closes the {{OfflineAudioContext}}. This will not automatically release + all {{AudioContext}}-created objects, but will suspend the progression + of the {{AudioContext}}'s {{BaseAudioContext/currentTime}}, and stop + processing audio data. + +
+ When close is called, execute these steps: + + 1. If [=this=]'s [=relevant global object=]'s + [=associated Document=] is not [=fully active=] then return + [=a promise rejected with=] "{{InvalidStateError}}" + {{DOMException}}. + + 1. Let promise be a new Promise. + + 1. If the {{[[control thread state]]}} flag on the + {{OfflineAudioContext}} is closed reject the + promise with {{InvalidStateError}}, abort these steps, + returning promise. + + 1. Set the {{[[control thread state]]}} flag on the + {{OfflineAudioContext}} to closed. + + 1. Queue a control message to close the + {{OfflineAudioContext}}. + + 1. Return promise. +
+ +
+ Running a control message to close an {{OfflineAudioContext}} + means running these steps on the rendering thread: + + 1. Set the {{[[rendering thread state]]}} to suspended. +
+ This will stop rendering. +
+ + 1. If this control message is being run in a reaction to the + document being unloaded, abort this algorithm. +
+ There is no need to notify the control thread in this case. +
+ + 1. + queue a media element task to execute the following steps: + + 1. Resolve promise. + 1. If the {{BaseAudioContext/state}} attribute of the + {{OfflineAudioContext}} is not already + "{{AudioContextState/closed}}": + 1. Set the {{BaseAudioContext/state}} attribute of the + {{OfflineAudioContext}} to + "{{AudioContextState/closed}}". + + 1. + queue a media element task to + fire an event named + {{BaseAudioContext/statechange}} at the + {{OfflineAudioContext}}. +
+