summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/lowshelf.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/lowshelf.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/lowshelf.c187
1 files changed, 97 insertions, 90 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/lowshelf.c b/apps/plugins/pdbox/PDa/extra/lowshelf.c
index ba32b6dba8..77086badb7 100644
--- a/apps/plugins/pdbox/PDa/extra/lowshelf.c
+++ b/apps/plugins/pdbox/PDa/extra/lowshelf.c
@@ -1,91 +1,98 @@
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/* ------------------- lowshelf ----------------------------*/ 23#pragma warning( disable : 4305 )
24 24#endif
25static t_class *lowshelf_class; 25#include <math.h>
26 26#include "filters.h"
27void lowshelf_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/* ------------------- lowshelf ----------------------------*/
31 t_float A = e_A(x->x_gain); 31
32 t_float cs = cos(omega); 32static t_class *lowshelf_class;
33 t_float sn = sin(omega); 33
34 t_float beta = e_beta(A,x->x_bw*0.01); 34void lowshelf_bang(t_rbjfilter *x)
35 35{
36 t_float b0 = A*((A+1) - (A-1)*cs + beta*sn); 36 t_atom at[5];
37 t_float b1 = 2.*A*((A-1) - (A+1)*cs); 37 t_float omega = e_omega(x->x_freq,x->x_rate);
38 t_float b2 = A*((A+1) - (A-1)*cs - beta*sn); 38 t_float A = e_A(x->x_gain);
39 t_float a0 = ((A+1) + (A-1)*cs + beta*sn); 39 t_float cs = cos(omega);
40 t_float a1 = -2.*((A-1) + (A+1)*cs); 40 t_float sn = sin(omega);
41 t_float a2 = ((A+1) + (A-1)*cs - beta*sn); 41 t_float beta = e_beta(A,x->x_bw*0.01);
42 42
43/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ 43 t_float b0 = A*((A+1) - (A-1)*cs + beta*sn);
44 44 t_float b1 = 2.*A*((A-1) - (A+1)*cs);
45 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { 45 t_float b2 = A*((A+1) - (A-1)*cs - beta*sn);
46 post("lowshelf: filter unstable -> resetting"); 46 t_float a0 = ((A+1) + (A-1)*cs + beta*sn);
47 a0=1.;a1=0.;a2=0.; 47 t_float a1 = -2.*((A-1) + (A+1)*cs);
48 b0=1.;b1=0.;b2=0.; 48 t_float a2 = ((A+1) + (A-1)*cs - beta*sn);
49 } 49
50 50/* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */
51 SETFLOAT(at,-a1/a0); 51
52 SETFLOAT(at+1,-a2/a0); 52 if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) {
53 SETFLOAT(at+2,b0/a0); 53 post("lowshelf: filter unstable -> resetting");
54 SETFLOAT(at+3,b1/a0); 54 a0=1.;a1=0.;a2=0.;
55 SETFLOAT(at+4,b2/a0); 55 b0=1.;b1=0.;b2=0.;
56 56 }
57 outlet_list(x->x_obj.ob_outlet,&s_list,5,at); 57
58} 58 SETFLOAT(at,-a1/a0);
59 59 SETFLOAT(at+1,-a2/a0);
60 60 SETFLOAT(at+2,b0/a0);
61void lowshelf_float(t_rbjfilter *x,t_floatarg f) 61 SETFLOAT(at+3,b1/a0);
62{ 62 SETFLOAT(at+4,b2/a0);
63 x->x_freq = f; 63
64 lowshelf_bang(x); 64 outlet_list(x->x_obj.ob_outlet,&s_list,5,at);
65} 65}
66 66
67 67
68static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw) 68void lowshelf_float(t_rbjfilter *x,t_floatarg f)
69{ 69{
70 t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class); 70 x->x_freq = f;
71 71 lowshelf_bang(x);
72 x->x_rate = 44100.0; 72}
73 outlet_new(&x->x_obj,&s_float); 73
74 floatinlet_new(&x->x_obj, &x->x_gain); 74
75 floatinlet_new(&x->x_obj, &x->x_bw); 75static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw)
76 if (f > 0.) x->x_freq = f; 76{
77 if (bw > 0.) x->x_bw = bw; 77 t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class);
78 if (g != 0.) x->x_gain = g; 78
79 return (x); 79 x->x_rate = 44100.0;
80} 80 outlet_new(&x->x_obj,&s_float);
81 81 floatinlet_new(&x->x_obj, &x->x_gain);
82 82 floatinlet_new(&x->x_obj, &x->x_bw);
83void lowshelf_setup(void) 83 if (f > 0.) x->x_freq = f;
84{ 84 if (bw > 0.) x->x_bw = bw;
85 lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0, 85 if (g != 0.) x->x_gain = g;
86 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); 86 return (x);
87 class_addbang(lowshelf_class,lowshelf_bang); 87}
88 class_addfloat(lowshelf_class,lowshelf_float); 88
89} 89
90 90void lowshelf_setup(void)
91{
92 lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0,
93 sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0);
94 class_addbang(lowshelf_class,lowshelf_bang);
95 class_addfloat(lowshelf_class,lowshelf_float);
96}
97
91 98