Commit 7d485f16 authored by Siarhei Siamashka's avatar Siarhei Siamashka
Browse files

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
parent 3ac56e28
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
}
/**
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
......
......@@ -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");
......
......@@ -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;
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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]);
......
......@@ -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) {
......
......@@ -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),
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment