Skip to content

Commit ad11e7a

Browse files
committed
codal_port/modaudio: Mostly use "alloc_size" instead of "used_size".
Signed-off-by: Damien George <[email protected]>
1 parent faa52ae commit ad11e7a

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
@@ -351,7 +351,7 @@ STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, size_t n_
351351
STATIC mp_obj_t audio_frame_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value_in) {
352352
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
353353
mp_int_t index = mp_obj_get_int(index_in);
354-
if (index < 0 || index >= self->used_size) {
354+
if (index < 0 || index >= self->alloc_size) {
355355
mp_raise_ValueError(MP_ERROR_TEXT("index out of bounds"));
356356
}
357357
if (value_in == MP_OBJ_NULL) {
@@ -374,7 +374,7 @@ static mp_obj_t audio_frame_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
374374
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
375375
switch (op) {
376376
case MP_UNARY_OP_LEN:
377-
return MP_OBJ_NEW_SMALL_INT(self->used_size);
377+
return MP_OBJ_NEW_SMALL_INT(self->alloc_size);
378378
default:
379379
return MP_OBJ_NULL; // op not supported
380380
}
@@ -384,14 +384,14 @@ static mp_int_t audio_frame_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufin
384384
(void)flags;
385385
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
386386
bufinfo->buf = self->data;
387-
bufinfo->len = self->used_size;
387+
bufinfo->len = self->alloc_size;
388388
bufinfo->typecode = 'b';
389389
return 0;
390390
}
391391

392392
static void add_into(microbit_audio_frame_obj_t *self, microbit_audio_frame_obj_t *other, bool add) {
393393
int mult = add ? 1 : -1;
394-
size_t size = MIN(self->used_size, other->used_size);
394+
size_t size = MIN(self->alloc_size, other->alloc_size);
395395
for (int i = 0; i < size; i++) {
396396
unsigned val = (int)self->data[i] + mult*(other->data[i]-128);
397397
// Clamp to 0-255
@@ -415,7 +415,7 @@ mp_obj_t copyfrom(mp_obj_t self_in, mp_obj_t other) {
415415
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
416416
mp_buffer_info_t bufinfo;
417417
mp_get_buffer_raise(other, &bufinfo, MP_BUFFER_READ);
418-
uint32_t len = MIN(bufinfo.len, self->used_size);
418+
uint32_t len = MIN(bufinfo.len, self->alloc_size);
419419
for (uint32_t i = 0; i < len; i++) {
420420
self->data[i] = ((uint8_t *)bufinfo.buf)[i];
421421
}
@@ -452,7 +452,7 @@ int32_t float_to_fixed(float f, uint32_t scale) {
452452

453453
static void mult(microbit_audio_frame_obj_t *self, float f) {
454454
int scaled = float_to_fixed(f, 15);
455-
for (int i = 0; i < self->used_size; i++) {
455+
for (int i = 0; i < self->alloc_size; i++) {
456456
unsigned val = ((((int)self->data[i]-128) * scaled) >> 15)+128;
457457
if (val > 255) {
458458
val = (1-(val>>31))*255;

0 commit comments

Comments
 (0)