Skip to content

Commit 320d3d5

Browse files
authored
Merge pull request #1618 from rtoy/1316-use-table-to-define-process
Fix #1316: use table to define process
2 parents 679aba0 + 3ffa925 commit 320d3d5

File tree

2 files changed

+114
-165
lines changed

2 files changed

+114
-165
lines changed

expected-errs.txt

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,55 @@ WARNING: Multiple elements have the same ID 'dom-decodeerrorcallback-error'.
99
Deduping, but this ID may not be stable across revisions.
1010
WARNING: Multiple elements have the same ID 'dom-decodesuccesscallback-decodeddata'.
1111
Deduping, but this ID may not be stable across revisions.
12-
LINE 1904: Can't find the 'contextOptions' argument of method 'OfflineAudioContext/OfflineAudioContext(numberOfChannels, length, sampleRate)' in the argumentdef block.
13-
LINE 2907: Can't find the 'destinationNode' argument of method 'AudioNode/connect(destinationParam, output)' in the argumentdef block.
14-
LINE 2907: Can't find the 'input' argument of method 'AudioNode/connect(destinationParam, output)' in the argumentdef block.
15-
LINE 3008: Can't find the 'destinationNode' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
16-
LINE 3018: Can't find the 'destinationNode' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
17-
LINE 3033: Can't find the 'destinationNode' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
18-
LINE 3033: Can't find the 'input' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
12+
LINE 1901: Can't find the 'contextOptions' argument of method 'OfflineAudioContext/OfflineAudioContext(numberOfChannels, length, sampleRate)' in the argumentdef block.
13+
LINE 2900: Can't find the 'destinationNode' argument of method 'AudioNode/connect(destinationParam, output)' in the argumentdef block.
14+
LINE 2900: Can't find the 'input' argument of method 'AudioNode/connect(destinationParam, output)' in the argumentdef block.
15+
LINE 3001: Can't find the 'destinationNode' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
16+
LINE 3011: Can't find the 'destinationNode' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
17+
LINE 3026: Can't find the 'destinationNode' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
18+
LINE 3026: Can't find the 'input' argument of method 'AudioNode/disconnect(destinationParam, output)' in the argumentdef block.
19+
LINE 9887: Can't find method '['AudioWorkletProcessor/process(inputs, outputs, parameters))']'.
1920
LINK ERROR: No 'idl-name' refs found for 'MediaStream'.
2021
<a data-link-type="idl-name" class="n" data-lt="MediaStream">MediaStream</a>
2122
LINK ERROR: No 'idl-name' refs found for 'MediaStreamTrack'.
2223
<a data-link-type="idl-name" class="n" data-lt="MediaStreamTrack">MediaStreamTrack</a>
23-
LINE 1470: No 'method' refs found for 'AudioContext()'.
24+
LINE 1469: No 'method' refs found for 'AudioContext()'.
2425
LINK ERROR: No 'idl-name' refs found for 'DOMHighResTimeStamp'.
2526
<a data-link-type="idl-name" class="n" data-lt="DOMHighResTimeStamp">DOMHighResTimeStamp</a>
2627
LINK ERROR: No 'idl-name' refs found for 'DOMHighResTimeStamp'.
2728
<a data-link-type="idl-name" data-lt="DOMHighResTimeStamp">DOMHighResTimeStamp</a>
28-
LINE 1904: No 'method' refs found for 'OfflineAudioContext(contextOptions)'.
29-
LINE 1928: No 'method' refs found for 'OfflineAudioContext(numberOfChannels, length, sampleRate)'.
30-
LINE 2222: No 'method' refs found for 'AudioBuffer()'.
31-
LINE 4091: No 'method' refs found for 'AnalyserNode()'.
32-
LINE 4528: No 'method' refs found for 'AudioBufferSourceNode()'.
33-
LINE 5743: No 'method' refs found for 'BiquadFilterNode()'.
34-
LINE 6157: No 'method' refs found for 'ChannelMergerNode()'.
35-
LINE 6269: No 'method' refs found for 'ChannelSplitterNode()'.
36-
LINE 6351: No 'method' refs found for 'ConstantSourceNode()'.
37-
LINE 6462: No 'method' refs found for 'ConvolverNode()'.
38-
LINE 6731: No 'method' refs found for 'DelayNode()'.
39-
LINE 6865: No 'method' refs found for 'DynamicsCompressorNode()'.
40-
LINE 7308: No 'method' refs found for 'GainNode()'.
41-
LINE 7415: No 'method' refs found for 'IIRFilterNode()'.
42-
LINE 7559: No 'method' refs found for 'MediaElementAudioSourceNode()'.
43-
LINE 7688: No 'method' refs found for 'MediaStreamAudioDestinationNode()'.
29+
LINE 1901: No 'method' refs found for 'OfflineAudioContext(contextOptions)'.
30+
LINE 1925: No 'method' refs found for 'OfflineAudioContext(numberOfChannels, length, sampleRate)'.
31+
LINE 2217: No 'method' refs found for 'AudioBuffer()'.
32+
LINE 4084: No 'method' refs found for 'AnalyserNode()'.
33+
LINE 4521: No 'method' refs found for 'AudioBufferSourceNode()'.
34+
LINE 5736: No 'method' refs found for 'BiquadFilterNode()'.
35+
LINE 6150: No 'method' refs found for 'ChannelMergerNode()'.
36+
LINE 6262: No 'method' refs found for 'ChannelSplitterNode()'.
37+
LINE 6344: No 'method' refs found for 'ConstantSourceNode()'.
38+
LINE 6455: No 'method' refs found for 'ConvolverNode()'.
39+
LINE 6724: No 'method' refs found for 'DelayNode()'.
40+
LINE 6858: No 'method' refs found for 'DynamicsCompressorNode()'.
41+
LINE 7301: No 'method' refs found for 'GainNode()'.
42+
LINE 7408: No 'method' refs found for 'IIRFilterNode()'.
43+
LINE 7552: No 'method' refs found for 'MediaElementAudioSourceNode()'.
44+
LINE 7681: No 'method' refs found for 'MediaStreamAudioDestinationNode()'.
4445
LINK ERROR: No 'idl-name' refs found for 'MediaStream'.
4546
<a data-link-type="idl-name" data-lt="MediaStream">MediaStream</a>
46-
LINE 7755: No 'method' refs found for 'MediaStreamAudioSourceNode()'.
47-
LINE 7825: No 'method' refs found for 'MediaStreamTrackAudioSourceNode()'.
47+
LINE 7748: No 'method' refs found for 'MediaStreamAudioSourceNode()'.
48+
LINE 7818: No 'method' refs found for 'MediaStreamTrackAudioSourceNode()'.
4849
LINK ERROR: No 'idl-name' refs found for 'MediaStreamTrack'.
4950
<a data-link-type="idl-name" data-lt="MediaStreamTrack">MediaStreamTrack</a>
50-
LINE 7964: No 'method' refs found for 'OscillatorNode()'.
51-
LINE 8339: No 'method' refs found for 'PannerNode()'.
52-
LINE 8744: No 'method' refs found for 'PeriodicWave()'.
53-
LINE 9056: No 'method' refs found for 'StereoPannerNode()'.
54-
LINE 9186: No 'method' refs found for 'WaveShaperNode()'.
55-
LINE 9624: No 'method' refs found for 'AudioWorkletNode()'.
51+
LINE 7957: No 'method' refs found for 'OscillatorNode()'.
52+
LINE 8332: No 'method' refs found for 'PannerNode()'.
53+
LINE 8737: No 'method' refs found for 'PeriodicWave()'.
54+
LINE 9049: No 'method' refs found for 'StereoPannerNode()'.
55+
LINE 9179: No 'method' refs found for 'WaveShaperNode()'.
56+
LINE 9618: No 'method' refs found for 'AudioWorkletNode()'.
5657
LINK ERROR: No 'idl-name' refs found for 'sequence<unsigned long>'.
5758
<a data-link-type="idl-name" data-lt="sequence&lt;unsigned long&gt;">sequence&lt;unsigned long&gt;</a>
5859
LINK ERROR: No 'idl-name' refs found for 'record<DOMString, double>'.
5960
<a data-link-type="idl-name" data-lt="record&lt;DOMString, double&gt;">record&lt;DOMString, double&gt;</a>
60-
LINE 9798: No 'method' refs found for 'AudioWorkletProcessor()'.
61+
LINE 9792: No 'method' refs found for 'AudioWorkletProcessor()'.
62+
LINE 9887: No 'method' refs found for 'process(inputs, outputs, parameters))'.
6163
YAY Successfully generated, but fatal errors were suppressed

index.bs

Lines changed: 79 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -9807,12 +9807,12 @@ Attributes</h5>
98079807
{{AudioWorkletNode}} and {{AudioWorkletProcessor}}.
98089808
</dl>
98099809

9810-
<h5 id="defining-a-valid-audioworkletprocessor">
9811-
Defining A Valid AudioWorkletProcessor</h5>
9810+
<h5 id="AudioWorkletProcessor-methods">
9811+
Methods</h5>
98129812

98139813
User can define a custom audio processor by extending
98149814
{{AudioWorkletProcessor}}. The subclass MUST define a method
9815-
named <code><dfn id="audioworkletprocessor-process">process()</dfn></code> that implements the audio processing
9815+
named {{process()}} that implements the audio processing
98169816
algorithm and have a valid static property named
98179817
<code><dfn>parameterDescriptors</dfn></code> which is an iterable
98189818
of {{AudioParamDescriptor}} that is looked up by the
@@ -9821,141 +9821,89 @@ of {{AudioParamDescriptor}} that is looked up by the
98219821
in the node. The <a href="#check-prototype-type">prototype type check step</a> and the <a href="#check-is-callable">process method is callable step</a> of <a data-link-for="AudioWorkletGlobalScope">registerProcessor()</a> ensure the
98229822
validity of a given {{AudioWorkletProcessor}} subclass.
98239823

9824-
An example of a valid subclass is as follows:
9825-
9826-
<pre line-numbers class="example" highlight="js" title="Subclassing AudioWorkletProcessor">
9827-
class MyProcessor extends AudioWorkletProcessor {
9828-
static get parameterDescriptors() {
9829-
return [{
9830-
name: 'myParam',
9831-
defaultValue: 0.5,
9832-
minValue: 0,
9833-
maxValue: 1,
9834-
automationRate: "k-rate"
9835-
}];
9836-
}
9837-
9838-
process(inputs, outputs, parameters) {
9839-
// Get the first input and output.
9840-
let input = inputs[0];
9841-
let output = outputs[0];
9842-
let myParam = parameters.myParam;
9843-
9844-
// A simple amplifier for single input and output.
9845-
for (let channel = 0; channel &lt; output.length; ++channel) {
9846-
for (let i = 0; i &lt; output[channel].length; ++i) {
9847-
output[channel][i] = input[channel][i] * myParam[0];
9848-
}
9849-
}
9850-
9851-
// To keep this processor alive.
9852-
return true;
9853-
}
9854-
}
9855-
</pre>
9856-
9857-
The <code>process()</code> method is called synchronously by the
9858-
audio <a>rendering thread</a> at every <a>render quantum</a>, if
9859-
ANY of the following <dfn>active processing conditions</dfn> are
9860-
true:
9824+
<dl dfn-type=method dfn-for="AudioWorkletProcessor">
9825+
: <dfn>process(inputs, outputs, parameters)</dfn>
9826+
::
9827+
Implements the audio processing algorithm for the
9828+
{{AudioWorkletProcessor}}.
98619829

9862-
1. The associated {{AudioWorkletProcessor}}'s <a>active
9863-
source</a> flag is equal to `true`.
9830+
The {{process()}} method is called
9831+
synchronously by the audio <a>rendering thread</a> at
9832+
every <a>render quantum</a>, if ANY of the following
9833+
<dfn dfn>active processing conditions</dfn> are true:
9834+
9835+
1. The associated {{AudioWorkletProcessor}}'s
9836+
<a>active source</a> flag is equal to `true`.
9837+
9838+
2. There are one or more connected inputs to the {{AudioWorkletNode}}.
9839+
9840+
The return value of this method controls the lifetime of the
9841+
{{AudioWorkletProcessor}}'s associated
9842+
{{AudioWorkletNode}}. At the conclusion of each call to the
9843+
{{process()}} method, <a href="https://tc39.github.io/ecma262/#sec-toboolean"><code>ToBoolean</code></a> (described in [[!ECMASCRIPT]])
9844+
is applied to the return value and the result is assigned to the associated AudioWorkletProcessor's <a>active source</a> flag. This in turn affects whether subsequent
9845+
invocations of {{process()}} occur, and has an impact on the lifetime of the node.
9846+
To propagate the flag change <a>queue a task</a> on the control thread to update the corresponding {{AudioWorkletNode}}'s <code>state</code> property accordingly.
9847+
9848+
<div class="note">
9849+
This lifetime policy can support a variety of approaches found in
9850+
built-in nodes, including the following:
9851+
9852+
* Nodes that transform their inputs, and are active only
9853+
while connected inputs and/or script references exist. Such
9854+
nodes SHOULD return <code>false</code> from
9855+
{{process()}} which allows the presence or absence of
9856+
connected inputs to determine whether active processing occurs.
9857+
9858+
* Nodes that transform their inputs, but which remain active
9859+
for a <a>tail-time</a> after their inputs are disconnected. In
9860+
this case, {{process()}} SHOULD return
9861+
`true` for some period of time after
9862+
<code>inputs</code> is found to contain zero channels. The
9863+
current time may be obtained from the global scope's
9864+
{{AudioWorkletGlobalScope/currentTime}} to
9865+
measure the start and end of this tail-time interval, or the
9866+
interval could be calculated dynamically depending on the
9867+
processor's internal state.
9868+
9869+
* Nodes that act as sources of output, typically with a
9870+
lifetime. Such nodes SHOULD return `true` from
9871+
{{process()}} until the point at which they are no
9872+
longer producing an output.
9873+
9874+
Note that the preceding definition implies that when no
9875+
return value is provided from an implementation of
9876+
{{process()}}, the effect is identical to returning
9877+
<code>false</code> (since the effective return value is the falsy
9878+
value <code>undefined</code>). This is a reasonable behavior for
9879+
any {{AudioWorkletProcessor}} that is active only when it has
9880+
active inputs.
9881+
</div>
98649882

9865-
2. There are one or more connected inputs to the
9866-
{{AudioWorkletNode}}.
9883+
If {{process()}} is not called during some rendering
9884+
quantum due to the lack of any applicable [=active processing conditions=], the result is as if the processor emitted
9885+
silence for this period.
98679886

9868-
The method is invoked with the following arguments:
9887+
<pre class=argumentdef for="AudioWorkletProcessor/process(inputs, outputs, parameters))">
9888+
inputs:
9889+
The input audio buffer from the incoming connections provided by the user agent. It has type <code>&lt;sequence&lt;sequence&lt;Float32Array>></code>. <code>inputs[n][m]</code> is a {{Float32Array}} of audio samples for the \(m\)th channel of the \(n\)th input. While the number of inputs is fixed at construction, the number of channels can be changed dynamically based on computedNumberOfChannels.
98699890

9870-
: <code>inputs</code> of type <code>sequence&lt;sequence&lt;Float32Array>></code>
9871-
::
9872-
The input audio buffer from the incoming connections provided
9873-
by the user agent. <code>inputs[n][m]</code> is a
9874-
{{Float32Array}} of audio samples for the
9875-
<code>m</code>th channel of <code>n</code>th input. While the
9876-
number of inputs is fixed at construction, the number of
9877-
channels can be changed dynamically based on
9878-
<a>computedNumberOfChannels</a>.
9879-
9880-
If no connections exist to the <code>n</code>th input of the
9881-
node during the current render quantum, then the content of
9882-
<code>inputs[n]</code> is an empty array, indicating that
9883-
zero channels of input are available. This is the only
9884-
circumstance under which the number of elements of
9885-
<code>inputs[n]</code> can be zero.
9886-
9887-
: <code>outputs</code> of type <code>sequence&lt;sequence&lt;Float32Array>></code>
9888-
::
9889-
The output audio buffer that is to be consumed by the user
9890-
agent. <code>outputs[n][m]</code> is a
9891-
{{Float32Array}} object containing the audio samples
9892-
for <code>m</code>th channel of <code>n</code>th output. The
9893-
number of channels in the output will match
9894-
<a>computedNumberOfChannels</a> only when the node has single
9895-
output.
9891+
If no connections exist to the \(n\)th input of the node during the current render quantum, then the content of <code>inputs[n]</code> is an empty array, indicating that zero channels of input are available. This is the only circumstance under which the number of elements of <code>inputs[n]</code> can be zero.
98969892

9897-
: <code>parameters</code> of type <code>Object</code>
9898-
::
9899-
A map of string keys and associated {{Float32Array}}s.
9900-
<code>parameters["name"]</code> corresponds to the automation
9901-
values of the {{AudioParam}} named
9902-
<code>"name"</code>.
9903-
9904-
For each array, the array contains the [=computedValue=] or
9905-
the parameter for all frames in the [=render quantum=].
9906-
However, if no automation is scheduled during
9907-
this [=render quantum=], the array MAY have length 1 with
9908-
the array element being the constant value of the
9909-
{{AudioParam}} for the [=render quantum=].
9910-
9911-
The return value of this method controls the lifetime of the
9912-
{{AudioWorkletProcessor}}'s associated
9913-
{{AudioWorkletNode}}. At the conclusion of each call to the
9914-
<code>process()</code> method, <a href="https://tc39.github.io/ecma262/#sec-toboolean"><code>ToBoolean</code></a> (described in [[!ECMASCRIPT]])
9915-
is applied to the return value and the result is assigned to the associated AudioWorkletProcessor's <a>active source</a> flag. This in turn affects whether subsequent
9916-
invocations of <code>process()</code> occur, and has an impact on the lifetime of the node.
9917-
To propagate the flag change <a>queue a task</a> on the control thread to update the corresponding {{AudioWorkletNode}}'s <code>state</code> property accordingly.
9893+
outputs:
9894+
The output audio buffer that is to be consumed by the user agent. It has type <code>&lt;sequence&lt;sequence&lt;Float32Array>></code>. <code>outputs[n][m]</code> is a {{Float32Array}} object containing the audio samples for \(m\)th channel of \(n\)th output. The number of channels in the output will match [=computedNumberOfChannels=] only when the node has single output.
99189895

9919-
<div class="note">
9920-
This lifetime policy can support a variety of approaches found in
9921-
built-in nodes, including the following:
9922-
9923-
* Nodes that transform their inputs, and are active only
9924-
while connected inputs and/or script references exist. Such
9925-
nodes SHOULD return <code>false</code> from
9926-
<code>process()</code> which allows the presence or absence of
9927-
connected inputs to determine whether active processing occurs.
9928-
9929-
* Nodes that transform their inputs, but which remain active
9930-
for a <a>tail-time</a> after their inputs are disconnected. In
9931-
this case, <code>process()</code> SHOULD return
9932-
`true` for some period of time after
9933-
<code>inputs</code> is found to contain zero channels. The
9934-
current time may be obtained from the global scope's
9935-
{{AudioWorkletGlobalScope/currentTime}} to
9936-
measure the start and end of this tail-time interval, or the
9937-
interval could be calculated dynamically depending on the
9938-
processor's internal state.
9939-
9940-
* Nodes that act as sources of output, typically with a
9941-
lifetime. Such nodes SHOULD return `true` from
9942-
<code>process()</code> until the point at which they are no
9943-
longer producing an output.
9944-
9945-
Note that the preceding definition implies that when no
9946-
return value is provided from an implementation of
9947-
<code>process()</code>, the effect is identical to returning
9948-
<code>false</code> (since the effective return value is the falsy
9949-
value <code>undefined</code>). This is a reasonable behavior for
9950-
any {{AudioWorkletProcessor}} that is active only when it has
9951-
active inputs.
9952-
</div>
9896+
parameters:
9897+
A map of string keys and associated {{Float32Array}}s. <code>parameters["name"]</code> corresponds to the automation values of the AudioParam named <code>"name"</code>.
99539898

9954-
If <code>process()</code> is not called during some rendering
9955-
quantum due to the lack of any applicable <a>active processing
9956-
conditions</a>, the result is as if the processor emitted
9957-
silence for this period.
9899+
For each array, the array contains the [=computedValue=] or the parameter for all frames in the [=render quantum=]. However, if no automation is scheduled during this render quantum, the array MAY have length 1 with the array element being the constant value of the {{AudioParam}} for the [=render quantum=].
9900+
</pre>
99589901

9902+
<div>
9903+
<em>Return type:</em> {{boolean}}
9904+
</div>
9905+
</dl>
9906+
99599907
<h5 dictionary lt="AudioParamDescriptor">
99609908
{{AudioParamDescriptor}}</h5>
99619909

@@ -10723,8 +10671,7 @@ operation such as resolution of {{Promise}}s in the {{AudioWorkletGlobalScope}}.
1072310671
<a href="#available-for-reading">make it available for reading</a>.
1072410672

1072510673
4. If this {{AudioNode}} is an {{AudioWorkletNode}}, invoke associated
10726-
{{AudioWorkletProcessor}}'s <a href="#audioworkletprocessor-process">
10727-
process</a> method to [=Computing a block of audio|compute a block of
10674+
{{AudioWorkletProcessor}}'s {{AudioWorkletProcessor/process()}} method to [=Computing a block of audio|compute a block of
1072810675
audio=] with the argument of [=input buffer=], output
1072910676
buffer and <a href="#input-audioparam-buffer">input AudioParam buffer
1073010677
</a>.

0 commit comments

Comments
 (0)