Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions system/include/emscripten/webaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern "C" {
#endif

typedef int EMSCRIPTEN_WEBAUDIO_T;
typedef int EMSCRIPTEN_AUDIO_WORKLET_NODE_T;

typedef struct EmscriptenWebAudioCreateAttributes
{
Expand Down Expand Up @@ -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);
Copy link
Collaborator

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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:

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.


// Create Wasm AudioWorklet thread. Call this function once at application startup to establish an AudioWorkletGlobalScope for your app.
// After the scope has been initialized, the given callback will fire.
Expand Down Expand Up @@ -99,8 +100,6 @@ void emscripten_create_wasm_audio_worklet_processor_async(EMSCRIPTEN_WEBAUDIO_T
// For this to change from the default 128, the context would need to be created with a yet unexposed WebAudioWorkletProcessorCreateOptions renderSizeHint, part of the 1.1 Web Audio API.
int emscripten_audio_context_quantum_size(EMSCRIPTEN_WEBAUDIO_T audioContext);

typedef int EMSCRIPTEN_AUDIO_WORKLET_NODE_T;

typedef struct AudioSampleFrame
{
// Number of audio channels to process (multiplied by samplesPerChannel gives the elements in data)
Expand Down Expand Up @@ -139,7 +138,7 @@ EMSCRIPTEN_AUDIO_WORKLET_NODE_T emscripten_create_wasm_audio_worklet_node(EMSCRI

// Connects a node's output to a target, e.g., connect the worklet node to the context.
// For outputIndex and inputIndex, see the AudioNode.connect() documentation (setting 0 as the default values)
void emscripten_audio_node_connect(EMSCRIPTEN_WEBAUDIO_T source, EMSCRIPTEN_WEBAUDIO_T destination, int outputIndex, int inputIndex);
void emscripten_audio_node_connect(EMSCRIPTEN_AUDIO_WORKLET_NODE_T source, EMSCRIPTEN_WEBAUDIO_T destination, int outputIndex, int inputIndex);

// Returns true if the current thread is executing a Wasm AudioWorklet, false otherwise.
// Note that calling this function can be relatively slow as it incurs a Wasm->JS transition,
Expand Down
Loading