[pulseaudio-discuss] [PATCH 10/13] loopback: Added a deadband to reduce rate hunting

Tanu Kaskinen tanuk at iki.fi
Tue Dec 8 14:04:28 PST 2015


On Wed, 2015-02-25 at 19:43 +0100, Georg Chini wrote:
> With USB or Bluetooth sources, the controller exhibited random
> deviations of new_rate around the correct value, due to latency jitter.
> Use the already-known latency error due to jitter, and assume that there
> is no latency difference if the difference is below that error margin.
> ---
>  src/modules/module-loopback.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
> index b733663..6b48fc6 100644
> --- a/src/modules/module-loopback.c
> +++ b/src/modules/module-loopback.c
> @@ -183,12 +183,12 @@ static void teardown(struct userdata *u) {
>  /* rate controller
>   * - maximum deviation from base rate is less than 1%
>   * - can create audible artifacts by changing the rate too quickly
> - * - exhibits hunting with USB or Bluetooth sources
> + * - deadband to handle error of latency measurement
>   */
>  static uint32_t rate_controller(
>                  uint32_t base_rate,
>                  pa_usec_t adjust_time,
> -                int32_t latency_difference_usec) {
> +                int32_t latency_difference_usec, pa_usec_t latency_error_usec) {
>  
>      uint32_t new_rate;
>      double min_cycles;
> @@ -198,6 +198,10 @@ static uint32_t rate_controller(
>      min_cycles = (double)abs(latency_difference_usec) / adjust_time / 0.0095 + 1;
>      new_rate = base_rate * (1.0 + (double)latency_difference_usec / min_cycles / adjust_time);
>  
> +    /* Adjust as good as physics allows (with some safety margin) */
> +    if (abs(latency_difference_usec) <= 2.5 * latency_error_usec + adjust_time / 2 / base_rate + 100)
> +       new_rate = base_rate;

There's that magic number 2.5 again...

What's that "adjust_time / 2 / base_rate"? The unit of that is seconds
squared, doesn't make sense to me...

Are you claiming that this results in adjustment that is as close to
optimal as physics allows? If so, what's the basis for that claim?

-- 
Tanu


More information about the pulseaudio-discuss mailing list