Skip to content

Commit 6465bba

Browse files
committed
codal_port/modaudio: Always round up AudioFrame size to chunk size.
Signed-off-by: Damien George <[email protected]>
1 parent ab29ab8 commit 6465bba

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/codal_port/modaudio.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, size_t n_
332332
mp_raise_ValueError(MP_ERROR_TEXT("size out of bounds"));
333333
} else {
334334
size = args[ARG_duration].u_int * rate / 1000;
335-
// Round up the size to the nearest AUDIO_CHUNK_SIZE.
336-
size = (size + AUDIO_CHUNK_SIZE - 1) & ~(AUDIO_CHUNK_SIZE - 1);
337335
}
338336

339337
return microbit_audio_frame_make_new(size, rate);
@@ -522,6 +520,10 @@ MP_DEFINE_CONST_OBJ_TYPE(
522520
);
523521

524522
microbit_audio_frame_obj_t *microbit_audio_frame_make_new(size_t size, uint32_t rate) {
523+
// Round up the size to the nearest AUDIO_CHUNK_SIZE.
524+
// This is needed to simplify the playback code, which works in chunks of size AUDIO_CHUNK_SIZE.
525+
size = (size + AUDIO_CHUNK_SIZE - 1) & ~(AUDIO_CHUNK_SIZE - 1);
526+
525527
microbit_audio_frame_obj_t *res = m_new_obj_var(microbit_audio_frame_obj_t, data, uint8_t, size);
526528
res->base.type = &microbit_audio_frame_type;
527529
res->alloc_size = size;

0 commit comments

Comments
 (0)