Skip to content

Commit

Permalink
codal_port/modaudio: Always round up AudioFrame size to chunk size.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Apr 22, 2024
1 parent ab29ab8 commit 6465bba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/codal_port/modaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, size_t n_
mp_raise_ValueError(MP_ERROR_TEXT("size out of bounds"));
} else {
size = args[ARG_duration].u_int * rate / 1000;
// Round up the size to the nearest AUDIO_CHUNK_SIZE.
size = (size + AUDIO_CHUNK_SIZE - 1) & ~(AUDIO_CHUNK_SIZE - 1);
}

return microbit_audio_frame_make_new(size, rate);
Expand Down Expand Up @@ -522,6 +520,10 @@ MP_DEFINE_CONST_OBJ_TYPE(
);

microbit_audio_frame_obj_t *microbit_audio_frame_make_new(size_t size, uint32_t rate) {
// Round up the size to the nearest AUDIO_CHUNK_SIZE.
// This is needed to simplify the playback code, which works in chunks of size AUDIO_CHUNK_SIZE.
size = (size + AUDIO_CHUNK_SIZE - 1) & ~(AUDIO_CHUNK_SIZE - 1);

microbit_audio_frame_obj_t *res = m_new_obj_var(microbit_audio_frame_obj_t, data, uint8_t, size);
res->base.type = &microbit_audio_frame_type;
res->alloc_size = size;
Expand Down

0 comments on commit 6465bba

Please sign in to comment.