diff options
author | Benjamin Larsson <banan@ludd.ltu.se> | 2006-04-22 21:21:16 +0000 |
---|---|---|
committer | Benjamin Larsson <banan@ludd.ltu.se> | 2006-04-22 21:21:16 +0000 |
commit | 176c142abcbfda1cc161ca8614ab07dffe505349 (patch) | |
tree | 1c223633c8290062bcda1f9b5cd01d5f8ab57e0a /libavcodec/ac3enc.c | |
parent | c6f9e821c36feda62c7b26c42378d5d2040316bf (diff) | |
download | ffmpeg-176c142abcbfda1cc161ca8614ab07dffe505349.tar.gz |
Patch to generate the ac3 window, based on code by Justin Ruggles.
Originally committed as revision 5310 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ac3enc.c')
-rw-r--r-- | libavcodec/ac3enc.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 5ec8b4f5ac..a587c647b5 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -81,6 +81,51 @@ static inline int16_t fix15(float a) return v; } + +/** + * Generate a Kaiser Window. + */ +static void k_window_init(int alpha, double *window, int n, int iter) +{ + int j, k; + double a, x; + a = alpha * M_PI / n; + a = a*a; + for(k=0; k<n; k++) { + x = k * (n - k) * a; + window[k] = 1.0; + for(j=iter; j>0; j--) { + window[k] = (window[k] * x / (j*j)) + 1.0; + } + } +} + +/** + * Generate a Kaiser-Bessel Derived Window. + * @param alpha determines window shape + * @param window array to fill with window values + * @param iter number of iterations to use in BesselI0 + */ + +static void kbd_window_init(int alpha, int16_t *out_window, int iter) +{ + int k, n2; + double kwindow[256]; + double window[256]; + + n2 = 256; + k_window_init(alpha, kwindow, n2, iter); + window[0] = kwindow[0]; + for(k=1; k<n2; k++) { + window[k] = window[k-1] + kwindow[k]; + } + for(k=0; k<n2; k++) { + window[k] = sqrt(window[k] / (window[n2-1]+1)); + //out_window[k] = round(window[k]*((1<<15)-1)); //enable this for a rounded window + out_window[k] = fix15(window[k]); + } +} + static inline int calc_lowcomp1(int a, int b0, int b1) { if ((b0 + 256) == b1) { @@ -882,6 +927,8 @@ static int AC3_encode_init(AVCodecContext *avctx) ac3_common_init(); /* mdct init */ + kbd_window_init(5.0, ac3_window, 50); + fft_init(MDCT_NBITS - 2); for(i=0;i<N/4;i++) { alpha = 2 * M_PI * (i + 1.0 / 8.0) / (float)N; |