aboutsummaryrefslogtreecommitdiff
path: root/filters/filters.h
diff options
context:
space:
mode:
authorGuenter Geiger <ggeiger@users.sourceforge.net>2002-06-17 10:13:57 +0000
committerGuenter Geiger <ggeiger@users.sourceforge.net>2002-06-17 10:13:57 +0000
commitfc3d3c0a4f110a23335398c327ac0a4fc949d5cb (patch)
tree1849d6afbe34cee9cec97bdb2295401f5126870b /filters/filters.h
This commit was generated by cvs2svn to compensate for changes in r12,svn2git-root
which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/ggee/; revision=13
Diffstat (limited to 'filters/filters.h')
-rwxr-xr-xfilters/filters.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/filters/filters.h b/filters/filters.h
new file mode 100755
index 0000000..6ff7962
--- /dev/null
+++ b/filters/filters.h
@@ -0,0 +1,74 @@
+/*
+
+ These filter coefficients computations are taken from
+ http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
+
+ written by Robert Bristow-Johnson
+
+*/
+
+
+#ifndef __GGEE_FILTERS_H__
+#define __GGEE_FILTERS_H__
+
+
+
+#ifndef M_PI
+#define M_PI 3.141593f
+#endif
+
+
+#include <math.h>
+#define LN2 0.69314718
+#define e_A(g) (pow(10,(g/40.)))
+#define e_omega(f,r) (2.0*M_PI*f/r)
+#define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega)))
+#define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1)))
+
+
+
+
+typedef struct _rbjfilter
+{
+ t_object x_obj;
+ t_float x_rate;
+ t_float x_freq;
+ t_float x_gain;
+ t_float x_bw;
+} t_rbjfilter;
+
+
+static int check_stability(t_float fb1,
+ t_float fb2,
+ t_float ff1,
+ t_float ff2,
+ t_float ff3)
+{
+ float discriminant = fb1 * fb1 + 4 * fb2;
+
+ if (discriminant < 0) /* imaginary roots -- resonant filter */
+ {
+ /* they're conjugates so we just check that the product
+ is less than one */
+ if (fb2 >= -1.0f) goto stable;
+ }
+ else /* real roots */
+ {
+ /* check that the parabola 1 - fb1 x - fb2 x^2 has a
+ vertex between -1 and 1, and that it's nonnegative
+ at both ends, which implies both roots are in [1-,1]. */
+ if (fb1 <= 2.0f && fb1 >= -2.0f &&
+ 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
+ goto stable;
+ }
+ return 0;
+stable:
+ return 1;
+}
+
+
+
+
+
+
+#endif