Skip to content

Commit 6ed41a0

Browse files
authored
Merge pull request #10529 from relic-se/audiomixer-mono
Added mono to stereo conversion and panning to `audiomixer.Mixer`
2 parents c202140 + 7b5587c commit 6ed41a0

File tree

20 files changed

+224
-51
lines changed

20 files changed

+224
-51
lines changed

ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CIRCUITPY__EVE = 1
1414
CIRCUITPY_CODEOP = 0
1515
CIRCUITPY_FLOPPYIO = 0
1616
CIRCUITPY_JPEGIO = 0
17+
CIRCUITPY_MSGPACK = 0
1718
CIRCUITPY_SYNTHIO = 0
1819
CIRCUITPY_VECTORIO = 0
1920

ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ QSPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "GD25Q16C,W25Q16JVxQ"
1111
LONGINT_IMPL = MPZ
1212

13+
CIRCUITPY__EVE = 1
1314
CIRCUITPY_CODEOP = 0
1415
CIRCUITPY_FLOPPYIO = 0
15-
CIRCUITPY_GIFIO = 0
1616
CIRCUITPY_JPEGIO = 0
17-
CIRCUITPY_TILEPALETTEMAPPER = 0
17+
CIRCUITPY_MSGPACK = 0
18+
CIRCUITPY_SYNTHIO = 0
19+
CIRCUITPY_VECTORIO = 0
1820

1921
CIRCUITPY_BITBANG_APA102 = 1
2022

ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CIRCUITPY__EVE = 1
1414
CIRCUITPY_CODEOP = 0
1515
CIRCUITPY_FLOPPYIO = 0
1616
CIRCUITPY_JPEGIO = 0
17+
CIRCUITPY_MSGPACK = 0
1718
CIRCUITPY_SYNTHIO = 0
1819
CIRCUITPY_VECTORIO = 0
1920

ports/atmel-samd/boards/seeeduino_wio_terminal/mpconfigboard.mk

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ CHIP_FAMILY = samd51
99
QSPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ"
1111
LONGINT_IMPL = MPZ
12+
13+
CIRCUITPY__EVE = 1
14+
CIRCUITPY_CODEOP = 0
1215
CIRCUITPY_FLOPPYIO = 0
13-
CIRCUITPY_FRAMEBUFFERIO = 0
16+
CIRCUITPY_JPEGIO = 0
17+
CIRCUITPY_MSGPACK = 0
18+
CIRCUITPY_PARALLELDISPLAYBUS = 0
19+
CIRCUITPY_RGBMATRIX = 0
20+
CIRCUITPY_SHARPDISPLAY = 0
1421
CIRCUITPY_SYNTHIO = 0
22+
CIRCUITPY_VECTORIO = 0

ports/espressif/boards/ai_thinker_esp32-c3s-2m/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ CIRCUITPY_ESP_FLASH_SIZE = 2MB
99

1010
CIRCUITPY_DUALBANK = 0
1111

12+
CIRCUITPY_JPEGIO = 0
13+
1214
CIRCUITPY_ESP_USB_SERIAL_JTAG = 0

shared-bindings/audiomixer/MixerVoice.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ MP_PROPERTY_GETSET(audiomixer_mixervoice_level_obj,
114114
(mp_obj_t)&audiomixer_mixervoice_get_level_obj,
115115
(mp_obj_t)&audiomixer_mixervoice_set_level_obj);
116116

117+
//| panning: synthio.BlockInput
118+
//| """Defines the channel(s) in which the voice appears, as a floating point number between
119+
//| -1 and 1. If your board does not support synthio, this property will only accept a float
120+
//| value. This property is ignored if ``audiomixer.Mixer.channel_count=1``.
121+
//|
122+
//| -1 is left channel only, 0 is both channels, and 1 is right channel. For fractional values,
123+
//| the note plays at full amplitude in one channel and partial amplitude in the other channel.
124+
//| For instance -.5 plays at full amplitude in the left channel and 1/2 amplitude in the right
125+
//| channel."""
126+
static mp_obj_t audiomixer_mixervoice_obj_get_panning(mp_obj_t self_in) {
127+
return common_hal_audiomixer_mixervoice_get_panning(self_in);
128+
}
129+
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixervoice_get_panning_obj, audiomixer_mixervoice_obj_get_panning);
130+
131+
static mp_obj_t audiomixer_mixervoice_obj_set_panning(mp_obj_t self_in, mp_obj_t panning_in) {
132+
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);
133+
common_hal_audiomixer_mixervoice_set_panning(self, panning_in);
134+
return mp_const_none;
135+
}
136+
MP_DEFINE_CONST_FUN_OBJ_2(audiomixer_mixervoice_set_panning_obj, audiomixer_mixervoice_obj_set_panning);
137+
138+
MP_PROPERTY_GETSET(audiomixer_mixervoice_panning_obj,
139+
(mp_obj_t)&audiomixer_mixervoice_get_panning_obj,
140+
(mp_obj_t)&audiomixer_mixervoice_set_panning_obj);
141+
117142
//| loop: bool
118143
//| """Get or set the loop status of the currently playing sample."""
119144
static mp_obj_t audiomixer_mixervoice_obj_get_loop(mp_obj_t self_in) {
@@ -158,6 +183,7 @@ static const mp_rom_map_elem_t audiomixer_mixervoice_locals_dict_table[] = {
158183
// Properties
159184
{ MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiomixer_mixervoice_playing_obj) },
160185
{ MP_ROM_QSTR(MP_QSTR_level), MP_ROM_PTR(&audiomixer_mixervoice_level_obj) },
186+
{ MP_ROM_QSTR(MP_QSTR_panning), MP_ROM_PTR(&audiomixer_mixervoice_panning_obj) },
161187
{ MP_ROM_QSTR(MP_QSTR_loop), MP_ROM_PTR(&audiomixer_mixervoice_loop_obj) },
162188
};
163189
static MP_DEFINE_CONST_DICT(audiomixer_mixervoice_locals_dict, audiomixer_mixervoice_locals_dict_table);

shared-bindings/audiomixer/MixerVoice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self);
1818
void common_hal_audiomixer_mixervoice_end(audiomixer_mixervoice_obj_t *self);
1919
mp_obj_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self);
2020
void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_obj_t gain);
21+
mp_obj_t common_hal_audiomixer_mixervoice_get_panning(audiomixer_mixervoice_obj_t *self);
22+
void common_hal_audiomixer_mixervoice_set_panning(audiomixer_mixervoice_obj_t *self, mp_obj_t value);
2123

2224
bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t *self);
2325

shared-module/audiocore/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ void audiosample_convert_s16s_u8s(uint8_t *buffer_out, const int16_t *buffer_in,
196196
}
197197
}
198198

199-
void audiosample_must_match(audiosample_base_t *self, mp_obj_t other_in) {
199+
void audiosample_must_match(audiosample_base_t *self, mp_obj_t other_in, bool allow_mono_to_stereo) {
200200
const audiosample_base_t *other = audiosample_check(other_in);
201201
if (other->sample_rate != self->sample_rate) {
202202
mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_sample_rate);
203203
}
204-
if (other->channel_count != self->channel_count) {
204+
if ((!allow_mono_to_stereo || (allow_mono_to_stereo && self->channel_count != 2)) && other->channel_count != self->channel_count) {
205205
mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_channel_count);
206206
}
207207
if (other->bits_per_sample != self->bits_per_sample) {

shared-module/audiocore/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static inline void audiosample_get_buffer_structure_checked(mp_obj_t self_in, bo
8989
audiosample_get_buffer_structure(audiosample_check(self_in), single_channel_output, single_buffer, samples_signed, max_buffer_length, spacing);
9090
}
9191

92-
void audiosample_must_match(audiosample_base_t *self, mp_obj_t other);
92+
void audiosample_must_match(audiosample_base_t *self, mp_obj_t other, bool allow_mono_to_stereo);
9393

9494
void audiosample_convert_u8m_s16s(int16_t *buffer_out, const uint8_t *buffer_in, size_t nframes);
9595
void audiosample_convert_u8s_s16s(int16_t *buffer_out, const uint8_t *buffer_in, size_t nframes);

shared-module/audiodelays/Chorus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool common_hal_audiodelays_chorus_get_playing(audiodelays_chorus_obj_t *self) {
166166
}
167167

168168
void common_hal_audiodelays_chorus_play(audiodelays_chorus_obj_t *self, mp_obj_t sample, bool loop) {
169-
audiosample_must_match(&self->base, sample);
169+
audiosample_must_match(&self->base, sample, false);
170170

171171
self->sample = sample;
172172
self->loop = loop;

0 commit comments

Comments
 (0)