-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Webaudio: Consistent use of node handle vs audio handle #23153
base: main
Are you sure you want to change the base?
Conversation
@@ -57,7 +58,7 @@ void emscripten_destroy_audio_context(EMSCRIPTEN_WEBAUDIO_T audioContext); | |||
// Disconnects the given audio node from its audio graph, and then releases | |||
// the JS object table reference to the given audio node. The specified handle | |||
// is invalid after calling this function. | |||
void emscripten_destroy_web_audio_node(EMSCRIPTEN_WEBAUDIO_T objectHandle); | |||
void emscripten_destroy_web_audio_node(EMSCRIPTEN_AUDIO_WORKLET_NODE_T objectHandle); |
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.
Can this API not be used without audio worklets?
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.
Can this API not be used without audio worklets?
Parts of it, but the it needs JS to create other node types.
(In general though, some of the functions need a node, others a worklet context, and often they’re interchangeable when creating a graph depending on the use.)
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.
If the types should be interchangeable, then perhaps EMSCRIPTEN_AUDIO_WORKLET_NODE_T
can just be removed entirely, and EMSCRIPTEN_WEBAUDIO_T
used everywhere? I can update to do that if preferred.
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.
Some parts of the API only work with a single type, others have tests like this and work with node or context:
emscripten/src/library_webaudio.js
Line 327 in d19c162
assert(dstNode instanceof (window.AudioContext || window.webkitAudioContext) || dstNode instanceof window.AudioNode, `Called emscripten_audio_node_connect() on handle ${destination} that is not an AudioContext or AudioNode, but of type ${dstNode}`); |
I don't think there's a correct choice.
Let see what @juj thinks |
There's currently some confusion in webaudio.h about node handle types vs the audio handle type -
EMSCRIPTEN_WEBAUDIO_T
is sometimes used to refer to nodes, where it should beEMSCRIPTEN_AUDIO_WORKLET_NODE_T
.emscripten_create_wasm_audio_worklet_node
returnsEMSCRIPTEN_AUDIO_WORKLET_NODE_T
but functionsemscripten_destroy_web_audio_node
andemscripten_audio_node_connect
expect the node handle to be passed as aEMSCRIPTEN_WEBAUDIO_T
. This PR straightens out those inconsistencies.It presently doesn't make any material difference since both handles are
typedef int
, so this PR just makes things clearer without changing any behaviour. If the typedefs ever change in future, it will become important.Changes
EMSCRIPTEN_AUDIO_WORKLET_NODE_T
node handle typedef to the top of the file alongside theEMSCRIPTEN_WEBAUDIO_T
definition.emscripten_destroy_web_audio_node
accepts a node handle.emscripten_audio_node_connect
accepts a node handle as its first argument.