]> git.sesse.net Git - ffmpeg/commitdiff
iir: change filter type if/else to a switch.
authorJustin Ruggles <justin.ruggles@gmail.com>
Thu, 20 Jan 2011 21:59:23 +0000 (21:59 +0000)
committerMans Rullgard <mans@mansr.com>
Thu, 20 Jan 2011 23:55:21 +0000 (23:55 +0000)
Simplifies error handling and makes it easier to add additional filter types.

Signed-off-by: Mans Rullgard <mans@mansr.com>
libavcodec/iirfilter.c

index 085482032b2e76162ef03801d43cb1311bd3e45b..6133a5405519126f53c4b311822627123354512d 100644 (file)
@@ -164,6 +164,7 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
                                                 float stopband, float ripple)
 {
     FFIIRFilterCoeffs *c;
+    int ret = 0;
 
     if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0)
         return NULL;
@@ -176,22 +177,22 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
                       init_fail);
     c->order = order;
 
-    if (filt_type == FF_FILTER_TYPE_BUTTERWORTH) {
-        if (butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
-            stopband)) {
-            goto init_fail;
-        }
-    } else if (filt_type == FF_FILTER_TYPE_BIQUAD) {
-        if (biquad_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
-            stopband)) {
-            goto init_fail;
-        }
-    } else {
+    switch (filt_type) {
+    case FF_FILTER_TYPE_BUTTERWORTH:
+        ret = butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
+                                      stopband);
+        break;
+    case FF_FILTER_TYPE_BIQUAD:
+        ret = biquad_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
+                                 stopband);
+        break;
+    default:
         av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n");
         goto init_fail;
     }
 
-    return c;
+    if (!ret)
+        return c;
 
 init_fail:
     ff_iir_filter_free_coeffs(c);