summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Swain <robert.swain@gmail.com>2008-06-22 15:12:27 +0000
committerRobert Swain <robert.swain@gmail.com>2008-06-22 15:12:27 +0000
commit9146e4d61c9de8fb86a7a9837705a0ad48fc547d (patch)
tree9a388e3225b3b770b2c2f3a26767fca52cf19079
parentd47f16074ff4678d0ea968318354fc8ca6e0ba90 (diff)
Add generic ff_sine_window_init function and implement in codecs appropriately
Originally committed as revision 13888 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/cook.c4
-rw-r--r--libavcodec/dsputil.h7
-rw-r--r--libavcodec/imc.c3
-rw-r--r--libavcodec/mdct.c7
-rw-r--r--libavcodec/nellymoserdec.c4
5 files changed, 19 insertions, 6 deletions
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index fa945ec841..6661ee4979 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -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)) {
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index cd9ae08211..0316a451b3 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -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);
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 80372b82b4..934de4a6a9 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -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);
diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c
index c51f809714..07eef2b3d4 100644
--- a/libavcodec/mdct.c
+++ b/libavcodec/mdct.c
@@ -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.
*/
diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index 5db963ebcf..b30400b680 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -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;
}