Add generic ff_sine_window_init function and implement in codecs appropriately
authorRobert Swain <robert.swain@gmail.com>
Sun, 22 Jun 2008 15:12:27 +0000 (15:12 +0000)
committerRobert Swain <robert.swain@gmail.com>
Sun, 22 Jun 2008 15:12:27 +0000 (15:12 +0000)
Originally committed as revision 13888 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/cook.c
libavcodec/dsputil.h
libavcodec/imc.c
libavcodec/mdct.c
libavcodec/nellymoserdec.c

index fa945ec..6661ee4 100644 (file)
@@ -239,9 +239,9 @@ static int init_cook_mlt(COOKContext *q) {
       return -1;
 
     /* Initialize the MLT window: simple sine window. */
-    alpha = M_PI / (2.0 * (float)mlt_size);
+    ff_sine_window_init(q->mlt_window, mlt_size);
     for(j=0 ; j<mlt_size ; j++)
-        q->mlt_window[j] = sin((j + 0.5) * alpha) * sqrt(2.0 / q->samples_per_channel);
+        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)) {
index cd9ae08..0316a45 100644 (file)
@@ -649,6 +649,13 @@ typedef struct MDCTContext {
  */
 void ff_kbd_window_init(float *window, float alpha, int n);
 
+/**
+ * Generate a sine window.
+ * @param   window  pointer to half window
+ * @param   n       size of half window
+ */
+void ff_sine_window_init(float *window, int n);
+
 int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
 void ff_imdct_calc(MDCTContext *s, FFTSample *output,
                 const FFTSample *input, FFTSample *tmp);
index 80372b8..934de4a 100644 (file)
@@ -102,8 +102,9 @@ static av_cold int imc_decode_init(AVCodecContext * avctx)
         q->old_floor[i] = 1.0;
 
     /* Build mdct window, a simple sine window normalized with sqrt(2) */
+    ff_sine_window_init(q->mdct_sine_window, COEFFS);
     for(i = 0; i < COEFFS; i++)
-        q->mdct_sine_window[i] = sin((i + 0.5) / 512.0 * M_PI) * sqrt(2.0);
+        q->mdct_sine_window[i] *= sqrt(2.0);
     for(i = 0; i < COEFFS/2; i++){
         q->post_cos[i] = cos(i / 256.0 * M_PI);
         q->post_sin[i] = sin(i / 256.0 * M_PI);
index c51f809..07eef2b 100644 (file)
@@ -48,6 +48,13 @@ void ff_kbd_window_init(float *window, float alpha, int n)
        window[i] = sqrt(local_window[i] / sum);
 }
 
+// Generate a sine window.
+void ff_sine_window_init(float *window, int n) {
+    int i;
+    for(i = 0; i < n; i++)
+        window[i] = sin((i + 0.5) / (2 * n) * M_PI);
+}
+
 /**
  * init MDCT or IMDCT computation.
  */
index 5db963e..b30400b 100644 (file)
@@ -148,9 +148,7 @@ static av_cold int decode_init(AVCodecContext * avctx) {
 
     /* Generate overlap window */
     if (!sine_window[0])
-        for (i=0 ; i<128; i++) {
-            sine_window[i] = sin((i + 0.5) / 256.0 * M_PI);
-        }
+        ff_sine_window_init(sine_window, 128);
 
     return 0;
 }