-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: added missing options to EmscriptenAudioWorkletNodeCreateOptions closes #23982 #25497
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
base: main
Are you sure you want to change the base?
Changes from all commits
32ee9d9
d9e8099
9b5b7dc
f9ad385
2d676c5
8693ac7
8a67632
1fd325d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,17 @@ typedef struct AudioParamFrame | |
|
||
typedef bool (*EmscriptenWorkletNodeProcessCallback)(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData4); | ||
|
||
typedef enum { | ||
WEBAUDIO_CHANNEL_COUNT_MODE_MAX = 0, | ||
WEBAUDIO_CHANNEL_COUNT_MODE_CLAMPED_MAX = 1, | ||
WEBAUDIO_CHANNEL_COUNT_MODE_EXPLICIT = 2 | ||
} WEBAUDIO_CHANNEL_COUNT_MODE; | ||
|
||
typedef enum { | ||
WEBAUDIO_CHANNEL_INTERPRETATION_SPEAKERS = 0, | ||
WEBAUDIO_CHANNEL_INTERPRETATION_DISCRETE = 1 | ||
} WEBAUDIO_CHANNEL_INTERPRETATION; | ||
|
||
typedef struct EmscriptenAudioWorkletNodeCreateOptions | ||
{ | ||
// How many audio nodes does this node take inputs from? Default=1 | ||
|
@@ -134,6 +145,10 @@ typedef struct EmscriptenAudioWorkletNodeCreateOptions | |
int numberOfOutputs; | ||
// For each output, specifies the number of audio channels (1=mono/2=stereo/etc.) for that output. Default=an array of ones for each output channel. | ||
int *outputChannelCounts; | ||
unsigned long channelCount; | ||
WEBAUDIO_CHANNEL_COUNT_MODE channelCountMode; | ||
WEBAUDIO_CHANNEL_INTERPRETATION channelInterpretation; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add here a short comment describing the default values of each? Hmm it seems that we get the struct initialization regression problem here.. that is, after this addition, all users must explicitly initialize these values to valid numbers; or their code will stop working? E.g. is existing users had code, say, EmscriptenAudioWorkletNodeCreateOptions options = {
.numberOfInputs = 2,
.numberOfOutputs = 2,
}; then when they update Emscripten to recompile their code, they will get implicit
and the spec says, So in this form, this update would cause all Web Audio utilizing code to break from running, unless they are updated. That is a bit annoying, since there is necessarily not a good way for developers to figure that out, and they might raise a bug report "I updated Emscripten and now I am getting an NotSupportedError exception. It used to work in previous version of Emscripten, so what did you regress?" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh now I see in the init code there was a Hmm, I suppose that's ok. It would be good to have a comment, e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cwoffenden what do you think about the struct init problem for the future? Should we try to model the struct so that all-zero-init should be preserved as a valid struct init with defaults? E.g. EmscriptenAudioWorkletNodeCreateOptions options = {}; would provide all zeros, and at JS side, we would always shoehorn the init to map to default values of an Audio Context? In WebGPU I have been explicitly using global constant data default-initialized struct constants, e.g. here: https://github.com/juj/wasm_webgpu/blob/3ed529956d1ee3f14f64c07769385e1929908f68/lib/lib_webgpu_cpp20.cpp#L34-L45 which would mean we would enforce users to do EmscriptenAudioWorkletNodeCreateOptions options = AUDIO_WORKLET_NODE_CREATE_DEFAULT_INITIALIZER; if they want to ensure forward compatibility with default values into the future. The default-zero-init for all fields would be preferred for code size and simplicity, though only if we can expect that any upcoming fields in the Web Audio spec would reasonably map from zero to the default. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m out for a week or so but jotting some quick thoughts down, I personally prefer (and use) the zero initialiser, with, for example, an enum There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, of course using zeroes is nice, though this is not a question of (just) programming style or preference. Rather the risk there is whether we will always be technically able to do this. For example, in this specific PR case we were just barely saved by a lucky happenstance that the new added param If that were not the case, then the above Though I suppose the resolution here is clear that we don't want to go the route of initializer structs (or functions, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we making the design changes and then merging this or is this good enough? |
||
|
||
} EmscriptenAudioWorkletNodeCreateOptions; | ||
|
||
// Instantiates the given AudioWorkletProcessor as an AudioWorkletNode, which continuously calls the specified processCallback() function on the browser's audio thread to perform audio processing. | ||
|
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 anonymous functions and
|| undefined
should be unnecessary here, they take up code size for no benefit.E.g.
channelCountMode: ['max','clamped-max','explicit'][{{{ makeGetValue(...) }}}],
looks like would be enough here?One thing to verify here is how do older browsers behave (or Safari) that do not yet support these options? If you run in an older browser that does not support any of this, would that cause an error?
It would be good to have a short test of non-default
channelCountMode
and non-defaultchannelInterpretation
to ensure that it works.