Skip to content

Conversation

@cwoffenden
Copy link
Collaborator

The renderSizeHint is 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:

test/runner interactive.test_audio_worklet_params_mixing

Which has been extended to request a large 2048 sample 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.

Copy link

@lindell lindell left a 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 :)

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

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.

Suggested change
return (val == 0) ? "default" : ((val < 0) ? "hardware" : val);
if (val == 0) return "default";
if (val == -1) return "hardware";
return val;

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not quantumSizeHint?

Copy link
Collaborator Author

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:

renderSizeHint: readRenderSizeHint({{{ makeGetValue('options', C_STRUCTS.EmscriptenWebAudioCreateAttributes.renderSizeHint, 'i32') }}})

Copy link
Collaborator

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
?

Copy link
Collaborator Author

@cwoffenden cwoffenden Nov 8, 2025

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.

#endif

// AUDIO_CONTEXT_RENDER_SIZE_DEFAULT and AUDIO_CONTEXT_RENDER_SIZE_HARDWARE
// into their AudioContextRenderSizeCategory enum, or take the positive int.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

@juj juj left a 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.

@juj juj merged commit 35482d3 into emscripten-core:main Nov 8, 2025
34 checks passed
@cwoffenden cwoffenden deleted the cw-render-quantum branch November 9, 2025 11:03
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.

4 participants