Skip to content

Commit

Permalink
codal_port/modaudio: Use AudioFrame rate as rate when playing it.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Jan 15, 2024
1 parent 0bd1b40 commit 0988fe0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/codal_port/modaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ STATIC void audio_data_fetcher(void) {
// We have the next AudioFrame.
audio_source_frame = MP_OBJ_TO_PTR(frame_obj);
audio_raw_offset = 0;
microbit_hal_audio_raw_set_rate(audio_source_frame->rate);
}

const uint8_t *src = &audio_source_frame->data[audio_raw_offset];
Expand Down Expand Up @@ -180,6 +181,7 @@ void microbit_audio_play_source(mp_obj_t src, mp_obj_t pin_select, bool wait, ui
} else if (mp_obj_is_type(src, &microbit_audio_frame_type)) {
audio_source_frame = MP_OBJ_TO_PTR(src);
audio_raw_offset = 0;
microbit_hal_audio_raw_set_rate(audio_source_frame->rate);
} else if (mp_obj_is_type(src, &mp_type_tuple) || mp_obj_is_type(src, &mp_type_list)) {
// A tuple/list passed in. Need to check if it contains SoundEffect instances.
size_t len;
Expand Down Expand Up @@ -495,6 +497,8 @@ STATIC mp_obj_t audio_frame_set_rate(mp_obj_t self_in, mp_obj_t rate_in) {
mp_raise_ValueError(MP_ERROR_TEXT("rate out of bounds"));
}
self->rate = rate;
// TODO: only set if this frame is currently being played
microbit_hal_audio_raw_set_rate(rate);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(audio_frame_set_rate_obj, audio_frame_set_rate);
Expand Down

0 comments on commit 0988fe0

Please sign in to comment.