Skip to content

Commit bb3f54a

Browse files
authored
Merge pull request #2996 from jepler/mixer-bugfixes
audiomixer: Fix garbled playback when voice 0 is stopped, audio pops
2 parents db04fd1 + 0722daf commit bb3f54a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

shared-module/audiomixer/Mixer.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,17 @@ static inline uint32_t pack8(uint32_t val) {
143143
static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
144144
audiomixer_mixervoice_obj_t* voice, bool voices_active,
145145
uint32_t* word_buffer, uint32_t length) {
146-
bool voice_done = voice->sample == NULL;
147-
while (!voice_done && length != 0) {
146+
while (length != 0) {
148147
if (voice->buffer_length == 0) {
149148
if (!voice->more_data) {
150149
if (voice->loop) {
151150
audiosample_reset_buffer(voice->sample, false, 0);
152151
} else {
153152
voice->sample = NULL;
154-
voice_done = true;
155153
break;
156154
}
157155
}
158-
if (!voice_done) {
156+
if (voice->sample) {
159157
// Load another buffer
160158
audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length);
161159
// Track length in terms of words.
@@ -230,10 +228,8 @@ static void mix_down_one_voice(audiomixer_mixer_obj_t* self,
230228
}
231229

232230
if (length && !voices_active) {
233-
uint32_t sample_value = self->bits_per_sample == 8
234-
? 0x80808080 : 0x80008000;
235231
for (uint32_t i = 0; i<length; i++) {
236-
word_buffer[i] = sample_value;
232+
word_buffer[i] = 0;
237233
}
238234
}
239235
}
@@ -269,9 +265,16 @@ audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t*
269265

270266
for (int32_t v = 0; v < self->voice_count; v++) {
271267
audiomixer_mixervoice_obj_t* voice = MP_OBJ_TO_PTR(self->voice[v]);
268+
if(voice->sample) {
269+
mix_down_one_voice(self, voice, voices_active, word_buffer, length);
270+
voices_active = true;
271+
}
272+
}
272273

273-
mix_down_one_voice(self, voice, voices_active, word_buffer, length);
274-
voices_active = true;
274+
if (!voices_active) {
275+
for (uint32_t i = 0; i<length; i++) {
276+
word_buffer[i] = 0;
277+
}
275278
}
276279

277280
if (!self->samples_signed) {

0 commit comments

Comments
 (0)