Skip to content

Commit 0988fe0

Browse files
committed
codal_port/modaudio: Use AudioFrame rate as rate when playing it.
Signed-off-by: Damien George <[email protected]>
1 parent 0bd1b40 commit 0988fe0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/codal_port/modaudio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ STATIC void audio_data_fetcher(void) {
119119
// We have the next AudioFrame.
120120
audio_source_frame = MP_OBJ_TO_PTR(frame_obj);
121121
audio_raw_offset = 0;
122+
microbit_hal_audio_raw_set_rate(audio_source_frame->rate);
122123
}
123124

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

0 commit comments

Comments
 (0)