@@ -78,7 +78,7 @@ STATIC void audio_data_fetcher(void) {
7878
7979 if (audio_source_frame != NULL ) {
8080 // An existing AudioFrame is being played, see if there's any data left.
81- if (audio_raw_offset >= audio_source_frame -> size ) {
81+ if (audio_raw_offset >= audio_source_frame -> alloc_size ) {
8282 // AudioFrame is exhausted.
8383 audio_source_frame = NULL ;
8484 }
@@ -323,7 +323,7 @@ STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, mp_uint_t
323323STATIC mp_obj_t audio_frame_subscr (mp_obj_t self_in , mp_obj_t index_in , mp_obj_t value_in ) {
324324 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
325325 mp_int_t index = mp_obj_get_int (index_in );
326- if (index < 0 || index >= self -> size ) {
326+ if (index < 0 || index >= self -> alloc_size ) {
327327 mp_raise_ValueError (MP_ERROR_TEXT ("index out of bounds" ));
328328 }
329329 if (value_in == MP_OBJ_NULL ) {
@@ -346,7 +346,7 @@ static mp_obj_t audio_frame_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
346346 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
347347 switch (op ) {
348348 case MP_UNARY_OP_LEN :
349- return MP_OBJ_NEW_SMALL_INT (self -> size );
349+ return MP_OBJ_NEW_SMALL_INT (self -> alloc_size );
350350 default :
351351 return MP_OBJ_NULL ; // op not supported
352352 }
@@ -356,14 +356,14 @@ static mp_int_t audio_frame_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufin
356356 (void )flags ;
357357 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
358358 bufinfo -> buf = self -> data ;
359- bufinfo -> len = self -> size ;
359+ bufinfo -> len = self -> alloc_size ;
360360 bufinfo -> typecode = 'b' ;
361361 return 0 ;
362362}
363363
364364static void add_into (microbit_audio_frame_obj_t * self , microbit_audio_frame_obj_t * other , bool add ) {
365365 int mult = add ? 1 : -1 ;
366- size_t size = MIN (self -> size , other -> size );
366+ size_t size = MIN (self -> alloc_size , other -> alloc_size );
367367 for (int i = 0 ; i < size ; i ++ ) {
368368 unsigned val = (int )self -> data [i ] + mult * (other -> data [i ]- 128 );
369369 // Clamp to 0-255
@@ -375,8 +375,8 @@ static void add_into(microbit_audio_frame_obj_t *self, microbit_audio_frame_obj_
375375}
376376
377377static microbit_audio_frame_obj_t * copy (microbit_audio_frame_obj_t * self ) {
378- microbit_audio_frame_obj_t * result = microbit_audio_frame_make_new (self -> size );
379- for (int i = 0 ; i < self -> size ; i ++ ) {
378+ microbit_audio_frame_obj_t * result = microbit_audio_frame_make_new (self -> alloc_size );
379+ for (int i = 0 ; i < self -> alloc_size ; i ++ ) {
380380 result -> data [i ] = self -> data [i ];
381381 }
382382 return result ;
@@ -386,7 +386,7 @@ mp_obj_t copyfrom(mp_obj_t self_in, mp_obj_t other) {
386386 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
387387 mp_buffer_info_t bufinfo ;
388388 mp_get_buffer_raise (other , & bufinfo , MP_BUFFER_READ );
389- uint32_t len = MIN (bufinfo .len , self -> size );
389+ uint32_t len = MIN (bufinfo .len , self -> alloc_size );
390390 for (uint32_t i = 0 ; i < len ; i ++ ) {
391391 self -> data [i ] = ((uint8_t * )bufinfo .buf )[i ];
392392 }
@@ -423,7 +423,7 @@ int32_t float_to_fixed(float f, uint32_t scale) {
423423
424424static void mult (microbit_audio_frame_obj_t * self , float f ) {
425425 int scaled = float_to_fixed (f , 15 );
426- for (int i = 0 ; i < self -> size ; i ++ ) {
426+ for (int i = 0 ; i < self -> alloc_size ; i ++ ) {
427427 unsigned val = ((((int )self -> data [i ]- 128 ) * scaled ) >> 15 )+ 128 ;
428428 if (val > 255 ) {
429429 val = (1 - (val >>31 ))* 255 ;
@@ -478,7 +478,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
478478microbit_audio_frame_obj_t * microbit_audio_frame_make_new (size_t size ) {
479479 microbit_audio_frame_obj_t * res = m_new_obj_var (microbit_audio_frame_obj_t , uint8_t , size );
480480 res -> base .type = & microbit_audio_frame_type ;
481- res -> size = size ;
481+ res -> alloc_size = size ;
482482 memset (res -> data , 128 , size );
483483 return res ;
484484}
0 commit comments