Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / x_acoustics.c
blob7559426becb1f04333007bceb3c278fbe3cd24bf
1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
5 /* utility functions for signals
6 */
8 #ifdef ROCKBOX
9 #include "plugin.h"
10 #include "../../pdbox.h"
11 #endif
13 #include "m_pd.h"
14 #include <math.h>
15 #define LOGTEN 2.302585092994
17 float mtof(float f)
19 if (f <= -1500) return(0);
20 else if (f > 1499) return(mtof(1499));
21 else return (8.17579891564 * exp(.0577622650 * f));
24 float ftom(float f)
26 return (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500);
29 float powtodb(float f)
31 if (f <= 0) return (0);
32 else
34 float val = 100 + 10./LOGTEN * log(f);
35 return (val < 0 ? 0 : val);
39 float rmstodb(float f)
41 if (f <= 0) return (0);
42 else
44 float val = 100 + 20./LOGTEN * log(f);
45 return (val < 0 ? 0 : val);
49 float dbtopow(float f)
51 if (f <= 0)
52 return(0);
53 else
55 if (f > 870)
56 f = 870;
57 return (exp((LOGTEN * 0.1) * (f-100.)));
61 float dbtorms(float f)
63 if (f <= 0)
64 return(0);
65 else
67 if (f > 485)
68 f = 485;
70 return (exp((LOGTEN * 0.05) * (f-100.)));
73 /* ------------- corresponding objects ----------------------- */
75 static t_class *mtof_class;
77 static void *mtof_new(void)
79 t_object *x = (t_object *)pd_new(mtof_class);
80 outlet_new(x, &s_float);
81 return (x);
84 static void mtof_float(t_object *x, t_float f)
86 outlet_float(x->ob_outlet, mtof(f));
90 static t_class *ftom_class;
92 static void *ftom_new(void)
94 t_object *x = (t_object *)pd_new(ftom_class);
95 outlet_new(x, &s_float);
96 return (x);
99 static void ftom_float(t_object *x, t_float f)
101 outlet_float(x->ob_outlet, ftom(f));
105 static t_class *rmstodb_class;
107 static void *rmstodb_new(void)
109 t_object *x = (t_object *)pd_new(rmstodb_class);
110 outlet_new(x, &s_float);
111 return (x);
114 static void rmstodb_float(t_object *x, t_float f)
116 outlet_float(x->ob_outlet, rmstodb(f));
120 static t_class *powtodb_class;
122 static void *powtodb_new(void)
124 t_object *x = (t_object *)pd_new(powtodb_class);
125 outlet_new(x, &s_float);
126 return (x);
129 static void powtodb_float(t_object *x, t_float f)
131 outlet_float(x->ob_outlet, powtodb(f));
135 static t_class *dbtopow_class;
137 static void *dbtopow_new(void)
139 t_object *x = (t_object *)pd_new(dbtopow_class);
140 outlet_new(x, &s_float);
141 return (x);
144 static void dbtopow_float(t_object *x, t_float f)
146 outlet_float(x->ob_outlet, dbtopow(f));
150 static t_class *dbtorms_class;
152 static void *dbtorms_new(void)
154 t_object *x = (t_object *)pd_new(dbtorms_class);
155 outlet_new(x, &s_float);
156 return (x);
159 static void dbtorms_float(t_object *x, t_float f)
161 outlet_float(x->ob_outlet, dbtorms(f));
165 void x_acoustics_setup(void)
167 t_symbol *s = gensym("acoustics.pd");
168 mtof_class = class_new(gensym("mtof"), mtof_new, 0,
169 sizeof(t_object), 0, 0);
170 class_addfloat(mtof_class, (t_method)mtof_float);
171 class_sethelpsymbol(mtof_class, s);
173 ftom_class = class_new(gensym("ftom"), ftom_new, 0,
174 sizeof(t_object), 0, 0);
175 class_addfloat(ftom_class, (t_method)ftom_float);
176 class_sethelpsymbol(ftom_class, s);
178 powtodb_class = class_new(gensym("powtodb"), powtodb_new, 0,
179 sizeof(t_object), 0, 0);
180 class_addfloat(powtodb_class, (t_method)powtodb_float);
181 class_sethelpsymbol(powtodb_class, s);
183 rmstodb_class = class_new(gensym("rmstodb"), rmstodb_new, 0,
184 sizeof(t_object), 0, 0);
185 class_addfloat(rmstodb_class, (t_method)rmstodb_float);
186 class_sethelpsymbol(rmstodb_class, s);
188 dbtopow_class = class_new(gensym("dbtopow"), dbtopow_new, 0,
189 sizeof(t_object), 0, 0);
190 class_addfloat(dbtopow_class, (t_method)dbtopow_float);
191 class_sethelpsymbol(dbtopow_class, s);
193 dbtorms_class = class_new(gensym("dbtorms"), dbtorms_new, 0,
194 sizeof(t_object), 0, 0);
195 class_addfloat(dbtorms_class, (t_method)dbtorms_float);
196 class_sethelpsymbol(dbtorms_class, s);