mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-02 05:12:02 +00:00
[client] audio: redesign playback synchronization
Model playback latency from the device period, arrival jitter, source packet phase, and resampler delay. Treat audio:latencyOffset as an explicit addition to this minimum and align the first device pull to the next packet deadline. This starts playback near its steady-state target without unnecessary prefill or startup underruns. Use a 512-frame default period as a practical low-latency baseline. Replace the startup clock hold with a one-sided proportional acquisition controller, then hand off to source/device rate feed-forward and a slow phase loop. Calibrate the logical device timeline at handoff, discard correction that opposes the current error, and slew-limit rate changes. This prevents startup drain, integral wind-up, overshoot, and long convergence while preserving clock-drift compensation. Allow audio backends to expose a real-time resampler and use PipeWire's adaptive resampler when version 1.4 or newer supports it. Retain libsamplerate as the fallback and add audio:resampler to select the implementation. Wait for PipeWire stream setup to complete and propagate rate-control failures cleanly. Track PipeWire input-consumption and output-equivalent clocks separately. The input clock measures ring latency while the output clock drives feed-forward using the ratio that governed each request. This removes delayed self-feedback that made adaptive resampling oscillate between the correction limits. Reduce audio:debug output to useful latency, clock, jitter, and xrun values, and scale the playback graph from the startup estimate. Update the option names and documentation for the new latency model.
This commit is contained in:
@@ -45,10 +45,13 @@ struct LG_AudioDevOps
|
||||
struct
|
||||
{
|
||||
/* setup the stream for playback but don't start it yet, returning false
|
||||
* if the stream could not be configured
|
||||
* if the stream could not be configured. If backend resampling is
|
||||
* requested, resamplerEnabled reports whether it was activated for this
|
||||
* stream.
|
||||
* Note: the pull function returns f32 samples
|
||||
*/
|
||||
bool (*setup)(int channels, int sampleRate, int requestedPeriodFrames,
|
||||
bool requestResampler, bool * resamplerEnabled,
|
||||
int * maxPeriodFrames, int * startFrames, LG_AudioPullFn pullFn);
|
||||
|
||||
/* called when there is data available to start playback */
|
||||
@@ -63,6 +66,10 @@ struct LG_AudioDevOps
|
||||
/* [optional] called to set muting of the output */
|
||||
void (*mute)(bool mute);
|
||||
|
||||
/* [optional] update the active backend resampler's output/input ratio.
|
||||
* Called from the backend's playback callback and must be realtime safe. */
|
||||
bool (*setRate)(double ratio);
|
||||
|
||||
/* return the current total playback latency in microseconds */
|
||||
uint64_t (*latency)(void);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user