-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[AUDIO_WORKET] Add support for setting the render quantum size #25747
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
Conversation
lindell
left a comment
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.
Thanks for a fast PR :)
src/lib/libwebaudio.js
Outdated
| // AUDIO_CONTEXT_RENDER_SIZE_DEFAULT and AUDIO_CONTEXT_RENDER_SIZE_HARDWARE | ||
| // into their AudioContextRenderSizeCategory enum, or take the positive int. | ||
| function readRenderSizeHint(val) { | ||
| return (val == 0) ? "default" : ((val < 0) ? "hardware" : val); |
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 it is better to be clearer and have a couple of extra lines here. Nested ternary expressions are hard to read.
| return (val == 0) ? "default" : ((val < 0) ? "hardware" : val); | |
| if (val == 0) return "default"; | |
| if (val == -1) return "hardware"; | |
| return val; |
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 agree, it's terrible to read, but @juj would've had something to say about the extra bytes!
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.
(Replaced with something less hideous)
| "latencyHint", | ||
| "sampleRate" | ||
| "sampleRate", | ||
| "renderSizeHint" |
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.
Why not quantumSizeHint?
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.
Why not
quantumSizeHint?
I copied what the JS API now calls it:
emscripten/src/lib/libwebaudio.js
Line 106 in e455f22
| renderSizeHint: readRenderSizeHint({{{ makeGetValue('options', C_STRUCTS.EmscriptenWebAudioCreateAttributes.renderSizeHint, 'i32') }}}) |
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 wonder if there are any users of this API yet, could we rename quantum -> render as well? E.g. in
$emscriptenGetContextQuantumSize -> $emscriptenGetContextRenderSize
emscripten_audio_context_quantum_size -> emscripten_audio_context_render_size
?
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 spec mixes the two, even for the renderSizeHint it says "This allows users to ask for a particular render quantum size".
Currently there's no reason to use this call, since it's always been 128. It's handy before the callback for calculating the stack size, and I should write an example of this.
src/lib/libwebaudio.js
Outdated
| #endif | ||
|
|
||
| // AUDIO_CONTEXT_RENDER_SIZE_DEFAULT and AUDIO_CONTEXT_RENDER_SIZE_HARDWARE | ||
| // into their AudioContextRenderSizeCategory enum, or take the positive int. |
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.
Wonder if a verb got cut off from this comment, or maybe this was intentionally brief?
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 made sense when I typed it... I'll clarify it.
| { | ||
| const char *latencyHint; // Specify one of "balanced", "interactive" or "playback" | ||
| uint32_t sampleRate; // E.g. 44100 or 48000 | ||
| int32_t renderSizeHint; // AUDIO_CONTEXT_RENDER_SIZE_* or number of samples |
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 presume since this is a hint, the context creation is allowed to not honor it?
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 presume since this is a hint, the context creation is allowed to not honor it?
From the spec:
https://webaudio.github.io/web-audio-api/#dom-audiocontextoptions-rendersizehint
"It is a hint that might not be honored."
juj
left a comment
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.
Looks great - I'll wait for that one comment before merging.
The
renderSizeHintis now available in Chrome Canary (--enable-features=WebAudioConfigurableRenderQuantum) so this can finally be tested. Most of the work was already done in preparation, so this required few changes.Test with:
Which has been extended to request a large
2048sample audio frame (which in an older browser will fallback to the default 128 samples).Note for me: look at why and since how long we can bust out of the stack without asserting. The stackAlloc() no longer appears to trip when requesting more bytes than
wwParams.stackSize.