@@ -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 }
@@ -334,7 +334,7 @@ STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, mp_uint_t
334334STATIC mp_obj_t audio_frame_subscr (mp_obj_t self_in , mp_obj_t index_in , mp_obj_t value_in ) {
335335 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
336336 mp_int_t index = mp_obj_get_int (index_in );
337- if (index < 0 || index >= self -> size ) {
337+ if (index < 0 || index >= self -> alloc_size ) {
338338 mp_raise_ValueError (MP_ERROR_TEXT ("index out of bounds" ));
339339 }
340340 if (value_in == MP_OBJ_NULL ) {
@@ -357,7 +357,7 @@ static mp_obj_t audio_frame_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
357357 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
358358 switch (op ) {
359359 case MP_UNARY_OP_LEN :
360- return MP_OBJ_NEW_SMALL_INT (self -> size );
360+ return MP_OBJ_NEW_SMALL_INT (self -> alloc_size );
361361 default :
362362 return MP_OBJ_NULL ; // op not supported
363363 }
@@ -367,14 +367,14 @@ static mp_int_t audio_frame_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufin
367367 (void )flags ;
368368 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
369369 bufinfo -> buf = self -> data ;
370- bufinfo -> len = self -> size ;
370+ bufinfo -> len = self -> alloc_size ;
371371 bufinfo -> typecode = 'b' ;
372372 return 0 ;
373373}
374374
375375static void add_into (microbit_audio_frame_obj_t * self , microbit_audio_frame_obj_t * other , bool add ) {
376376 int mult = add ? 1 : -1 ;
377- size_t size = MIN (self -> size , other -> size );
377+ size_t size = MIN (self -> alloc_size , other -> alloc_size );
378378 for (int i = 0 ; i < size ; i ++ ) {
379379 unsigned val = (int )self -> data [i ] + mult * (other -> data [i ]- 128 );
380380 // Clamp to 0-255
@@ -386,8 +386,8 @@ static void add_into(microbit_audio_frame_obj_t *self, microbit_audio_frame_obj_
386386}
387387
388388static microbit_audio_frame_obj_t * copy (microbit_audio_frame_obj_t * self ) {
389- microbit_audio_frame_obj_t * result = microbit_audio_frame_make_new (self -> size );
390- for (int i = 0 ; i < self -> size ; i ++ ) {
389+ microbit_audio_frame_obj_t * result = microbit_audio_frame_make_new (self -> alloc_size );
390+ for (int i = 0 ; i < self -> alloc_size ; i ++ ) {
391391 result -> data [i ] = self -> data [i ];
392392 }
393393 return result ;
@@ -397,7 +397,7 @@ mp_obj_t copyfrom(mp_obj_t self_in, mp_obj_t other) {
397397 microbit_audio_frame_obj_t * self = (microbit_audio_frame_obj_t * )self_in ;
398398 mp_buffer_info_t bufinfo ;
399399 mp_get_buffer_raise (other , & bufinfo , MP_BUFFER_READ );
400- uint32_t len = MIN (bufinfo .len , self -> size );
400+ uint32_t len = MIN (bufinfo .len , self -> alloc_size );
401401 for (uint32_t i = 0 ; i < len ; i ++ ) {
402402 self -> data [i ] = ((uint8_t * )bufinfo .buf )[i ];
403403 }
@@ -434,7 +434,7 @@ int32_t float_to_fixed(float f, uint32_t scale) {
434434
435435static void mult (microbit_audio_frame_obj_t * self , float f ) {
436436 int scaled = float_to_fixed (f , 15 );
437- for (int i = 0 ; i < self -> size ; i ++ ) {
437+ for (int i = 0 ; i < self -> alloc_size ; i ++ ) {
438438 unsigned val = ((((int )self -> data [i ]- 128 ) * scaled ) >> 15 )+ 128 ;
439439 if (val > 255 ) {
440440 val = (1 - (val >>31 ))* 255 ;
@@ -489,7 +489,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
489489microbit_audio_frame_obj_t * microbit_audio_frame_make_new (size_t size ) {
490490 microbit_audio_frame_obj_t * res = m_new_obj_var (microbit_audio_frame_obj_t , uint8_t , size );
491491 res -> base .type = & microbit_audio_frame_type ;
492- res -> size = size ;
492+ res -> alloc_size = size ;
493493 memset (res -> data , 128 , size );
494494 return res ;
495495}
0 commit comments