@@ -405,7 +405,13 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
405
405
if (self -> right_channel == & pin_PA02 ) {
406
406
right_channel_reg = (uint32_t )& DAC -> DATABUF [0 ].reg ;
407
407
}
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 ) {
409
415
result = audio_dma_setup_playback (& self -> left_dma , sample , loop , false, 0 ,
410
416
false /* output unsigned */ ,
411
417
left_channel_reg ,
@@ -415,7 +421,11 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
415
421
false /* output unsigned */ ,
416
422
left_channel_reg ,
417
423
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 ) {
419
429
result = audio_dma_setup_playback (& self -> right_dma , sample , loop , true, 1 ,
420
430
false /* output unsigned */ ,
421
431
right_channel_reg ,
0 commit comments