Repository navigation
libdmaudio and the dmaudio service: mixing streams for the audio devices - #1
Merged
Merged
Conversation
libdmaudio (one in the system) holds everything: applications open streams on a device in the format of their samples (any rate, 1-8 channels, S16/S24/S32) and write into lock-free buffers of their own; the mixer converts each to the device's format (linear interpolation of the rate, channel mapping), scales it by its volume and sums them in 24 bits. libdmaudio_serve() serves a device's node: it configures it, mixes a period at a time and writes it, paced by the node's DMA, stops the node while nothing plays, and applies the master volume (on the node or the mix). Streams of processes that are gone are dropped. dmaudio is the service - main() calling libdmaudio_serve() -, started per audio device by configs/dmaudio.rules. audiotone, audioplay (WAV) and audioctl are tools; test_libdmaudio tests the mixer without a node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The top layer of the audio stack: a mixer for the audio devices.
libdmaudio_serve()configures the node (AUDIO_CONFIGURE; a fixed-format SAI keeps its own) and takes the format fromAUDIO_GET_STREAM. It then mixes and writes 10 ms periods, paced by the node's DMA rather than a timer. After 2 s with nothing to play it drains and stops the node; the next samples start it again. The master volume and mute go to the node, or to the mix when the node has none.main()callinglibdmaudio_serve(), under 1 kB. It runs at priority 3, above the applications.configs/dmaudio.rulesstartsdmaudio@<name>for every node reported asaudio; options go in the unit'sargs=.audiotone(sine tones, one stream each),audioplay(PCM WAV),audioctl(list devices, volume, mute).docs/api-reference.md, README.Not implemented yet: capture (recording streams), and a better resampler than linear interpolation.
Testing
test_libdmaudio(host, 16 steps) mixes a device registered without a node. It covers conversions, mono/stereo, S24/S32 output, sums and clamping, volume, 24→48 kHz interpolation, full buffers and timeouts, drain, underruns, pause, and a device that goes away.build/dmfby hand (not released yet):dmaudio wm8994 /dev/wm8994started by the rule. This needs Report the nodes after their friends, on the hot-plug worker dmdevfs#69; with dmdevfs 1.5 the codec is not reported.audiotone -f 440 -t 3: 22050 Hz mono into 48 kHz stereo, 3.45 s, 0 underruns.audiotonewith three tones at once: three streams mixed, 0 underruns.audioplayof a 3 s 44.1 kHz 24-bit stereo WAV from the SD card: 3.48 s.🤖 Generated with Claude Code