diff options
author | Rostislav Pehlivanov <atomnuker@gmail.com> | 2015-12-14 21:53:09 +0300 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2015-12-14 21:53:09 +0300 |
commit | ade31b9424f6bb8f70f277b1acb4575d312ed955 (patch) | |
tree | dfbf76b662cccb5001b39c0c2e27379852e11cdb | |
parent | 932cbc846f5574ed6b775a0fd586e70b5c8f84a2 (diff) |
aacenc: switch to using the RNG from libavutil
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>
-rw-r--r-- | libavcodec/aaccoder.c | 8 | ||||
-rw-r--r-- | libavcodec/aacenc.c | 2 | ||||
-rw-r--r-- | libavcodec/aacenc.h | 2 | ||||
-rw-r--r-- | libavcodec/aacenc_utils.h | 10 |
4 files changed, 9 insertions, 13 deletions
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index 7e55494fe6..15d467b870 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -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]); diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 3406f43e2e..ec09063e84 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -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); diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h index d8bed82abe..2b721d374f 100644 --- a/libavcodec/aacenc.h +++ b/libavcodec/aacenc.h @@ -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 diff --git a/libavcodec/aacenc_utils.h b/libavcodec/aacenc_utils.h index 5b308f2efe..736e4a06da 100644 --- a/libavcodec/aacenc_utils.h +++ b/libavcodec/aacenc_utils.h @@ -183,16 +183,6 @@ static av_always_inline float bval2bmax(float b) } /* - * 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 * map to valid, nonzero bands of the form w*16+g (with w being the initial |