[FFmpeg-devel] [PATCH] ac3dec: fix non-optimal dithering of zero bit mantissas

Michael Niedermayer michaelni at gmx.at
Sat Jan 5 22:06:17 CET 2013


On Sat, Jan 05, 2013 at 11:37:55AM +0100, madshi wrote:
> Hey guys,
> 
> the latest revision of the (E-)AC3 spec says:
> 
> > The optimum scaling for the dither words is to take a
> > uniform distribution of values between –1 and +1, and
> > scale this by 0.707, resulting in a uniform distribution
> > between +0.707 and –0.707
> 
> Currently the AC3 decoder applies a dithering of only +0.5 .. -0.5.
> According to the spec this is "also acceptable", but it's not the "optimum
> scaling". The effects of this non-optimal dithering are clearly visible in
> frequency graphs. Basically high frequencies are lower in volume than they
> should be. You can test this yourself by looking at the following files:
> 
> http://madshi.net/libavAc3Fix.rar
> 
> Load the WAV files into Audacity, then for each WAV in the Audacity menu
> choose "analyze -> frequency analyzis". You can see that the "azid" and
> "liba52" decoders have a better high frequency response than the "libav"
> decoder. However, look at "libav_patched" which shows the results when
> using the proper amount of dithering in the libav AC3 decoder.
> 
> Attached is a patch which modifies the AC3 decoder to apply the optimum
> dithering.
> 
> (av_lfg_get() does return values in the range 0..FFFFFFFF, correct?)
> 
> Best regards, Mathias.

> diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
> index ea4a218..a30b123 100644
> --- a/libavcodec/ac3dec.c
> +++ b/libavcodec/ac3dec.c
> @@ -442,7 +442,7 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
>          switch (bap) {
>          case 0:
>              if (dither)
> -                mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
> +                mantissa = (av_lfg_get(&s->dith_state) / 362) - 5932275;

divisions are slow, i would suggest:

mantissa = (((av_lfg_get(&s->dith_state)>>8)*181)>>8) - 5931008

(untested, thus testing is needed and welcome)

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130105/69521611/attachment.asc>


More information about the ffmpeg-devel mailing list