summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/bandpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/bandpass.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/bandpass.c180
1 files changed, 94 insertions, 86 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/bandpass.c b/apps/plugins/pdbox/PDa/extra/bandpass.c
index 127a1eee06..50a0b42e86 100644
--- a/apps/plugins/pdbox/PDa/extra/bandpass.c
+++ b/apps/plugins/pdbox/PDa/extra/bandpass.c
@@ -1,87 +1,95 @@
1 1
2/* (C) Guenter Geiger <geiger@epy.co.at> */ 2/* (C) Guenter Geiger <geiger@epy.co.at> */
3 3
4 4
5/* 5/*
6 6
7 These filter coefficients computations are taken from 7 These filter coefficients computations are taken from
8 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt 8 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
9 9
10 written by Robert Bristow-Johnson 10 written by Robert Bristow-Johnson
11 11
12*/ 12*/
13 13
14#include "m_pd.h" 14#ifdef ROCKBOX
15#ifdef NT 15#include "plugin.h"
16#pragma warning( disable : 4244 ) 16#include "pdbox.h"
17#pragma warning( disable : 4305 ) 17#include "m_pd.h"
18#endif 18#include "math.h"
19#include <math.h> 19#include "filters.h"
20#include "filters.h" 20#else /* ROCKBOX */
21 21#include "m_pd.h"
22/* ------------------- bandpass ----------------------------*/ 22#ifdef NT
23 23#pragma warning( disable : 4244 )
24static t_class *bandpass_class; 24#pragma warning( disable : 4305 )
25 25#endif
26void bandpass_bang(t_rbjfilter *x) 26#include <math.h>
27{ 27#include "filters.h"
28 t_atom at[5]; 28#endif /* ROCKBOX */
29 t_float omega = e_omega(x->x_freq,x->x_rate); 29
30 t_float alpha = e_alpha(x->x_bw* 0.01,omega); 30/* ------------------- bandpass ----------------------------*/
31 t_float b1 = 0.; 31
32 t_float b0 = alpha; 32static t_class *bandpass_class;
33 t_float b2 = -alpha; 33
34 t_float a0 = 1 + alpha; 34void bandpass_bang(t_rbjfilter *x)
35 t_float a1 = -2.*cos(omega); 35{
36 t_float a2 = 1 - alpha; 36 t_atom at[5];
37 37 t_float omega = e_omega(x->x_freq,x->x_rate);
38/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ 38 t_float alpha = e_alpha(x->x_bw* 0.01,omega);
39 39 t_float b1 = 0.;
40 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { 40 t_float b0 = alpha;
41 post("bandpass: filter unstable -> resetting"); 41 t_float b2 = -alpha;
42 a0=1.;a1=0.;a2=0.; 42 t_float a0 = 1 + alpha;
43 b0=1.;b1=0.;b2=0.; 43 t_float a1 = -2.*cos(omega);
44 } 44 t_float a2 = 1 - alpha;
45 45
46 SETFLOAT(at,-a1/a0); 46/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
47 SETFLOAT(at+1,-a2/a0); 47
48 SETFLOAT(at+2,b0/a0); 48 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
49 SETFLOAT(at+3,b1/a0); 49 post("bandpass: filter unstable -> resetting");
50 SETFLOAT(at+4,b2/a0); 50 a0=1.;a1=0.;a2=0.;
51 51 b0=1.;b1=0.;b2=0.;
52 outlet_list(x->x_obj.ob_outlet,&s_list,5,at); 52 }
53} 53
54 54 SETFLOAT(at,-a1/a0);
55 55 SETFLOAT(at+1,-a2/a0);
56void bandpass_float(t_rbjfilter *x,t_floatarg f) 56 SETFLOAT(at+2,b0/a0);
57{ 57 SETFLOAT(at+3,b1/a0);
58 x->x_freq = f; 58 SETFLOAT(at+4,b2/a0);
59 bandpass_bang(x); 59
60} 60 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
61 61}
62 62
63static void *bandpass_new(t_floatarg f,t_floatarg bw) 63
64{ 64void bandpass_float(t_rbjfilter *x,t_floatarg f)
65 t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class); 65{
66 66 x->x_freq = f;
67 x->x_rate = 44100.0; 67 bandpass_bang(x);
68 outlet_new(&x->x_obj,&s_float); 68}
69/* floatinlet_new(&x->x_obj, &x->x_gain); */ 69
70 floatinlet_new(&x->x_obj, &x->x_bw); 70
71 if (f > 0.) x->x_freq = f; 71static void *bandpass_new(t_floatarg f,t_floatarg bw)
72 if (bw > 0.) x->x_bw = bw; 72{
73 return (x); 73 t_rbjfilter *x = (t_rbjfilter *)pd_new(bandpass_class);
74} 74
75 75 x->x_rate = 44100.0;
76 76 outlet_new(&x->x_obj,&s_float);
77void bandpass_setup(void) 77/* floatinlet_new(&x->x_obj, &x->x_gain); */
78{ 78 floatinlet_new(&x->x_obj, &x->x_bw);
79 bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0, 79 if (f > 0.) x->x_freq = f;
80 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0); 80 if (bw > 0.) x->x_bw = bw;
81 class_addbang(bandpass_class,bandpass_bang); 81 return (x);
82 class_addfloat(bandpass_class,bandpass_float); 82}
83} 83
84 84
85 85void bandpass_setup(void)
86 86{
87 bandpass_class = class_new(gensym("bandpass"), (t_newmethod)bandpass_new, 0,
88 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,0);
89 class_addbang(bandpass_class,bandpass_bang);
90 class_addfloat(bandpass_class,bandpass_float);
91}
92
93
94
87 95