[MPlayer-dev-eng] [PATCH] af_pan: hard clipping, and more than 100% of source channels

Guillaume POIRIER poirierg at gmail.com
Sat Sep 3 09:40:09 CEST 2005


Hi,

On 9/3/05, Corey Hickey <bugfood-ml at fatooh.org> wrote:
> With af_pan it is currently possible to exceed the proper range of float
> values to be passed to the sound driver, resulting in unpleasant clicks.
> 
> $ mplayer file.mp3 -af pan=2:1:1:1:1
> 
> If attached a patch to use hard clipping the same way af_volume does,
> and to print a verbose-level message whenever it has to.

[..]


>        register float* tin = in;
>        for(k=0;k<nchi;k++)
>         x += tin[k] * s->level[j][k];
> -      out[j] = x;
> +      if(x > 1.0 || x < -1.0)
> +        af_msg(AF_MSG_VERBOSE, "[pan] Clipping out-of-range value: %f\n", x);
> +      out[j] = clamp(x, -1.0, 1.0);
>      }
>      out+= ncho;
>      in+= nchi;

It is not a good idea to use af_msg like this: it may cause a big
slowdown even when you do not use "-v".
Here's what Rich has to say about it:

<quote mode=dalias>
calling af_msg on each clipped sample could result in massive slowdown
even if -v isn't used. One approach would be to increment a counter
each time clipping occurs and then at the end print a message if
anything was clipped.
Also it's a waste to do both the if(x>1 || x<-1) and the clamp(),
since they probably both do the float comparisons.
It would be faster to do:

if (x>1.0) { clip++; out[j] = 1.0; } else if (x<-1.0) { clip++; out[j]
= -1.0; } else out[j] = x;
</quote>

Other than that, the rest of patch is Okay.

Guillaume
-- 
Reading doesn't hurt, really!
  -- Dominik 'Rathann' Mierzejewski




More information about the MPlayer-dev-eng mailing list