FFT: Prevent user from attempting hops smaller than SC's block size
[supercollider.git] / server / plugins / ReverbUGens.cpp
bloba6ac43ca2584e295a6c5f28812d78a4cfcf5e9bc
1 // FreeVerb UGens
2 // faust code generation experiments. blackrain 07/2005
3 /* Copyright (c) 2005 blackrain <blackrain.sc@gmail.com>. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "SC_PlugIn.h"
20 // gcc3.3 mathlib doesnt know these yet
21 #if gccversion < 4
22 #define powf pow
23 #define sqrtf sqrt
24 #endif
26 static InterfaceTable *ft;
28 struct FreeVerb : public Unit
30 int iota0;
31 int iota1;
32 int iota2;
33 int iota3;
34 int iota4;
35 int iota5;
36 int iota6;
37 int iota7;
38 int iota8;
39 int iota9;
40 int iota10;
41 int iota11;
43 float R0_1;
44 float R1_1;
45 float R2_1;
46 float R3_1;
47 float R0_0;
48 float R1_0;
49 float R2_0;
50 float R3_0;
51 float R4_0;
52 float R5_0;
53 float R6_0;
54 float R7_0;
55 float R8_0;
56 float R9_0;
57 float R10_0;
58 float R11_0;
59 float R12_0;
60 float R13_0;
61 float R14_0;
62 float R15_0;
63 float R16_0;
64 float R17_0;
65 float R18_0;
66 float R19_0;
68 float dline0[225];
69 float dline1[341];
70 float dline2[441];
71 float dline3[556];
72 float dline4[1617];
73 float dline5[1557];
74 float dline6[1491];
75 float dline7[1422];
76 float dline8[1277];
77 float dline9[1116];
78 float dline10[1188];
79 float dline11[1356];
83 /* GVerb work */
84 #define FDNORDER 4
86 typedef struct {
87 int size;
88 int idx;
89 float* buf;
90 } g_fixeddelay;
92 typedef struct {
93 int size;
94 float coef;
95 int idx;
96 float* buf;
97 } g_diffuser;
99 typedef struct {
100 float damping;
101 float delay;
102 } g_damper;
106 struct GVerb : public Unit
108 float roomsize, revtime, damping, spread, inputbandwidth, drylevel, earlylevel, taillevel;
109 float maxroomsize;
110 float maxdelay, largestdelay;
111 g_damper *inputdamper;
112 g_fixeddelay *fdndels[FDNORDER];
113 float fdngains[FDNORDER];
114 int fdnlens[FDNORDER];
115 g_damper *fdndamps[FDNORDER];
116 double alpha;
117 float u[FDNORDER], f[FDNORDER], d[FDNORDER];
118 g_diffuser *ldifs[FDNORDER];
119 g_diffuser *rdifs[FDNORDER];
120 g_fixeddelay *tapdelay;
121 int taps[FDNORDER];
122 float tapgains[FDNORDER];
123 float earlylevelslope, taillevelslope, drylevelslope;
124 float fdngainslopes[FDNORDER], tapgainslopes[FDNORDER];
125 // make the CALCSLOPE values part of the struct
126 // calculate changes first, store them
127 // grab values and use in the sample loop
130 extern "C"
132 void FreeVerb_Ctor(FreeVerb *unit);
133 void FreeVerb_next(FreeVerb *unit, int inNumSamples);
136 void GVerb_Ctor(GVerb *unit);
137 void GVerb_Dtor(GVerb *unit);
138 void GVerb_next(GVerb* unit, int inNumSamples);
142 void FreeVerb_Ctor(FreeVerb *unit)
144 SETCALC(FreeVerb_next);
146 unit->iota0 = 0;
147 unit->iota1 = 0;
148 unit->iota2 = 0;
149 unit->iota3 = 0;
150 unit->iota4 = 0;
151 unit->iota5 = 0;
152 unit->iota6 = 0;
153 unit->iota7 = 0;
154 unit->iota8 = 0;
155 unit->iota9 = 0;
156 unit->iota10 = 0;
157 unit->iota11 = 0;
159 unit->R0_0 = 0.0;
160 unit->R1_0 = 0.0;
161 unit->R2_0 = 0.0;
162 unit->R3_0 = 0.0;
163 unit->R4_0 = 0.0;
164 unit->R5_0 = 0.0;
165 unit->R6_0 = 0.0;
166 unit->R7_0 = 0.0;
167 unit->R8_0 = 0.0;
168 unit->R9_0 = 0.0;
169 unit->R10_0 = 0.0;
170 unit->R11_0 = 0.0;
171 unit->R12_0 = 0.0;
172 unit->R13_0 = 0.0;
173 unit->R14_0 = 0.0;
174 unit->R15_0 = 0.0;
175 unit->R16_0 = 0.0;
176 unit->R17_0 = 0.0;
177 unit->R18_0 = 0.0;
178 unit->R19_0 = 0.0;
180 unit->R0_1 = 0.0;
181 unit->R1_1 = 0.0;
182 unit->R2_1 = 0.0;
183 unit->R3_1 = 0.0;
185 for(int i=0; i<225; i++) unit->dline0[i] = 0.0;
186 for(int i=0; i<341; i++) unit->dline1[i] = 0.0;
187 for(int i=0; i<441; i++) unit->dline2[i] = 0.0;
188 for(int i=0; i<556; i++) unit->dline3[i] = 0.0;
189 for(int i=0; i<1617; i++) unit->dline4[i] = 0.0;
190 for(int i=0; i<1557; i++) unit->dline5[i] = 0.0;
191 for(int i=0; i<1491; i++) unit->dline6[i] = 0.0;
192 for(int i=0; i<1422; i++) unit->dline7[i] = 0.0;
193 for(int i=0; i<1277; i++) unit->dline8[i] = 0.0;
194 for(int i=0; i<1116; i++) unit->dline9[i] = 0.0;
195 for(int i=0; i<1188; i++) unit->dline10[i] = 0.0;
196 for(int i=0; i<1356; i++) unit->dline11[i] = 0.0;
198 FreeVerb_next(unit, 1);
201 void FreeVerb_next(FreeVerb *unit, int inNumSamples)
203 float* input0 = IN(0);
204 float* output0 = OUT(0);
206 float ftemp0 = IN0(1); // mix
207 if (ftemp0 > 1.) ftemp0 = 1.;
208 if (ftemp0 < 0.) ftemp0 = 0.;
209 float ftemp1 = (1 - ftemp0);
211 float room = IN0(2); // room
212 if (room > 1.) room = 1.;
213 if (room < 0.) room = 0.;
214 float ftemp5 = (0.700000f + (0.280000f * room));
216 float damp = IN0(3); // damp
217 if (damp > 1.) damp = 1.;
218 if (damp < 0.) damp = 0.;
219 float ftemp6 = (0.400000f * damp);
220 float ftemp7 = (1 - ftemp6);
222 int iota0 = unit->iota0;
223 int iota1 = unit->iota1;
224 int iota2 = unit->iota2;
225 int iota3 = unit->iota3;
226 int iota4 = unit->iota4;
227 int iota5 = unit->iota5;
228 int iota6 = unit->iota6;
229 int iota7 = unit->iota7;
230 int iota8 = unit->iota8;
231 int iota9 = unit->iota9;
232 int iota10 = unit->iota10;
233 int iota11 = unit->iota11;
235 float R0_1 = unit->R0_1;
236 float R1_1 = unit->R1_1;
237 float R2_1 = unit->R2_1;
238 float R3_1 = unit->R3_1;
240 float R0_0 = unit->R0_0;
241 float R1_0 = unit->R1_0;
242 float R2_0 = unit->R2_0;
243 float R3_0 = unit->R3_0;
244 float R4_0 = unit->R4_0;
245 float R5_0 = unit->R5_0;
246 float R6_0 = unit->R6_0;
247 float R7_0 = unit->R7_0;
248 float R8_0 = unit->R8_0;
249 float R9_0 = unit->R9_0;
250 float R10_0 = unit->R10_0;
251 float R11_0 = unit->R11_0;
252 float R12_0 = unit->R12_0;
253 float R13_0 = unit->R13_0;
254 float R14_0 = unit->R14_0;
255 float R15_0 = unit->R15_0;
256 float R16_0 = unit->R16_0;
257 float R17_0 = unit->R17_0;
258 float R18_0 = unit->R18_0;
259 float R19_0 = unit->R19_0;
261 float *dline0 = unit->dline0;
262 float *dline1 = unit->dline1;
263 float *dline2 = unit->dline2;
264 float *dline3 = unit->dline3;
265 float *dline4 = unit->dline4;
266 float *dline5 = unit->dline5;
267 float *dline6 = unit->dline6;
268 float *dline7 = unit->dline7;
269 float *dline8 = unit->dline8;
270 float *dline9 = unit->dline9;
271 float *dline10 = unit->dline10;
272 float *dline11 = unit->dline11;
274 for (int i=0; i<inNumSamples; i++) {
275 float ftemp2 = input0[i];
276 float ftemp4 = (1.500000e-02f * ftemp2);
277 if (++iota0 == 225) iota0=0;
278 float T0 = dline0[iota0];
279 if (++iota1 == 341) iota1=0;
280 float T1 = dline1[iota1];
281 if (++iota2 == 441) iota2=0;
282 float T2 = dline2[iota2];
283 if (++iota3 == 556) iota3=0;
284 float T3 = dline3[iota3];
285 if (++iota4 == 1617) iota4=0;
286 float T4 = dline4[iota4];
288 R5_0 = ((ftemp7 * R4_0) + (ftemp6 * R5_0));
289 dline4[iota4] = (ftemp4 + (ftemp5 * R5_0));
290 R4_0 = T4;
291 if (++iota5 == 1557) iota5=0;
292 float T5 = dline5[iota5];
293 R7_0 = ((ftemp7 * R6_0) + (ftemp6 * R7_0));
294 dline5[iota5] = (ftemp4 + (ftemp5 * R7_0));
295 R6_0 = T5;
296 if (++iota6 == 1491) iota6=0;
297 float T6 = dline6[iota6];
298 R9_0 = ((ftemp7 * R8_0) + (ftemp6 * R9_0));
299 dline6[iota6] = (ftemp4 + (ftemp5 * R9_0));
300 R8_0 = T6;
301 if (++iota7 == 1422) iota7=0;
302 float T7 = dline7[iota7];
303 R11_0 = ((ftemp7 * R10_0) + (ftemp6 * R11_0));
304 dline7[iota7] = (ftemp4 + (ftemp5 * R11_0));
305 R10_0 = T7;
306 if (++iota8 == 1277) iota8=0;
307 float T8 = dline8[iota8];
308 R13_0 = ((ftemp7 * R12_0) + (ftemp6 * R13_0));
309 dline8[iota8] = (ftemp4 + (ftemp5 * R13_0));
310 R12_0 = T8;
311 if (++iota9 == 1116) iota9=0;
312 float T9 = dline9[iota9];
313 R15_0 = ((ftemp7 * R14_0) + (ftemp6 * R15_0));
314 dline9[iota9] = (ftemp4 + (ftemp5 * R15_0));
315 R14_0 = T9;
316 if (++iota10 == 1188) iota10=0;
317 float T10 = dline10[iota10];
318 R17_0 = ((ftemp7 * R16_0) + (ftemp6 * R17_0));
319 dline10[iota10] = (ftemp4 + (ftemp5 * R17_0));
320 R16_0 = T10;
321 if (++iota11 == 1356) iota11=0;
322 float T11 = dline11[iota11];
323 R19_0 = ((ftemp7 * R18_0) + (ftemp6 * R19_0));
324 dline11[iota11] = (ftemp4 + (ftemp5 * R19_0));
325 R18_0 = T11;
326 float ftemp8 = (R16_0 + R18_0);
327 dline3[iota3] = ((((0.500000f * R3_0) + R4_0) + (R6_0 + R8_0)) + ((R10_0 + R12_0) + (R14_0 + ftemp8)));
328 R3_0 = T3;
329 R3_1 = (R3_0 - (((R4_0 + R6_0) + (R8_0 + R10_0)) + ((R12_0 + R14_0) + ftemp8)));
330 dline2[iota2] = ((0.500000f * R2_0) + R3_1);
331 R2_0 = T2;
332 R2_1 = (R2_0 - R3_1);
333 dline1[iota1] = ((0.500000f * R1_0) + R2_1);
334 R1_0 = T1;
335 R1_1 = (R1_0 - R2_1);
336 dline0[iota0] = ((0.500000f * R0_0) + R1_1);
337 R0_0 = T0;
338 R0_1 = (R0_0 - R1_1);
339 output0[i] = ((ftemp1 * ftemp2) + (ftemp0 * R0_1));
343 unit->iota0 = iota0;
344 unit->iota1 = iota1;
345 unit->iota2 = iota2;
346 unit->iota3 = iota3;
347 unit->iota4 = iota4;
348 unit->iota5 = iota5;
349 unit->iota6 = iota6;
350 unit->iota7 = iota7;
351 unit->iota8 = iota8;
352 unit->iota9 = iota9;
353 unit->iota10 = iota10;
354 unit->iota11 = iota11;
356 unit->R0_1 = R0_1;
357 unit->R1_1 = R1_1;
358 unit->R2_1 = R2_1;
359 unit->R3_1 = R3_1;
361 unit->R0_0 = R0_0;
362 unit->R1_0 = R1_0;
363 unit->R2_0 = R2_0;
364 unit->R3_0 = R3_0;
365 unit->R4_0 = R4_0;
366 unit->R5_0 = R5_0;
367 unit->R6_0 = R6_0;
368 unit->R7_0 = R7_0;
369 unit->R8_0 = R8_0;
370 unit->R9_0 = R9_0;
371 unit->R10_0 = R10_0;
372 unit->R11_0 = R11_0;
373 unit->R12_0 = R12_0;
374 unit->R13_0 = R13_0;
375 unit->R14_0 = R14_0;
376 unit->R15_0 = R15_0;
377 unit->R16_0 = R16_0;
378 unit->R17_0 = R17_0;
379 unit->R18_0 = R18_0;
380 unit->R19_0 = R19_0;
383 // FreeVerb2
384 struct FreeVerb2 : public Unit
386 int iota0;
387 int iota1;
388 int iota2;
389 int iota3;
390 int iota4;
391 int iota5;
392 int iota6;
393 int iota7;
394 int iota8;
395 int iota9;
396 int iota10;
397 int iota11;
398 int iota12;
399 int iota13;
400 int iota14;
401 int iota15;
402 int iota16;
403 int iota17;
404 int iota18;
405 int iota19;
406 int iota20;
407 int iota21;
408 int iota22;
409 int iota23;
410 float R0_1;
411 float R1_1;
412 float R2_1;
413 float R3_1;
414 float R0_0;
415 float R1_0;
416 float R2_0;
417 float R3_0;
418 float R4_0;
419 float R5_0;
420 float R6_0;
421 float R7_0;
422 float R8_0;
423 float R9_0;
424 float R10_0;
425 float R11_0;
426 float R12_0;
427 float R13_0;
428 float R14_0;
429 float R15_0;
430 float R16_0;
431 float R17_0;
432 float R18_0;
433 float R19_0;
434 float R20_0;
435 float R21_0;
436 float R22_0;
437 float R23_0;
438 float R24_0;
439 float R25_0;
440 float R26_0;
441 float R27_0;
442 float R28_0;
443 float R29_0;
444 float R30_0;
445 float R31_0;
446 float R32_0;
447 float R33_0;
448 float R34_0;
449 float R35_0;
450 float R36_0;
451 float R37_0;
452 float R38_0;
453 float R39_0;
454 float R20_1;
455 float R21_1;
456 float R22_1;
457 float R23_1;
458 float dline0[225];
459 float dline1[341];
460 float dline2[441];
461 float dline3[556];
462 float dline4[1617];
463 float dline5[1557];
464 float dline6[1491];
465 float dline7[1422];
466 float dline8[1277];
467 float dline9[1116];
468 float dline10[1188];
469 float dline11[1356];
470 float dline12[248];
471 float dline13[364];
472 float dline14[464];
473 float dline15[579];
474 float dline16[1640];
475 float dline17[1580];
476 float dline18[1514];
477 float dline19[1445];
478 float dline20[1300];
479 float dline21[1139];
480 float dline22[1211];
481 float dline23[1379];
484 extern "C"
486 void FreeVerb2_Ctor(FreeVerb2 *unit);
487 void FreeVerb2_next(FreeVerb2 *unit, int inNumSamples);
491 void FreeVerb2_Ctor(FreeVerb2 *unit)
493 SETCALC(FreeVerb2_next);
495 unit->iota0 = 0;
496 unit->iota1 = 0;
497 unit->iota2 = 0;
498 unit->iota3 = 0;
499 unit->iota4 = 0;
500 unit->iota5 = 0;
501 unit->iota6 = 0;
502 unit->iota7 = 0;
503 unit->iota8 = 0;
504 unit->iota9 = 0;
505 unit->iota10 = 0;
506 unit->iota11 = 0;
507 unit->iota12 = 0;
508 unit->iota13 = 0;
509 unit->iota14 = 0;
510 unit->iota15 = 0;
511 unit->iota16 = 0;
512 unit->iota17 = 0;
513 unit->iota18 = 0;
514 unit->iota19 = 0;
515 unit->iota20 = 0;
516 unit->iota21 = 0;
517 unit->iota22 = 0;
518 unit->iota23 = 0;
520 unit->R0_0 = 0.0;
521 unit->R1_0 = 0.0;
522 unit->R2_0 = 0.0;
523 unit->R3_0 = 0.0;
524 unit->R4_0 = 0.0;
525 unit->R5_0 = 0.0;
526 unit->R6_0 = 0.0;
527 unit->R7_0 = 0.0;
528 unit->R8_0 = 0.0;
529 unit->R9_0 = 0.0;
530 unit->R10_0 = 0.0;
531 unit->R11_0 = 0.0;
532 unit->R12_0 = 0.0;
533 unit->R13_0 = 0.0;
534 unit->R14_0 = 0.0;
535 unit->R15_0 = 0.0;
536 unit->R16_0 = 0.0;
537 unit->R17_0 = 0.0;
538 unit->R18_0 = 0.0;
539 unit->R19_0 = 0.0;
540 unit->R20_0 = 0.0;
541 unit->R21_0 = 0.0;
542 unit->R22_0 = 0.0;
543 unit->R23_0 = 0.0;
544 unit->R24_0 = 0.0;
545 unit->R25_0 = 0.0;
546 unit->R26_0 = 0.0;
547 unit->R27_0 = 0.0;
548 unit->R28_0 = 0.0;
549 unit->R29_0 = 0.0;
550 unit->R30_0 = 0.0;
551 unit->R31_0 = 0.0;
552 unit->R32_0 = 0.0;
553 unit->R33_0 = 0.0;
554 unit->R34_0 = 0.0;
555 unit->R35_0 = 0.0;
556 unit->R36_0 = 0.0;
557 unit->R37_0 = 0.0;
558 unit->R38_0 = 0.0;
559 unit->R39_0 = 0.0;
561 unit->R0_1 = 0.0;
562 unit->R1_1 = 0.0;
563 unit->R2_1 = 0.0;
564 unit->R3_1 = 0.0;
566 unit->R23_1 = 0.0;
567 unit->R22_1 = 0.0;
568 unit->R21_1 = 0.0;
569 unit->R20_1 = 0.0;
571 for(int i=0; i<225; i++) unit->dline0[i] = 0.0;
572 for(int i=0; i<341; i++) unit->dline1[i] = 0.0;
573 for(int i=0; i<441; i++) unit->dline2[i] = 0.0;
574 for(int i=0; i<556; i++) unit->dline3[i] = 0.0;
575 for(int i=0; i<1617; i++) unit->dline4[i] = 0.0;
576 for(int i=0; i<1557; i++) unit->dline5[i] = 0.0;
577 for(int i=0; i<1491; i++) unit->dline6[i] = 0.0;
578 for(int i=0; i<1422; i++) unit->dline7[i] = 0.0;
579 for(int i=0; i<1277; i++) unit->dline8[i] = 0.0;
580 for(int i=0; i<1116; i++) unit->dline9[i] = 0.0;
581 for(int i=0; i<1188; i++) unit->dline10[i] = 0.0;
582 for(int i=0; i<1356; i++) unit->dline11[i] = 0.0;
583 for(int i=0; i<248; i++) unit->dline12[i] = 0.0;
584 for(int i=0; i<364; i++) unit->dline13[i] = 0.0;
585 for(int i=0; i<464; i++) unit->dline14[i] = 0.0;
586 for(int i=0; i<579; i++) unit->dline15[i] = 0.0;
587 for(int i=0; i<1640; i++) unit->dline16[i] = 0.0;
588 for(int i=0; i<1580; i++) unit->dline17[i] = 0.0;
589 for(int i=0; i<1514; i++) unit->dline18[i] = 0.0;
590 for(int i=0; i<1445; i++) unit->dline19[i] = 0.0;
591 for(int i=0; i<1300; i++) unit->dline20[i] = 0.0;
592 for(int i=0; i<1139; i++) unit->dline21[i] = 0.0;
593 for(int i=0; i<1211; i++) unit->dline22[i] = 0.0;
594 for(int i=0; i<1379; i++) unit->dline23[i] = 0.0;
596 FreeVerb2_next(unit, 1);
599 void FreeVerb2_next(FreeVerb2 *unit, int inNumSamples)
601 float* input0 = IN(0);
602 float* input1 = IN(1);
603 float* output0 = OUT(0);
604 float* output1 = OUT(1);
606 float ftemp0 = IN0(2); // mix
607 if (ftemp0 > 1.) ftemp0 = 1.;
608 if (ftemp0 < 0.) ftemp0 = 0.;
609 float ftemp1 = (1 - ftemp0);
611 float room = IN0(3); // room
612 if (room > 1.) room = 1.;
613 if (room < 0.) room = 0.;
614 float ftemp5 = (0.700000f + (0.280000f * room));
616 float damp = IN0(4); // damp
617 if (damp > 1.) damp = 1.;
618 if (damp < 0.) damp = 0.;
619 float ftemp6 = (0.400000f * damp);
620 float ftemp7 = (1 - ftemp6);
622 float R0_0 = unit->R0_0;
623 float R1_0 = unit->R1_0;
624 float R2_0 = unit->R2_0;
625 float R3_0 = unit->R3_0;
626 float R4_0 = unit->R4_0;
627 float R5_0 = unit->R5_0;
628 float R6_0 = unit->R6_0;
629 float R7_0 = unit->R7_0;
630 float R8_0 = unit->R8_0;
631 float R9_0 = unit->R9_0;
632 float R10_0 = unit->R10_0;
633 float R11_0 = unit->R11_0;
634 float R12_0 = unit->R12_0;
635 float R13_0 = unit->R13_0;
636 float R14_0 = unit->R14_0;
637 float R15_0 = unit->R15_0;
638 float R16_0 = unit->R16_0;
639 float R17_0 = unit->R17_0;
640 float R18_0 = unit->R18_0;
641 float R19_0 = unit->R19_0;
642 float R20_0 = unit->R20_0;
643 float R21_0 = unit->R21_0;
644 float R22_0 = unit->R22_0;
645 float R23_0 = unit->R23_0;
646 float R24_0 = unit->R24_0;
647 float R25_0 = unit->R25_0;
648 float R26_0 = unit->R26_0;
649 float R27_0 = unit->R27_0;
650 float R28_0 = unit->R28_0;
651 float R29_0 = unit->R29_0;
652 float R30_0 = unit->R30_0;
653 float R31_0 = unit->R31_0;
654 float R32_0 = unit->R32_0;
655 float R33_0 = unit->R33_0;
656 float R34_0 = unit->R34_0;
657 float R35_0 = unit->R35_0;
658 float R36_0 = unit->R36_0;
659 float R37_0 = unit->R37_0;
660 float R38_0 = unit->R38_0;
661 float R39_0 = unit->R39_0;
663 float R0_1 = unit->R0_1;
664 float R1_1 = unit->R1_1;
665 float R2_1 = unit->R2_1;
666 float R3_1 = unit->R3_1;
668 float R23_1 = unit->R23_1;
669 float R22_1 = unit->R22_1;
670 float R21_1 = unit->R21_1;
671 float R20_1 = unit->R20_1;
673 int iota0 = unit->iota0;
674 int iota1 = unit->iota1;
675 int iota2 = unit->iota2;
676 int iota3 = unit->iota3;
677 int iota4 = unit->iota4;
678 int iota5 = unit->iota5;
679 int iota6 = unit->iota6;
680 int iota7 = unit->iota7;
681 int iota8 = unit->iota8;
682 int iota9 = unit->iota9;
683 int iota10 = unit->iota10;
684 int iota11 = unit->iota11;
685 int iota12 = unit->iota12;
686 int iota13 = unit->iota13;
687 int iota14 = unit->iota14;
688 int iota15 = unit->iota15;
689 int iota16 = unit->iota16;
690 int iota17 = unit->iota17;
691 int iota18 = unit->iota18;
692 int iota19 = unit->iota19;
693 int iota20 = unit->iota20;
694 int iota21 = unit->iota21;
695 int iota22 = unit->iota22;
696 int iota23 = unit->iota23;
698 float *dline0 = unit->dline0;
699 float *dline1 = unit->dline1;
700 float *dline2 = unit->dline2;
701 float *dline3 = unit->dline3;
702 float *dline4 = unit->dline4;
703 float *dline5 = unit->dline5;
704 float *dline6 = unit->dline6;
705 float *dline7 = unit->dline7;
706 float *dline8 = unit->dline8;
707 float *dline9 = unit->dline9;
708 float *dline10 = unit->dline10;
709 float *dline11 = unit->dline11;
710 float *dline12 = unit->dline12;
711 float *dline13 = unit->dline13;
712 float *dline14 = unit->dline14;
713 float *dline15 = unit->dline15;
714 float *dline16 = unit->dline16;
715 float *dline17 = unit->dline17;
716 float *dline18 = unit->dline18;
717 float *dline19 = unit->dline19;
718 float *dline20 = unit->dline20;
719 float *dline21 = unit->dline21;
720 float *dline22 = unit->dline22;
721 float *dline23 = unit->dline23;
723 for (int i=0; i<inNumSamples; i++) {
725 float ftemp2 = input0[i];
726 if (++iota0 == 225) iota0=0;
727 float T0 = dline0[iota0];
728 if (++iota1 == 341) iota1=0;
729 float T1 = dline1[iota1];
730 if (++iota2 == 441) iota2=0;
731 float T2 = dline2[iota2];
732 if (++iota3 == 556) iota3=0;
733 float T3 = dline3[iota3];
734 if (++iota4 == 1617) iota4=0;
735 float T4 = dline4[iota4];
736 float ftemp3 = input1[i];
737 float ftemp4 = (1.500000e-02f * (ftemp2 + ftemp3));
738 R5_0 = ((ftemp7 * R4_0) + (ftemp6 * R5_0));
739 dline4[iota4] = (ftemp4 + (ftemp5 * R5_0));
740 R4_0 = T4;
741 if (++iota5 == 1557) iota5=0;
742 float T5 = dline5[iota5];
743 R7_0 = ((ftemp7 * R6_0) + (ftemp6 * R7_0));
744 dline5[iota5] = (ftemp4 + (ftemp5 * R7_0));
745 R6_0 = T5;
746 if (++iota6 == 1491) iota6=0;
747 float T6 = dline6[iota6];
748 R9_0 = ((ftemp7 * R8_0) + (ftemp6 * R9_0));
749 dline6[iota6] = (ftemp4 + (ftemp5 * R9_0));
750 R8_0 = T6;
751 if (++iota7 == 1422) iota7=0;
752 float T7 = dline7[iota7];
753 R11_0 = ((ftemp7 * R10_0) + (ftemp6 * R11_0));
754 dline7[iota7] = (ftemp4 + (ftemp5 * R11_0));
755 R10_0 = T7;
756 if (++iota8 == 1277) iota8=0;
757 float T8 = dline8[iota8];
758 R13_0 = ((ftemp7 * R12_0) + (ftemp6 * R13_0));
759 dline8[iota8] = (ftemp4 + (ftemp5 * R13_0));
760 R12_0 = T8;
761 if (++iota9 == 1116) iota9=0;
762 float T9 = dline9[iota9];
763 R15_0 = ((ftemp7 * R14_0) + (ftemp6 * R15_0));
764 dline9[iota9] = (ftemp4 + (ftemp5 * R15_0));
765 R14_0 = T9;
766 if (++iota10 == 1188) iota10=0;
767 float T10 = dline10[iota10];
768 R17_0 = ((ftemp7 * R16_0) + (ftemp6 * R17_0));
769 dline10[iota10] = (ftemp4 + (ftemp5 * R17_0));
770 R16_0 = T10;
771 if (++iota11 == 1356) iota11=0;
772 float T11 = dline11[iota11];
773 R19_0 = ((ftemp7 * R18_0) + (ftemp6 * R19_0));
774 dline11[iota11] = (ftemp4 + (ftemp5 * R19_0));
775 R18_0 = T11;
776 float ftemp8 = (R16_0 + R18_0);
777 dline3[iota3] = ((((0.500000f * R3_0) + R4_0) + (R6_0 + R8_0)) + ((R10_0 + R12_0) + (R14_0 + ftemp8)));
778 R3_0 = T3;
779 R3_1 = (R3_0 - (((R4_0 + R6_0) + (R8_0 + R10_0)) + ((R12_0 + R14_0) + ftemp8)));
780 dline2[iota2] = ((0.500000f * R2_0) + R3_1);
781 R2_0 = T2;
782 R2_1 = (R2_0 - R3_1);
783 dline1[iota1] = ((0.500000f * R1_0) + R2_1);
784 R1_0 = T1;
785 R1_1 = (R1_0 - R2_1);
786 dline0[iota0] = ((0.500000f * R0_0) + R1_1);
787 R0_0 = T0;
788 R0_1 = (R0_0 - R1_1);
789 output0[i] = ((ftemp1 * ftemp2) + (ftemp0 * R0_1));
791 // right chn
792 if (++iota12 == 248) iota12=0;
793 float T12 = dline12[iota12];
794 if (++iota13 == 364) iota13=0;
795 float T13 = dline13[iota13];
796 if (++iota14 == 464) iota14=0;
797 float T14 = dline14[iota14];
798 if (++iota15 == 579) iota15=0;
799 float T15 = dline15[iota15];
800 if (++iota16 == 1640) iota16=0;
801 float T16 = dline16[iota16];
802 R25_0 = ((ftemp7 * R24_0) + (ftemp6 * R25_0));
803 dline16[iota16] = (ftemp4 + (ftemp5 * R25_0));
804 R24_0 = T16;
805 if (++iota17 == 1580) iota17=0;
806 float T17 = dline17[iota17];
807 R27_0 = ((ftemp7 * R26_0) + (ftemp6 * R27_0));
808 dline17[iota17] = (ftemp4 + (ftemp5 * R27_0));
809 R26_0 = T17;
810 if (++iota18 == 1514) iota18=0;
811 float T18 = dline18[iota18];
812 R29_0 = ((ftemp7 * R28_0) + (ftemp6 * R29_0));
813 dline18[iota18] = (ftemp4 + (ftemp5 * R29_0));
814 R28_0 = T18;
815 if (++iota19 == 1445) iota19=0;
816 float T19 = dline19[iota19];
817 R31_0 = ((ftemp7 * R30_0) + (ftemp6 * R31_0));
818 dline19[iota19] = (ftemp4 + (ftemp5 * R31_0));
819 R30_0 = T19;
820 if (++iota20 == 1300) iota20=0;
821 float T20 = dline20[iota20];
822 R33_0 = ((ftemp7 * R32_0) + (ftemp6 * R33_0));
823 dline20[iota20] = (ftemp4 + (ftemp5 * R33_0));
824 R32_0 = T20;
825 if (++iota21 == 1139) iota21=0;
826 float T21 = dline21[iota21];
827 R35_0 = ((ftemp7 * R34_0) + (ftemp6 * R35_0));
828 dline21[iota21] = (ftemp4 + (ftemp5 * R35_0));
829 R34_0 = T21;
830 if (++iota22 == 1211) iota22=0;
831 float T22 = dline22[iota22];
832 R37_0 = ((ftemp7 * R36_0) + (ftemp6 * R37_0));
833 dline22[iota22] = (ftemp4 + (ftemp5 * R37_0));
834 R36_0 = T22;
835 if (++iota23 == 1379) iota23=0;
836 float T23 = dline23[iota23];
837 R39_0 = ((ftemp7 * R38_0) + (ftemp6 * R39_0));
838 dline23[iota23] = (ftemp4 + (ftemp5 * R39_0));
839 R38_0 = T23;
840 float ftemp9 = (R36_0 + R38_0);
841 dline15[iota15] = ((((0.500000f * R23_0) + R24_0) + (R26_0 + R28_0)) + ((R30_0 + R32_0) +
842 (R34_0 + ftemp9)));
843 R23_0 = T15;
844 R23_1 = (R23_0 - (((R24_0 + R26_0) + (R28_0 + R30_0)) + ((R32_0 + R34_0) + ftemp9)));
845 dline14[iota14] = ((0.500000f * R22_0) + R23_1);
846 R22_0 = T14;
847 R22_1 = (R22_0 - R23_1);
848 dline13[iota13] = ((0.500000f * R21_0) + R22_1);
849 R21_0 = T13;
850 R21_1 = (R21_0 - R22_1);
851 dline12[iota12] = ((0.500000f * R20_0) + R21_1);
852 R20_0 = T12;
853 R20_1 = (R20_0 - R21_1);
854 output1[i] = ((ftemp1 * ftemp3) + (ftemp0 * R20_1));
857 unit->iota0 = iota0;
858 unit->iota1 = iota1;
859 unit->iota2 = iota2;
860 unit->iota3 = iota3;
861 unit->iota4 = iota4;
862 unit->iota5 = iota5;
863 unit->iota6 = iota6;
864 unit->iota7 = iota7;
865 unit->iota8 = iota8;
866 unit->iota9 = iota9;
867 unit->iota10 = iota10;
868 unit->iota11 = iota11;
869 unit->iota12 = iota12;
870 unit->iota13 = iota13;
871 unit->iota14 = iota14;
872 unit->iota15 = iota15;
873 unit->iota16 = iota16;
874 unit->iota17 = iota17;
875 unit->iota18 = iota18;
876 unit->iota19 = iota19;
877 unit->iota20 = iota20;
878 unit->iota21 = iota21;
879 unit->iota22 = iota22;
880 unit->iota23 = iota23;
882 unit->R0_1 = R0_1;
883 unit->R1_1 = R1_1;
884 unit->R2_1 = R2_1;
885 unit->R3_1 = R3_1;
887 unit->R20_1 = R20_1;
888 unit->R21_1 = R21_1;
889 unit->R22_1 = R22_1;
890 unit->R23_1 = R23_1;
892 unit->R0_0 = R0_0;
893 unit->R1_0 = R1_0;
894 unit->R2_0 = R2_0;
895 unit->R3_0 = R3_0;
896 unit->R4_0 = R4_0;
897 unit->R5_0 = R5_0;
898 unit->R6_0 = R6_0;
899 unit->R7_0 = R7_0;
900 unit->R8_0 = R8_0;
901 unit->R9_0 = R9_0;
902 unit->R10_0 = R10_0;
903 unit->R11_0 = R11_0;
904 unit->R12_0 = R12_0;
905 unit->R13_0 = R13_0;
906 unit->R14_0 = R14_0;
907 unit->R15_0 = R15_0;
908 unit->R16_0 = R16_0;
909 unit->R17_0 = R17_0;
910 unit->R18_0 = R18_0;
911 unit->R19_0 = R19_0;
912 unit->R20_0 = R20_0;
913 unit->R21_0 = R21_0;
914 unit->R22_0 = R22_0;
915 unit->R23_0 = R23_0;
916 unit->R24_0 = R24_0;
917 unit->R25_0 = R25_0;
918 unit->R26_0 = R26_0;
919 unit->R27_0 = R27_0;
920 unit->R28_0 = R28_0;
921 unit->R29_0 = R29_0;
922 unit->R30_0 = R30_0;
923 unit->R31_0 = R31_0;
924 unit->R32_0 = R32_0;
925 unit->R33_0 = R33_0;
926 unit->R34_0 = R34_0;
927 unit->R35_0 = R35_0;
928 unit->R36_0 = R36_0;
929 unit->R37_0 = R37_0;
930 unit->R38_0 = R38_0;
931 unit->R39_0 = R39_0;
937 #define TRUE 1
938 #define FALSE 0
940 typedef union {
941 float f;
942 #ifdef _WIN32
943 long int i;
944 #else
945 int32_t i;
946 #endif
947 } ls_pcast32;
949 static inline float flush_to_zero(float f)
951 ls_pcast32 v;
952 v.f = f;
953 // original: return (v.i & 0x7f800000) == 0 ? 0.0f : f;
954 // version from Tim Blechmann
955 return (v.i & 0x7f800000) < 0x08000000 ? 0.0f : f;
958 int isprime(int n)
960 unsigned int i;
961 const unsigned int lim = (int)sqrtf((float)n);
963 if (n == 2) return(TRUE);
964 if ((n & 1) == 0) return(FALSE);
965 for(i = 3; i <= lim; i += 2)
966 if ((n % i) == 0) return(FALSE);
967 return(TRUE);
970 int nearestprime(int n, float rerror)
972 int bound,k;
974 if (isprime(n)) return(n);
975 /* assume n is large enough and n*rerror enough smaller than n */
976 bound = (int)(n * rerror);
977 for(k = 1; k <= bound; k++) {
978 if (isprime(n+k)) return(n+k);
979 if (isprime(n-k)) return(n-k);
981 return(-1);
984 static inline int f_round(float f){
985 ls_pcast32 p;
986 p.f = f;
987 p.f += (3<<22);
988 return p.i - 0x4b400000;
991 g_damper *make_damper(GVerb *unit, float damping){
992 g_damper* p;
993 p = (g_damper*)RTAlloc(unit->mWorld, sizeof(g_damper));
994 p->damping = damping;
995 p->delay = 0.f;
996 return(p);
999 void free_damper(GVerb *unit, g_damper *p){
1000 RTFree(unit->mWorld, p);
1003 g_diffuser *make_diffuser(GVerb *unit, int size, float coef){
1004 g_diffuser* p;
1005 p = (g_diffuser*)RTAlloc(unit->mWorld, sizeof(g_diffuser));
1006 p->size = size;
1007 p->coef = coef;
1008 p->idx = 0;
1009 p->buf = (float*)RTAlloc(unit->mWorld, size * sizeof(float));
1010 Clear(size, p->buf);
1011 return(p);
1014 void free_diffuser(GVerb *unit, g_diffuser *p){
1015 RTFree(unit->mWorld, p->buf);
1016 RTFree(unit->mWorld, p);
1019 g_fixeddelay *make_fixeddelay(GVerb *unit, int size, int maxsize){
1020 g_fixeddelay *p;
1021 p = (g_fixeddelay*)RTAlloc(unit->mWorld, sizeof(g_fixeddelay));
1022 p->size = size;
1023 p->idx = 0;
1024 p->buf = (float*)RTAlloc(unit->mWorld, maxsize * sizeof(float));
1025 Clear(maxsize, p->buf);
1026 return(p);
1029 void free_fixeddelay(GVerb *unit, g_fixeddelay *p){
1030 RTFree(unit->mWorld, p->buf);
1031 RTFree(unit->mWorld, p);
1034 static inline float diffuser_do(GVerb *unit, g_diffuser *p, float x){
1035 float y,w;
1036 w = x - p->buf[p->idx] * p->coef;
1037 w = flush_to_zero(w);
1038 y = p->buf[p->idx] + w * p->coef;
1039 p->buf[p->idx] = zapgremlins(w);
1040 p->idx = (p->idx + 1) % p->size;
1041 return(y);
1044 static inline float fixeddelay_read(GVerb *unit, g_fixeddelay *p, int n){
1045 int i;
1046 i = (p->idx - n + p->size) % p->size;
1047 return(p->buf[i]);
1050 static inline void fixeddelay_write(GVerb *unit, g_fixeddelay *p, float x){
1051 p->buf[p->idx] = zapgremlins(x);
1052 p->idx = (p->idx + 1) % p->size;
1055 static inline void damper_set(GVerb *unit, g_damper *p, float damping){
1056 p->damping = damping;
1059 static inline float damper_do(GVerb *unit, g_damper *p, float x){
1060 float y;
1061 y = x*(1.0-p->damping) + p->delay*p->damping;
1062 p->delay = zapgremlins(y);
1063 return(y);
1066 static inline void gverb_fdnmatrix(float *a, float *b){
1067 const float dl0 = a[0], dl1 = a[1], dl2 = a[2], dl3 = a[3];
1068 b[0] = 0.5f*(+dl0 + dl1 - dl2 - dl3);
1069 b[1] = 0.5f*(+dl0 - dl1 - dl2 + dl3);
1070 b[2] = 0.5f*(-dl0 + dl1 - dl2 + dl3);
1071 b[3] = 0.5f*(+dl0 + dl1 + dl2 + dl3);
1074 static inline void gverb_set_roomsize(GVerb *unit, const float a)
1076 unsigned int i;
1078 if (a <= 1.0 || sc_isnan(a)) {
1079 unit->roomsize = 1.0;
1080 } else {
1081 if(a >= unit->maxroomsize)
1082 unit->roomsize = unit->maxroomsize - 1.;
1083 else
1084 unit->roomsize = a;
1087 unit->largestdelay = SAMPLERATE * unit->roomsize / 340.0; // * 0.00294f;
1089 // the line below causes everything to blow up.... why?????
1090 // unit->fdnlens[0] = nearestprime((int)(unit->largestdelay), 0.5);
1091 unit->fdnlens[1] = (int)(0.816490*unit->largestdelay);
1092 unit->fdnlens[2] = (int)(0.707100*unit->largestdelay);
1093 unit->fdnlens[3] = (int)(0.632450*unit->largestdelay);
1095 for(i = 0; i < FDNORDER; i++) {
1096 float oldfdngain = unit->fdngains[i];
1097 unit->fdngains[i] = -powf((float)unit->alpha, unit->fdnlens[i]);
1098 unit->fdngainslopes[i] = CALCSLOPE(unit->fdngains[i], oldfdngain);
1101 unit->taps[0] = 5 + (int)(0.410 * unit->largestdelay);
1102 unit->taps[1] = 5 + (int)(0.300 * unit->largestdelay);
1103 unit->taps[2] = 5 + (int)(0.155 * unit->largestdelay);
1104 unit->taps[3] = 5; //+ f_round(0.000 * largestdelay);
1106 for(i = 0; i < FDNORDER; i++) {
1107 float oldtapgain = unit->tapgains[i];
1108 unit->tapgains[i] = pow(unit->alpha, unit->taps[i]);
1109 unit->tapgainslopes[i] = CALCSLOPE(unit->tapgains[i], oldtapgain);
1114 static inline void gverb_set_revtime(GVerb *unit, float a)
1116 float ga;
1117 double n;
1118 unsigned int i;
1120 unit->revtime = a;
1122 ga = 0.001;
1123 n = SAMPLERATE * a;
1124 unit->alpha = (double)powf(ga,(float)(1.f/n));
1126 for(i = 0; i < FDNORDER; i++) {
1127 float oldfdngain = unit->fdngains[i];
1128 unit->fdngains[i] = -powf((float)unit->alpha, unit->fdnlens[i]);
1129 unit->fdngainslopes[i] = CALCSLOPE(unit->fdngains[i], oldfdngain);
1134 static inline void gverb_set_damping(GVerb *unit,float a)
1136 unsigned int i;
1138 unit->damping = a;
1139 for(i = 0; i < FDNORDER; i++) {
1140 damper_set(unit, unit->fdndamps[i], unit->damping);
1144 static inline void gverb_set_inputbandwidth(GVerb *unit,float a)
1146 unit->inputbandwidth = a;
1147 damper_set(unit, unit->inputdamper, 1.0 - unit->inputbandwidth);
1150 static inline float gverb_set_earlylevel(GVerb *unit, float a)
1152 float oldearly = unit->earlylevel;
1153 unit->earlylevel = a;
1154 unit->earlylevelslope = CALCSLOPE(a, oldearly);
1155 return(oldearly);
1158 static inline float gverb_set_taillevel(GVerb *unit, float a)
1160 float oldtail = unit->taillevel;
1161 unit->taillevel = a;
1162 unit->taillevelslope = CALCSLOPE(a, oldtail);
1163 return(oldtail);
1166 static inline float gverb_set_drylevel(GVerb *unit, float a)
1168 float olddry = unit->drylevel;
1169 unit->drylevel = a;
1170 unit->drylevelslope = CALCSLOPE(a, olddry);
1171 return(olddry);
1174 void GVerb_Ctor(GVerb *unit)
1176 SETCALC(GVerb_next);
1177 float roomsize = unit->roomsize = IN0(1);
1178 float revtime = unit->revtime = IN0(2);
1179 float damping = unit->damping = IN0(3);
1180 float inputbandwidth = unit->inputbandwidth = 0.; //IN0(4);
1181 float spread = unit->spread = IN0(5);
1182 unit->drylevel = 0.; //IN0(6);
1183 unit->earlylevel = 0.; // IN0(7);
1184 unit->taillevel = 0.; //IN0(8);
1186 float maxroomsize = unit->maxroomsize = IN0(9);
1188 float maxdelay = unit->maxdelay = SAMPLERATE*maxroomsize/340.f;
1189 float largestdelay = unit->largestdelay = SAMPLERATE*roomsize/340.f;
1191 // make the inputdamper
1192 unit->inputdamper = make_damper(unit, 1. - inputbandwidth);
1194 //float ga = powf(10.f, -60.f/20.f);
1195 float ga = 0.001f;
1196 float n = SAMPLERATE * revtime;
1197 double alpha = unit->alpha = pow((double)ga, 1./(double)n);
1198 float gbmul[4] = {1.000, 0.816490, 0.707100, 0.632450};
1199 for(int i = 0; i < FDNORDER; ++i){
1200 float gb = gbmul[i] * largestdelay;
1201 if(i == 0){
1202 unit->fdnlens[i] = nearestprime((int)gb, 0.5);
1203 } else {
1204 unit->fdnlens[i] = f_round(gb);
1206 unit->fdngains[i] = -powf((float)alpha, unit->fdnlens[i]);
1208 // make the fixeddelay lines and dampers
1209 for(int i = 0; i < FDNORDER; i++){
1210 unit->fdndels[i] = make_fixeddelay(unit, (int)unit->fdnlens[i], (int)maxdelay+1000);
1211 unit->fdndamps[i] = make_damper(unit, damping); // damping is the same as fdndamping in source
1214 // diffuser section
1215 float diffscale = (float)unit->fdnlens[3]/(210. + 159. + 562. + 410.);
1216 float spread1 = spread;
1217 float spread2 = 3.0 * spread;
1219 int b = 210;
1220 float r = 0.125541;
1221 int a = (int)(spread1 * r);
1222 int c = 210+159 + a;
1223 int cc = c - b;
1224 r = 0.854046;
1225 a = (int)(spread2 * r);
1226 int d = 210 + 159 + 562 + a;
1227 int dd = d - c;
1228 int e = 1341 - d;
1230 unit->ldifs[0] = make_diffuser(unit, f_round(diffscale * b), 0.75);
1231 unit->ldifs[1] = make_diffuser(unit, f_round(diffscale * cc), 0.75);
1232 unit->ldifs[2] = make_diffuser(unit, f_round(diffscale * dd), 0.625);
1233 unit->ldifs[3] = make_diffuser(unit, f_round(diffscale * e), 0.625);
1234 b = 210;
1235 r = -0.568366;
1236 a = (int)(spread1 * r);
1237 c = 210 + 159 + a;
1238 cc = c - b;
1239 r = -0.126815;
1240 a = (int)(spread2 * r);
1241 d = 210 + 159 + 562 + a;
1242 dd = d - c;
1243 e = 1341 - d;
1245 unit->rdifs[0] = make_diffuser(unit, f_round(diffscale * b), 0.75);
1246 unit->rdifs[1] = make_diffuser(unit, f_round(diffscale * cc), 0.75);
1247 unit->rdifs[2] = make_diffuser(unit, f_round(diffscale * dd), 0.625);
1248 unit->rdifs[3] = make_diffuser(unit, f_round(diffscale * e), 0.625);
1250 unit->taps[0] = 5 + (int)(0.410 * largestdelay);
1251 unit->taps[1] = 5 + (int)(0.300 * largestdelay);
1252 unit->taps[2] = 5 + (int)(0.155 * largestdelay);
1253 unit->taps[3] = 5; //+ f_round(0.000 * largestdelay);
1255 for(int i = 0; i < FDNORDER; i++) {
1256 unit->tapgains[i] = pow(alpha,(double)unit->taps[i]);
1259 unit->tapdelay = make_fixeddelay(unit, 44000, 44000);
1261 // init the slope values
1262 unit->earlylevelslope = unit->drylevelslope = unit->taillevelslope = 0.f;
1263 ClearUnitOutputs(unit, 1);
1266 void GVerb_Dtor(GVerb *unit)
1268 free_damper(unit, unit->inputdamper);
1269 free_fixeddelay(unit, unit->tapdelay);
1271 for(int i = 0; i < FDNORDER; i++){
1272 free_fixeddelay(unit, unit->fdndels[i]);
1273 free_damper(unit, unit->fdndamps[i]);
1274 free_diffuser(unit, unit->ldifs[i]);
1275 free_diffuser(unit, unit->rdifs[i]);
1279 void GVerb_next(GVerb* unit, int inNumSamples)
1281 float* in = IN(0);
1282 float* outl = OUT(0);
1283 float* outr = OUT(1);
1284 float roomsize = IN0(1);
1285 float revtime = IN0(2);
1286 float damping = IN0(3);
1287 float inputbandwidth = IN0(4);
1288 //float spread = IN0(5); // spread can only be set at inittime
1289 float drylevel = IN0(6);
1290 float earlylevel = IN0(7);
1291 float taillevel = IN0(8);
1292 float earlylevelslope, taillevelslope, drylevelslope;
1293 float* fdngainslopes;
1294 float* tapgainslopes;
1295 g_diffuser** ldifs = unit->ldifs;
1296 g_diffuser** rdifs = unit->rdifs;
1297 float* u = unit->u;
1298 float* f = unit->f;
1299 float* d = unit->d;
1300 g_damper* inputdamper = unit->inputdamper;
1301 float* tapgains = unit->tapgains;
1302 g_fixeddelay* tapdelay = unit->tapdelay;
1303 int* taps = unit->taps;
1304 g_damper** fdndamps = unit->fdndamps;
1305 g_fixeddelay** fdndels = unit->fdndels;
1306 float* fdngains = unit->fdngains;
1307 int* fdnlens = unit->fdnlens;
1309 if((roomsize != unit->roomsize) || (revtime != unit->revtime) || (damping != unit->damping) ||
1310 (inputbandwidth != unit->inputbandwidth) || (drylevel != unit->drylevel) ||
1311 (earlylevel != unit->earlylevel) || (taillevel != unit->taillevel)) {
1312 // these should calc slopes for k-rate interpolation
1313 gverb_set_roomsize(unit, roomsize);
1314 gverb_set_revtime(unit, revtime);
1315 gverb_set_damping(unit, damping);
1316 gverb_set_inputbandwidth(unit, inputbandwidth);
1317 drylevel = gverb_set_drylevel(unit, drylevel);
1318 earlylevel = gverb_set_earlylevel(unit, earlylevel);
1319 taillevel = gverb_set_taillevel(unit, taillevel);
1322 earlylevelslope = unit->earlylevelslope;
1323 taillevelslope = unit->taillevelslope;
1324 drylevelslope = unit->drylevelslope;
1325 fdngainslopes = unit->fdngainslopes;
1326 tapgainslopes = unit->tapgainslopes;
1329 for(int i = 0; i < inNumSamples; i++){
1330 float sign, sum, lsum, rsum, x;
1331 if(sc_isnan(in[i])) x = 0.f; else x = in[i];
1332 sum = 0.f;
1333 sign = 1.f;
1335 float z = damper_do(unit, inputdamper, x);
1336 z = diffuser_do(unit, ldifs[0], z);
1338 for(int j = 0; j < FDNORDER; j++) {
1339 u[j] = tapgains[j] * fixeddelay_read(unit, tapdelay, taps[j]);
1342 fixeddelay_write(unit, tapdelay, z);
1344 for(int j = 0; j < FDNORDER; j++) {
1345 d[j] = damper_do(unit, fdndamps[j],
1346 fdngains[j] *
1347 fixeddelay_read(unit, fdndels[j], fdnlens[j]));
1350 for(int j = 0; j < FDNORDER; j++) {
1351 sum += sign * (taillevel * d[j] + earlylevel * u[j]);
1352 sign = -sign;
1355 sum += x * earlylevel;
1356 lsum = sum;
1357 rsum = sum;
1359 gverb_fdnmatrix(d, f);
1361 for(int j = 0; j < FDNORDER; j++) {
1362 fixeddelay_write(unit, fdndels[j], u[j] + f[j]);
1365 lsum = diffuser_do(unit, ldifs[1],lsum);
1366 lsum = diffuser_do(unit, ldifs[2],lsum);
1367 lsum = diffuser_do(unit, ldifs[3],lsum);
1368 rsum = diffuser_do(unit, rdifs[1],rsum);
1369 rsum = diffuser_do(unit, rdifs[2],rsum);
1370 rsum = diffuser_do(unit, rdifs[3],rsum);
1372 x = x * drylevel;
1373 outl[i] = lsum + x;
1374 outr[i] = rsum + x;
1376 drylevel += drylevelslope;
1377 taillevel += taillevelslope;
1378 earlylevel += earlylevelslope;
1379 for(int j = 0; j < FDNORDER; j++){
1380 fdngains[j] += fdngainslopes[j];
1381 tapgains[j] += tapgainslopes[j];
1385 // store vals back to the struct
1386 for(int i = 0; i < FDNORDER; i++){
1387 unit->ldifs[i] = ldifs[i];
1388 unit->rdifs[i] = rdifs[i];
1389 unit->u[i] = u[i];
1390 unit->f[i] = f[i];
1391 unit->d[i] = d[i];
1392 unit->tapgains[i] = tapgains[i];
1393 unit->taps[i] = taps[i];
1394 unit->fdndamps[i] = fdndamps[i];
1395 unit->fdndels[i] = fdndels[i];
1396 unit->fdngains[i] = fdngains[i];
1397 unit->fdnlens[i] = fdnlens[i];
1398 unit->fdngainslopes[i] = 0.f;
1399 unit->tapgainslopes[i] = 0.f;
1401 unit->inputdamper = inputdamper;
1402 unit->tapdelay = tapdelay;
1403 // clear the slopes
1404 unit->earlylevelslope = unit->taillevelslope = unit->drylevelslope = 0.f;
1407 PluginLoad(Reverb)
1409 ft = inTable;
1410 DefineSimpleUnit(FreeVerb);
1411 DefineSimpleUnit(FreeVerb2);
1412 DefineDtorUnit(GVerb);