Skip to content

Commit b35c045

Browse files
markshannondpgeorge
authored andcommitted
Allow any buffer to be copied into an audio frame. Fix typo in AudioFrame type struct.
1 parent ce36e0d commit b35c045

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

source/microbit/modaudio.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,11 @@ static microbit_audio_frame_obj_t *copy(microbit_audio_frame_obj_t *self) {
546546

547547
mp_obj_t copyfrom(mp_obj_t self_in, mp_obj_t other) {
548548
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
549-
if (mp_obj_get_type(other) != &microbit_audio_frame_type) {
550-
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Must be an AudioBuffer"));
551-
}
552-
for (int i = 0; i < AUDIO_CHUNK_SIZE; i++) {
553-
self->data[i] = ((microbit_audio_frame_obj_t *)other)->data[i];
549+
mp_buffer_info_t bufinfo;
550+
mp_get_buffer_raise(other, &bufinfo, MP_BUFFER_READ);
551+
uint32_t len = bufinfo.len > AUDIO_CHUNK_SIZE ? AUDIO_CHUNK_SIZE : bufinfo.len;
552+
for (uint32_t i = 0; i < len; i++) {
553+
self->data[i] = ((uint8_t *)bufinfo.buf)[i];
554554
}
555555
return mp_const_none;
556556
}
@@ -640,7 +640,7 @@ const mp_obj_type_t microbit_audio_frame_type = {
640640
.buffer_p = { .get_buffer = audio_frame_get_buffer },
641641
.stream_p = NULL,
642642
.bases_tuple = NULL,
643-
.locals_dict = (mp_obj_dict_t*)&microbit_audio_frame_locals_dict_table,
643+
.locals_dict = (mp_obj_dict_t*)&microbit_audio_frame_locals_dict,
644644
};
645645

646646
microbit_audio_frame_obj_t *new_microbit_audio_frame(void) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy