Optimize decodeplane32().
[ffmpeg.git] / libavcodec / iirfilter.c
index dc78c7f..90af431 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 /**
- * @file libavcodec/iirfilter.c
+ * @file
  * different IIR filters implementation
  */
 
@@ -47,7 +47,7 @@ typedef struct FFIIRFilterState{
 /// maximum supported filter order
 #define MAXORDER 30
 
-struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(enum IIRFilterType filt_type,
+av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(enum IIRFilterType filt_type,
                                                     enum IIRFilterMode filt_mode,
                                                     int order, float cutoff_ratio,
                                                     float stopband, float ripple)
@@ -112,7 +112,7 @@ struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(enum IIRFilterType filt_type
     return c;
 }
 
-struct FFIIRFilterState* ff_iir_filter_init_state(int order)
+av_cold struct FFIIRFilterState* ff_iir_filter_init_state(int order)
 {
     FFIIRFilterState* s = av_mallocz(sizeof(FFIIRFilterState) + sizeof(s->x[0]) * (order - 1));
     return s;
@@ -163,12 +163,12 @@ void ff_iir_filter(const struct FFIIRFilterCoeffs *c, struct FFIIRFilterState *s
     }
 }
 
-void ff_iir_filter_free_state(struct FFIIRFilterState *state)
+av_cold void ff_iir_filter_free_state(struct FFIIRFilterState *state)
 {
     av_free(state);
 }
 
-void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs)
+av_cold void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs)
 {
     if(coeffs){
         av_free(coeffs->cx);
@@ -177,3 +177,39 @@ void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs)
     av_free(coeffs);
 }
 
+#ifdef TEST
+#define FILT_ORDER 4
+#define SIZE 1024
+int main(void)
+{
+    struct FFIIRFilterCoeffs *fcoeffs = NULL;
+    struct FFIIRFilterState  *fstate  = NULL;
+    float cutoff_coeff = 0.4;
+    int16_t x[SIZE], y[SIZE];
+    int i;
+    FILE* fd;
+
+    fcoeffs = ff_iir_filter_init_coeffs(FF_FILTER_TYPE_BUTTERWORTH,
+                                        FF_FILTER_MODE_LOWPASS, FILT_ORDER,
+                                        cutoff_coeff, 0.0, 0.0);
+    fstate  = ff_iir_filter_init_state(FILT_ORDER);
+
+    for (i = 0; i < SIZE; i++) {
+        x[i] = lrint(0.75 * INT16_MAX * sin(0.5*M_PI*i*i/SIZE));
+    }
+
+    ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1);
+
+    fd = fopen("in.bin", "w");
+    fwrite(x, sizeof(x[0]), SIZE, fd);
+    fclose(fd);
+
+    fd = fopen("out.bin", "w");
+    fwrite(y, sizeof(y[0]), SIZE, fd);
+    fclose(fd);
+
+    ff_iir_filter_free_coeffs(fcoeffs);
+    ff_iir_filter_free_state(fstate);
+    return 0;
+}
+#endif /* TEST */