[FFmpeg-devel] [PATCH] Use LCG to generate random data for dither instead of CPU-intesive LFG.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Apr 25 20:42:21 CEST 2011


I am not able to hear any difference.
Differences in FATE tests:
AC3:
stddev:    4.91 PSNR: 82.50 MAXDIFF:   55 bytes:   804864/   804864
stddev:    0.28 PSNR:107.16 MAXDIFF:    2 bytes:  1032192/  1032192

EAC3:
stddev:   20.26 PSNR: 70.20 MAXDIFF: 1054 bytes:   884736/   884736
stddev:   13.27 PSNR: 73.87 MAXDIFF:  215 bytes:  2998272/  2998272
stddev:    5.93 PSNR: 80.87 MAXDIFF:  100 bytes:   804864/   804864
(no difference in fourth test)
---
 libavcodec/ac3dec.c  |    9 +++++----
 libavcodec/ac3dec.h  |    2 +-
 libavcodec/eac3dec.c |    6 ++++--
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 431f67d..747a7d8 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -183,7 +183,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
     dsputil_init(&s->dsp, avctx);
     ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
     ff_fmt_convert_init(&s->fmt_conv, avctx);
-    av_lfg_init(&s->dith_state, 0);
+    s->dith_state = 0x79381c11;
 
     /* allow downmixing to stereo or mono */
     if (avctx->channels > 0 && avctx->request_channels > 0 &&
@@ -448,9 +448,10 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
         int mantissa;
         switch(bap){
             case 0:
-                if (dither)
-                    mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
-                else
+                if (dither) {
+                    mantissa = s->dith_state >> 9;
+                    s->dith_state = s->dith_state * 1664525 + 1013904223;
+                } else
                     mantissa = 0;
                 break;
             case 1:
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 91008e5..f8dbe1a 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -184,7 +184,7 @@ typedef struct {
 
 ///@defgroup dithering zero-mantissa dithering
     int dither_flag[AC3_MAX_CHANNELS];      ///< dither flags                           (dithflg)
-    AVLFG dith_state;                       ///< for dither generation
+    int32_t dith_state;                     ///< for dither generation
 ///@}
 
 ///@defgroup imdct IMDCT
diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c
index 40f571f..ecc0224 100644
--- a/libavcodec/eac3dec.c
+++ b/libavcodec/eac3dec.c
@@ -143,7 +143,8 @@ void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
             float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f/(1<<31));
             float sscale = s->spx_signal_blend[ch][bnd];
             for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
-                float noise  = nscale * (int32_t)av_lfg_get(&s->dith_state);
+                float noise  = nscale * s->dith_state;
+                s->dith_state = s->dith_state * 1664525 + 1013904223;
                 s->transform_coeffs[ch][bin]   *= sscale;
                 s->transform_coeffs[ch][bin++] += noise;
             }
@@ -241,7 +242,8 @@ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
         if (!hebap) {
             /* zero-mantissa dithering */
             for (blk = 0; blk < 6; blk++) {
-                s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
+                s->pre_mantissa[ch][bin][blk] = s->dith_state >> 9;
+                s->dith_state = s->dith_state * 1664525 + 1013904223;
             }
         } else if (hebap < 8) {
             /* Vector Quantization */
-- 
1.7.4.4



More information about the ffmpeg-devel mailing list