Skip to content

Commit 4e3ac1d

Browse files
committed
codal_port/modaudio: Mostly use "alloc_size" instead of "used_size".
Signed-off-by: Damien George <damien@micropython.org>
1 parent f1b03ee commit 4e3ac1d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/codal_port/modaudio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, size_t n_
337337
static mp_obj_t audio_frame_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value_in) {
338338
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
339339
mp_int_t index = mp_obj_get_int(index_in);
340-
if (index < 0 || index >= self->used_size) {
340+
if (index < 0 || index >= self->alloc_size) {
341341
mp_raise_ValueError(MP_ERROR_TEXT("index out of bounds"));
342342
}
343343
if (value_in == MP_OBJ_NULL) {
@@ -360,7 +360,7 @@ static mp_obj_t audio_frame_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
360360
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
361361
switch (op) {
362362
case MP_UNARY_OP_LEN:
363-
return MP_OBJ_NEW_SMALL_INT(self->used_size);
363+
return MP_OBJ_NEW_SMALL_INT(self->alloc_size);
364364
default:
365365
return MP_OBJ_NULL; // op not supported
366366
}
@@ -370,14 +370,14 @@ static mp_int_t audio_frame_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufin
370370
(void)flags;
371371
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
372372
bufinfo->buf = self->data;
373-
bufinfo->len = self->used_size;
373+
bufinfo->len = self->alloc_size;
374374
bufinfo->typecode = 'b';
375375
return 0;
376376
}
377377

378378
static void add_into(microbit_audio_frame_obj_t *self, microbit_audio_frame_obj_t *other, bool add) {
379379
int mult = add ? 1 : -1;
380-
size_t size = MIN(self->used_size, other->used_size);
380+
size_t size = MIN(self->alloc_size, other->alloc_size);
381381
for (int i = 0; i < size; i++) {
382382
unsigned val = (int)self->data[i] + mult*(other->data[i]-128);
383383
// Clamp to 0-255
@@ -401,7 +401,7 @@ mp_obj_t copyfrom(mp_obj_t self_in, mp_obj_t other) {
401401
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
402402
mp_buffer_info_t bufinfo;
403403
mp_get_buffer_raise(other, &bufinfo, MP_BUFFER_READ);
404-
uint32_t len = MIN(bufinfo.len, self->used_size);
404+
uint32_t len = MIN(bufinfo.len, self->alloc_size);
405405
for (uint32_t i = 0; i < len; i++) {
406406
self->data[i] = ((uint8_t *)bufinfo.buf)[i];
407407
}
@@ -438,7 +438,7 @@ int32_t float_to_fixed(float f, uint32_t scale) {
438438

439439
static void mult(microbit_audio_frame_obj_t *self, float f) {
440440
int scaled = float_to_fixed(f, 15);
441-
for (int i = 0; i < self->used_size; i++) {
441+
for (int i = 0; i < self->alloc_size; i++) {
442442
unsigned val = ((((int)self->data[i]-128) * scaled) >> 15)+128;
443443
if (val > 255) {
444444
val = (1-(val>>31))*255;

0 commit comments

Comments
 (0)