Skip to content

Commit a5956ea

Browse files
committed
Revert to original functionality when synthio is not supported.
1 parent e37502c commit a5956ea

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

shared-bindings/audiomixer/MixerVoice.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include "py/objproperty.h"
1414
#include "py/runtime.h"
1515
#include "shared-bindings/util.h"
16+
#if CIRCUITPY_SYNTHIO
1617
#include "shared-module/synthio/block.h"
18+
#endif
1719

1820
//| class MixerVoice:
1921
//| """Voice objects used with Mixer
@@ -77,7 +79,9 @@ static mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *po
7779
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_stop_obj, 1, audiomixer_mixervoice_obj_stop);
7880

7981
//| level: synthio.BlockInput
80-
//| """The volume level of a voice, as a floating point number between 0 and 1."""
82+
//| """The volume level of a voice, as a floating point number between 0 and 1. If your board
83+
//| does not support synthio, this property will only accept a float value.
84+
//| """
8185
static mp_obj_t audiomixer_mixervoice_obj_get_level(mp_obj_t self_in) {
8286
return common_hal_audiomixer_mixervoice_get_level(self_in);
8387
}

shared-module/audiomixer/Mixer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,18 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t *self,
188188
}
189189
}
190190

191-
uint32_t n = MIN(MIN(voice->buffer_length, length), SYNTHIO_MAX_DUR * self->channel_count);
192191
uint32_t *src = voice->remaining_buffer;
193192

193+
#if CIRCUITPY_SYNTHIO
194+
uint32_t n = MIN(MIN(voice->buffer_length, length), SYNTHIO_MAX_DUR * self->channel_count);
195+
194196
// Get the current level from the BlockInput. These may change at run time so you need to do bounds checking if required.
195197
shared_bindings_synthio_lfo_tick(self->sample_rate);
196198
uint16_t level = (uint16_t)(synthio_block_slot_get_limited(&voice->level, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0)) * (1 << 15));
199+
#else
200+
uint32_t n = MIN(voice->buffer_length, length);
201+
uint16_t level = voice->level;
202+
#endif
197203

198204
// First active voice gets copied over verbatim.
199205
if (!voices_active) {

shared-module/audiomixer/MixerVoice.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t *se
2323
}
2424

2525
mp_obj_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self) {
26+
#if CIRCUITPY_SYNTHIO
2627
return self->level.obj;
28+
#else
29+
return mp_obj_new_float((mp_float_t)self->level / (1 << 15));
30+
#endif
2731
}
2832

2933
void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_obj_t arg) {
34+
#if CIRCUITPY_SYNTHIO
3035
synthio_block_assign_slot(arg, &self->level, MP_QSTR_level);
36+
#else
37+
self->level = (uint16_t)(mp_arg_validate_obj_float_range(arg, 0, 1, MP_QSTR_level) * (1 << 15));
38+
#endif
3139
}
3240

3341
bool common_hal_audiomixer_mixervoice_get_loop(audiomixer_mixervoice_obj_t *self) {

shared-module/audiomixer/MixerVoice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#include "shared-module/audiomixer/__init__.h"
1111
#include "shared-module/audiomixer/Mixer.h"
12+
#if CIRCUITPY_SYNTHIO
1213
#include "shared-module/synthio/block.h"
14+
#endif
1315

1416
typedef struct {
1517
mp_obj_base_t base;
@@ -19,5 +21,9 @@ typedef struct {
1921
bool more_data;
2022
uint32_t *remaining_buffer;
2123
uint32_t buffer_length;
24+
#if CIRCUITPY_SYNTHIO
2225
synthio_block_slot_t level;
26+
#else
27+
uint16_t level;
28+
#endif
2329
} audiomixer_mixervoice_obj_t;

0 commit comments

Comments
 (0)