Skip to content

Commit eb1b639

Browse files
committed
codal_port/modaudio: Fix play init'ing to handle exceptions in iterator.
Signed-off-by: Damien George <[email protected]>
1 parent b670a86 commit eb1b639

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/codal_port/modaudio.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,24 @@ void microbit_audio_play_source(mp_obj_t src, mp_obj_t pin_select, bool wait, ui
142142
audio_init(sample_rate);
143143
microbit_pin_audio_select(pin_select);
144144

145-
audio_source_iter = NULL;
146-
147145
if (mp_obj_is_type(src, &microbit_sound_type)) {
148146
// TODO support wait=True mode
149147
const microbit_sound_obj_t *sound = (const microbit_sound_obj_t *)MP_OBJ_TO_PTR(src);
150148
microbit_hal_audio_play_expression_by_name(sound->name);
151149
return;
152150
}
153151

152+
// Get the iterator and start the audio running.
154153
audio_source_iter = mp_getiter(src, NULL);
155-
audio_data_fetcher();
156154
audio_running = true;
157-
if (!wait) {
158-
return;
159-
}
160-
while (audio_running) {
161-
mp_handle_pending(true);
162-
microbit_hal_idle();
155+
audio_data_fetcher();
156+
157+
if (wait) {
158+
// Wait the audio to exhaust the iterator.
159+
while (audio_running) {
160+
mp_handle_pending(true);
161+
microbit_hal_idle();
162+
}
163163
}
164164
}
165165

0 commit comments

Comments
 (0)