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
26 static InterfaceTable
*ft
;
28 struct FreeVerb
: public Unit
106 struct GVerb
: public Unit
108 float roomsize
, revtime
, damping
, spread
, inputbandwidth
, drylevel
, earlylevel
, taillevel
;
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
];
117 float u
[FDNORDER
], f
[FDNORDER
], d
[FDNORDER
];
118 g_diffuser
*ldifs
[FDNORDER
];
119 g_diffuser
*rdifs
[FDNORDER
];
120 g_fixeddelay
*tapdelay
;
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
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
);
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
));
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
));
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
));
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
));
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
));
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
));
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
));
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
));
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
)));
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
);
332 R2_1
= (R2_0
- R3_1
);
333 dline1
[iota1
] = ((0.500000f
* R1_0
) + R2_1
);
335 R1_1
= (R1_0
- R2_1
);
336 dline0
[iota0
] = ((0.500000f
* R0_0
) + R1_1
);
338 R0_1
= (R0_0
- R1_1
);
339 output0
[i
] = ((ftemp1
* ftemp2
) + (ftemp0
* R0_1
));
353 unit
->iota10
= iota10
;
354 unit
->iota11
= iota11
;
384 struct FreeVerb2
: public Unit
486 void FreeVerb2_Ctor(FreeVerb2
*unit
);
487 void FreeVerb2_next(FreeVerb2
*unit
, int inNumSamples
);
491 void FreeVerb2_Ctor(FreeVerb2
*unit
)
493 SETCALC(FreeVerb2_next
);
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
));
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
));
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
));
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
));
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
));
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
));
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
));
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
));
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
)));
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
);
782 R2_1
= (R2_0
- R3_1
);
783 dline1
[iota1
] = ((0.500000f
* R1_0
) + R2_1
);
785 R1_1
= (R1_0
- R2_1
);
786 dline0
[iota0
] = ((0.500000f
* R0_0
) + R1_1
);
788 R0_1
= (R0_0
- R1_1
);
789 output0
[i
] = ((ftemp1
* ftemp2
) + (ftemp0
* R0_1
));
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
));
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
));
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
));
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
));
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
));
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
));
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
));
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
));
840 float ftemp9
= (R36_0
+ R38_0
);
841 dline15
[iota15
] = ((((0.500000f
* R23_0
) + R24_0
) + (R26_0
+ R28_0
)) + ((R30_0
+ R32_0
) +
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
);
847 R22_1
= (R22_0
- R23_1
);
848 dline13
[iota13
] = ((0.500000f
* R21_0
) + R22_1
);
850 R21_1
= (R21_0
- R22_1
);
851 dline12
[iota12
] = ((0.500000f
* R20_0
) + R21_1
);
853 R20_1
= (R20_0
- R21_1
);
854 output1
[i
] = ((ftemp1
* ftemp3
) + (ftemp0
* R20_1
));
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
;
949 static inline float flush_to_zero(float 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
;
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
);
970 int nearestprime(int n
, float rerror
)
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
);
984 static inline int f_round(float f
){
988 return p
.i
- 0x4b400000;
991 g_damper
*make_damper(GVerb
*unit
, float damping
){
993 p
= (g_damper
*)RTAlloc(unit
->mWorld
, sizeof(g_damper
));
994 p
->damping
= damping
;
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
){
1005 p
= (g_diffuser
*)RTAlloc(unit
->mWorld
, sizeof(g_diffuser
));
1009 p
->buf
= (float*)RTAlloc(unit
->mWorld
, size
* sizeof(float));
1010 Clear(size
, p
->buf
);
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
){
1021 p
= (g_fixeddelay
*)RTAlloc(unit
->mWorld
, sizeof(g_fixeddelay
));
1024 p
->buf
= (float*)RTAlloc(unit
->mWorld
, maxsize
* sizeof(float));
1025 Clear(maxsize
, p
->buf
);
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
){
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
;
1044 static inline float fixeddelay_read(GVerb
*unit
, g_fixeddelay
*p
, int n
){
1046 i
= (p
->idx
- n
+ p
->size
) % p
->size
;
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
){
1061 y
= x
*(1.0-p
->damping
) + p
->delay
*p
->damping
;
1062 p
->delay
= zapgremlins(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
)
1078 if (a
<= 1.0 || sc_isnan(a
)) {
1079 unit
->roomsize
= 1.0;
1081 if(a
>= unit
->maxroomsize
)
1082 unit
->roomsize
= unit
->maxroomsize
- 1.;
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
)
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
)
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
);
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
);
1166 static inline float gverb_set_drylevel(GVerb
*unit
, float a
)
1168 float olddry
= unit
->drylevel
;
1170 unit
->drylevelslope
= CALCSLOPE(a
, 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);
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
;
1202 unit
->fdnlens
[i
] = nearestprime((int)gb
, 0.5);
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
1215 float diffscale
= (float)unit
->fdnlens
[3]/(210. + 159. + 562. + 410.);
1216 float spread1
= spread
;
1217 float spread2
= 3.0 * spread
;
1221 int a
= (int)(spread1
* r
);
1222 int c
= 210+159 + a
;
1225 a
= (int)(spread2
* r
);
1226 int d
= 210 + 159 + 562 + a
;
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);
1236 a
= (int)(spread1
* r
);
1240 a
= (int)(spread2
* r
);
1241 d
= 210 + 159 + 562 + a
;
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
)
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
;
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
];
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
],
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
]);
1355 sum
+= x
* earlylevel
;
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
);
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
];
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
;
1404 unit
->earlylevelslope
= unit
->taillevelslope
= unit
->drylevelslope
= 0.f
;
1410 DefineSimpleUnit(FreeVerb
);
1411 DefineSimpleUnit(FreeVerb2
);
1412 DefineDtorUnit(GVerb
);