[FFmpeg-cvslog] r18855 - in trunk/libavcodec: aac.c aacenc.c ac3dec.c atrac3.c cook.c dca.c dsputil.h fft-test.c mdct.c nellymoserdec.c nellymoserenc.c vorbis_dec.c vorbis_enc.c wmadec.c wmaenc.c

serge subversion
Sat May 16 16:17:08 CEST 2009


Author: serge
Date: Sat May 16 16:17:08 2009
New Revision: 18855

Log:
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.

Modified:
   trunk/libavcodec/aac.c
   trunk/libavcodec/aacenc.c
   trunk/libavcodec/ac3dec.c
   trunk/libavcodec/atrac3.c
   trunk/libavcodec/cook.c
   trunk/libavcodec/dca.c
   trunk/libavcodec/dsputil.h
   trunk/libavcodec/fft-test.c
   trunk/libavcodec/mdct.c
   trunk/libavcodec/nellymoserdec.c
   trunk/libavcodec/nellymoserenc.c
   trunk/libavcodec/vorbis_dec.c
   trunk/libavcodec/vorbis_enc.c
   trunk/libavcodec/wmadec.c
   trunk/libavcodec/wmaenc.c

Modified: trunk/libavcodec/aac.c
==============================================================================
--- trunk/libavcodec/aac.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/aac.c	Sat May 16 16:17:08 2009	(r18855)
@@ -500,8 +500,8 @@ static av_cold int aac_decode_init(AVCod
         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);

Modified: trunk/libavcodec/aacenc.c
==============================================================================
--- trunk/libavcodec/aacenc.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/aacenc.c	Sat May 16 16:17:08 2009	(r18855)
@@ -214,8 +214,8 @@ static av_cold int aac_encode_init(AVCod
     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);

Modified: trunk/libavcodec/ac3dec.c
==============================================================================
--- trunk/libavcodec/ac3dec.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/ac3dec.c	Sat May 16 16:17:08 2009	(r18855)
@@ -194,8 +194,8 @@ static av_cold int ac3_decode_init(AVCod
 
     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);

Modified: trunk/libavcodec/atrac3.c
==============================================================================
--- trunk/libavcodec/atrac3.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/atrac3.c	Sat May 16 16:17:08 2009	(r18855)
@@ -268,7 +268,7 @@ static av_cold void init_atrac3_transfor
     }
 
     /* Initialize the MDCT transform. */
-    ff_mdct_init(&mdct_ctx, 9, 1);
+    ff_mdct_init(&mdct_ctx, 9, 1, 1.0);
 }
 
 /**

Modified: trunk/libavcodec/cook.c
==============================================================================
--- trunk/libavcodec/cook.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/cook.c	Sat May 16 16:17:08 2009	(r18855)
@@ -259,7 +259,7 @@ static av_cold int init_cook_mlt(COOKCon
         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;
     }

Modified: trunk/libavcodec/dca.c
==============================================================================
--- trunk/libavcodec/dca.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/dca.c	Sat May 16 16:17:08 2009	(r18855)
@@ -1318,7 +1318,7 @@ static av_cold int dca_decode_init(AVCod
     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;

Modified: trunk/libavcodec/dsputil.h
==============================================================================
--- trunk/libavcodec/dsputil.h	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/dsputil.h	Sat May 16 16:17:08 2009	(r18855)
@@ -771,7 +771,7 @@ extern float ff_sine_2048[2048];
 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);

Modified: trunk/libavcodec/fft-test.c
==============================================================================
--- trunk/libavcodec/fft-test.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/fft-test.c	Sat May 16 16:17:08 2009	(r18855)
@@ -223,7 +223,7 @@ int main(int argc, char **argv)
             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");

Modified: trunk/libavcodec/mdct.c
==============================================================================
--- trunk/libavcodec/mdct.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/mdct.c	Sat May 16 16:17:08 2009	(r18855)
@@ -68,10 +68,10 @@ av_cold void ff_sine_window_init(float *
 /**
  * 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 @@ av_cold int ff_mdct_init(MDCTContext *s,
     if (!s->tsin)
         goto fail;
 
+    theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0);
+    scale = sqrt(fabs(scale));
     for(i=0;i<n4;i++) {
-        alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;
-        s->tcos[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;

Modified: trunk/libavcodec/nellymoserdec.c
==============================================================================
--- trunk/libavcodec/nellymoserdec.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/nellymoserdec.c	Sat May 16 16:17:08 2009	(r18855)
@@ -130,7 +130,7 @@ static av_cold int decode_init(AVCodecCo
 
     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);
 

Modified: trunk/libavcodec/nellymoserenc.c
==============================================================================
--- trunk/libavcodec/nellymoserenc.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/nellymoserenc.c	Sat May 16 16:17:08 2009	(r18855)
@@ -145,7 +145,7 @@ static av_cold int encode_init(AVCodecCo
 
     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 */

Modified: trunk/libavcodec/vorbis_dec.c
==============================================================================
--- trunk/libavcodec/vorbis_dec.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/vorbis_dec.c	Sat May 16 16:17:08 2009	(r18855)
@@ -896,8 +896,8 @@ static int vorbis_parse_id_hdr(vorbis_co
     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]);

Modified: trunk/libavcodec/vorbis_enc.c
==============================================================================
--- trunk/libavcodec/vorbis_enc.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/vorbis_enc.c	Sat May 16 16:17:08 2009	(r18855)
@@ -359,8 +359,8 @@ static void create_vorbis_context(vorbis
     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) {

Modified: trunk/libavcodec/wmadec.c
==============================================================================
--- trunk/libavcodec/wmadec.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/wmadec.c	Sat May 16 16:17:08 2009	(r18855)
@@ -110,7 +110,7 @@ static int wma_decode_init(AVCodecContex
 
     /* 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),

Modified: trunk/libavcodec/wmaenc.c
==============================================================================
--- trunk/libavcodec/wmaenc.c	Sat May 16 12:29:55 2009	(r18854)
+++ trunk/libavcodec/wmaenc.c	Sat May 16 16:17:08 2009	(r18855)
@@ -63,7 +63,7 @@ static int encode_init(AVCodecContext * 
 
     /* 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);



More information about the ffmpeg-cvslog mailing list