Skip to content

Conversation

juj
Copy link
Collaborator

@juj juj commented Sep 22, 2025

Given that we have a function emscripten_audio_context_quantum_size(EMSCRIPTEN_WEBAUDIO_T audioContext), also add a function emscripten_audio_context_sample_rate(EMSCRIPTEN_WEBAUDIO_T audioContext) to easily get the sampling rate of the context graph.

Will need to add some tests etc. though putting this up already to organize PRs.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Seems reasonable.

#if ASSERTIONS
assert(EmAudio[contextHandle], `Called emscripten_audio_context_sample_rate() with an invalid Web Audio Context handle ${contextHandle}`);
assert(EmAudio[contextHandle] instanceof (window.AudioContext || window.webkitAudioContext), `Called emscripten_audio_context_sample_rate() on handle ${contextHandle} that is not an AudioContext, but of type ${EmAudio[contextHandle]}`);
#endif
Copy link
Collaborator

@sbc100 sbc100 Sep 22, 2025

Choose a reason for hiding this comment

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

How about adding a getAudioContext(handle) helper that can take care of adding these assertions to all APIs that need to lookup a handler like this?

Then this would just be emscripten_audio_context_sample_rate: (handle) => getAudioContext(handle)['sampleRate'],

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.

2 participants