Repository navigation
Play DSD over PCM (DoP) on capable DACs - #324
manuel-alcocer wants to merge 5 commits into
Conversation
DoP carries DSD64 as 176.4 kHz PCM, DSD128 as 352.8 kHz and DSD256 as 705.6 kHz. Format detection only probed 44.1/48/96/192 kHz, so a server could never send a DoP stream to a DAC that supports it. Each extra rate is still probed against the device before it is offered.
A DoP (DSD over PCM) stream is only DSD while every sample stays bit-exact: scaling it hides the markers from the DAC, which then plays it as full-scale noise. Skip software volume when a buffer carries the alternating 0x05/0xFA markers; the volume of DSD is set on the amp.
There was a problem hiding this comment.
🟡 Changes recommended
Zero-padding causes partial DoP buffers at stream tails or queue underruns to be misclassified, allowing software volume scaling to corrupt their markers.
2 open issues
What changed in this PR
This PR adds support for DSD over PCM (DoP) playback on capable DACs by expanding audio-format detection and preserving detected DoP buffers during software volume processing.
Changes:
- Probes additional sample rates, including those used for DSD64, DSD128, and DSD256.
- Detects alternating DoP markers and bypasses software attenuation for matching buffers.
- Adds tests for marker detection, volume behavior, and device-supported DoP rates.
| File | Description |
|---|---|
tests/test_audio.py |
Tests DoP detection, unchanged DoP output, and ordinary PCM scaling. |
tests/test_audio_devices.py |
Tests advertising supported DoP rates while excluding unsupported rates. |
sendspin/audio.py |
Adds DoP marker detection and software-volume bypass. |
sendspin/audio_devices.py |
Expands the sample rates probed for playback support. |
Review effort: Balanced
The DoP check looked at the first eight frames of each output buffer, so a callback holding a few DoP frames before zero padding, DoP that starts after start-gating silence, or a PCM/DoP transition inside one buffer was scaled as a whole and its markers were corrupted. Classify every frame instead: a run of alternating markers counts as DoP when it is at least eight frames long, continues the DoP run that ended the previous callback, or reaches the end of the buffer. Software volume now scales only the PCM stretches between DoP runs, and clear() forgets the carried-over marker.
Underrun padding, a device underflow and mute wrote zero bytes, which end the DoP marker sequence: the DAC drops out of DSD mode and has to lock again, often with a click. While DoP plays, fill those gaps with DoP frames that carry the DSD idle pattern (0x69) and keep the markers alternating, and mute only the payload of DoP frames. DoP is now tracked on every callback, not only below 100% volume. Two fast paths keep that cheap: a PCM buffer that neither continues DoP nor starts or ends with a marker, and a buffer that simply continues the running marker sequence (about 12 us per 2048 frames on an Orange Pi 3B, against 550 us for the full classification).
|
Closing, since a Sendspin server has no way to know whether a player's DAC accepts DoP, so PDM/DSD sent this way plays as noise on every player that doesn't. In this player, DoP also breaks each time drift correction repeats or skips a frame, and leaving DoP frames unscaled means the player ignores the volume it reports. Native PDM/DSD playback would need its own format in the Sendspin spec, since that's the only way a player can tell the server it accepts it. Spec: |


What does this implement/fix?
This lets the CLI play DSD as DoP (DSD over PCM) on a DAC that supports it.
DoP packs DSD into ordinary PCM frames: DSD64 travels as 176.4 kHz, DSD128 as 352.8 kHz and DSD256 as 705.6 kHz. The DAC spots the alternating marker bytes (0x05 / 0xFA) and switches to native DSD playback. It only works if every sample reaches the DAC unchanged.
Two things got in the way:
The CLI never offered the DoP rates. Format detection only tried 44.1, 48, 96 and 192 kHz, so a server could not send a DoP stream even to a DAC that supports it. The list now also covers 88.2, 176.4, 352.8, 384, 705.6 and 768 kHz. Each rate is still tried against the device before it is offered, so nothing changes on hardware that does not support it.
Software volume ruined DoP. Scaling the samples hides the markers, and the DAC plays the result as full-scale noise. The player now checks the first frames of each buffer for the DoP markers, and if they are there it leaves the buffer alone. For DSD, the volume is set on the amplifier. Plain PCM is detected as before and still gets the software volume. A regular PCM signal practically never produces that alternating marker pattern across all channels.
The server side, which sends DSF files as DoP to a Sendspin player, is in music-assistant/server#7429. For playback to stay bit-exact over time this works best together with
--clock-source dac(#318), which stops drift correction from inserting or dropping samples. The two changes do not depend on each other in code.Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocumentationmaintenancecidependencies