libavcodec/iirfilter.c File Reference

different IIR filters implementation More...

#include "iirfilter.h"
#include <math.h>

Go to the source code of this file.

Data Structures

struct  FFIIRFilterCoeffs
 IIR filter global parameters. More...
struct  FFIIRFilterState
 IIR filter state. More...

Defines

#define MAXORDER   30
 maximum supported filter order
#define CONV_S16(dest, source)   dest = av_clip_int16(lrintf(source));
#define CONV_FLT(dest, source)   dest = source;
#define FILTER_BW_O4_1(i0, i1, i2, i3, fmt)
#define FILTER_BW_O4(type, fmt)
#define FILTER_DIRECT_FORM_II(type, fmt)
#define FILTER_O2(type, fmt)

Functions

static int butterworth_init_coeffs (void *avc, struct FFIIRFilterCoeffs *c, enum IIRFilterMode filt_mode, int order, float cutoff_ratio, float stopband)
static int biquad_init_coeffs (void *avc, struct FFIIRFilterCoeffs *c, enum IIRFilterMode filt_mode, int order, float cutoff_ratio, float stopband)
av_cold struct FFIIRFilterCoeffsff_iir_filter_init_coeffs (void *avc, enum IIRFilterType filt_type, enum IIRFilterMode filt_mode, int order, float cutoff_ratio, float stopband, float ripple)
 Initialize filter coefficients.
av_cold struct FFIIRFilterStateff_iir_filter_init_state (int order)
 Create new filter state.
void ff_iir_filter (const struct FFIIRFilterCoeffs *c, struct FFIIRFilterState *s, int size, const int16_t *src, int sstep, int16_t *dst, int dstep)
 Perform IIR filtering on signed 16-bit input samples.
void ff_iir_filter_flt (const struct FFIIRFilterCoeffs *c, struct FFIIRFilterState *s, int size, const float *src, int sstep, float *dst, int dstep)
 Perform IIR filtering on floating-point input samples.
av_cold void ff_iir_filter_free_state (struct FFIIRFilterState *state)
 Free filter state.
av_cold void ff_iir_filter_free_coeffs (struct FFIIRFilterCoeffs *coeffs)
 Free filter coefficients.


Detailed Description

different IIR filters implementation

Definition in file iirfilter.c.


Define Documentation

#define CONV_FLT ( dest,
source   )     dest = source;

Definition at line 208 of file iirfilter.c.

#define CONV_S16 ( dest,
source   )     dest = av_clip_int16(lrintf(source));

Definition at line 206 of file iirfilter.c.

#define FILTER_BW_O4 ( type,
fmt   ) 

Value:

{           \
    int i;                                  \
    const type *src0 = src;                 \
    type       *dst0 = dst;                 \
    for (i = 0; i < size; i += 4) {         \
        float in, res;                      \
        FILTER_BW_O4_1(0, 1, 2, 3, fmt);    \
        FILTER_BW_O4_1(1, 2, 3, 0, fmt);    \
        FILTER_BW_O4_1(2, 3, 0, 1, fmt);    \
        FILTER_BW_O4_1(3, 0, 1, 2, fmt);    \
    }                                       \
}

Definition at line 222 of file iirfilter.c.

Referenced by ff_iir_filter(), and ff_iir_filter_flt().

#define FILTER_BW_O4_1 ( i0,
i1,
i2,
i3,
fmt   ) 

Value:

in = *src0 * c->gain                            \
         + c->cy[0]*s->x[i0] + c->cy[1]*s->x[i1]    \
         + c->cy[2]*s->x[i2] + c->cy[3]*s->x[i3];   \
    res =  (s->x[i0] + in      )*1                  \
         + (s->x[i1] + s->x[i3])*4                  \
         +  s->x[i2]            *6;                 \
    CONV_##fmt(*dst0, res)                          \
    s->x[i0] = in;                                  \
    src0 += sstep;                                  \
    dst0 += dstep;

Definition at line 210 of file iirfilter.c.

#define FILTER_DIRECT_FORM_II ( type,
fmt   ) 

Value:

{                                  \
    int i;                                                                  \
    const type *src0 = src;                                                 \
    type       *dst0 = dst;                                                 \
    for (i = 0; i < size; i++) {                                            \
        int j;                                                              \
        float in, res;                                                      \
        in = *src0 * c->gain;                                               \
        for(j = 0; j < c->order; j++)                                       \
            in += c->cy[j] * s->x[j];                                       \
        res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1];    \
        for(j = 1; j < c->order >> 1; j++)                                  \
            res += (s->x[j] + s->x[c->order - j]) * c->cx[j];               \
        for(j = 0; j < c->order - 1; j++)                                   \
            s->x[j] = s->x[j + 1];                                          \
        CONV_##fmt(*dst0, res)                                              \
        s->x[c->order - 1] = in;                                            \
        src0 += sstep;                                                      \
        dst0 += dstep;                                                      \
    }                                                                       \
}

Definition at line 235 of file iirfilter.c.

Referenced by ff_iir_filter(), and ff_iir_filter_flt().

#define FILTER_O2 ( type,
fmt   ) 

Value:

{                                              \
    int i;                                                                  \
    const type *src0 = src;                                                 \
    type       *dst0 = dst;                                                 \
    for (i = 0; i < size; i++) {                                            \
        float in = *src0   * c->gain  +                                     \
                   s->x[0] * c->cy[0] +                                     \
                   s->x[1] * c->cy[1];                                      \
        CONV_##fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1])                \
        s->x[0] = s->x[1];                                                  \
        s->x[1] = in;                                                       \
        src0 += sstep;                                                      \
        dst0 += dstep;                                                      \
    }                                                                       \
}

Definition at line 257 of file iirfilter.c.

Referenced by ff_iir_filter(), and ff_iir_filter_flt().

#define MAXORDER   30

maximum supported filter order

Definition at line 48 of file iirfilter.c.

Referenced by butterworth_init_coeffs(), and ff_iir_filter_init_coeffs().


Function Documentation

static int biquad_init_coeffs ( void *  avc,
struct FFIIRFilterCoeffs c,
enum IIRFilterMode  filt_mode,
int  order,
float  cutoff_ratio,
float  stopband 
) [static]

Definition at line 115 of file iirfilter.c.

Referenced by ff_iir_filter_init_coeffs().

static int butterworth_init_coeffs ( void *  avc,
struct FFIIRFilterCoeffs c,
enum IIRFilterMode  filt_mode,
int  order,
float  cutoff_ratio,
float  stopband 
) [static]

Definition at line 50 of file iirfilter.c.

Referenced by ff_iir_filter_init_coeffs().

void ff_iir_filter ( const struct FFIIRFilterCoeffs coeffs,
struct FFIIRFilterState state,
int  size,
const int16_t *  src,
int  sstep,
int16_t *  dst,
int  dstep 
)

Perform IIR filtering on signed 16-bit input samples.

Parameters:
coeffs pointer to filter coefficients
state pointer to filter state
size input length
src source samples
sstep source stride
dst filtered samples (destination may be the same as input)
dstep destination stride

Definition at line 273 of file iirfilter.c.

Referenced by ff_psy_preprocess().

void ff_iir_filter_flt ( const struct FFIIRFilterCoeffs coeffs,
struct FFIIRFilterState state,
int  size,
const float *  src,
int  sstep,
float *  dst,
int  dstep 
)

Perform IIR filtering on floating-point input samples.

Parameters:
coeffs pointer to filter coefficients
state pointer to filter state
size input length
src source samples
sstep source stride
dst filtered samples (destination may be the same as input)
dstep destination stride

Definition at line 286 of file iirfilter.c.

av_cold void ff_iir_filter_free_coeffs ( struct FFIIRFilterCoeffs coeffs  ) 

Free filter coefficients.

Parameters:
coeffs pointer allocated with ff_iir_filter_init_coeffs()

Definition at line 304 of file iirfilter.c.

Referenced by ff_iir_filter_init_coeffs(), and ff_psy_preprocess_end().

av_cold void ff_iir_filter_free_state ( struct FFIIRFilterState state  ) 

Free filter state.

Parameters:
state pointer allocated with ff_iir_filter_init_state()

Definition at line 299 of file iirfilter.c.

Referenced by ff_psy_preprocess_end().

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 
) [read]

Initialize filter coefficients.

Parameters:
avc a pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct
filt_type filter type (e.g. Butterworth)
filt_mode filter mode (e.g. lowpass)
order filter order
cutoff_ratio cutoff to input frequency ratio
stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes)
ripple ripple factor (used only in Chebyshev filters)
Returns:
pointer to filter coefficients structure or NULL if filter cannot be created

Definition at line 158 of file iirfilter.c.

Referenced by ff_psy_preprocess_init().

av_cold struct FFIIRFilterState* ff_iir_filter_init_state ( int  order  )  [read]

Create new filter state.

Parameters:
order filter order
Returns:
pointer to new filter state or NULL if state creation fails

Definition at line 200 of file iirfilter.c.

Referenced by ff_psy_preprocess_init().


Generated on Fri Oct 26 02:39:45 2012 for FFmpeg by  doxygen 1.5.8