[FFmpeg-cvslog] Split out Butterworth filter coeff init to a separate function.
Justin Ruggles
git
Fri Jan 21 20:40:03 CET 2011
ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Jan 20 19:06:15 2011 +0000| [2293b0b698ce44d34897cc092bf1eb6b3571b7f8] | committer: Michael Niedermayer
Split out Butterworth filter coeff init to a separate function.
Signed-off-by: Mans Rullgard <mans at mansr.com>
(cherry picked from commit 30112adadf06fe2f9500e4da365eb8a58095c940)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2293b0b698ce44d34897cc092bf1eb6b3571b7f8
---
libavcodec/iirfilter.c | 64 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
index 38c0808..c0ac947 100644
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@ -47,29 +47,25 @@ typedef struct FFIIRFilterState{
/// maximum supported filter order
#define MAXORDER 30
-av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
- enum IIRFilterType filt_type,
- enum IIRFilterMode filt_mode,
- int order, float cutoff_ratio,
- float stopband, float ripple)
+static int butterworth_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
+ enum IIRFilterMode filt_mode,
+ int order, float cutoff_ratio,
+ float stopband)
{
int i, j;
- FFIIRFilterCoeffs *c;
double wa;
double p[MAXORDER + 1][2];
- if(filt_type != FF_FILTER_TYPE_BUTTERWORTH || filt_mode != FF_FILTER_MODE_LOWPASS)
- return NULL;
- if(order <= 1 || (order & 1) || order > MAXORDER || cutoff_ratio >= 1.0)
- return NULL;
-
- FF_ALLOCZ_OR_GOTO(avc, c, sizeof(FFIIRFilterCoeffs),
- init_fail);
- FF_ALLOC_OR_GOTO (avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1),
- init_fail);
- FF_ALLOC_OR_GOTO (avc, c->cy, sizeof(c->cy[0]) * order,
- init_fail);
- c->order = order;
+ if (filt_mode != FF_FILTER_MODE_LOWPASS) {
+ av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
+ "low-pass filter mode\n");
+ return -1;
+ }
+ if (order & 1) {
+ av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports "
+ "even filter orders\n");
+ return -1;
+ }
wa = 2 * tan(M_PI * 0.5 * cutoff_ratio);
@@ -113,6 +109,38 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
}
c->gain /= 1 << order;
+ return 0;
+}
+
+av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
+ enum IIRFilterType filt_type,
+ enum IIRFilterMode filt_mode,
+ int order, float cutoff_ratio,
+ float stopband, float ripple)
+{
+ FFIIRFilterCoeffs *c;
+
+ if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0)
+ return NULL;
+
+ FF_ALLOCZ_OR_GOTO(avc, c, sizeof(FFIIRFilterCoeffs),
+ init_fail);
+ FF_ALLOC_OR_GOTO (avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1),
+ init_fail);
+ FF_ALLOC_OR_GOTO (avc, c->cy, sizeof(c->cy[0]) * order,
+ 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 {
+ av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n");
+ goto init_fail;
+ }
+
return c;
init_fail:
More information about the ffmpeg-cvslog
mailing list