Skip to content

RP2040 PWMAudioOut: Release DMA channels after play has finished #4958

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
Jul 2, 2021

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Jul 1, 2021

Fix RP2040 PWMAudioOut stopping playing completely. It will stop playing after playing six samples.

"Scratchiness" and other audio quality issues are not necessarily addressed by this.

The essential problem was that the 12 DMA channels were being used up because the two that were being used were not freed after use, due to a missing

        audio_dma_stop(&self->dma);

in PWMAudioOut.c.

In the course of this I made some other more minor changes:

  • Rename single_channel to single_channel_output to clarify its meaning. This changed a lot of files.
  • Do pin claiming in PWMOut, not in PWMAudioOut.
  • Fix up uses of DMA_CH0_CTRL_TRIG_EN_BITS and DMA_CH1_CTRL_TRIG_EN_BITS. They are actually the same value, but it's possible in some future processor they might not be, so I regularized the use.
  • Reorder one struct's fields to save a bit of space.

@dhalbert dhalbert requested a review from tannewt July 1, 2021 21:45
tannewt
tannewt previously approved these changes Jul 1, 2021
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.

Good find! Thank you!

@dhalbert
Copy link
Collaborator Author

dhalbert commented Jul 2, 2021

Fixed one failing build. Ready for re-review. I will look at crackling audio separately, since this fixes an immediate problem.

@dhalbert
Copy link
Collaborator Author

dhalbert commented Jul 2, 2021

@kevinjwalters This may partially fix #4208, but I have not tested it for noisy output yet. I was testing with an artificial audio file with non-audible data to make sure the buffers were filling properly.

Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

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

Makes sense, but didn't test.

@dhalbert dhalbert merged commit c37f354 into adafruit:main Jul 2, 2021
@dhalbert dhalbert deleted the rp2040-audio-fixes branch July 2, 2021 14:07
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.

3 participants