Repository navigation
Reuse the open audio output stream between streams - #204
Open
CrazyDiam0nd-gh wants to merge 1 commit into
Open
CrazyDiam0nd-gh wants to merge 1 commit into
CrazyDiam0nd-gh wants to merge 1 commit into
Conversation
A new SyncedPlayer was built for every StreamStart. A freshly opened output stream is cold: while it settles, the output delay reported by the OS overshoots by a few hundred milliseconds and then relaxes over several seconds. The sync corrector reads that as drift, speeds playback up by up to 4%, overshoots, and then slows it down, which is audible as a warble for 5-10 seconds at the start of every playlist. On CreatePlayer, keep the existing output stream if the PCM format is the same, the freshly resolved output device is the same as the one the open stream was built for, and the previous stream ended no more than 10 minutes ago. Otherwise rebuild as before. The device is still re-resolved on every StreamStart, so the behavior from music-assistant#40 (a vanished or reconnected device is picked up at the next play) is kept; if the device identity cannot be determined the stream is rebuilt. The reuse decision is a pure function with unit tests.
This branch has not been deployed
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.
Reuse the open audio output stream between streams
Fixes an audible warble (slow/wobbly pitch for 5-10 s) at the start of every playlist on Linux. Addresses #203 for every play after the first; the first play after launch is covered by the library PR linked at the bottom, so this should not close the issue on its own.
Problem
run_playback_threadbuilds a newSyncedPlayeron everyCreatePlayer, i.e. at everyStreamStart. A freshly opened output stream is cold: while it settles, the output delay the OS reports overshoots by a few hundred milliseconds (about 550 ms within the first second on my setup) and then relaxes back to its resting value (about 250 ms) over ~5 s. The audio plays gaplessly, but the sync error is measured against that delay, so it swings by the same amount. The corrector reads the swing as drift, speeds playback up by up to 4% (drop_every=25), overshoots, and then slows it down by about 1.5% (insert_every=54..70).Evidence
sendspin-rs, same server, same Flatpak sandbox) with one persistent output stream: no warble, start errors of 4-47 ms, corrections of 0.2-0.5%.sendspin-rsversion, PipeWire quantum, network.Change
On
CreatePlayer, keep the existing output stream if all of these hold, otherwise rebuild exactly as before:OUTPUT_STREAM_REUSE_MAX_IDLE).The device is still re-resolved on every
StreamStart, so the behavior from #40 (a device that disappeared or reconnected is picked up at the next play) is kept. If the device identity cannot be determined, the stream is rebuilt. The reuse decision is the pure functioncan_reuse_output_stream, with unit tests.Testing
cargo fmt --check,cargo clippy --all-targets --all-features -- -D warnings,cargo test(132 passed, 4 new).Reusing open audio output stream, and none of the later plays warbled.Notes
sendspin-rsatv0.3.5, so it will need a version bump once that is released.