Skip to content

Commit fd2627c

Browse files
committed
Support mono to stereo conversion in audiomixer.Mixer
1 parent 48d945f commit fd2627c

File tree

12 files changed

+142
-43
lines changed

12 files changed

+142
-43
lines changed

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;

shared-module/audiodelays/Echo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self) {
204204
}
205205

206206
void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop) {
207-
audiosample_must_match(&self->base, sample);
207+
audiosample_must_match(&self->base, sample, false);
208208

209209
self->sample = sample;
210210
self->loop = loop;

shared-module/audiodelays/MultiTapDelay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ bool common_hal_audiodelays_multi_tap_delay_get_playing(audiodelays_multi_tap_de
285285
}
286286

287287
void common_hal_audiodelays_multi_tap_delay_play(audiodelays_multi_tap_delay_obj_t *self, mp_obj_t sample, bool loop) {
288-
audiosample_must_match(&self->base, sample);
288+
audiosample_must_match(&self->base, sample, false);
289289

290290
self->sample = sample;
291291
self->loop = loop;

shared-module/audiodelays/PitchShift.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool common_hal_audiodelays_pitch_shift_get_playing(audiodelays_pitch_shift_obj_
143143
}
144144

145145
void common_hal_audiodelays_pitch_shift_play(audiodelays_pitch_shift_obj_t *self, mp_obj_t sample, bool loop) {
146-
audiosample_must_match(&self->base, sample);
146+
audiosample_must_match(&self->base, sample, false);
147147

148148
self->sample = sample;
149149
self->loop = loop;

shared-module/audiofilters/Distortion.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ bool common_hal_audiofilters_distortion_get_playing(audiofilters_distortion_obj_
141141
}
142142

143143
void common_hal_audiofilters_distortion_play(audiofilters_distortion_obj_t *self, mp_obj_t sample, bool loop) {
144-
audiosample_must_match(&self->base, sample);
144+
audiosample_must_match(&self->base, sample, false);
145145

146146
self->sample = sample;
147147
self->loop = loop;

shared-module/audiofilters/Filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool common_hal_audiofilters_filter_get_playing(audiofilters_filter_obj_t *self)
143143
}
144144

145145
void common_hal_audiofilters_filter_play(audiofilters_filter_obj_t *self, mp_obj_t sample, bool loop) {
146-
audiosample_must_match(&self->base, sample);
146+
audiosample_must_match(&self->base, sample, false);
147147

148148
self->sample = sample;
149149
self->loop = loop;

shared-module/audiofilters/Phaser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool common_hal_audiofilters_phaser_get_playing(audiofilters_phaser_obj_t *self)
130130
}
131131

132132
void common_hal_audiofilters_phaser_play(audiofilters_phaser_obj_t *self, mp_obj_t sample, bool loop) {
133-
audiosample_must_match(&self->base, sample);
133+
audiosample_must_match(&self->base, sample, false);
134134

135135
self->sample = sample;
136136
self->loop = loop;

shared-module/audiofreeverb/Freeverb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool common_hal_audiofreeverb_freeverb_get_playing(audiofreeverb_freeverb_obj_t
195195
}
196196

197197
void common_hal_audiofreeverb_freeverb_play(audiofreeverb_freeverb_obj_t *self, mp_obj_t sample, bool loop) {
198-
audiosample_must_match(&self->base, sample);
198+
audiosample_must_match(&self->base, sample, false);
199199

200200
self->sample = sample;
201201
self->loop = loop;

0 commit comments

Comments
 (0)