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
10 #define LOGTEN 2.302585092994
14 if (f
<= -1500) return(0);
15 else if (f
> 1499) return(mtof(1499));
16 else return (8.17579891564 * exp(.0577622650 * f
));
21 return (f
> 0 ? 17.3123405046 * log(.12231220585 * f
) : -1500);
24 float powtodb(float f
)
26 if (f
<= 0) return (0);
29 float val
= 100 + 10./LOGTEN
* log(f
);
30 return (val
< 0 ? 0 : val
);
34 float rmstodb(float f
)
36 if (f
<= 0) return (0);
39 float val
= 100 + 20./LOGTEN
* log(f
);
40 return (val
< 0 ? 0 : val
);
44 float dbtopow(float f
)
52 return (exp((LOGTEN
* 0.1) * (f
-100.)));
56 float dbtorms(float f
)
65 return (exp((LOGTEN
* 0.05) * (f
-100.)));
68 /* ------------- corresponding objects ----------------------- */
70 static t_class
*mtof_class
;
72 static void *mtof_new(void)
74 t_object
*x
= (t_object
*)pd_new(mtof_class
);
75 outlet_new(x
, &s_float
);
79 static void mtof_float(t_object
*x
, t_float f
)
81 outlet_float(x
->ob_outlet
, mtof(f
));
85 static t_class
*ftom_class
;
87 static void *ftom_new(void)
89 t_object
*x
= (t_object
*)pd_new(ftom_class
);
90 outlet_new(x
, &s_float
);
94 static void ftom_float(t_object
*x
, t_float f
)
96 outlet_float(x
->ob_outlet
, ftom(f
));
100 static t_class
*rmstodb_class
;
102 static void *rmstodb_new(void)
104 t_object
*x
= (t_object
*)pd_new(rmstodb_class
);
105 outlet_new(x
, &s_float
);
109 static void rmstodb_float(t_object
*x
, t_float f
)
111 outlet_float(x
->ob_outlet
, rmstodb(f
));
115 static t_class
*powtodb_class
;
117 static void *powtodb_new(void)
119 t_object
*x
= (t_object
*)pd_new(powtodb_class
);
120 outlet_new(x
, &s_float
);
124 static void powtodb_float(t_object
*x
, t_float f
)
126 outlet_float(x
->ob_outlet
, powtodb(f
));
130 static t_class
*dbtopow_class
;
132 static void *dbtopow_new(void)
134 t_object
*x
= (t_object
*)pd_new(dbtopow_class
);
135 outlet_new(x
, &s_float
);
139 static void dbtopow_float(t_object
*x
, t_float f
)
141 outlet_float(x
->ob_outlet
, dbtopow(f
));
145 static t_class
*dbtorms_class
;
147 static void *dbtorms_new(void)
149 t_object
*x
= (t_object
*)pd_new(dbtorms_class
);
150 outlet_new(x
, &s_float
);
154 static void dbtorms_float(t_object
*x
, t_float f
)
156 outlet_float(x
->ob_outlet
, dbtorms(f
));
160 void x_acoustics_setup(void)
162 t_symbol
*s
= gensym("acoustics.pd");
163 mtof_class
= class_new(gensym("mtof"), mtof_new
, 0,
164 sizeof(t_object
), 0, 0);
165 class_addfloat(mtof_class
, (t_method
)mtof_float
);
166 class_sethelpsymbol(mtof_class
, s
);
168 ftom_class
= class_new(gensym("ftom"), ftom_new
, 0,
169 sizeof(t_object
), 0, 0);
170 class_addfloat(ftom_class
, (t_method
)ftom_float
);
171 class_sethelpsymbol(ftom_class
, s
);
173 powtodb_class
= class_new(gensym("powtodb"), powtodb_new
, 0,
174 sizeof(t_object
), 0, 0);
175 class_addfloat(powtodb_class
, (t_method
)powtodb_float
);
176 class_sethelpsymbol(powtodb_class
, s
);
178 rmstodb_class
= class_new(gensym("rmstodb"), rmstodb_new
, 0,
179 sizeof(t_object
), 0, 0);
180 class_addfloat(rmstodb_class
, (t_method
)rmstodb_float
);
181 class_sethelpsymbol(rmstodb_class
, s
);
183 dbtopow_class
= class_new(gensym("dbtopow"), dbtopow_new
, 0,
184 sizeof(t_object
), 0, 0);
185 class_addfloat(dbtopow_class
, (t_method
)dbtopow_float
);
186 class_sethelpsymbol(dbtopow_class
, s
);
188 dbtorms_class
= class_new(gensym("dbtorms"), dbtorms_new
, 0,
189 sizeof(t_object
), 0, 0);
190 class_addfloat(dbtorms_class
, (t_method
)dbtorms_float
);
191 class_sethelpsymbol(dbtorms_class
, s
);
194 /* Copyright (c) 1997-1999 Miller Puckette.
195 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
196 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
198 /* utility functions for signals
203 #define LOGTEN 2.302585092994
207 if (f
<= -1500) return(0);
208 else if (f
> 1499) return(mtof(1499));
209 else return (8.17579891564 * exp(.0577622650 * f
));
214 return (f
> 0 ? 17.3123405046 * log(.12231220585 * f
) : -1500);
217 float powtodb(float f
)
219 if (f
<= 0) return (0);
222 float val
= 100 + 10./LOGTEN
* log(f
);
223 return (val
< 0 ? 0 : val
);
227 float rmstodb(float f
)
229 if (f
<= 0) return (0);
232 float val
= 100 + 20./LOGTEN
* log(f
);
233 return (val
< 0 ? 0 : val
);
237 float dbtopow(float f
)
245 return (exp((LOGTEN
* 0.1) * (f
-100.)));
249 float dbtorms(float f
)
258 return (exp((LOGTEN
* 0.05) * (f
-100.)));
261 /* ------------- corresponding objects ----------------------- */
263 static t_class
*mtof_class
;
265 static void *mtof_new(void)
267 t_object
*x
= (t_object
*)pd_new(mtof_class
);
268 outlet_new(x
, &s_float
);
272 static void mtof_float(t_object
*x
, t_float f
)
274 outlet_float(x
->ob_outlet
, mtof(f
));
278 static t_class
*ftom_class
;
280 static void *ftom_new(void)
282 t_object
*x
= (t_object
*)pd_new(ftom_class
);
283 outlet_new(x
, &s_float
);
287 static void ftom_float(t_object
*x
, t_float f
)
289 outlet_float(x
->ob_outlet
, ftom(f
));
293 static t_class
*rmstodb_class
;
295 static void *rmstodb_new(void)
297 t_object
*x
= (t_object
*)pd_new(rmstodb_class
);
298 outlet_new(x
, &s_float
);
302 static void rmstodb_float(t_object
*x
, t_float f
)
304 outlet_float(x
->ob_outlet
, rmstodb(f
));
308 static t_class
*powtodb_class
;
310 static void *powtodb_new(void)
312 t_object
*x
= (t_object
*)pd_new(powtodb_class
);
313 outlet_new(x
, &s_float
);
317 static void powtodb_float(t_object
*x
, t_float f
)
319 outlet_float(x
->ob_outlet
, powtodb(f
));
323 static t_class
*dbtopow_class
;
325 static void *dbtopow_new(void)
327 t_object
*x
= (t_object
*)pd_new(dbtopow_class
);
328 outlet_new(x
, &s_float
);
332 static void dbtopow_float(t_object
*x
, t_float f
)
334 outlet_float(x
->ob_outlet
, dbtopow(f
));
338 static t_class
*dbtorms_class
;
340 static void *dbtorms_new(void)
342 t_object
*x
= (t_object
*)pd_new(dbtorms_class
);
343 outlet_new(x
, &s_float
);
347 static void dbtorms_float(t_object
*x
, t_float f
)
349 outlet_float(x
->ob_outlet
, dbtorms(f
));
353 void x_acoustics_setup(void)
355 t_symbol
*s
= gensym("acoustics.pd");
356 mtof_class
= class_new(gensym("mtof"), mtof_new
, 0,
357 sizeof(t_object
), 0, 0);
358 class_addfloat(mtof_class
, (t_method
)mtof_float
);
359 class_sethelpsymbol(mtof_class
, s
);
361 ftom_class
= class_new(gensym("ftom"), ftom_new
, 0,
362 sizeof(t_object
), 0, 0);
363 class_addfloat(ftom_class
, (t_method
)ftom_float
);
364 class_sethelpsymbol(ftom_class
, s
);
366 powtodb_class
= class_new(gensym("powtodb"), powtodb_new
, 0,
367 sizeof(t_object
), 0, 0);
368 class_addfloat(powtodb_class
, (t_method
)powtodb_float
);
369 class_sethelpsymbol(powtodb_class
, s
);
371 rmstodb_class
= class_new(gensym("rmstodb"), rmstodb_new
, 0,
372 sizeof(t_object
), 0, 0);
373 class_addfloat(rmstodb_class
, (t_method
)rmstodb_float
);
374 class_sethelpsymbol(rmstodb_class
, s
);
376 dbtopow_class
= class_new(gensym("dbtopow"), dbtopow_new
, 0,
377 sizeof(t_object
), 0, 0);
378 class_addfloat(dbtopow_class
, (t_method
)dbtopow_float
);
379 class_sethelpsymbol(dbtopow_class
, s
);
381 dbtorms_class
= class_new(gensym("dbtorms"), dbtorms_new
, 0,
382 sizeof(t_object
), 0, 0);
383 class_addfloat(dbtorms_class
, (t_method
)dbtorms_float
);
384 class_sethelpsymbol(dbtorms_class
, s
);