diff options
author | Siarhei Siamashka <siarhei.siamashka@gmail.com> | 2009-05-16 14:17:08 +0000 |
---|---|---|
committer | Siarhei Siamashka <siarhei.siamashka@gmail.com> | 2009-05-16 14:17:08 +0000 |
commit | 7d485f165f7f6313002da1fe67c2742f0fbb16c9 (patch) | |
tree | 87e68249904f3c5bc7dcfc05df2eea10fd318ea2 /libavcodec | |
parent | 3ac56e28b0a3fc84ccac9ac7e359f0f29567f8a0 (diff) | |
download | ffmpeg-7d485f165f7f6313002da1fe67c2742f0fbb16c9.tar.gz |
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.
Originally committed as revision 18855 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/aac.c | 4 | ||||
-rw-r--r-- | libavcodec/aacenc.c | 4 | ||||
-rw-r--r-- | libavcodec/ac3dec.c | 4 | ||||
-rw-r--r-- | libavcodec/atrac3.c | 2 | ||||
-rw-r--r-- | libavcodec/cook.c | 2 | ||||
-rw-r--r-- | libavcodec/dca.c | 2 | ||||
-rw-r--r-- | libavcodec/dsputil.h | 2 | ||||
-rw-r--r-- | libavcodec/fft-test.c | 2 | ||||
-rw-r--r-- | libavcodec/mdct.c | 12 | ||||
-rw-r--r-- | libavcodec/nellymoserdec.c | 2 | ||||
-rw-r--r-- | libavcodec/nellymoserenc.c | 2 | ||||
-rw-r--r-- | libavcodec/vorbis_dec.c | 4 | ||||
-rw-r--r-- | libavcodec/vorbis_enc.c | 4 | ||||
-rw-r--r-- | libavcodec/wmadec.c | 2 | ||||
-rw-r--r-- | libavcodec/wmaenc.c | 2 |
15 files changed, 26 insertions, 24 deletions
diff --git a/libavcodec/aac.c b/libavcodec/aac.c index 5427d7c672..25c74b8157 100644 --- a/libavcodec/aac.c +++ b/libavcodec/aac.c @@ -500,8 +500,8 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) { 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 --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index cdc8ba0405..5537b7eac4 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -214,8 +214,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) 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 --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index b3382bd120..7d9d0142df 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -194,8 +194,8 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) 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 --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 49a818e3a7..c0825cb5b5 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -268,7 +268,7 @@ static av_cold void init_atrac3_transforms(ATRAC3Context *q) { } /* Initialize the MDCT transform. */ - ff_mdct_init(&mdct_ctx, 9, 1); + ff_mdct_init(&mdct_ctx, 9, 1, 1.0); } /** diff --git a/libavcodec/cook.c b/libavcodec/cook.c index fa9dc2b7ce..b90949fb70 100644 --- a/libavcodec/cook.c +++ b/libavcodec/cook.c @@ -259,7 +259,7 @@ static av_cold int init_cook_mlt(COOKContext *q) { 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 --git a/libavcodec/dca.c b/libavcodec/dca.c index 1529fdd6b8..b42d3df083 100644 --- a/libavcodec/dca.c +++ b/libavcodec/dca.c @@ -1318,7 +1318,7 @@ static av_cold int dca_decode_init(AVCodecContext * avctx) 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 --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index 9dc89409c4..f54d74d285 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -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); diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c index 1cefa3202f..a1e436c11c 100644 --- a/libavcodec/fft-test.c +++ b/libavcodec/fft-test.c @@ -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"); diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c index 7bd4d77f68..8a42adb4f3 100644 --- a/libavcodec/mdct.c +++ b/libavcodec/mdct.c @@ -68,10 +68,10 @@ av_cold void ff_sine_window_init(float *window, int n) { /** * 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, int nbits, int inverse) 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; diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c index 98f0ec3224..a1f55266bf 100644 --- a/libavcodec/nellymoserdec.c +++ b/libavcodec/nellymoserdec.c @@ -130,7 +130,7 @@ static av_cold int decode_init(AVCodecContext * avctx) { 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 --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c index 1bb6c666ab..52ee2bc03b 100644 --- a/libavcodec/nellymoserenc.c +++ b/libavcodec/nellymoserenc.c @@ -145,7 +145,7 @@ static av_cold int encode_init(AVCodecContext *avctx) 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 --git a/libavcodec/vorbis_dec.c b/libavcodec/vorbis_dec.c index b304e7be8f..f7b10e61b3 100644 --- a/libavcodec/vorbis_dec.c +++ b/libavcodec/vorbis_dec.c @@ -896,8 +896,8 @@ static int vorbis_parse_id_hdr(vorbis_context *vc){ 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 --git a/libavcodec/vorbis_enc.c b/libavcodec/vorbis_enc.c index 9c91859abe..b6533aca53 100644 --- a/libavcodec/vorbis_enc.c +++ b/libavcodec/vorbis_enc.c @@ -359,8 +359,8 @@ static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * av 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 --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c index 67d934f0f4..e06990230a 100644 --- a/libavcodec/wmadec.c +++ b/libavcodec/wmadec.c @@ -110,7 +110,7 @@ static int wma_decode_init(AVCodecContext * avctx) /* 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 --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c index a8ba6b0b66..95e5929c7d 100644 --- a/libavcodec/wmaenc.c +++ b/libavcodec/wmaenc.c @@ -63,7 +63,7 @@ static int encode_init(AVCodecContext * avctx){ /* 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); |