[FFmpeg-devel] [PATCH 2/3] lavfi: EBU R.128 channel weights

Clément Bœsch ubitux at gmail.com
Sat Jan 19 01:35:48 CET 2013


On Fri, Jan 18, 2013 at 05:13:29AM +0000, sedacca at comcast.net wrote:
> Correct the recognition of channel layouts for good channel weight in
> the loudness computation.
> 
> This suggested patch is 2 of 3 for Ticket #2144 "libavfilter ebur128
> loudness inaccuracy, irregular time interval, LFE interference".
> This suggested patch supersedes the contribution of January 15, 2013
> in the thread “[PATCH] lavfi: EBU R.128 irreg time, ch weights, skip
> LFE” which combined multiple fixes in one patch.
> 
> ---
>  libavfilter/f_ebur128.c |   20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c
> index 85fddad..3e0cabc 100644
> --- a/libavfilter/f_ebur128.c
> +++ b/libavfilter/f_ebur128.c
> @@ -314,12 +314,15 @@ static int config_video_output(AVFilterLink *outlink)
>  static int config_audio_output(AVFilterLink *outlink)
>  {
>      int i;
> +    int idx_bitposn = 0;
>      AVFilterContext *ctx = outlink->src;
>      EBUR128Context *ebur128 = ctx->priv;
>      const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
>  
>  #define BACK_MASK (AV_CH_BACK_LEFT    |AV_CH_BACK_CENTER    |AV_CH_BACK_RIGHT| \
> -                   AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT)
> +                   AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
> +                   AV_CH_SIDE_LEFT                          |AV_CH_SIDE_RIGHT| \
> +                   AV_CH_SURROUND_DIRECT_LEFT               |AV_CH_SURROUND_DIRECT_RIGHT)

Assuming this extended mask indeed still focus on "back" outputs, ok.

>  
>      ebur128->nb_channels  = nb_channels;
>      ebur128->ch_weighting = av_calloc(nb_channels, sizeof(*ebur128->ch_weighting));
> @@ -328,13 +331,16 @@ static int config_audio_output(AVFilterLink *outlink)
>  
>      for (i = 0; i < nb_channels; i++) {
>  
> +        /* find the next bit that is set starting from the right */
> +        while ((outlink->channel_layout & 1ULL<<idx_bitposn) == 0 && idx_bitposn < 63)
> +            idx_bitposn++;
> +
>          /* channel weighting */
> -        if ((outlink->channel_layout & 1ULL<<i) == AV_CH_LOW_FREQUENCY)
> -            continue;
> -        if (outlink->channel_layout & 1ULL<<i & BACK_MASK)
> -            ebur128->ch_weighting[i] = 1.41;
> -        else
> -            ebur128->ch_weighting[i] = 1.0;
> +        ebur128->ch_weighting[i] = 1.0;
> +        if (1ULL<<idx_bitposn & AV_CH_LOW_FREQUENCY  ) ebur128->ch_weighting[i] = 0;
> +        if (1ULL<<idx_bitposn & AV_CH_LOW_FREQUENCY_2) ebur128->ch_weighting[i] = 0;
> +        if (1ULL<<idx_bitposn & BACK_MASK            ) ebur128->ch_weighting[i] = 1.41;

else if ?

> +        idx_bitposn++;
>  
>          /* bins buffer for the two integration window (400ms and 3s) */
>          ebur128->i400.cache[i]  = av_calloc(I400_BINS,  sizeof(*ebur128->i400.cache[0]));

This might be ok, but I'd like someone familiar with channel layouts to
comment on this; hint about the algo: this part of the code is mean to set
a channel weighting for some "classes" of channels: low frequency channels
are ignored (so ch weight = 0), back channels are emphased (weigthing
1.41), and the rest is unchanged (ch weight = 1).

I don't have more time for today (sorry), so please someone from the team
apply this if the above is verified.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130119/0af1c7d1/attachment.asc>


More information about the ffmpeg-devel mailing list