Skip to content

Commit 3559080

Browse files
committed
Changed error handling to early-out
1 parent 28c72a5 commit 3559080

File tree

4 files changed

+158
-158
lines changed

4 files changed

+158
-158
lines changed

test/webaudio/audioworklet_2x_in_hard_pan.c

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,53 +97,53 @@ bool onClick(int type, const EmscriptenMouseEvent* e, void* data) {
9797

9898
// Audio processor created, now register the audio callback
9999
void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
100-
if (success) {
101-
printf("Audio worklet processor created\n");
102-
printf("Click to toggle audio playback\n");
103-
104-
// Stereo output, two inputs
105-
int outputChannelCounts[2] = { 2 };
106-
EmscriptenAudioWorkletNodeCreateOptions opts = {
107-
.numberOfInputs = 2,
108-
.numberOfOutputs = 1,
109-
.outputChannelCounts = outputChannelCounts
110-
};
111-
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
112-
emscripten_audio_node_connect(worklet, context, 0, 0);
113-
114-
// Create the two mono source nodes and connect them to the two inputs
115-
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
116-
beatID = createTrack(context, "audio_files/emscripten-beat-mono.mp3", true);
117-
if (beatID) {
118-
emscripten_audio_node_connect(beatID, worklet, 0, 0);
119-
}
120-
bassID = createTrack(context, "audio_files/emscripten-bass-mono.mp3", true);
121-
if (bassID) {
122-
emscripten_audio_node_connect(bassID, worklet, 0, 1);
123-
}
124-
125-
// Register a click to start playback
126-
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
127-
128-
// Register the counter that exits the test after one second of mixing
129-
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
130-
} else {
100+
if (!success) {
131101
printf("Audio worklet node creation failed\n");
102+
return;
103+
}
104+
printf("Audio worklet processor created\n");
105+
printf("Click to toggle audio playback\n");
106+
107+
// Stereo output, two inputs
108+
int outputChannelCounts[2] = { 2 };
109+
EmscriptenAudioWorkletNodeCreateOptions opts = {
110+
.numberOfInputs = 2,
111+
.numberOfOutputs = 1,
112+
.outputChannelCounts = outputChannelCounts
113+
};
114+
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
115+
emscripten_audio_node_connect(worklet, context, 0, 0);
116+
117+
// Create the two mono source nodes and connect them to the two inputs
118+
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
119+
beatID = createTrack(context, "audio_files/emscripten-beat-mono.mp3", true);
120+
if (beatID) {
121+
emscripten_audio_node_connect(beatID, worklet, 0, 0);
132122
}
123+
bassID = createTrack(context, "audio_files/emscripten-bass-mono.mp3", true);
124+
if (bassID) {
125+
emscripten_audio_node_connect(bassID, worklet, 0, 1);
126+
}
127+
128+
// Register a click to start playback
129+
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
130+
131+
// Register the counter that exits the test after one second of mixing
132+
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
133133
}
134134

135135
// Worklet thread inited, now create the audio processor
136136
void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
137-
if (success) {
138-
printf("Audio worklet initialised\n");
139-
140-
WebAudioWorkletProcessorCreateOptions opts = {
141-
.name = "mixer",
142-
};
143-
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
144-
} else {
137+
if (!success) {
145138
printf("Audio worklet failed to initialise\n");
139+
return;
146140
}
141+
printf("Audio worklet initialised\n");
142+
143+
WebAudioWorkletProcessorCreateOptions opts = {
144+
.name = "mixer",
145+
};
146+
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
147147
}
148148

149149
int main() {

test/webaudio/audioworklet_2x_in_out_stereo.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -96,55 +96,55 @@ bool onClick(int type, const EmscriptenMouseEvent* e, void* data) {
9696

9797
// Audio processor created, now register the audio callback
9898
void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
99-
if (success) {
100-
printf("Audio worklet processor created\n");
101-
printf("Click to toggle audio playback\n");
102-
103-
// Two stereo outputs, two inputs
104-
int outputChannelCounts[2] = { 2, 2 };
105-
EmscriptenAudioWorkletNodeCreateOptions opts = {
106-
.numberOfInputs = 2,
107-
.numberOfOutputs = 2,
108-
.outputChannelCounts = outputChannelCounts
109-
};
110-
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
111-
// Both outputs connected to the context
112-
emscripten_audio_node_connect(worklet, context, 0, 0);
113-
emscripten_audio_node_connect(worklet, context, 1, 0);
114-
115-
// Create the two stereo source nodes and connect them to the two inputs
116-
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
117-
beatID = createTrack(context, "audio_files/emscripten-beat.mp3", true);
118-
if (beatID) {
119-
emscripten_audio_node_connect(beatID, worklet, 0, 0);
120-
}
121-
bassID = createTrack(context, "audio_files/emscripten-bass.mp3", true);
122-
if (bassID) {
123-
emscripten_audio_node_connect(bassID, worklet, 0, 1);
124-
}
125-
126-
// Register a click to start playback
127-
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
128-
129-
// Register the counter that exits the test after one second of mixing
130-
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
131-
} else {
99+
if (!success) {
132100
printf("Audio worklet node creation failed\n");
101+
return;
102+
}
103+
printf("Audio worklet processor created\n");
104+
printf("Click to toggle audio playback\n");
105+
106+
// Two stereo outputs, two inputs
107+
int outputChannelCounts[2] = { 2, 2 };
108+
EmscriptenAudioWorkletNodeCreateOptions opts = {
109+
.numberOfInputs = 2,
110+
.numberOfOutputs = 2,
111+
.outputChannelCounts = outputChannelCounts
112+
};
113+
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
114+
// Both outputs connected to the context
115+
emscripten_audio_node_connect(worklet, context, 0, 0);
116+
emscripten_audio_node_connect(worklet, context, 1, 0);
117+
118+
// Create the two stereo source nodes and connect them to the two inputs
119+
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
120+
beatID = createTrack(context, "audio_files/emscripten-beat.mp3", true);
121+
if (beatID) {
122+
emscripten_audio_node_connect(beatID, worklet, 0, 0);
133123
}
124+
bassID = createTrack(context, "audio_files/emscripten-bass.mp3", true);
125+
if (bassID) {
126+
emscripten_audio_node_connect(bassID, worklet, 0, 1);
127+
}
128+
129+
// Register a click to start playback
130+
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
131+
132+
// Register the counter that exits the test after one second of mixing
133+
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
134134
}
135135

136136
// Worklet thread inited, now create the audio processor
137137
void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
138-
if (success) {
139-
printf("Audio worklet initialised\n");
140-
141-
WebAudioWorkletProcessorCreateOptions opts = {
142-
.name = "mixer",
143-
};
144-
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
145-
} else {
138+
if (!success) {
146139
printf("Audio worklet failed to initialise\n");
140+
return;
147141
}
142+
printf("Audio worklet initialised\n");
143+
144+
WebAudioWorkletProcessorCreateOptions opts = {
145+
.name = "mixer",
146+
};
147+
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
148148
}
149149

150150
int main() {

test/webaudio/audioworklet_in_out_mono.c

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -108,53 +108,53 @@ bool onClick(int type, const EmscriptenMouseEvent* e, void* data) {
108108

109109
// Audio processor created, now register the audio callback
110110
void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
111-
if (success) {
112-
printf("Audio worklet processor created\n");
113-
printf("Click to toggle audio playback\n");
114-
115-
// Mono output, two inputs
116-
int outputChannelCounts[1] = { 1 };
117-
EmscriptenAudioWorkletNodeCreateOptions opts = {
118-
.numberOfInputs = 2,
119-
.numberOfOutputs = 1,
120-
.outputChannelCounts = outputChannelCounts
121-
};
122-
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
123-
emscripten_audio_node_connect(worklet, context, 0, 0);
124-
125-
// Create the two mono source nodes and connect them to the two inputs
126-
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
127-
beatID = createTrack(context, "audio_files/emscripten-beat-mono.mp3", true);
128-
if (beatID) {
129-
emscripten_audio_node_connect(beatID, worklet, 0, 0);
130-
}
131-
bassID = createTrack(context, "audio_files/emscripten-bass-mono.mp3", true);
132-
if (bassID) {
133-
emscripten_audio_node_connect(bassID, worklet, 0, 1);
134-
}
135-
136-
// Register a click to start playback
137-
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
138-
139-
// Register the counter that exits the test after one second of mixing
140-
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
141-
} else {
111+
if (!success) {
142112
printf("Audio worklet node creation failed\n");
113+
return;
114+
}
115+
printf("Audio worklet processor created\n");
116+
printf("Click to toggle audio playback\n");
117+
118+
// Mono output, two inputs
119+
int outputChannelCounts[1] = { 1 };
120+
EmscriptenAudioWorkletNodeCreateOptions opts = {
121+
.numberOfInputs = 2,
122+
.numberOfOutputs = 1,
123+
.outputChannelCounts = outputChannelCounts
124+
};
125+
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
126+
emscripten_audio_node_connect(worklet, context, 0, 0);
127+
128+
// Create the two mono source nodes and connect them to the two inputs
129+
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
130+
beatID = createTrack(context, "audio_files/emscripten-beat-mono.mp3", true);
131+
if (beatID) {
132+
emscripten_audio_node_connect(beatID, worklet, 0, 0);
143133
}
134+
bassID = createTrack(context, "audio_files/emscripten-bass-mono.mp3", true);
135+
if (bassID) {
136+
emscripten_audio_node_connect(bassID, worklet, 0, 1);
137+
}
138+
139+
// Register a click to start playback
140+
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
141+
142+
// Register the counter that exits the test after one second of mixing
143+
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
144144
}
145145

146146
// Worklet thread inited, now create the audio processor
147147
void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
148-
if (success) {
149-
printf("Audio worklet initialised\n");
150-
151-
WebAudioWorkletProcessorCreateOptions opts = {
152-
.name = "mixer",
153-
};
154-
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
155-
} else {
148+
if (!success) {
156149
printf("Audio worklet failed to initialise\n");
150+
return;
157151
}
152+
printf("Audio worklet initialised\n");
153+
154+
WebAudioWorkletProcessorCreateOptions opts = {
155+
.name = "mixer",
156+
};
157+
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
158158
}
159159

160160
int main() {

test/webaudio/audioworklet_in_out_stereo.c

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -108,53 +108,53 @@ bool onClick(int type, const EmscriptenMouseEvent* e, void* data) {
108108

109109
// Audio processor created, now register the audio callback
110110
void processorCreated(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
111-
if (success) {
112-
printf("Audio worklet processor created\n");
113-
printf("Click to toggle audio playback\n");
114-
115-
// Stereo output, two inputs
116-
int outputChannelCounts[1] = { 2 };
117-
EmscriptenAudioWorkletNodeCreateOptions opts = {
118-
.numberOfInputs = 2,
119-
.numberOfOutputs = 1,
120-
.outputChannelCounts = outputChannelCounts
121-
};
122-
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
123-
emscripten_audio_node_connect(worklet, context, 0, 0);
124-
125-
// Create the two stereo source nodes and connect them to the two inputs
126-
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
127-
beatID = createTrack(context, "audio_files/emscripten-beat.mp3", true);
128-
if (beatID) {
129-
emscripten_audio_node_connect(beatID, worklet, 0, 0);
130-
}
131-
bassID = createTrack(context, "audio_files/emscripten-bass.mp3", true);
132-
if (bassID) {
133-
emscripten_audio_node_connect(bassID, worklet, 0, 1);
134-
}
135-
136-
// Register a click to start playback
137-
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
138-
139-
// Register the counter that exits the test after one second of mixing
140-
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
141-
} else {
111+
if (!success) {
142112
printf("Audio worklet node creation failed\n");
113+
return;
114+
}
115+
printf("Audio worklet processor created\n");
116+
printf("Click to toggle audio playback\n");
117+
118+
// Stereo output, two inputs
119+
int outputChannelCounts[1] = { 2 };
120+
EmscriptenAudioWorkletNodeCreateOptions opts = {
121+
.numberOfInputs = 2,
122+
.numberOfOutputs = 1,
123+
.outputChannelCounts = outputChannelCounts
124+
};
125+
EMSCRIPTEN_AUDIO_WORKLET_NODE_T worklet = emscripten_create_wasm_audio_worklet_node(context, "mixer", &opts, &process, NULL);
126+
emscripten_audio_node_connect(worklet, context, 0, 0);
127+
128+
// Create the two stereo source nodes and connect them to the two inputs
129+
// Note: we can connect the sources to the same input and it'll get mixed for us, but that's not the point
130+
beatID = createTrack(context, "audio_files/emscripten-beat.mp3", true);
131+
if (beatID) {
132+
emscripten_audio_node_connect(beatID, worklet, 0, 0);
143133
}
134+
bassID = createTrack(context, "audio_files/emscripten-bass.mp3", true);
135+
if (bassID) {
136+
emscripten_audio_node_connect(bassID, worklet, 0, 1);
137+
}
138+
139+
// Register a click to start playback
140+
emscripten_set_click_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, WA_2_VOIDP(context), false, &onClick);
141+
142+
// Register the counter that exits the test after one second of mixing
143+
emscripten_set_timeout_loop(&playedAndMixed, 16, NULL);
144144
}
145145

146146
// Worklet thread inited, now create the audio processor
147147
void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
148-
if (success) {
149-
printf("Audio worklet initialised\n");
150-
151-
WebAudioWorkletProcessorCreateOptions opts = {
152-
.name = "mixer",
153-
};
154-
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
155-
} else {
148+
if (!success) {
156149
printf("Audio worklet failed to initialise\n");
150+
return;
157151
}
152+
printf("Audio worklet initialised\n");
153+
154+
WebAudioWorkletProcessorCreateOptions opts = {
155+
.name = "mixer",
156+
};
157+
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
158158
}
159159

160160
int main() {

0 commit comments

Comments
 (0)