Skip to content

samd: When possible, use one DMA channel for stereo AudioOut #2552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2020

Conversation

jepler
Copy link

@jepler jepler commented Jan 26, 2020

.. 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.

This will end up conflicting with #2533, which should be rebased if this is accepted first. In fact, if this is accepted, then in lieu of #2533 it is probably better to extend audio_dma_convert_signed and ditch the sibling dma channel code. Other parts of that PR would still apply, as far as getting rid of the "single channel" flags through the audio stack.

.. 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.
@jepler jepler requested a review from tannewt January 26, 2020 21:39
With the previous change, stereo mp3 playback changed from needing
4 2304-byte allocations to needing 2 4604-byte allocations.  This was
enough to cause MemoryErrors with regularity.

By using m_realloc() here, the existing memory region can be used.
m_realloc() also works on the first invocation, because m_realloc(NULL, sz)
just calls m_malloc of sz.
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for testing this and improving it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants