aacenc: switch to using the RNG from libavutil
authorRostislav Pehlivanov <atomnuker@gmail.com>
Mon, 14 Dec 2015 18:53:09 +0000 (18:53 +0000)
committerRostislav Pehlivanov <atomnuker@gmail.com>
Mon, 14 Dec 2015 18:53:09 +0000 (18:53 +0000)
PSNR doesn't change as expected. The AAC spec doesn't really say
anything about how exactly to generate noise.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
libavcodec/aaccoder.c
libavcodec/aacenc.c
libavcodec/aacenc.h
libavcodec/aacenc_utils.h

index 7e55494fe6697f3e21277d1f78331da5995b8e93..15d467b8706d942327b5321e0fcbf7a311279ef4 100644 (file)
@@ -693,8 +693,12 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne
                 float band_energy, scale, pns_senergy;
                 const int start_c = (w+w2)*128+sce->ics.swb_offset[g];
                 band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
-                for (i = 0; i < sce->ics.swb_sizes[g]; i++)
-                    PNS[i] = s->random_state = lcg_random(s->random_state);
+                for (i = 0; i < sce->ics.swb_sizes[g]; i+=2) {
+                    double rnd[2];
+                    av_bmg_get(&s->lfg, rnd);
+                    PNS[i+0] = (float)rnd[0];
+                    PNS[i+1] = (float)rnd[1];
+                }
                 band_energy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]);
                 scale = noise_amp/sqrtf(band_energy);
                 s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]);
index 3406f43e2ed0733c270605c4694b1a90d94f8dcc..ec09063e84b9d1707b220fa17bc44a6ba2237d4f 100644 (file)
@@ -904,7 +904,6 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
 
     s->channels = avctx->channels;
     s->chan_map = aac_chan_configs[s->channels-1];
-    s->random_state = 0x1f2e3d4c;
     s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120;
     avctx->extradata_size = 5;
     avctx->frame_size = 1024;
@@ -997,6 +996,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
         goto fail;
     s->psypp = ff_psy_preprocess_init(avctx);
     ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON);
+    av_lfg_init(&s->lfg, 0x72adca55);
 
     if (HAVE_MIPSDSP)
         ff_aac_coder_init_mips(s);
index d8bed82abe7c789f46294635c71bcdd90e135679..2b721d374f48e870f11d807e3ba03edfe7a6aab4 100644 (file)
@@ -23,6 +23,7 @@
 #define AVCODEC_AACENC_H
 
 #include "libavutil/float_dsp.h"
+#include "libavutil/lfg.h"
 #include "avcodec.h"
 #include "put_bits.h"
 
@@ -100,6 +101,7 @@ typedef struct AACEncContext {
     FFTContext mdct1024;                         ///< long (1024 samples) frame transform context
     FFTContext mdct128;                          ///< short (128 samples) frame transform context
     AVFloatDSPContext *fdsp;
+    AVLFG lfg;                                   ///< PRNG needed for PNS
     float *planar_samples[8];                    ///< saved preprocessed input
 
     int profile;                                 ///< copied from avctx
index 5b308f2efe5ff796bdb0cb24e1c93bd5e248295b..736e4a06dadea0732390aeec14a99043002e61ac 100644 (file)
@@ -182,16 +182,6 @@ static av_always_inline float bval2bmax(float b)
     return 0.001f + 0.0035f * (b*b*b) / (15.5f*15.5f*15.5f);
 }
 
-/*
- * linear congruential pseudorandom number generator, copied from the decoder
- */
-static inline int lcg_random(unsigned previous_val)
-{
-    union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 };
-    return v.s;
-}
-
-
 /*
  * Compute a nextband map to be used with SF delta constraint utilities.
  * The nextband array should contain 128 elements, and positions that don't