Skip to content

Commit

Permalink
codal_port/modaudio: Make sure final partial audio data is sent out.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Sep 18, 2024
1 parent 4c957c4 commit df4cb05
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/codal_port/modaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void microbit_audio_stop(void) {
audio_output_buffer_offset = 0;
audio_source_frame = NULL;
audio_source_track = NULL;
audio_source_iter = NULL;
audio_source_iter = MP_OBJ_NULL;
audio_source_frame_offset = 0;
audio_current_sound_level = 0;
microbit_hal_audio_stop_expression();
Expand All @@ -92,7 +92,6 @@ static void audio_data_pull_from_source(void) {

if (audio_source_iter == MP_OBJ_NULL) {
// Audio iterator is already exhausted.
microbit_audio_stop();
return;
}

Expand All @@ -111,7 +110,7 @@ static void audio_data_pull_from_source(void) {
}
if (frame_obj == MP_OBJ_STOP_ITERATION) {
// End of audio iterator.
microbit_audio_stop();
audio_source_iter = MP_OBJ_NULL;
return;
}

Expand All @@ -128,7 +127,7 @@ static void audio_data_pull_from_source(void) {
microbit_hal_audio_raw_set_rate(audio_source_track->rate);
} else {
// Audio iterator did not return an AudioFrame/AudioTrack/AudioRecording.
microbit_audio_stop();
audio_source_iter = MP_OBJ_NULL;
mp_sched_exception(mp_obj_new_exception_msg(&mp_type_TypeError, MP_ERROR_TEXT("not an AudioFrame")));
return;
}
Expand All @@ -144,6 +143,7 @@ static void audio_data_fetcher(mp_sched_node_t *node) {

if (audio_output_buffer_offset == 0) {
// No output data left, finish output streaming.
microbit_audio_stop();
return;
}

Expand Down

0 comments on commit df4cb05

Please sign in to comment.