Skip to content
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

Merged
merged 21 commits into from Nov 19, 2020

Conversation

rtoy
Copy link
Member

@rtoy rtoy commented Sep 22, 2020

Instead of sequence<sequence<Float32Array>>, use FrozenArray<FrozenArray<Float32Array>>.

Define a callback function as well.


Preview | Diff

Instead of `sequence<sequence<Float32Array>>`, use
`FrozenArray<FrozenArray<Float32Array>>`.

Define a callback function as well.
@rtoy rtoy marked this pull request as draft September 22, 2020 21:53
@rtoy rtoy changed the title Fix #1933: Use FrozeArray for AudioWorkletProcessor process() Fix #1933: Use FrozenArray for AudioWorkletProcessor process() Sep 24, 2020
@rtoy
Copy link
Member Author

rtoy commented Sep 24, 2020

Note to self: Making process() be a callback is easy. Just not sure how to integrate that into the spec appropriately.

@rtoy
Copy link
Member Author

rtoy commented Sep 25, 2020

bikeshed: AudioWorkletProcessCallback would be a more specific name, which might be useful should any other AudioWorkletProcessor callbacks be added in the future.

That works for me.

@rtoy
Copy link
Member Author

rtoy commented Sep 25, 2020

The third parameter has named properties rather than indexed properties and so is not an array. It is a frozen object, but there is no such pre-defined WebIDL type. It can be simply object here, with details described in the prose.

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.
@rtoy
Copy link
Member Author

rtoy commented Sep 25, 2020

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.
Copy link
Member

@hoch hoch left a 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 -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a redundant space

Copy link
Member Author

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()=]
Copy link
Member

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?

Copy link
Member Author

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&lt;sequence&lt;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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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*.
Copy link
Member

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.

Copy link
Member Author

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.
@hoch hoch self-requested a review October 2, 2020 15:21
index.bs Outdated
The input audio buffer from the incoming connections provided by the user agent. It has type <code>sequence&lt;sequence&lt;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
Copy link
Member

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}}.
Copy link
Member

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.

Copy link
Member Author

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.*
Copy link
Member

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...".

Copy link
Member Author

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

Copy link
Member

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

rtoy and others added 13 commits October 2, 2020 09:42
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.
@rtoy
Copy link
Member Author

rtoy commented Nov 3, 2020

Question: Should we add a something like Example 38 in https://heycam.github.io/webidl/#idl-callback-functions? That is add a method, say, performOp(AudioWorkletProcessCallback process)?

This is a pretty big change in interface so perhaps that's too late for that.

@karlt
Copy link
Contributor

karlt commented Nov 4, 2020

Question: Should we add a something like Example 38 in https://heycam.github.io/webidl/#idl-callback-functions? That is add a method, say, performOp(AudioWorkletProcessCallback process)?

That shouldn't be necessary. performOperation in Example 38 identifies the callback, but for AudioWorkletProcessCallback, this is provided by the process property on the registered processor.

@rtoy
Copy link
Member Author

rtoy commented Nov 6, 2020

Question: Should we add a something like Example 38 in https://heycam.github.io/webidl/#idl-callback-functions? That is add a method, say, performOp(AudioWorkletProcessCallback process)?

That shouldn't be necessary. performOperation in Example 38 identifies the callback, but for AudioWorkletProcessCallback, this is provided by the process property on the registered processor.

Works for me. Thanks!

@rtoy rtoy marked this pull request as ready for review November 6, 2020 22:32
@rtoy
Copy link
Member Author

rtoy commented Nov 6, 2020

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.

@rtoy rtoy requested review from padenot and hoch November 12, 2020 17:42
Copy link
Member

@hoch hoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants