Skip to content

Commit 79f4344

Browse files
committed
fix playing mono files on stereo output
1 parent 3056365 commit 79f4344

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ports/atmel-samd/common-hal/audioio/AudioOut.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,13 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
405405
if (self->right_channel == &pin_PA02) {
406406
right_channel_reg = (uint32_t)&DAC->DATABUF[0].reg;
407407
}
408-
if (right_channel_reg == left_channel_reg + 2 && audiosample_bits_per_sample(sample) == 16) {
408+
409+
size_t num_channels = audiosample_channel_count(sample);
410+
411+
if (num_channels == 2 &&
412+
// Are DAC channels sequential?
413+
left_channel_reg + 2 == right_channel_reg &&
414+
audiosample_bits_per_sample(sample) == 16) {
409415
result = audio_dma_setup_playback(&self->left_dma, sample, loop, false, 0,
410416
false /* output unsigned */,
411417
left_channel_reg,
@@ -415,7 +421,11 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
415421
false /* output unsigned */,
416422
left_channel_reg,
417423
left_channel_trigger);
418-
if (right_channel_reg != 0 && result == AUDIO_DMA_OK) {
424+
// Don't play back on right channel unless stereo.
425+
// TODO possibility: Set up non-incrementing DMA on one channel so they use the same samples?
426+
// Right now, playing back mono on both channels causes sample to play twice as fast.
427+
if (num_channels == 2 &&
428+
right_channel_reg != 0 && result == AUDIO_DMA_OK) {
419429
result = audio_dma_setup_playback(&self->right_dma, sample, loop, true, 1,
420430
false /* output unsigned */,
421431
right_channel_reg,

0 commit comments

Comments
 (0)