# HG changeset patch # User serge # Date 1242483428 0 # Node ID 67a20f0eb42cd1bca2c4282e564df27cd1f9b792 # Parent 8a65ae8929fb790866c64f2066658549f58bd3ee Support for getting (i)MDCT output multiplied by a constant scaling factor. Scaling (i)MDCT output has no runtime overhead and can be used to improve performance of audio codecs. All the changes are only needed in 'ff_mdct_init' function and slow down initialization a bit. diff -r 8a65ae8929fb -r 67a20f0eb42c aac.c --- a/aac.c Sat May 16 06:39:08 2009 +0000 +++ b/aac.c Sat May 16 14:17:08 2009 +0000 @@ -500,8 +500,8 @@ ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), 352); - ff_mdct_init(&ac->mdct, 11, 1); - ff_mdct_init(&ac->mdct_small, 8, 1); + ff_mdct_init(&ac->mdct, 11, 1, 1.0); + ff_mdct_init(&ac->mdct_small, 8, 1, 1.0); // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); diff -r 8a65ae8929fb -r 67a20f0eb42c aacenc.c --- a/aacenc.c Sat May 16 06:39:08 2009 +0000 +++ b/aacenc.c Sat May 16 14:17:08 2009 +0000 @@ -214,8 +214,8 @@ s->samplerate_index = i; dsputil_init(&s->dsp, avctx); - ff_mdct_init(&s->mdct1024, 11, 0); - ff_mdct_init(&s->mdct128, 8, 0); + ff_mdct_init(&s->mdct1024, 11, 0, 1.0); + ff_mdct_init(&s->mdct128, 8, 0, 1.0); // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); diff -r 8a65ae8929fb -r 67a20f0eb42c ac3dec.c --- a/ac3dec.c Sat May 16 06:39:08 2009 +0000 +++ b/ac3dec.c Sat May 16 14:17:08 2009 +0000 @@ -194,8 +194,8 @@ ac3_common_init(); ac3_tables_init(); - ff_mdct_init(&s->imdct_256, 8, 1); - ff_mdct_init(&s->imdct_512, 9, 1); + ff_mdct_init(&s->imdct_256, 8, 1, 1.0); + ff_mdct_init(&s->imdct_512, 9, 1, 1.0); ff_kbd_window_init(s->window, 5.0, 256); dsputil_init(&s->dsp, avctx); av_lfg_init(&s->dith_state, 0); diff -r 8a65ae8929fb -r 67a20f0eb42c atrac3.c --- a/atrac3.c Sat May 16 06:39:08 2009 +0000 +++ b/atrac3.c Sat May 16 14:17:08 2009 +0000 @@ -268,7 +268,7 @@ } /* Initialize the MDCT transform. */ - ff_mdct_init(&mdct_ctx, 9, 1); + ff_mdct_init(&mdct_ctx, 9, 1, 1.0); } /** diff -r 8a65ae8929fb -r 67a20f0eb42c cook.c --- a/cook.c Sat May 16 06:39:08 2009 +0000 +++ b/cook.c Sat May 16 14:17:08 2009 +0000 @@ -259,7 +259,7 @@ q->mlt_window[j] *= sqrt(2.0 / q->samples_per_channel); /* Initialize the MDCT. */ - if (ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size)+1, 1)) { + if (ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size)+1, 1, 1.0)) { av_free(q->mlt_window); return -1; } diff -r 8a65ae8929fb -r 67a20f0eb42c dca.c --- a/dca.c Sat May 16 06:39:08 2009 +0000 +++ b/dca.c Sat May 16 14:17:08 2009 +0000 @@ -1318,7 +1318,7 @@ dca_init_vlcs(); dsputil_init(&s->dsp, avctx); - ff_mdct_init(&s->imdct, 6, 1); + ff_mdct_init(&s->imdct, 6, 1, 1.0); for(i = 0; i < 6; i++) s->samples_chanptr[i] = s->samples + i * 256; diff -r 8a65ae8929fb -r 67a20f0eb42c dsputil.h --- a/dsputil.h Sat May 16 06:39:08 2009 +0000 +++ b/dsputil.h Sat May 16 14:17:08 2009 +0000 @@ -771,7 +771,7 @@ extern float ff_sine_4096[4096]; extern float *ff_sine_windows[6]; -int ff_mdct_init(MDCTContext *s, int nbits, int inverse); +int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale); void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input); void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input); void ff_imdct_calc_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input); diff -r 8a65ae8929fb -r 67a20f0eb42c fft-test.c --- a/fft-test.c Sat May 16 06:39:08 2009 +0000 +++ b/fft-test.c Sat May 16 14:17:08 2009 +0000 @@ -223,7 +223,7 @@ av_log(NULL, AV_LOG_INFO,"IMDCT"); else av_log(NULL, AV_LOG_INFO,"MDCT"); - ff_mdct_init(m, fft_nbits, do_inverse); + ff_mdct_init(m, fft_nbits, do_inverse, 1.0); } else { if (do_inverse) av_log(NULL, AV_LOG_INFO,"IFFT"); diff -r 8a65ae8929fb -r 67a20f0eb42c mdct.c --- a/mdct.c Sat May 16 06:39:08 2009 +0000 +++ b/mdct.c Sat May 16 14:17:08 2009 +0000 @@ -68,10 +68,10 @@ /** * init MDCT or IMDCT computation. */ -av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse) +av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale) { int n, n4, i; - double alpha; + double alpha, theta; memset(s, 0, sizeof(*s)); n = 1 << nbits; @@ -85,10 +85,12 @@ if (!s->tsin) goto fail; + theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0); + scale = sqrt(fabs(scale)); for(i=0;itcos[i] = -cos(alpha); - s->tsin[i] = -sin(alpha); + alpha = 2 * M_PI * (i + theta) / n; + s->tcos[i] = -cos(alpha) * scale; + s->tsin[i] = -sin(alpha) * scale; } if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0) goto fail; diff -r 8a65ae8929fb -r 67a20f0eb42c nellymoserdec.c --- a/nellymoserdec.c Sat May 16 06:39:08 2009 +0000 +++ b/nellymoserdec.c Sat May 16 14:17:08 2009 +0000 @@ -130,7 +130,7 @@ s->avctx = avctx; av_lfg_init(&s->random_state, ff_random_get_seed()); - ff_mdct_init(&s->imdct_ctx, 8, 1); + ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); dsputil_init(&s->dsp, avctx); diff -r 8a65ae8929fb -r 67a20f0eb42c nellymoserenc.c --- a/nellymoserenc.c Sat May 16 06:39:08 2009 +0000 +++ b/nellymoserenc.c Sat May 16 14:17:08 2009 +0000 @@ -145,7 +145,7 @@ avctx->frame_size = NELLY_SAMPLES; s->avctx = avctx; - ff_mdct_init(&s->mdct_ctx, 8, 0); + ff_mdct_init(&s->mdct_ctx, 8, 0, 1.0); dsputil_init(&s->dsp, avctx); /* Generate overlap window */ diff -r 8a65ae8929fb -r 67a20f0eb42c vorbis_dec.c --- a/vorbis_dec.c Sat May 16 06:39:08 2009 +0000 +++ b/vorbis_dec.c Sat May 16 14:17:08 2009 +0000 @@ -896,8 +896,8 @@ vc->saved = av_mallocz((vc->blocksize[1]/4)*vc->audio_channels * sizeof(float)); vc->previous_window=0; - ff_mdct_init(&vc->mdct[0], bl0, 1); - ff_mdct_init(&vc->mdct[1], bl1, 1); + ff_mdct_init(&vc->mdct[0], bl0, 1, 1.0); + ff_mdct_init(&vc->mdct[1], bl1, 1, 1.0); AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); diff -r 8a65ae8929fb -r 67a20f0eb42c vorbis_enc.c --- a/vorbis_enc.c Sat May 16 06:39:08 2009 +0000 +++ b/vorbis_enc.c Sat May 16 14:17:08 2009 +0000 @@ -359,8 +359,8 @@ venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; - ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0); - ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0); + ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0); + ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0); } static void put_float(PutBitContext * pb, float f) { diff -r 8a65ae8929fb -r 67a20f0eb42c wmadec.c --- a/wmadec.c Sat May 16 06:39:08 2009 +0000 +++ b/wmadec.c Sat May 16 14:17:08 2009 +0000 @@ -110,7 +110,7 @@ /* init MDCT */ for(i = 0; i < s->nb_block_sizes; i++) - ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1); + ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1, 1.0); if (s->use_noise_coding) { init_vlc(&s->hgain_vlc, HGAINVLCBITS, sizeof(ff_wma_hgain_huffbits), diff -r 8a65ae8929fb -r 67a20f0eb42c wmaenc.c --- a/wmaenc.c Sat May 16 06:39:08 2009 +0000 +++ b/wmaenc.c Sat May 16 14:17:08 2009 +0000 @@ -63,7 +63,7 @@ /* init MDCT */ for(i = 0; i < s->nb_block_sizes; i++) - ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0); + ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0); avctx->block_align= s->block_align= avctx->bit_rate*(int64_t)s->frame_len / (avctx->sample_rate*8);