Mercurial > libavcodec.hg
comparison mdct.c @ 9658:67a20f0eb42c libavcodec
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.
author | serge |
---|---|
date | Sat, 16 May 2009 14:17:08 +0000 |
parents | d527872fdf26 |
children | 50ec8930f99e |
comparison
equal
deleted
inserted
replaced
9657:8a65ae8929fb | 9658:67a20f0eb42c |
---|---|
66 } | 66 } |
67 | 67 |
68 /** | 68 /** |
69 * init MDCT or IMDCT computation. | 69 * init MDCT or IMDCT computation. |
70 */ | 70 */ |
71 av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse) | 71 av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale) |
72 { | 72 { |
73 int n, n4, i; | 73 int n, n4, i; |
74 double alpha; | 74 double alpha, theta; |
75 | 75 |
76 memset(s, 0, sizeof(*s)); | 76 memset(s, 0, sizeof(*s)); |
77 n = 1 << nbits; | 77 n = 1 << nbits; |
78 s->nbits = nbits; | 78 s->nbits = nbits; |
79 s->n = n; | 79 s->n = n; |
83 goto fail; | 83 goto fail; |
84 s->tsin = av_malloc(n4 * sizeof(FFTSample)); | 84 s->tsin = av_malloc(n4 * sizeof(FFTSample)); |
85 if (!s->tsin) | 85 if (!s->tsin) |
86 goto fail; | 86 goto fail; |
87 | 87 |
88 theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0); | |
89 scale = sqrt(fabs(scale)); | |
88 for(i=0;i<n4;i++) { | 90 for(i=0;i<n4;i++) { |
89 alpha = 2 * M_PI * (i + 1.0 / 8.0) / n; | 91 alpha = 2 * M_PI * (i + theta) / n; |
90 s->tcos[i] = -cos(alpha); | 92 s->tcos[i] = -cos(alpha) * scale; |
91 s->tsin[i] = -sin(alpha); | 93 s->tsin[i] = -sin(alpha) * scale; |
92 } | 94 } |
93 if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0) | 95 if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0) |
94 goto fail; | 96 goto fail; |
95 return 0; | 97 return 0; |
96 fail: | 98 fail: |