New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1933: Use FrozenArray for AudioWorkletProcessor process() #2250
Conversation
Instead of `sequence<sequence<Float32Array>>`, use `FrozenArray<FrozenArray<Float32Array>>`. Define a callback function as well.
Note to self: Making |
That works for me. |
Yes, my mistake. Too much search-and-replace. I'll have to ask @hoch exactly how he did this. |
Rename AudioWorkletProcessorCallback to AudioWorletProcessCallback The third parameter is an object, not frozen array.
Several changes here in no particular order: - Tell bikeshed that `object` is the webidl concept - Fix parameter names for the process callback (plurals, as used in the descriptions) - Rename the dfn for "Processing an input buffer" from "process" to "processing-input-buffer". - Fix up links to `process()` to point to the right place. - The old section on the process method is broken up into two sections. The main one is renaming it to "callback AudioWorkletProcessCallback". This contains most fo the main text. A subsection then describes the parameters to the callback.
I think the latest revision is closer to what we want, but I'm not 100% sure. Still have to describe what happens with all of the FrozenArrays and the callback parameters object map if you do something bad. But I hope this is close enough that we can now concentrate on getting the right text for that. |
The callback idea fixes the errors from defining the process method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how to make a connection between AudioWorkletProcessCallback
to AudioWorkletProcessor.process()
.
index.bs
Outdated
@@ -43,7 +43,10 @@ Markup Shorthands: markdown on, dfn on, css off | |||
spec: ECMAScript; url: https://tc39.github.io/ecma262/#sec-data-blocks; type: dfn; text: data block; | |||
url: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia; type: method; for: MediaDevices; text: getUserMedia() | |||
</pre> | |||
|
|||
<!-- We want IDL object --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, bikeshed was choosing something else when we did {{object}}
. This makes it link to object
in the webidl spec, which is want we want, I think.
index.bs
Outdated
callback AudioWorkletProcessCallback = | ||
boolean (FrozenArray<FrozenArray<Float32Array>> inputs, | ||
FrozenArray<FrozenArray<Float32Array>> outputs, | ||
object parameters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a redundant space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
index.bs
Outdated
@@ -10373,7 +10381,7 @@ interface AudioWorkletProcessor { | |||
|
|||
: <dfn>[[callable process]]</dfn> | |||
:: | |||
A boolean flag representing whether {{AudioWorkletProcessor/process()}} is | |||
A boolean flag representing whether [=process()=] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're missing is
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
index.bs
Outdated
The input audio buffer from the incoming connections provided by the user agent. It has type <code>sequence<sequence<Float32Array>></code>.<code class="nobreak">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=]. | ||
|
||
If there are no [=actively processing=] {{AudioNode}}s connected to the \(n\)th input of the {{AudioWorkletNode}} for 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. | ||
The [=process()=] callback function is called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of explaining how this is invoked here, referring https://webaudio.github.io/web-audio-api/#rendering-loop directly might be clearer and more specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was pretty much in the original, but I can reference the rendering loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think referencing the algorithm itself would be more thorough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove this and just reference the algorithm.
index.bs
Outdated
</h6> | ||
The {{AudioWorkletProcessCallback}} function has the following parameters: | ||
|
||
*Insert text here about how these FrozenArrays behave if they get transferred*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will get reallocated when the array topology changes or it is transferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some new text here. PTAL.
Add text to say inputs/outputs are recycled unless the topology changes (number of channels, array is transferred). Then new arrays are allocated.
index.bs
Outdated
The input audio buffer from the incoming connections provided by the user agent. It has type <code>sequence<sequence<Float32Array>></code>.<code class="nobreak">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=]. | ||
|
||
If there are no [=actively processing=] {{AudioNode}}s connected to the \(n\)th input of the {{AudioWorkletNode}} for 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. | ||
The [=process()=] callback function is called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think referencing the algorithm itself would be more thorough.
index.bs
Outdated
|
||
parameters: | ||
An [=ordered map=] of <var>name</var> → <var>parameterValues</var>. <code>parameters["<var>name</var>"]</code> returns <var>parameterValues</var>, which is a {{Float32Array}} with the automation values of the <var>name</var> {{AudioParam}}. | ||
This callback returns a {{boolean}}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IDL shows the return type. Not sure if this is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should be removed.
index.bs
Outdated
|
||
For each array, the array contains the [=computedValue=] of 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=]. | ||
|
||
*Insert text here about how these aren't freshly allocated each time, unless the object is transferred.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still says "Insert text here...".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A reminder that this still needs to be fixed. Either here or in the part about inputs/outputs.
reallocated if any part of the | ||
{{AudioWorkletProcessCallback/inputs!!argument}} or | ||
{{AudioWorkletProcessCallback/outputs!!argument}} arrays are | ||
transferred. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't include parameters
object. We can (and Chrome does) freeze the object and reallocate if the topology changes.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/modules/webaudio/audio_worklet_processor.cc;l=460
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, the comments in #1933 says we'd have to do much more work than just saying "Freeze" because there's no WebIDL concept of freeze other than FrozenArrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. It's less ideal, but we can directly refer ECMAScript algorithm:
https://tc39.es/ecma262/#sec-object.freeze
Or start from WebIDL's FrozenArray's algorithm:
https://heycam.github.io/webidl/#es-frozen-array
Still need description of how parameters are frozen.
Update for Safari and for Edge
Update IDL results for newer browsers
Update summaries for new browsers. Fails = 6573 - passes
This isn't really a typo but an issue with bikeshed not leaving a space at line breaks. See speced/bikeshed#1470.
…dio#2253) * Address WebAudio#2185: Duplicate IDs for Decode callbacks The decode callbacks were multiply defining their arguments. Instead, just have the descriptions of the arguments just link back to the IDL that defines the args. * Update expected errors
As a workaround, clone the bikeshed repo and install bikeshed from the repo. Ideally, want just want to use the version with pip3 instead of cloning the current version of bikeshed, but that's producing unexpected errors. We'll do this for now and recheck at some later date when bikeshed is updated and revert to the old version.
…ebAudio#2264) When using dark mode, use a different background color for the even rows of the channel ordering table so that the entries are visible. While we're at it, make the headings for the audio node properties table, the audio param values table, and the enumeration description table look a little better in dark mode. This is done by specifying a brighter green to make it a bit more legible.
Question: Should we add a something like Example 38 in https://heycam.github.io/webidl/#idl-callback-functions? That is add a method, say, This is a pretty big change in interface so perhaps that's too late for that. |
That shouldn't be necessary. |
Works for me. Thanks! |
PTAL. I think I have all the pieces in place now. The preview diff is kind of hard to follow. Perhaps using that and the preview would make it easier to see what was changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Instead of
sequence<sequence<Float32Array>>
, useFrozenArray<FrozenArray<Float32Array>>
.Define a callback function as well.
Preview | Diff