Skip to content

Commit 97a9791

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

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
@@ -340,7 +340,7 @@ STATIC mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, size_t n_
340340
STATIC mp_obj_t audio_frame_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value_in) {
341341
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
342342
mp_int_t index = mp_obj_get_int(index_in);
343-
if (index < 0 || index >= self->used_size) {
343+
if (index < 0 || index >= self->alloc_size) {
344344
mp_raise_ValueError(MP_ERROR_TEXT("index out of bounds"));
345345
}
346346
if (value_in == MP_OBJ_NULL) {
@@ -363,7 +363,7 @@ static mp_obj_t audio_frame_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
363363
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
364364
switch (op) {
365365
case MP_UNARY_OP_LEN:
366-
return MP_OBJ_NEW_SMALL_INT(self->used_size);
366+
return MP_OBJ_NEW_SMALL_INT(self->alloc_size);
367367
default:
368368
return MP_OBJ_NULL; // op not supported
369369
}
@@ -373,14 +373,14 @@ static mp_int_t audio_frame_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufin
373373
(void)flags;
374374
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
375375
bufinfo->buf = self->data;
376-
bufinfo->len = self->used_size;
376+
bufinfo->len = self->alloc_size;
377377
bufinfo->typecode = 'b';
378378
return 0;
379379
}
380380

381381
static void add_into(microbit_audio_frame_obj_t *self, microbit_audio_frame_obj_t *other, bool add) {
382382
int mult = add ? 1 : -1;
383-
size_t size = MIN(self->used_size, other->used_size);
383+
size_t size = MIN(self->alloc_size, other->alloc_size);
384384
for (int i = 0; i < size; i++) {
385385
unsigned val = (int)self->data[i] + mult*(other->data[i]-128);
386386
// Clamp to 0-255
@@ -404,7 +404,7 @@ mp_obj_t copyfrom(mp_obj_t self_in, mp_obj_t other) {
404404
microbit_audio_frame_obj_t *self = (microbit_audio_frame_obj_t *)self_in;
405405
mp_buffer_info_t bufinfo;
406406
mp_get_buffer_raise(other, &bufinfo, MP_BUFFER_READ);
407-
uint32_t len = MIN(bufinfo.len, self->used_size);
407+
uint32_t len = MIN(bufinfo.len, self->alloc_size);
408408
for (uint32_t i = 0; i < len; i++) {
409409
self->data[i] = ((uint8_t *)bufinfo.buf)[i];
410410
}
@@ -441,7 +441,7 @@ int32_t float_to_fixed(float f, uint32_t scale) {
441441

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

0 commit comments

Comments
 (0)