FFmpeg
iirfilter.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <math.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 
23 #include "libavutil/libm.h"
24 
25 #include "libavcodec/iirfilter.h"
26 #include "libavcodec/iirfilter.c"
27 
28 #define FILT_ORDER 4
29 #define SIZE 1024
30 
31 static void iir_filter_int16(const struct FFIIRFilterCoeffs *c,
32  struct FFIIRFilterState *s, int size,
33  const int16_t *src, ptrdiff_t sstep,
34  int16_t *dst, ptrdiff_t dstep)
35 {
36  if (c->order == 2) {
37  FILTER_O2(int16_t, S16)
38  } else if (c->order == 4) {
39  FILTER_BW_O4(int16_t, S16)
40  } else {
41  FILTER_DIRECT_FORM_II(int16_t, S16)
42  }
43 }
44 
45 int main(void)
46 {
47  struct FFIIRFilterCoeffs *fcoeffs = NULL;
48  struct FFIIRFilterState *fstate = NULL;
49  float cutoff_coeff = 0.4;
50  int16_t x[SIZE], y[SIZE];
51  int i;
52 
55  cutoff_coeff, 0.0, 0.0);
57 
58  for (i = 0; i < SIZE; i++)
59  x[i] = lrint(0.75 * INT16_MAX * sin(0.5 * M_PI * i * i / SIZE));
60 
61  iir_filter_int16(fcoeffs, fstate, SIZE, x, 1, y, 1);
62 
63  for (i = 0; i < SIZE; i++)
64  printf("%6d %6d\n", x[i], y[i]);
65 
68  return 0;
69 }
FFIIRFilterState
IIR filter state.
Definition: iirfilter.c:51
iirfilter.h
libm.h
FILTER_BW_O4
#define FILTER_BW_O4(type, fmt)
Definition: iirfilter.c:229
SIZE
#define SIZE
Definition: iirfilter.c:29
iir_filter_int16
static void iir_filter_int16(const struct FFIIRFilterCoeffs *c, struct FFIIRFilterState *s, int size, const int16_t *src, ptrdiff_t sstep, int16_t *dst, ptrdiff_t dstep)
Definition: iirfilter.c:31
lrint
#define lrint
Definition: tablegen.h:53
FFIIRFilterCoeffs
IIR filter global parameters.
Definition: iirfilter.c:41
s
#define s(width, name)
Definition: cbs_vp9.c:198
main
int main(void)
Definition: iirfilter.c:45
FILT_ORDER
#define FILT_ORDER
Definition: iirfilter.c:28
NULL
#define NULL
Definition: coverity.c:32
FF_FILTER_MODE_LOWPASS
@ FF_FILTER_MODE_LOWPASS
Definition: iirfilter.h:44
ff_iir_filter_init_coeffs
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)
Initialize filter coefficients.
Definition: iirfilter.c:166
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
FILTER_O2
#define FILTER_O2(type, fmt)
Definition: iirfilter.c:264
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
size
int size
Definition: twinvq_data.h:10344
printf
printf("static const uint8_t my_array[100] = {\n")
M_PI
#define M_PI
Definition: mathematics.h:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
iirfilter.c
ff_iir_filter_free_coeffsp
av_cold void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffsp)
Free filter coefficients.
Definition: iirfilter.c:310
FFIIRFilterState::x
float x[1]
Definition: iirfilter.c:52
FILTER_DIRECT_FORM_II
#define FILTER_DIRECT_FORM_II(type, fmt)
Definition: iirfilter.c:242
ff_iir_filter_init_state
av_cold struct FFIIRFilterState * ff_iir_filter_init_state(int order)
Create new filter state.
Definition: iirfilter.c:205
ff_iir_filter_free_statep
av_cold void ff_iir_filter_free_statep(struct FFIIRFilterState **state)
Free and zero filter state.
Definition: iirfilter.c:305
FF_FILTER_TYPE_BUTTERWORTH
@ FF_FILTER_TYPE_BUTTERWORTH
Definition: iirfilter.h:38
src
#define src
Definition: vp8dsp.c:248