diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/x_acoustics.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/x_acoustics.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/x_acoustics.c | 386 |
1 files changed, 386 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/x_acoustics.c b/apps/plugins/pdbox/PDa/src/x_acoustics.c new file mode 100644 index 0000000000..8fc04f77d1 --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/x_acoustics.c | |||
@@ -0,0 +1,386 @@ | |||
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. */ | ||
4 | |||
5 | /* utility functions for signals | ||
6 | */ | ||
7 | |||
8 | #include "m_pd.h" | ||
9 | #include <math.h> | ||
10 | #define LOGTEN 2.302585092994 | ||
11 | |||
12 | float mtof(float f) | ||
13 | { | ||
14 | if (f <= -1500) return(0); | ||
15 | else if (f > 1499) return(mtof(1499)); | ||
16 | else return (8.17579891564 * exp(.0577622650 * f)); | ||
17 | } | ||
18 | |||
19 | float ftom(float f) | ||
20 | { | ||
21 | return (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500); | ||
22 | } | ||
23 | |||
24 | float powtodb(float f) | ||
25 | { | ||
26 | if (f <= 0) return (0); | ||
27 | else | ||
28 | { | ||
29 | float val = 100 + 10./LOGTEN * log(f); | ||
30 | return (val < 0 ? 0 : val); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | float rmstodb(float f) | ||
35 | { | ||
36 | if (f <= 0) return (0); | ||
37 | else | ||
38 | { | ||
39 | float val = 100 + 20./LOGTEN * log(f); | ||
40 | return (val < 0 ? 0 : val); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | float dbtopow(float f) | ||
45 | { | ||
46 | if (f <= 0) | ||
47 | return(0); | ||
48 | else | ||
49 | { | ||
50 | if (f > 870) | ||
51 | f = 870; | ||
52 | return (exp((LOGTEN * 0.1) * (f-100.))); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | float dbtorms(float f) | ||
57 | { | ||
58 | if (f <= 0) | ||
59 | return(0); | ||
60 | else | ||
61 | { | ||
62 | if (f > 485) | ||
63 | f = 485; | ||
64 | } | ||
65 | return (exp((LOGTEN * 0.05) * (f-100.))); | ||
66 | } | ||
67 | |||
68 | /* ------------- corresponding objects ----------------------- */ | ||
69 | |||
70 | static t_class *mtof_class; | ||
71 | |||
72 | static void *mtof_new(void) | ||
73 | { | ||
74 | t_object *x = (t_object *)pd_new(mtof_class); | ||
75 | outlet_new(x, &s_float); | ||
76 | return (x); | ||
77 | } | ||
78 | |||
79 | static void mtof_float(t_object *x, t_float f) | ||
80 | { | ||
81 | outlet_float(x->ob_outlet, mtof(f)); | ||
82 | } | ||
83 | |||
84 | |||
85 | static t_class *ftom_class; | ||
86 | |||
87 | static void *ftom_new(void) | ||
88 | { | ||
89 | t_object *x = (t_object *)pd_new(ftom_class); | ||
90 | outlet_new(x, &s_float); | ||
91 | return (x); | ||
92 | } | ||
93 | |||
94 | static void ftom_float(t_object *x, t_float f) | ||
95 | { | ||
96 | outlet_float(x->ob_outlet, ftom(f)); | ||
97 | } | ||
98 | |||
99 | |||
100 | static t_class *rmstodb_class; | ||
101 | |||
102 | static void *rmstodb_new(void) | ||
103 | { | ||
104 | t_object *x = (t_object *)pd_new(rmstodb_class); | ||
105 | outlet_new(x, &s_float); | ||
106 | return (x); | ||
107 | } | ||
108 | |||
109 | static void rmstodb_float(t_object *x, t_float f) | ||
110 | { | ||
111 | outlet_float(x->ob_outlet, rmstodb(f)); | ||
112 | } | ||
113 | |||
114 | |||
115 | static t_class *powtodb_class; | ||
116 | |||
117 | static void *powtodb_new(void) | ||
118 | { | ||
119 | t_object *x = (t_object *)pd_new(powtodb_class); | ||
120 | outlet_new(x, &s_float); | ||
121 | return (x); | ||
122 | } | ||
123 | |||
124 | static void powtodb_float(t_object *x, t_float f) | ||
125 | { | ||
126 | outlet_float(x->ob_outlet, powtodb(f)); | ||
127 | } | ||
128 | |||
129 | |||
130 | static t_class *dbtopow_class; | ||
131 | |||
132 | static void *dbtopow_new(void) | ||
133 | { | ||
134 | t_object *x = (t_object *)pd_new(dbtopow_class); | ||
135 | outlet_new(x, &s_float); | ||
136 | return (x); | ||
137 | } | ||
138 | |||
139 | static void dbtopow_float(t_object *x, t_float f) | ||
140 | { | ||
141 | outlet_float(x->ob_outlet, dbtopow(f)); | ||
142 | } | ||
143 | |||
144 | |||
145 | static t_class *dbtorms_class; | ||
146 | |||
147 | static void *dbtorms_new(void) | ||
148 | { | ||
149 | t_object *x = (t_object *)pd_new(dbtorms_class); | ||
150 | outlet_new(x, &s_float); | ||
151 | return (x); | ||
152 | } | ||
153 | |||
154 | static void dbtorms_float(t_object *x, t_float f) | ||
155 | { | ||
156 | outlet_float(x->ob_outlet, dbtorms(f)); | ||
157 | } | ||
158 | |||
159 | |||
160 | void x_acoustics_setup(void) | ||
161 | { | ||
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); | ||
167 | |||
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); | ||
172 | |||
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); | ||
177 | |||
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); | ||
182 | |||
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); | ||
187 | |||
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); | ||
192 | } | ||
193 | |||
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. */ | ||
197 | |||
198 | /* utility functions for signals | ||
199 | */ | ||
200 | |||
201 | #include "m_pd.h" | ||
202 | #include <math.h> | ||
203 | #define LOGTEN 2.302585092994 | ||
204 | |||
205 | float mtof(float f) | ||
206 | { | ||
207 | if (f <= -1500) return(0); | ||
208 | else if (f > 1499) return(mtof(1499)); | ||
209 | else return (8.17579891564 * exp(.0577622650 * f)); | ||
210 | } | ||
211 | |||
212 | float ftom(float f) | ||
213 | { | ||
214 | return (f > 0 ? 17.3123405046 * log(.12231220585 * f) : -1500); | ||
215 | } | ||
216 | |||
217 | float powtodb(float f) | ||
218 | { | ||
219 | if (f <= 0) return (0); | ||
220 | else | ||
221 | { | ||
222 | float val = 100 + 10./LOGTEN * log(f); | ||
223 | return (val < 0 ? 0 : val); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | float rmstodb(float f) | ||
228 | { | ||
229 | if (f <= 0) return (0); | ||
230 | else | ||
231 | { | ||
232 | float val = 100 + 20./LOGTEN * log(f); | ||
233 | return (val < 0 ? 0 : val); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | float dbtopow(float f) | ||
238 | { | ||
239 | if (f <= 0) | ||
240 | return(0); | ||
241 | else | ||
242 | { | ||
243 | if (f > 870) | ||
244 | f = 870; | ||
245 | return (exp((LOGTEN * 0.1) * (f-100.))); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | float dbtorms(float f) | ||
250 | { | ||
251 | if (f <= 0) | ||
252 | return(0); | ||
253 | else | ||
254 | { | ||
255 | if (f > 485) | ||
256 | f = 485; | ||
257 | } | ||
258 | return (exp((LOGTEN * 0.05) * (f-100.))); | ||
259 | } | ||
260 | |||
261 | /* ------------- corresponding objects ----------------------- */ | ||
262 | |||
263 | static t_class *mtof_class; | ||
264 | |||
265 | static void *mtof_new(void) | ||
266 | { | ||
267 | t_object *x = (t_object *)pd_new(mtof_class); | ||
268 | outlet_new(x, &s_float); | ||
269 | return (x); | ||
270 | } | ||
271 | |||
272 | static void mtof_float(t_object *x, t_float f) | ||
273 | { | ||
274 | outlet_float(x->ob_outlet, mtof(f)); | ||
275 | } | ||
276 | |||
277 | |||
278 | static t_class *ftom_class; | ||
279 | |||
280 | static void *ftom_new(void) | ||
281 | { | ||
282 | t_object *x = (t_object *)pd_new(ftom_class); | ||
283 | outlet_new(x, &s_float); | ||
284 | return (x); | ||
285 | } | ||
286 | |||
287 | static void ftom_float(t_object *x, t_float f) | ||
288 | { | ||
289 | outlet_float(x->ob_outlet, ftom(f)); | ||
290 | } | ||
291 | |||
292 | |||
293 | static t_class *rmstodb_class; | ||
294 | |||
295 | static void *rmstodb_new(void) | ||
296 | { | ||
297 | t_object *x = (t_object *)pd_new(rmstodb_class); | ||
298 | outlet_new(x, &s_float); | ||
299 | return (x); | ||
300 | } | ||
301 | |||
302 | static void rmstodb_float(t_object *x, t_float f) | ||
303 | { | ||
304 | outlet_float(x->ob_outlet, rmstodb(f)); | ||
305 | } | ||
306 | |||
307 | |||
308 | static t_class *powtodb_class; | ||
309 | |||
310 | static void *powtodb_new(void) | ||
311 | { | ||
312 | t_object *x = (t_object *)pd_new(powtodb_class); | ||
313 | outlet_new(x, &s_float); | ||
314 | return (x); | ||
315 | } | ||
316 | |||
317 | static void powtodb_float(t_object *x, t_float f) | ||
318 | { | ||
319 | outlet_float(x->ob_outlet, powtodb(f)); | ||
320 | } | ||
321 | |||
322 | |||
323 | static t_class *dbtopow_class; | ||
324 | |||
325 | static void *dbtopow_new(void) | ||
326 | { | ||
327 | t_object *x = (t_object *)pd_new(dbtopow_class); | ||
328 | outlet_new(x, &s_float); | ||
329 | return (x); | ||
330 | } | ||
331 | |||
332 | static void dbtopow_float(t_object *x, t_float f) | ||
333 | { | ||
334 | outlet_float(x->ob_outlet, dbtopow(f)); | ||
335 | } | ||
336 | |||
337 | |||
338 | static t_class *dbtorms_class; | ||
339 | |||
340 | static void *dbtorms_new(void) | ||
341 | { | ||
342 | t_object *x = (t_object *)pd_new(dbtorms_class); | ||
343 | outlet_new(x, &s_float); | ||
344 | return (x); | ||
345 | } | ||
346 | |||
347 | static void dbtorms_float(t_object *x, t_float f) | ||
348 | { | ||
349 | outlet_float(x->ob_outlet, dbtorms(f)); | ||
350 | } | ||
351 | |||
352 | |||
353 | void x_acoustics_setup(void) | ||
354 | { | ||
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); | ||
360 | |||
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); | ||
365 | |||
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); | ||
370 | |||
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); | ||
375 | |||
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); | ||
380 | |||
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); | ||
385 | } | ||
386 | |||