Skip to content

Properly handle audio dma underflow #8121

Open
@jepler

Description

@jepler

CircuitPython version

8.2.0-rc.0

Code/REPL

# Run any code using audiobusio
# and at the same time, perform a lengthy write to the CIRCUITPY drive

Behavior

The audio mostly works fine, however, when the audio dma underflows due to not running background tasks frequently enough, unrelated memory is treated as audio data. This can sound like static, a chirp, a honk, etc.

This happens especially frequently when writing to the CIRCUITPY drive, because normal code in flash can't be executed during an erase/write cycle.

Description

No response

Additional information

The code in audio_dma.c has two DMA descriptors (call them A and B) which chain to each other, so without intervention, A will be DMA'd, then B, then, A, then B, and so on forever.

This happens whether or not the background tasks run.

Unlike on some systems, triggering a DMA transfer does not reset its address to a start address; instead, the address continues getting incremented. So if the buffer is at [say] 0xf000 .. 0xf200 then the first underflow will actually play audio data from 0xf200 to 0xf400, then from 0xf400 to 0xf600, and so on. This data will .. not sound good.

It would be nice if the audio stopped, or output the quiescent value, when DMA underflows.

This probably involves un-chaining the DMAs. I tried implementing this, but didn't quickly (1h) come up with something that worked better than the status quo, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions