-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[test] Add audio worklet parameter tests (and tidy other interactive tests) #23659
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
Changes from all commits
0384fad
632bd0d
6fc8fbe
27a0573
a55981e
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 | ||
---|---|---|---|---|
@@ -1,6 +1,5 @@ | ||||
#include <assert.h> | ||||
#include <string.h> | ||||
#include <stdio.h> | ||||
|
||||
#include <emscripten/em_js.h> | ||||
#include <emscripten/webaudio.h> | ||||
|
@@ -16,30 +15,41 @@ | |||
|
||||
// Callback to process and copy the audio tracks | ||||
bool process(int numInputs, const AudioSampleFrame* inputs, int numOutputs, AudioSampleFrame* outputs, int numParams, const AudioParamFrame* params, void* data) { | ||||
#ifdef TEST_AND_EXIT | ||||
audioProcessedCount++; | ||||
#endif | ||||
|
||||
// Twin mono in, single stereo out | ||||
// Twin mono in (or disabled), single stereo out | ||||
assert(numInputs == 2 && numOutputs == 1); | ||||
assert(inputs[0].numberOfChannels == 1 && inputs[1].numberOfChannels == 1); | ||||
assert(inputs[0].numberOfChannels == 0 || inputs[0].numberOfChannels == 1); | ||||
assert(inputs[1].numberOfChannels == 0 || inputs[1].numberOfChannels == 1); | ||||
assert(outputs[0].numberOfChannels == 2); | ||||
// All with the same number of samples | ||||
assert(inputs[0].samplesPerChannel == inputs[1].samplesPerChannel); | ||||
assert(inputs[0].samplesPerChannel == outputs[0].samplesPerChannel); | ||||
// Now with all known quantities we can memcpy the data | ||||
int samplesPerChannel = inputs[0].samplesPerChannel; | ||||
memcpy(outputs[0].data, inputs[0].data, samplesPerChannel * sizeof(float)); | ||||
memcpy(outputs[0].data + samplesPerChannel, inputs[1].data, samplesPerChannel * sizeof(float)); | ||||
// Now with all known quantities we can memcpy the L&R data (or zero it if the | ||||
// channels are disabled) | ||||
int bytesPerChannel = outputs[0].samplesPerChannel * sizeof(float); | ||||
float* outputData = outputs[0].data; | ||||
if (inputs[0].numberOfChannels > 0) { | ||||
memcpy(outputData, inputs[0].data, bytesPerChannel); | ||||
} else { | ||||
memset(outputData, 0, bytesPerChannel); | ||||
} | ||||
outputData += outputs[0].samplesPerChannel; | ||||
if (inputs[1].numberOfChannels > 0) { | ||||
memcpy(outputData, inputs[1].data, bytesPerChannel); | ||||
} else { | ||||
memset(outputData, 0, bytesPerChannel); | ||||
} | ||||
return true; | ||||
} | ||||
|
||||
// Audio processor created, now register the audio callback | ||||
void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) { | ||||
if (!success) { | ||||
printf("Audio worklet node creation failed\n"); | ||||
return; | ||||
} | ||||
printf("Audio worklet processor created\n"); | ||||
printf("Click to toggle audio playback\n"); | ||||
assert(success && "Audio worklet failed in processorCreated()"); | ||||
emscripten_out("Audio worklet processor created"); | ||||
emscripten_out("Click to toggle audio playback"); | ||||
|
||||
// Stereo output, two inputs | ||||
int outputChannelCounts[2] = { 2 }; | ||||
|
@@ -65,6 +75,13 @@ void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) { | |||
// Register a click to start playback | ||||
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick); | ||||
|
||||
// Register the counter that exits the test after one second of mixing | ||||
#ifdef TEST_AND_EXIT | ||||
// Register the counter that exits the test after one second of playback | ||||
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL); | ||||
#endif | ||||
} | ||||
|
||||
// This implementation has no custom start-up requirements | ||||
EmscriptenStartWebAudioWorkletCallback getStartCallback(void) { | ||||
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. Why does this need to be a function that returns a function? Why not just declare a function called 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. It was because most tests return and use this default function in the shared code:
Whereas one needed a custom implementation, so this was the cleanest way to keep most of the code shared. 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. (Cleanest way and still keeping it C) |
||||
return &initialised; | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.