resampler: Add pa_resampler_prepare() and pa_resampler_get_delay() functions

The pa_resampler_get_delay() function allows to retrieve the current resampler
delay in input samples for all supported resamplers. The return value is a double
to maintain precision when using variable rate resamplers. Because in many places
the delay is needed in usec, pa_resampler_get_delay_usec() was also supplied.

The speex resampler now skips leading zero samples to provide meaningful delay values.

In the next patch, the pa_resampler_prepare() function will be used to train the
resampler after a rewind. It takes data from a history memblockq and runs it through
the resampler. The output data is discarded.

To make this logic possible, the soxr resampler had to be converted to use variable
rate. The fixed rate version has a variable delay, therefore the logic above could
not be applied. Additionally, with fixed rate, the delay is larger than 150ms in
some situations, while with variable rate the delay is fixed and comparable to the
other resamplers.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/120>
This commit is contained in:
Georg Chini 2021-01-01 00:22:11 +01:00 committed by PulseAudio Marge Bot
parent 1bfabd6512
commit 656179a8fe
6 changed files with 142 additions and 28 deletions

View file

@ -876,7 +876,7 @@ void pa_source_output_process_rewind(pa_source_output *o, size_t nbytes /* in so
o->process_rewind(o, nbytes);
if (o->thread_info.resampler)
pa_resampler_rewind(o->thread_info.resampler, nbytes);
pa_resampler_rewind(o->thread_info.resampler, nbytes, NULL, 0);
} else
pa_memblockq_seek(o->thread_info.delay_memblockq, - ((int64_t) nbytes), PA_SEEK_RELATIVE, true);
@ -1701,6 +1701,7 @@ int pa_source_output_process_msg(pa_msgobject *mo, int code, void *userdata, int
pa_usec_t *r = userdata;
r[0] += pa_bytes_to_usec(pa_memblockq_get_length(o->thread_info.delay_memblockq), &o->source->sample_spec);
r[0] += pa_resampler_get_delay_usec(o->thread_info.resampler);
r[1] += pa_source_get_latency_within_thread(o->source, false);
return 0;