Skip to content

Commit cb6193b

Browse files
committed
samd: When possible, use one DMA channel for stereo AudioOut
.. the documentation doesn't make this clear, but in practice it works to write both of the DATABUF registers at the same time. This should also reduce the amount of wear and tear DMA puts on the system, as the number of transfers is cut in half. (the number of bytes transferred remains the same, though) In principle, this could cover all stereo cases if audio_dma_convert_signed also learned to 16-bit extend and swap values. However, this is the case that matters for stereo mp3 playback on PyGamer. Testing performed: Listened to some tracks with good stereo separation.
1 parent c2fd303 commit cb6193b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,22 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self,
397397
if (self->right_channel == &pin_PA02) {
398398
right_channel_reg = (uint32_t) &DAC->DATABUF[0].reg;
399399
}
400-
result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0,
401-
false /* output unsigned */,
402-
left_channel_reg,
403-
left_channel_trigger);
404-
if (right_channel_reg != 0 && result == AUDIO_DMA_OK) {
405-
result = audio_dma_setup_playback(&self->right_dma, sample, loop, true, 1,
400+
if(right_channel_reg == left_channel_reg + 2 && audiosample_bits_per_sample(sample) == 16) {
401+
result = audio_dma_setup_playback(&self->left_dma, sample, loop, false, 0,
406402
false /* output unsigned */,
407-
right_channel_reg,
408-
right_channel_trigger);
403+
left_channel_reg,
404+
left_channel_trigger);
405+
} else {
406+
result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0,
407+
false /* output unsigned */,
408+
left_channel_reg,
409+
left_channel_trigger);
410+
if (right_channel_reg != 0 && result == AUDIO_DMA_OK) {
411+
result = audio_dma_setup_playback(&self->right_dma, sample, loop, true, 1,
412+
false /* output unsigned */,
413+
right_channel_reg,
414+
right_channel_trigger);
415+
}
409416
}
410417
#endif
411418
if (result != AUDIO_DMA_OK) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy