sink-input: Implement resampler pseudo rewinding

System Internals / PulseAudio - Georg Chini [chini.tk] - 3 November 2021 18:37 UTC

This patch uses the two previous patches to implemnt pseudo-rewinding for the resamplers by feeding some old data into the resampler after a reset. This is necessary because PA is using external resamplers that do not implement rewinding.

To get exactly the same output data from the resampler after a rewind if possible, the matching period is calculated. This is the number of input samples that produces an integral number of output samples. After the matching period, the resampler state repeats. If the matching period is not too large, feeding history into the resampler will start at a point that is a multiple of the matching period back in time. Then the resampler will produce exactly the same samples.

The PA_RESAMPLER_MAX_HISTORY value has been replaced by PA_RESAMPLER_MAX_DELAY_USEC and the required number of history samples is calculated from the sink input sample rate. The number of history samples can be as large as about 12500.

This fixes glitches during volume changes when the sink runs on a rate different from the sink input rate.

Part-of:

da539ed33 sink-input: Implement resampler pseudo rewinding
src/pulsecore/resampler.c | 43 ++++++++++++++++
src/pulsecore/resampler.h | 13 ++++-
src/pulsecore/sink-input.c | 126 ++++++++++++++++++++++++++++++++++++++-------
3 files changed, 161 insertions(+), 21 deletions(-)

Upstream: cgit.freedesktop.org


  • Share