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