-
Notifications
You must be signed in to change notification settings - Fork 7
/
biquad.h
63 lines (51 loc) · 1.81 KB
/
biquad.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Simple implementation of Biquad filters -- Tom St Denis
*
* Based on the work
Cookbook formulae for audio EQ biquad filter coefficients
---------------------------------------------------------
by Robert Bristow-Johnson, pbjrbj@viconet.com a.k.a. robert@audioheads.com
* Available on the web at
http://www.smartelectronix.com/musicdsp/text/filters005.txt
* Enjoy.
*
* This work is hereby placed in the public domain for all purposes, whether
* commercial, free [as in speech] or educational, etc. Use the code and please
* give me credit if you wish.
*
* Tom St Denis -- http://tomstdenis.home.dhs.org
*/
/* this would be biquad.h */
#include <math.h>
#include <stdlib.h>
#ifndef M_LN2
#define M_LN2 0.69314718055994530942
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/* whatever sample type you want */
typedef double smp_type;
/* this holds the data required to update samples thru a filter */
typedef struct {
smp_type a0, a1, a2, a3, a4;
smp_type can_a0, can_a1, can_a2 ; /* canonical a0,a1,a2 */
smp_type can_b0, can_b1, can_b2 ; /* canonical b0,b1,b2 */
smp_type x1, x2, y1, y2;
}
biquad;
extern smp_type BiQuad(smp_type sample, biquad * b);
extern biquad *BiQuad_new(int type, smp_type dbGain, /* gain of filter */
smp_type freq, /* center frequency */
smp_type srate, /* sampling rate */
smp_type bandwidth); /* bandwidth in octaves */
/* filter types */
enum {
LPF, /* low pass filter */
HPF, /* High pass filter */
BPF, /* band pass filter */
NOTCH, /* Notch Filter */
PEQ, /* Peaking band EQ filter */
LSH, /* Low shelf filter */
HSH /* High shelf filter */
};
double BiQuad_response(double freq, double srate, biquad *p, double *from_formula) ;