rdk

Check-in [37d5ec1ca6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:compiled /initrd/mnt/dev_save/dsp/rdk/zita_extended/zita_tripledat_values.dsp to zita_tripledat_values.jgtk using f2jgtk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | www
Files: files | file ages | folders
SHA1:37d5ec1ca644d1fdf973c4f022d8cbde7cb29d75
User & Date: root 2018-12-20 11:45:40
Context
2018-12-20
12:24
compiled /initrd/mnt/dev_save/dsp/rdk/SchlemmerReverb/zita_ref1b.dsp to zita_ref1b.jgtk using f2jgtk. matches zita_ref0.dsp? check-in: 3dff632415 user: root tags: www
11:45
compiled /initrd/mnt/dev_save/dsp/rdk/zita_extended/zita_tripledat_values.dsp to zita_tripledat_values.jgtk using f2jgtk. check-in: 37d5ec1ca6 user: root tags: www
2018-12-19
18:28
SchlemmerReverb/zita_ref1.jgtk --> preset: hmm () (/initrd/mnt/dev_save/dsp/rdk/SchlemmerReverb/zita_ref1-presets) check-in: c5e849e97d user: root tags: www
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SchlemmerReverb/zita_ref0-presets/lex-dennon.

1

2

3

4

5
6
7
8

9

10
11
12
13
14
1 zita_ref0//GUTS/ER_ctl/Reverb_In//DIR_WD

0.222 zita_ref0/RT0

128 zita_ref0/ZT_DX

0.3 zita_ref0/ZT_L1

-0.5 zita_ref0/ZT_L2
0.5 zita_ref0/LR
0.17 zita_ref0/DISTANCE
0.62 zita_ref0/APDELAY_PERCENT

0.62 zita_ref0/AP_G

1 zita_ref0/ER_COMPRESSION_FACTOR
1.32 zita_ref0/ROOMSIZE
0.007 zita_ref0/rdk.sinusDepth
0.91 zita_ref0/rdk.sinusFreqHz


>

>

>

>




>

>





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1 zita_ref0//GUTS/ER_ctl/Reverb_In//DIR_WD

0.222 zita_ref0/RT0

128 zita_ref0/ZT_DX

0.3 zita_ref0/ZT_L1

-0.5 zita_ref0/ZT_L2
0.5 zita_ref0/LR
0.17 zita_ref0/DISTANCE
0.62 zita_ref0/APDELAY_PERCENT

0.62 zita_ref0/AP_G

1 zita_ref0/ER_COMPRESSION_FACTOR
1.32 zita_ref0/ROOMSIZE
0.007 zita_ref0/rdk.sinusDepth
0.91 zita_ref0/rdk.sinusFreqHz

Changes to SchlemmerReverb/zita_ref1.defaults.

1
2

3
4


5
6
7
8

9
10
11
12
13
14
15
16
17
18
//defaults:


RoomSize=1;
APDELAY_PERCENT=0.62;



DIR_WD=0.5;
Outdelay=256;
Outlevel(i)=0.1;


SIM_ROOM(1)=42.00;
SIM_ROOM(2)=23.00;
SIM_ROOM(3)=17.30;
SIM_SOURCE(1)=0.900;
SIM_SOURCE(2)=0.480;
SIM_SOURCE(3)=0.200;
SIM_DESTINATION(1)=0.618;
SIM_DESTINATION(2)=0.600;
SIM_DESTINATION(3)=0.200; 


>


>
>

|
|
|
>


|
|
|
|
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//defaults:

RT=0.222;
RoomSize=1;
APDELAY_PERCENT=0.62;
ER_COMPRESSION_FACTOR=1;
AP_G=0.62;

DIR_WD=1;
Outdelay=128;//samples
Outlevel(1)=0.3;
Outlevel(2)=-0.5;

SIM_ROOM(1)=42.00;
SIM_ROOM(2)=19.00;
SIM_ROOM(3)=16.00;
SIM_SOURCE(1)=33/42;
SIM_SOURCE(2)=11/19;
SIM_SOURCE(3)=3/16;
SIM_DESTINATION(1)=0.17; //(Ls-1)*DISTANCE;
SIM_DESTINATION(2)=0.5;//(B)*(LR);
SIM_DESTINATION(3)=1/16; 

Changes to SchlemmerReverb/zita_ref1.dsp.

1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
15
16
17
18
19
20
21
22







23
24
25
26
27
28
29
30
31
32


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//import("all.lib");
import("maxmsp.lib");

import("common.lib");
import("classic6.lib");

//import("revgui.lib");

import("zita_ref1.gui");
import("zita_ref1.defaults");



/* klingt der _sim-lfo_ wirklich genau so gut?
sinusi=library("../rdk.lib").sinusi(freq,phase);
................................................................................
zitaLFO(i)=sinusi(ZT_GUI_SinusFreqHz,i*.125 )*(ZT_GUI_SinusDepth)+1.0;
  ZT_GUI_SinusFreqHz=1;
  ZT_SinusFreqHz=1;
  ZT_GUI_SinusDepth=0.01;
  ZT_SinusDepth=0.01;
*/

process = zt.zita_distrib2(8):zitaCore:reflevel(8):dir.eq82<:bus(16):(revb,ref8):bus(4):>bus(2);







  //DIR_WD=0.5;//nentry("[0]DIR_WD",0,0,1,0.001);

revb=bus(8):>bus(2):par(i,2,*(gui.OUTLEVEL(1)));
ref8=//pot(8,1):
  bus(8):>bus(2):par(i,2,@(gui.OUTDELAY)):par(i,2,*(gui.OUTLEVEL(2)));

zitaCore = zt[
  ///step 1: main loop
    //swap things in main fb loop
    zita_rev_fdn(zt.f1,zt.f2,zt.t60dc,zt.t60m,zt.fsmax)=


      ((bus(2*zt.N):>zt.fbdelaylines(zt.N):zt.allpass_combs(zt.N))
      ~(zt.feedbackmatrix(zt.N):cl.wdn(8,zt.delayfilters(zt.N,zt.freqs,zt.durs),gui.ZT_GUI_FLTON)
      :cl.wdn(8,reverbtime(zt.N),(1-(gui.ZT_GUI_FLTON)))));

    //tdelay(i)=myval(i); => doesn't work
  ]
  //.zita_rev1
  .zita_rev_fdn(zt.f1,zt.f2,zt.t60dc,zt.t60m,zt.fsmax)
;

  //apdelay(i) = SR/1000.*(apdelay_ms(i)) *zitaLFO(i) ; //ff_del
  //tdelay_ms(i) = reflectiondelay_ms(i) - (1-(APDELAY_PERCENT(i))) ; //fdn_del
  //                                     ^BUG?: * intended?
  //apdelay_ms(i) = reflectiondelay_ms(i) * APDELAY_PERCENT(i) ; 

my_apdelay(i)=sim.ssq(i+1)*gui.ZT_GUI_APPERCENT*SR/1000.0;







>







 







|
>
>
>
>
>
>
>






<
|
<
<
>
>
|
|
|

<
|
<
<
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37


38
39
40
41
42
43

44


45
46
47
48
49
50
51
52
//import("all.lib");
import("maxmsp.lib");

import("common.lib");
import("classic6.lib");

//import("revgui.lib");
//import("zita_ref1.lib");
import("zita_ref1.gui");
import("zita_ref1.defaults");



/* klingt der _sim-lfo_ wirklich genau so gut?
sinusi=library("../rdk.lib").sinusi(freq,phase);
................................................................................
zitaLFO(i)=sinusi(ZT_GUI_SinusFreqHz,i*.125 )*(ZT_GUI_SinusDepth)+1.0;
  ZT_GUI_SinusFreqHz=1;
  ZT_SinusFreqHz=1;
  ZT_GUI_SinusDepth=0.01;
  ZT_SinusDepth=0.01;
*/

process = zt.zita_distrib2(8)
  :zitaCore
  //:reflevel(8)
  //:dir.eq82
  <:bus(16):
    (revb,
    ref8)
    :bus(4):>bus(2);
  //DIR_WD=0.5;//nentry("[0]DIR_WD",0,0,1,0.001);

revb=bus(8):>bus(2):par(i,2,*(gui.OUTLEVEL(1)));
ref8=//pot(8,1):
  bus(8):>bus(2):par(i,2,@(gui.OUTDELAY)):par(i,2,*(gui.OUTLEVEL(2)));


///step 1: main loop


zitaCore(f1,f2,t60dc,t60m,fsmax) = zt.zita_rev_fdn(f1,f2,t60dc,t60m,fsmax);

//((bus(2*zt.N):>zt.fbdelaylines(zt.N):zt.allpass_combs(zt.N))
//      ~(zt.feedbackmatrix(zt.N):cl.wdn(8,zt.delayfilters(zt.N,zt.freqs,zt.durs),gui.ZT_GUI_FLTON)
//      :cl.wdn(8,reverbtime(zt.N),(1-(gui.ZT_GUI_FLTON)))));







  //apdelay(i) = SR/1000.*(apdelay_ms(i)) *zitaLFO(i) ; //ff_del
  //tdelay_ms(i) = reflectiondelay_ms(i) - (1-(APDELAY_PERCENT(i))) ; //fdn_del
  //                                     ^BUG?: * intended?
  //apdelay_ms(i) = reflectiondelay_ms(i) * APDELAY_PERCENT(i) ; 

my_apdelay(i)=sim.ssq(i+1)*gui.ZT_GUI_APPERCENT*SR/1000.0;

Changes to SchlemmerReverb/zita_ref1.gui.

1
2
3
4
5
6
7

8
9

10










11
12
13
14
15
16
17


18
19
20
21
22
23
24

25
26
27
28
29
30
31
guigroup1(fx)=vgroup("[1]Zita_Extended",tgroup("",vgroup("1 Room Model",fx)));
guigroup2(fx)=vgroup("[1]Zita_Extended",tgroup("",vgroup("2 Reverb",fx)));
guigroup3(fx)=vgroup("[1]Zita_Extended",tgroup("",hgroup("3 Outmix",fx)));

  SIM_GUI_ROOM(i)       =guigroup1(hgroup("1",nentry("SIM_ROOM(%i)[unit:m][style:knob]",SIM_ROOM(i),0,100,0.01)));
  SIM_GUI_SOURCE(i)     =guigroup1(hgroup("2",nentry("SIM_SOURCE(%i)[unit:percent][style:knob]",SIM_SOURCE(i),0,1,.001))); 
  SIM_GUI_DESTINATION(i)=guigroup1(hgroup("3",nentry("SIM_DESTINATION(%i)[unit:percent][style:knob]",SIM_DESTINATION(i),0,1,.001))); 

  
  DIR_GUI_WD            =guigroup3(vgroup("[3]Directivity",vgroup("[3]Flute",nentry("[4]DIR_WD[style:knob]",DIR_WD,0,1,0.01))));

  MAIN_GUI_RS           =guigroup2(hslider("[0]RoomSize",RoomSize,0.010,4,.001));










  
gui=environment {

ZT_GUI_FLTON    =guigroup2(checkbox("ZT_GUI_FLTON"));
MAINFB	        =guigroup2(hslider("[12]RT",0,0,.999,.001));
ERCOMPRESSION   =guigroup2(hslider("[17]ER COMPRESSION FACTOR",.66,0,1,.01));
ZT_GUI_APPERCENT=guigroup2(hslider("[13]APDELAY_PERCENT",APDELAY_PERCENT,0,1,.01));


AP_G(i)         =guigroup2(hslider("[15]AP_G",0.63 ,0,.9,.01));    


    OUTDELAY      =guigroup3(vgroup("[2]Out2",nentry("[0]Outdelay",Outdelay,0,4000,1)));
    OUTLEVEL(1)   =guigroup3(vgroup("[1]Out1",nentry("[0]Outlevel(1)",Outlevel(1),-1,1,0.001)*BYBOX(1)));
    OUTLEVEL(2)   =guigroup3(vgroup("[2]Out2",nentry("[0]Outlevel(2)",Outlevel(2),-1,1,0.001)*BYBOX(2)));
    BYBOX(i) = 1-checkbox("BY(%i)");

  
};
  
//info groups
desc1(fx)=hgroup("Large Hall Algorithm 480L",fx);
desc2(fx)=hgroup("[1]Main User Interface",fx);
smallgroup(fx)=hgroup("",hgroup("",hgroup("",fx)));
|
|





>

|
>
|
>
>
>
>
>
>
>
>
>
>



<
<
<
<
>
>
|


<
<
<
<
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25




26
27
28
29
30




31
32
33
34
35
36
37
38
guigroup1(fx)=vgroup("[1]Zita_Extended",tgroup("",vgroup("2 Room Model",fx)));
guigroup2(fx)=vgroup("[1]Zita_Extended",tgroup("",vgroup("1 Reverb",fx)));
guigroup3(fx)=vgroup("[1]Zita_Extended",tgroup("",hgroup("3 Outmix",fx)));

  SIM_GUI_ROOM(i)       =guigroup1(hgroup("1",nentry("SIM_ROOM(%i)[unit:m][style:knob]",SIM_ROOM(i),0,100,0.01)));
  SIM_GUI_SOURCE(i)     =guigroup1(hgroup("2",nentry("SIM_SOURCE(%i)[unit:percent][style:knob]",SIM_SOURCE(i),0,1,.001))); 
  SIM_GUI_DESTINATION(i)=guigroup1(hgroup("3",nentry("SIM_DESTINATION(%i)[unit:percent][style:knob]",SIM_DESTINATION(i),0,1,.001))); 
  SIM_GUI_RS            =guigroup2(hslider("[0]RoomSize",RoomSize,0.010,4,.001));
  
  DIR_GUI_DIRECTIVITY_WD=guigroup3(vgroup("[3]Directivity",vgroup("[3]Flute",nentry("[4]DIR_WD[style:knob]",DIR_WD,0,1,0.01))));
  
  ZE_GUI_APG(i)         =guigroup2(hslider("[15]AP_G",AP_G,0,.9,.01)); 
  ZE_GUI_FLTON          =guigroup2(checkbox("compare_loss_filters"));
  
  ZE_GUI_MAINFB         =guigroup2(hslider("[12]RT",RT,0,.999,.001));
  ZE_GUI_ERCOMPRESSION  =guigroup2(hslider("[17]ER_COMPRESSION_FACTOR",ER_COMPRESSION_FACTOR,0,1,.01));
  ZE_GUI_APPERCENT=guigroup2(hslider("[13]APDELAY_PERCENT",APDELAY_PERCENT,0,1,.01));
  
  ZE_GUI_OUTDELAY      =guigroup3(vgroup("[2]Out2",nentry("[0]Outdelay",Outdelay,0,4000,1)));
  ZE_GUI_OUTLEVEL(1)   =guigroup3(vgroup("[1]Out1",nentry("[0]Outlevel(1)",Outlevel(1),-1,1,0.001)*BYBOX(1)));
  ZE_GUI_OUTLEVEL(2)   =guigroup3(vgroup("[2]Out2",nentry("[0]Outlevel(2)",Outlevel(2),-1,1,0.001)*BYBOX(2)));
  BYBOX(i) = 1-checkbox("BY(%i)");
  
gui=environment {







//AP_G(i)         =guigroup2(hslider("[15]AP_G",AP_G,0,.9,.01));    







  
};
  
//info groups
desc1(fx)=hgroup("Large Hall Algorithm 480L",fx);
desc2(fx)=hgroup("[1]Main User Interface",fx);
smallgroup(fx)=hgroup("",hgroup("",hgroup("",fx)));

Added SchlemmerReverb/zita_ref1.lib.













































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
sim = environment {

//-----------------------------------------------
//      ER: source image model (shoebox)
//-----------------------------------------------

/*** room model *****************

Coordinates:
(R)oom        <Rx,Ry,Rz> 
(S)ource      <Sx,Sy,Sz>
(D)estination <Dx,Dy,Dz>

            front    
         x           
         ^ +------+  
           ¦ (S)  ¦ hight:z
           ¦______¦  
     left  ¦      ¦  right
           ¦  (D) ¦  
           ¦      ¦  
         0 +------+  
          0       > y 
             rear     

*********************************/ 

lfox= osci(2)*.02;// *nentry("[1 unit:%%]rdk.lfoDepth",.02,0,.02,.001) + 1 ;
lfoy= osci(3)*.02;
lfoz= osci(5)*.01;

Rx = SIM_GUI_ROOM(1)*SIM_GUI_RS;
Ry = SIM_GUI_ROOM(2)*SIM_GUI_RS;
Rz = SIM_GUI_ROOM(3)*SIM_GUI_RS;

Sx = SIM_GUI_SOURCE(1)*Rx +lfox;
Sy = SIM_GUI_SOURCE(2)*Ry +lfoy;
Sz = SIM_GUI_SOURCE(3)*Rz +lfoz;

Dx = SIM_GUI_DESTINATION(1)*Rx; 
Dy = SIM_GUI_DESTINATION(2)*Ry;
Dz = SIM_GUI_DESTINATION(3)*Rz;

//mirror images in shoebox room
r(Rx,Ry,Rz,Sx,Sy,Sz) = Rx,Ry,Rz,      Sx, 2*Ry-Sy,      Sz;
l(Rx,Ry,Rz,Sx,Sy,Sz) = Rx,Ry,Rz,      Sx,     -Sy,      Sz;
v(Rx,Ry,Rz,Sx,Sy,Sz) = Rx,Ry,Rz, 2*Rx-Sx,      Sy,      Sz;
h(Rx,Ry,Rz,Sx,Sy,Sz) = Rx,Ry,Rz,     -Sx,      Sy,      Sz;
b(Rx,Ry,Rz,Sx,Sy,Sz) = Rx,Ry,Rz,      Sx,      Sy,     -Sz;
d(Rx,Ry,Rz,Sx,Sy,Sz) = Rx,Ry,Rz,      Sx,      Sy, 2*Rz-Sz;

//Direct sound
D0 = vec(Dx,Dy,Dz, Sx,Sy,Sz):max(0.5); //meter (allows 1st reflection +6dB if distance >1m)
//Vector arithmetics
vec(Dx,Dy,Dz,SSQx,SSQy,SSQz) = sqrt( pow(SSQx-Dx, 2) + pow(SSQy-Dy, 2) + pow(SSQz-Dz, 2)) ; //meter
refm(image) = (Rx,Ry,Rz,Sx,Sy,Sz : image : !,!,!,_,_,_ : vec(Dx,Dy,Dz)) ; //meter

//pattern
ref(1) = refm(l);
ref(2) = refm(r);
ref(3) = refm(l:d);
ref(4) = refm(r:d);
ref(5) = refm(l:v);
ref(6) = refm(r:v);
ref(7) = refm(l:d:h);
ref(8) = refm(r:d:h);

ssq(1) = ref(1)-D0:max(1):cl.m2ms;
ssq(2) = ref(2)-D0:max(1):cl.m2ms;
ssq(3) = ref(3)-D0:max(1):cl.m2ms;
ssq(4) = ref(4)-D0:max(1):cl.m2ms;
ssq(5) = ref(5)-D0:max(1):cl.m2ms;
ssq(6) = ref(6)-D0:max(1):cl.m2ms;
ssq(7) = ref(7)-D0:max(1):cl.m2ms;
ssq(8) = ref(8)-D0:max(1):cl.m2ms;

//ssq(i) = ref(i)-(D0):cl.m2ms; //milliseconds

//lev(i) = D0/(ref(i);

};

dir = environment {

//convert maxmsp filtergraf~ data to FAUST maxmsp.lib...
//bq(a,b,c,d,e,x) = biquad(x,a,b,c,-d,-e) ; //faust < 0.9.58
bq = biquad; //faust >= 0.9.58

	//Directivity +damping for typical angles (*flute*)
  //coeffs calculated in max/msp, see http://...my hp...
  //todo: write awk program to generate this file
	f1 		= bq(0.778342, -1.557887, 0.779562, -1.998412, 0.998434) 
			: bq(1.010895, -1.984542, 0.973962, -1.984542, 0.984857)
			: bq(1.003048, -1.976456, 0.974663, -1.976456, 0.97771)
			: bq(1.008643, -1.945218, 0.941521, -1.945218, 0.950164)
			: bq(1.000702, -1.835624, 0.853712, -1.835624, 0.854414)
			: bq(1.000646, -1.744797, 0.817466, -1.744797, 0.818112)
			: bq(1.006305, -1.48838, 0.761466, -1.48838, 0.767771) ;

	f2 		= bq(0.853169, -1.707658, 0.854508, -1.998412, 0.998434)
			: bq(1.002863, -1.9799, 0.977351, -1.9799, 0.980214)
			: bq(0.996158, -1.969549, 0.974642, -1.969549, 0.970799)
			: bq(0.98459, -1.92056, 0.940854, -1.92056, 0.925443)
			: bq(0.994906, -1.830226, 0.854054, -1.830226, 0.84896)
			: bq(1.001092, -1.745185, 0.817424, -1.745185, 0.818516)
			: bq(1.004413, -1.487008, 0.761728, -1.487008, 0.766141) ;
	 
	f3 		= bq(0.658591, -1.318201, 0.659624, -1.998412, 0.998434)
			: bq(1.023436, -1.988192, 0.965071, -1.988192, 0.988507)
			: bq(1.00903, -1.980994, 0.973221, -1.980994, 0.982251)
			: bq(1.022493, -1.955188, 0.937667, -1.955188, 0.96016)
			: bq(1.00153, -1.836378, 0.853645, -1.836378, 0.855175)
			: bq(1.001812, -1.745807, 0.817353, -1.745807, 0.819164)
			: bq(1.009758, -1.490856, 0.760954, -1.490856, 0.770711) ;

	f4 		= bq(0.627894, -1.256758, 0.628879, -1.998412, 0.998434)
			: bq(1.018041, -1.985641, 0.967914, -1.985641, 0.985956)
			: bq(1.008185, -1.980429, 0.9735, -1.980429, 0.981686)
			: bq(1.005841, -1.94284, 0.941939, -1.94284, 0.94778)
			: bq(0.995605, -1.830888, 0.854024, -1.830888, 0.849629)
			: bq(1.001739, -1.745744, 0.81736, -1.745744, 0.819099)
			: bq(1.010747, -1.491558, 0.760799, -1.491558, 0.77154) ;

eq81 = f1,f2,f3,f4,_,_,_,_;
eq82 = cl.wdn(4,(f1,f2,f3,f4),DIR_GUI_DIRECTIVITY_WD),_,_,_,_;
eq83 = bus(8):>bus(4):f1,f2,f3,f4<:bus(8);

};

cla = environment {

wdn(n,fx,ctl)=par(i,n,_)<:(fx : par(i,n,*(ctl))),par(i,n,*(1-(ctl))):>par(i,n,_); // ctl=1; => wet

};

Added SchlemmerReverb/zita_ref1a.dsp.















































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
//import("all.lib");
import("maxmsp.lib");

//import("common.lib");
import("classic6.lib");

//import("revgui.lib");
import("zita_ref1.lib");
import("zita_ref1.gui");
import("zita_ref1.defaults");



/* klingt der _sim-lfo_ wirklich genau so gut?
sinusi=library("../rdk.lib").sinusi(freq,phase);
zitaLFO(i)=sinusi(ZT_GUI_SinusFreqHz,i*.125 )*(ZT_GUI_SinusDepth)+1.0;
  ZT_GUI_SinusFreqHz=1;
  ZT_SinusFreqHz=1;
  ZT_GUI_SinusDepth=0.01;
  ZT_SinusDepth=0.01;
*/

process = //zt.zita_distrib2(8):
  //zt.zita_rev_fdn(zt.f1,zt.f2,zt.t60dc,zt.t60m,zt.fsmax)
  zitaCore
  //:reflevel(8)
  //:dir.eq82
  //<:bus(16):
  //  (revb,
  //  ref8)
  //  :bus(4):>bus(2);
  //DIR_WD=0.5;//nentry("[0]DIR_WD",0,0,1,0.001);
;

revb=bus(8):>bus(2):par(i,2,*(gui.OUTLEVEL(1)));
ref8=//pot(8,1):
  bus(8):>bus(2):par(i,2,@(gui.OUTDELAY)):par(i,2,*(gui.OUTLEVEL(2)));

zitaCore=((bus(2*8):>ze.fbdelaylines(8):ze.allpass_combs(8))
      ~(zt.feedbackmatrix(8):cl.wdn(8,zt.delayfilters(8,zt.freqs,zt.durs),ZE_GUI_FLTON)
      :cl.wdn(8,ze.reverbtime(8),(1-(ZE_GUI_FLTON)))));

ze = environment{
  
///step 1: main loop
reverbtime(N) = par(i,N,*(ZE_GUI_MAINFB)) ;
///step 2.0: change delay to fdelay
fbdelaylines(zt.N)=par(i,zt.N,(fdelay(zt.maxfbdelay(i),(ze.fbdelay(i)))));
///step 2.1: change *g to UI
allpass_combs(N)=par(i,zt.N,(allpass_fcomb(zt.maxapdelay(i),ze.apdelay(i),ZE_GUI_APG(i)))) with {
  
  allpass_fcomb(maxdel,N,aN) = (+ <: fdelay(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : + ;//filters.lib
  }; 
///step 3: change delay(i) lenths to reflect SIM
apdelay(i)=sim.ssq(i+1)*gui.ZE_GUI_APPERCENT*SR/1000.0; //samples
fbdelay(i)=sim.ssq(i+1)*SR/1000.0;

};

  //apdelay(i) = SR/1000.*(apdelay_ms(i)) *zitaLFO(i) ; //ff_del
  //tdelay_ms(i) = reflectiondelay_ms(i) - (1-(APDELAY_PERCENT(i))) ; //fdn_del
  //                                     ^BUG?: * intended?
  //apdelay_ms(i) = reflectiondelay_ms(i) * APDELAY_PERCENT(i) ; 

my_apdelay(i)=sim.ssq(i+1)*gui.ZT_GUI_APPERCENT*SR/1000.0;
my_tdelay(i)=sim.ssq(i+1)*SR/1000.0;//bug wie oben ///samples

reflevel(N) = par(i,N,*(reflectionlevel(i)));
reflectionlevel(i) = sim.D0/(sim.ref(i+1)) *(gui.ERCOMPRESSION) + makeup ;
 makeup = 1 - gui.ERCOMPRESSION ;

/*
revb=bus(8):>bus(2):par(i,2,*(ZT_GUI_L1));
ref8=//pot(8,1):
  bus(8):>bus(2):par(i,2,@(ZT_GUI_DX)):par(i,2,*(ZT_GUI_L2));

ch=8;
pot(n,j) = par(i,n,cl.panpot(ZTMX_PAN(i+1,j)));

//some GUI. todo: rename param
ZT_GUI_DX = nentry("[0]ZT_DX",ZT_DX,0,4000,1);
ZT_GUI_L2 = nentry("[0]ZT_L2",ZT_L2,-1,1,0.001);
ZT_GUI_L1 = nentry("[0]ZT_L1",ZT_L1,-1,1,0.001);
*/

//import lit. from old/effect.lib:
zt = environment {
  
  zita_rev_fdn(f1,f2,t60dc,t60m,fsmax) =
  ((bus(2*N) :> allpass_combs(N) : feedbackmatrix(N)) ~
   (delayfilters(N,freqs,durs) : fbdelaylines(N)));

  N = 8;

  // Delay-line lengths in seconds:
  apdelays = (0.020346, 0.024421, 0.031604, 0.027333, 0.022904,
              0.029291, 0.013458, 0.019123); // feedforward delays in seconds
  tdelays = ( 0.153129, 0.210389, 0.127837, 0.256891, 0.174713,
              0.192303, 0.125000, 0.219991); // total delays in seconds
///step 2.0: replace delay lengths with values from source image model (SIM)
  tdelay(i) = floor(0.5 + SR*take(i+1,tdelays)); // samples
  apdelay(i) = floor(0.5 + SR*take(i+1,apdelays));
  //tdelay(i) = my_tdelay(i);//floor(0.5 + SR*take(i+1,tdelays)); // samples
  //apdelay(i) = my_apdelay(i);//floor(0.5 + SR*take(i+1,apdelays));
///------------------------------------------------------------------------
  fbdelay(i) = tdelay(i) - apdelay(i);
  // NOTE: Since SR is not bounded at compile time, we can't use it to
  // allocate delay lines; hence, the fsmax parameter:
  tdelaymaxfs(i) = floor(0.5 + fsmax*take(i+1,tdelays));
  apdelaymaxfs(i) = floor(0.5 + fsmax*take(i+1,apdelays));
  fbdelaymaxfs(i) = tdelaymaxfs(i) - apdelaymaxfs(i);
  nextpow2(x) = ceil(log(x)/log(2.0));
  maxapdelay(i) = int(2.0^max(1.0,nextpow2(apdelaymaxfs(i))));
  maxfbdelay(i) = int(2.0^max(1.0,nextpow2(fbdelaymaxfs(i))));

  apcoeff(i) = select2(i&1,0.6,-0.6);  // allpass comb-filter coefficient
///step 3.0: replace g* with gui
  allpass_combs(N) =
    par(i,N,(allpass_comb(maxapdelay(i),apdelay(i),apcoeff(i)))); 
    //par(i,N,(allpass_comb(maxapdelay(i),apdelay(i),(gui.AP_G(i)*(-1))))); 
///------------------------------------------------^^^^^^^-----
  fbdelaylines(N) = par(i,N,(delay(maxfbdelay(i),(fbdelay(i)))));
  freqs = (f1,f2); durs = (t60dc,t60m);
  delayfilters(N,freqs,durs) = par(i,N,filter(i,freqs,durs));
  feedbackmatrix(N) = hadamard(N); // math.lib

  staynormal = 10.0^(-20); // let signals decay well below LSB, but not to zero

  special_lowpass(g,f) = smooth(p) with {
    // unity-dc-gain lowpass needs gain g at frequency f => quadratic formula:
    p = mbo2 - sqrt(max(0,mbo2*mbo2 - 1.0)); // other solution is unstable
    mbo2 = (1.0 - gs*c)/(1.0 - gs); // NOTE: must ensure |g|<1 (t60m finite)
    gs = g*g;
    c = cos(2.0*PI*f/float(SR));
  };

  filter(i,freqs,durs) = lowshelf_lowpass(i)/sqrt(float(N))+staynormal
  with {
    lowshelf_lowpass(i) = gM*low_shelf1_l(g0/gM,f(1)):special_lowpass(gM,f(2));
    low_shelf1_l(G0,fx,x) = x + (G0-1)*lowpass(1,fx,x); // filter.lib
    g0 = g(0,i);
    gM = g(1,i);
    f(k) = take(k,freqs);
    dur(j) = take(j+1,durs);
    n60(j) = dur(j)*SR; // decay time in samples
    g(j,i) = exp(-3.0*log(10.0)*tdelay(i)/n60(j));
  };
  
  // Stereo input delay used by zita_rev1 in both stereo and ambisonics mode:
  zita_in_delay(rdel) = zita_delay_mono(rdel), zita_delay_mono(rdel) with {
    zita_delay_mono(rdel) = delay(8192,SR*rdel*0.001) * 0.3;
  };

  // Stereo input mapping used by zita_rev1 in both stereo and ambisonics mode:
  zita_distrib2(N) = _,_ <: fanflip(N) with {
     fanflip(4) = _,_,*(-1),*(-1);
     fanflip(N) = fanflip(N/2),fanflip(N/2);
  };

  /* not used here
  //--------------------------- zita_rev_fdn_demo ------------------------------
  // zita_rev_fdn_demo = zita_rev_fdn (above) + basic GUI
  //
  // USAGE:
  //   bus(8) : zita_rev_fdn_demo(f1,f2,t60dc,t60m,fsmax) : bus(8)
  //
  // WHERE
  //   (args and references as for zita_rev_fdn above)

  zita_rev_fdn_demo = zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
  with {
    fsmax = 48000.0;
    fdn_group(x) = hgroup(
      "Zita_Rev Internal FDN Reverb [tooltip: ~ Zita_Rev's internal 8x8 Feedback Delay Network (FDN) & Schroeder allpass-comb reverberator.  See Faust's effect.lib for documentation and references]",x);
    t60dc = fdn_group(vslider("[1] Low RT60 [unit:s] [style:knob]
      [style:knob]
      [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
      3, 1, 8, 0.1));
    f1 = fdn_group(vslider("[2] LF X [unit:Hz] [style:knob] [scale:log]
      [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
      200, 50, 1000, 1));
    t60m = fdn_group(vslider("[3] Mid RT60 [unit:s] [style:knob] [scale:log]
      [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
      2, 1, 8, 0.1));
    f2 = fdn_group(vslider("[4] HF Damping [unit:Hz] [style:knob] [scale:log]
      [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
      6000, 1500, 0.49*fsmax, 1));
  };
  */

  //---------------------------- zita_rev1_stereo ---------------------------
  // Extend zita_rev_fdn to include zita_rev1 input/output mapping in stereo mode.
  //
  // USAGE:
  //   _,_ : zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax) : _,_
  //
  // WHERE
  //   rdel  = delay (in ms) before reverberation begins (e.g., 0 to ~100 ms)
  //   (remaining args and refs as for zita_rev_fdn above)

  zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax) =
     zita_in_delay(rdel)
   : zita_distrib2(N)
   : zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
   : output2(N)
  with {
   N = 8;
   output2(N) = outmix(N) : *(t1),*(t1);
   t1 = 0.37; // zita-rev1 linearly ramps from 0 to t1 over one buffer
   outmix(4) = !,butterfly(2),!; // probably the result of some experimenting!
   outmix(N) = outmix(N/2),par(i,N/2,!);
  };

  /* not used here
  //----------------------------- zita_rev1_ambi ---------------------------
  // Extend zita_rev_fdn to include zita_rev1 input/output mapping in
  // "ambisonics mode", as provided in the Linux C++ version.
  //
  // USAGE:
  //   _,_ : zita_rev1_ambi(rgxyz,rdel,f1,f2,t60dc,t60m,fsmax) : _,_,_,_
  //
  // WHERE
  //   rgxyz = relative gain of lanes 1,4,2 to lane 0 in output (e.g., -9 to 9)
  //   (remaining args and references as for zita_rev1_stereo above)

  zita_rev1_ambi(rgxyz,rdel,f1,f2,t60dc,t60m,fsmax) =
     zita_in_delay(rdel)
   : zita_distrib2(N)
   : zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
   : output4(N) // ambisonics mode
  with {
    N=8;
    output4(N) = select4 : *(t0),*(t1),*(t1),*(t1);
    select4 = _,_,_,!,_,!,!,! : _,_,cross with { cross(x,y) = y,x; };
    t0 = 1.0/sqrt(2.0);
    t1 = t0 * 10.0^(0.05 * rgxyz);
  };
  */
  
  //---------------------------------- zita_rev1 ------------------------------
  // Example GUI for zita_rev1_stereo (mostly following the Linux zita-rev1 GUI).
  //
  // Only the dry/wet and output level parameters are "dezippered" here.  If
  // parameters are to be varied in real time, use "smooth(0.999)" or the like
  // in the same way.
  //
  // REFERENCE:
  //   http://www.kokkinizita.net/linuxaudio/zita-rev1-doc/quickguide.html
  //
  // DEPENDENCIES:
  //   filter.lib (peak_eq_rm)

  zita_rev1(x,y) = zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax,x,y)
            : out_eq : dry_wet(x,y) : out_level;
  //with {

    fsmax = 48000.0;  // highest sampling rate that will be used

    fdn_group(x) = hgroup(
      "[0] Zita_Rev1 [tooltip: ~ ZITA REV1 FEEDBACK DELAY NETWORK (FDN) & SCHROEDER ALLPASS-COMB REVERBERATOR (8x8). See Faust's effect.lib for documentation and references]", x);

    in_group(x) = fdn_group(hgroup("[1] Input", x));

    rdel = in_group(vslider("[1] In Delay [unit:ms] [style:knob]
                    [tooltip: Delay in ms before reverberation begins]",
                    60,20,100,1));

    freq_group(x) = fdn_group(hgroup("[2] Decay Times in Bands (see tooltips)", x));

    f1 = freq_group(vslider("[1] LF X [unit:Hz] [style:knob] [scale:log]
         [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
         200, 50, 1000, 1));

    t60dc = freq_group(vslider("[2] Low RT60 [unit:s] [style:knob] [scale:log]
            [style:knob] [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
            3, 1, 8, 0.1));

    t60m = freq_group(vslider("[3] Mid RT60 [unit:s] [style:knob] [scale:log]
            [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
            2, 1, 8, 0.1));

    f2 = freq_group(vslider("[4] HF Damping [unit:Hz] [style:knob] [scale:log]
         [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
         6000, 1500, 0.49*fsmax, 1));

    out_eq = pareq_stereo(eq1f,eq1l,eq1q) : pareq_stereo(eq2f,eq2l,eq2q);
  // Zolzer style peaking eq (not used in zita-rev1) (filter.lib):
  // pareq_stereo(eqf,eql,Q) = peak_eq(eql,eqf,eqf/Q), peak_eq(eql,eqf,eqf/Q);
  // Regalia-Mitra peaking eq with "Q" hard-wired near sqrt(g)/2 (filter.lib):
    pareq_stereo(eqf,eql,Q) = peak_eq_rm(eql,eqf,tpbt), peak_eq_rm(eql,eqf,tpbt)
    with {
      tpbt = wcT/sqrt(max(0,g)); // tan(PI*B/SR), B bw in Hz (Q^2 ~ g/4)
      wcT = 2*PI*eqf/SR;  // peak frequency in rad/sample
      g = db2linear(eql); // peak gain
    };

    eq1_group(x) = fdn_group(hgroup("[3] RM Peaking Equalizer 1", x));

    eq1f = eq1_group(vslider("[1] Eq1 Freq [unit:Hz] [style:knob] [scale:log]
         [tooltip: Center-frequency of second-order Regalia-Mitra peaking equalizer section 1]",
         315, 40, 2500, 1));

    eq1l = eq1_group(vslider("[2] Eq1 Level [unit:dB] [style:knob]
         [tooltip: Peak level in dB of second-order Regalia-Mitra peaking equalizer section 1]",
         0, -15, 15, 0.1));

    eq1q = eq1_group(vslider("[3] Eq1 Q [style:knob]
         [tooltip: Q = centerFrequency/bandwidth of second-order peaking equalizer section 1]",
         3, 0.1, 10, 0.1));

    eq2_group(x) = fdn_group(hgroup("[4] RM Peaking Equalizer 2", x));

    eq2f = eq2_group(vslider("[1] Eq2 Freq [unit:Hz] [style:knob] [scale:log]
         [tooltip: Center-frequency of second-order Regalia-Mitra peaking equalizer section 2]",
         1500, 160, 10000, 1));

    eq2l = eq2_group(vslider("[2] Eq2 Level [unit:dB] [style:knob]
         [tooltip: Peak level in dB of second-order Regalia-Mitra peaking equalizer section 2]",
         0, -15, 15, 0.1));

    eq2q = eq2_group(vslider("[3] Eq2 Q [style:knob]
         [tooltip: Q = centerFrequency/bandwidth of second-order peaking equalizer section 2]",
         3, 0.1, 10, 0.1));

    out_group(x)  = fdn_group(hgroup("[5] Output", x));

    dry_wet(x,y) = *(wet) + dry*x, *(wet) + dry*y with {
      wet = 0.5*(drywet+1.0);
      dry = 1.0-wet;
    };

    drywet = out_group(vslider("[1] Dry/Wet Mix [style:knob]
         [tooltip: -1 = dry, 1 = wet]",
         0, -1.0, 1.0, 0.01)) : smooth(0.999);

    out_level = *(gain),*(gain);

    gain = out_group(vslider("[2] Level [unit:dB] [style:knob]
      [tooltip: Output scale factor]", -20, -70, 40, 0.1))
      : db2linear : smooth(0.999);

  //};
};

Added SchlemmerReverb/zita_ref1b.dsp.



























































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//import("all.lib");
import("maxmsp.lib");

//import("common.lib");
import("classic6.lib");

//import("revgui.lib");
import("zita_ref1.lib");
import("zita_ref1.gui");
import("zita_ref1.defaults");



/* klingt der _sim-lfo_ wirklich genau so gut?
sinusi=library("../rdk.lib").sinusi(freq,phase);
zitaLFO(i)=sinusi(ZT_GUI_SinusFreqHz,i*.125 )*(ZT_GUI_SinusDepth)+1.0;
  ZT_GUI_SinusFreqHz=1;
  ZT_SinusFreqHz=1;
  ZT_GUI_SinusDepth=0.01;
  ZT_SinusDepth=0.01;
*/

process = zt.zita_distrib2(8):
  //zt.zita_rev_fdn(zt.f1,zt.f2,zt.t60dc,zt.t60m,zt.fsmax)
  zitaCore
  :ze.reflevel(zt.N)
  :dir.eq82
  :ze.lexicon_trick(zt.N)
  :bus(2)
;




zitaCore=((bus(2*zt.N):>ze.fbdelaylines(zt.N):ze.allpass_combs(zt.N))
      ~(zt.feedbackmatrix(zt.N):cl.wdn(zt.N,zt.delayfilters(zt.N,zt.freqs,zt.durs),ZE_GUI_FLTON)
      :cl.wdn(zt.N,ze.reverbtime(zt.N),(1-(ZE_GUI_FLTON)))));

ze = environment{
  
///step 1: main loop
reverbtime(N) = par(i,N,*(ZE_GUI_MAINFB)) ;
///step 2.0: change delay to fdelay
fbdelaylines(zt.N)=par(i,zt.N,(fdelay(zt.maxfbdelay(i),(ze.fbdelay(i)))));
///step 2.1: change *g to UI
allpass_combs(N)=par(i,zt.N,(allpass_fcomb(zt.maxapdelay(i),ze.apdelay(i),ZE_GUI_APG(i)))) with {
  
  allpass_fcomb(maxdel,N,aN) = (+ <: fdelay(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : + ;//filters.lib
  }; 
///step 3: change delay(i) lenths to reflect SIM
apdelay(i)=sim.ssq(i+1)*gui.ZE_GUI_APPERCENT*SR/1000.0; //samples //rename ssq reflection
fbdelay(i)=sim.ssq(i+1)*SR/1000.0;

///step 4: change delay(i) lenths to reflect SIM
reflevel(N) = par(i,N,*(reflectionlevel(i)));
reflectionlevel(i) = sim.D0/(sim.ref(i+1)) *(ZE_GUI_ERCOMPRESSION) + makeup ;
 makeup = 1 - ZE_GUI_ERCOMPRESSION ;

///step 5: apply the lexicon trick
lexicon_trick(N)=bus(N)<:bus(2*N):(reva,refb):bus(4):>bus(2)
with {
  reva=bus(N):>bus(2):par(i,2,*(ZE_GUI_OUTLEVEL(1)));
  refb=bus(N):>bus(2):par(i,2,@(ZE_GUI_OUTDELAY)):par(i,2,*(ZE_GUI_OUTLEVEL(2)));
  };

};

  //apdelay(i) = SR/1000.*(apdelay_ms(i)) *zitaLFO(i) ; //ff_del
  //tdelay_ms(i) = reflectiondelay_ms(i) - (1-(APDELAY_PERCENT(i))) ; //fdn_del
  //                                     ^BUG?: * intended?
  //apdelay_ms(i) = reflectiondelay_ms(i) * APDELAY_PERCENT(i) ; 

my_apdelay(i)=sim.ssq(i+1)*gui.ZT_GUI_APPERCENT*SR/1000.0;
my_tdelay(i)=sim.ssq(i+1)*SR/1000.0;//bug wie oben ///samples



/*
revb=bus(8):>bus(2):par(i,2,*(ZT_GUI_L1));
ref8=//pot(8,1):
  bus(8):>bus(2):par(i,2,@(ZT_GUI_DX)):par(i,2,*(ZT_GUI_L2));

ch=8;
pot(n,j) = par(i,n,cl.panpot(ZTMX_PAN(i+1,j)));

//some GUI. todo: rename param
ZT_GUI_DX = nentry("[0]ZT_DX",ZT_DX,0,4000,1);
ZT_GUI_L2 = nentry("[0]ZT_L2",ZT_L2,-1,1,0.001);
ZT_GUI_L1 = nentry("[0]ZT_L1",ZT_L1,-1,1,0.001);
*/

//import lit. from old/effect.lib:
zt = environment {
  
  zita_rev_fdn(f1,f2,t60dc,t60m,fsmax) =
  ((bus(2*N) :> allpass_combs(N) : feedbackmatrix(N)) ~
   (delayfilters(N,freqs,durs) : fbdelaylines(N)));

  N = 8;

  // Delay-line lengths in seconds:
  apdelays = (0.020346, 0.024421, 0.031604, 0.027333, 0.022904,
              0.029291, 0.013458, 0.019123); // feedforward delays in seconds
  tdelays = ( 0.153129, 0.210389, 0.127837, 0.256891, 0.174713,
              0.192303, 0.125000, 0.219991); // total delays in seconds
///step 2.0: replace delay lengths with values from source image model (SIM)
  tdelay(i) = floor(0.5 + SR*take(i+1,tdelays)); // samples
  apdelay(i) = floor(0.5 + SR*take(i+1,apdelays));
  //tdelay(i) = my_tdelay(i);//floor(0.5 + SR*take(i+1,tdelays)); // samples
  //apdelay(i) = my_apdelay(i);//floor(0.5 + SR*take(i+1,apdelays));
///------------------------------------------------------------------------
  fbdelay(i) = tdelay(i) - apdelay(i);
  // NOTE: Since SR is not bounded at compile time, we can't use it to
  // allocate delay lines; hence, the fsmax parameter:
  tdelaymaxfs(i) = floor(0.5 + fsmax*take(i+1,tdelays));
  apdelaymaxfs(i) = floor(0.5 + fsmax*take(i+1,apdelays));
  fbdelaymaxfs(i) = tdelaymaxfs(i) - apdelaymaxfs(i);
  nextpow2(x) = ceil(log(x)/log(2.0));
  maxapdelay(i) = int(2.0^max(1.0,nextpow2(apdelaymaxfs(i))));
  maxfbdelay(i) = int(2.0^max(1.0,nextpow2(fbdelaymaxfs(i))));

  apcoeff(i) = select2(i&1,0.6,-0.6);  // allpass comb-filter coefficient
///step 3.0: replace g* with gui
  allpass_combs(N) =
    par(i,N,(allpass_comb(maxapdelay(i),apdelay(i),apcoeff(i)))); 
    //par(i,N,(allpass_comb(maxapdelay(i),apdelay(i),(gui.AP_G(i)*(-1))))); 
///------------------------------------------------^^^^^^^-----
  fbdelaylines(N) = par(i,N,(delay(maxfbdelay(i),(fbdelay(i)))));
  freqs = (f1,f2); durs = (t60dc,t60m);
  delayfilters(N,freqs,durs) = par(i,N,filter(i,freqs,durs));
  feedbackmatrix(N) = hadamard(N); // math.lib

  staynormal = 10.0^(-20); // let signals decay well below LSB, but not to zero

  special_lowpass(g,f) = smooth(p) with {
    // unity-dc-gain lowpass needs gain g at frequency f => quadratic formula:
    p = mbo2 - sqrt(max(0,mbo2*mbo2 - 1.0)); // other solution is unstable
    mbo2 = (1.0 - gs*c)/(1.0 - gs); // NOTE: must ensure |g|<1 (t60m finite)
    gs = g*g;
    c = cos(2.0*PI*f/float(SR));
  };

  filter(i,freqs,durs) = lowshelf_lowpass(i)/sqrt(float(N))+staynormal
  with {
    lowshelf_lowpass(i) = gM*low_shelf1_l(g0/gM,f(1)):special_lowpass(gM,f(2));
    low_shelf1_l(G0,fx,x) = x + (G0-1)*lowpass(1,fx,x); // filter.lib
    g0 = g(0,i);
    gM = g(1,i);
    f(k) = take(k,freqs);
    dur(j) = take(j+1,durs);
    n60(j) = dur(j)*SR; // decay time in samples
    g(j,i) = exp(-3.0*log(10.0)*tdelay(i)/n60(j));
  };
  
  // Stereo input delay used by zita_rev1 in both stereo and ambisonics mode:
  zita_in_delay(rdel) = zita_delay_mono(rdel), zita_delay_mono(rdel) with {
    zita_delay_mono(rdel) = delay(8192,SR*rdel*0.001) * 0.3;
  };

  // Stereo input mapping used by zita_rev1 in both stereo and ambisonics mode:
  zita_distrib2(N) = _,_ <: fanflip(N) with {
     fanflip(4) = _,_,*(-1),*(-1);
     fanflip(N) = fanflip(N/2),fanflip(N/2);
  };

  /* not used here
  //--------------------------- zita_rev_fdn_demo ------------------------------
  // zita_rev_fdn_demo = zita_rev_fdn (above) + basic GUI
  //
  // USAGE:
  //   bus(8) : zita_rev_fdn_demo(f1,f2,t60dc,t60m,fsmax) : bus(8)
  //
  // WHERE
  //   (args and references as for zita_rev_fdn above)

  zita_rev_fdn_demo = zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
  with {
    fsmax = 48000.0;
    fdn_group(x) = hgroup(
      "Zita_Rev Internal FDN Reverb [tooltip: ~ Zita_Rev's internal 8x8 Feedback Delay Network (FDN) & Schroeder allpass-comb reverberator.  See Faust's effect.lib for documentation and references]",x);
    t60dc = fdn_group(vslider("[1] Low RT60 [unit:s] [style:knob]
      [style:knob]
      [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
      3, 1, 8, 0.1));
    f1 = fdn_group(vslider("[2] LF X [unit:Hz] [style:knob] [scale:log]
      [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
      200, 50, 1000, 1));
    t60m = fdn_group(vslider("[3] Mid RT60 [unit:s] [style:knob] [scale:log]
      [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
      2, 1, 8, 0.1));
    f2 = fdn_group(vslider("[4] HF Damping [unit:Hz] [style:knob] [scale:log]
      [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
      6000, 1500, 0.49*fsmax, 1));
  };
  */

  //---------------------------- zita_rev1_stereo ---------------------------
  // Extend zita_rev_fdn to include zita_rev1 input/output mapping in stereo mode.
  //
  // USAGE:
  //   _,_ : zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax) : _,_
  //
  // WHERE
  //   rdel  = delay (in ms) before reverberation begins (e.g., 0 to ~100 ms)
  //   (remaining args and refs as for zita_rev_fdn above)

  zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax) =
     zita_in_delay(rdel)
   : zita_distrib2(N)
   : zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
   : output2(N)
  with {
   N = 8;
   output2(N) = outmix(N) : *(t1),*(t1);
   t1 = 0.37; // zita-rev1 linearly ramps from 0 to t1 over one buffer
   outmix(4) = !,butterfly(2),!; // probably the result of some experimenting!
   outmix(N) = outmix(N/2),par(i,N/2,!);
  };

  /* not used here
  //----------------------------- zita_rev1_ambi ---------------------------
  // Extend zita_rev_fdn to include zita_rev1 input/output mapping in
  // "ambisonics mode", as provided in the Linux C++ version.
  //
  // USAGE:
  //   _,_ : zita_rev1_ambi(rgxyz,rdel,f1,f2,t60dc,t60m,fsmax) : _,_,_,_
  //
  // WHERE
  //   rgxyz = relative gain of lanes 1,4,2 to lane 0 in output (e.g., -9 to 9)
  //   (remaining args and references as for zita_rev1_stereo above)

  zita_rev1_ambi(rgxyz,rdel,f1,f2,t60dc,t60m,fsmax) =
     zita_in_delay(rdel)
   : zita_distrib2(N)
   : zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
   : output4(N) // ambisonics mode
  with {
    N=8;
    output4(N) = select4 : *(t0),*(t1),*(t1),*(t1);
    select4 = _,_,_,!,_,!,!,! : _,_,cross with { cross(x,y) = y,x; };
    t0 = 1.0/sqrt(2.0);
    t1 = t0 * 10.0^(0.05 * rgxyz);
  };
  */
  
  //---------------------------------- zita_rev1 ------------------------------
  // Example GUI for zita_rev1_stereo (mostly following the Linux zita-rev1 GUI).
  //
  // Only the dry/wet and output level parameters are "dezippered" here.  If
  // parameters are to be varied in real time, use "smooth(0.999)" or the like
  // in the same way.
  //
  // REFERENCE:
  //   http://www.kokkinizita.net/linuxaudio/zita-rev1-doc/quickguide.html
  //
  // DEPENDENCIES:
  //   filter.lib (peak_eq_rm)

  zita_rev1(x,y) = zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax,x,y)
            : out_eq : dry_wet(x,y) : out_level;
  //with {

    fsmax = 48000.0;  // highest sampling rate that will be used

    fdn_group(x) = hgroup(
      "[0] Zita_Rev1 [tooltip: ~ ZITA REV1 FEEDBACK DELAY NETWORK (FDN) & SCHROEDER ALLPASS-COMB REVERBERATOR (8x8). See Faust's effect.lib for documentation and references]", x);

    in_group(x) = fdn_group(hgroup("[1] Input", x));

    rdel = in_group(vslider("[1] In Delay [unit:ms] [style:knob]
                    [tooltip: Delay in ms before reverberation begins]",
                    60,20,100,1));

    freq_group(x) = fdn_group(hgroup("[2] Decay Times in Bands (see tooltips)", x));

    f1 = freq_group(vslider("[1] LF X [unit:Hz] [style:knob] [scale:log]
         [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
         200, 50, 1000, 1));

    t60dc = freq_group(vslider("[2] Low RT60 [unit:s] [style:knob] [scale:log]
            [style:knob] [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
            3, 1, 8, 0.1));

    t60m = freq_group(vslider("[3] Mid RT60 [unit:s] [style:knob] [scale:log]
            [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
            2, 1, 8, 0.1));

    f2 = freq_group(vslider("[4] HF Damping [unit:Hz] [style:knob] [scale:log]
         [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
         6000, 1500, 0.49*fsmax, 1));

    out_eq = pareq_stereo(eq1f,eq1l,eq1q) : pareq_stereo(eq2f,eq2l,eq2q);
  // Zolzer style peaking eq (not used in zita-rev1) (filter.lib):
  // pareq_stereo(eqf,eql,Q) = peak_eq(eql,eqf,eqf/Q), peak_eq(eql,eqf,eqf/Q);
  // Regalia-Mitra peaking eq with "Q" hard-wired near sqrt(g)/2 (filter.lib):
    pareq_stereo(eqf,eql,Q) = peak_eq_rm(eql,eqf,tpbt), peak_eq_rm(eql,eqf,tpbt)
    with {
      tpbt = wcT/sqrt(max(0,g)); // tan(PI*B/SR), B bw in Hz (Q^2 ~ g/4)
      wcT = 2*PI*eqf/SR;  // peak frequency in rad/sample
      g = db2linear(eql); // peak gain
    };

    eq1_group(x) = fdn_group(hgroup("[3] RM Peaking Equalizer 1", x));

    eq1f = eq1_group(vslider("[1] Eq1 Freq [unit:Hz] [style:knob] [scale:log]
         [tooltip: Center-frequency of second-order Regalia-Mitra peaking equalizer section 1]",
         315, 40, 2500, 1));

    eq1l = eq1_group(vslider("[2] Eq1 Level [unit:dB] [style:knob]
         [tooltip: Peak level in dB of second-order Regalia-Mitra peaking equalizer section 1]",
         0, -15, 15, 0.1));

    eq1q = eq1_group(vslider("[3] Eq1 Q [style:knob]
         [tooltip: Q = centerFrequency/bandwidth of second-order peaking equalizer section 1]",
         3, 0.1, 10, 0.1));

    eq2_group(x) = fdn_group(hgroup("[4] RM Peaking Equalizer 2", x));

    eq2f = eq2_group(vslider("[1] Eq2 Freq [unit:Hz] [style:knob] [scale:log]
         [tooltip: Center-frequency of second-order Regalia-Mitra peaking equalizer section 2]",
         1500, 160, 10000, 1));

    eq2l = eq2_group(vslider("[2] Eq2 Level [unit:dB] [style:knob]
         [tooltip: Peak level in dB of second-order Regalia-Mitra peaking equalizer section 2]",
         0, -15, 15, 0.1));

    eq2q = eq2_group(vslider("[3] Eq2 Q [style:knob]
         [tooltip: Q = centerFrequency/bandwidth of second-order peaking equalizer section 2]",
         3, 0.1, 10, 0.1));

    out_group(x)  = fdn_group(hgroup("[5] Output", x));

    dry_wet(x,y) = *(wet) + dry*x, *(wet) + dry*y with {
      wet = 0.5*(drywet+1.0);
      dry = 1.0-wet;
    };

    drywet = out_group(vslider("[1] Dry/Wet Mix [style:knob]
         [tooltip: -1 = dry, 1 = wet]",
         0, -1.0, 1.0, 0.01)) : smooth(0.999);

    out_level = *(gain),*(gain);

    gain = out_group(vslider("[2] Level [unit:dB] [style:knob]
      [tooltip: Output scale factor]", -20, -70, 40, 0.1))
      : db2linear : smooth(0.999);

  //};
};

Added SchlemmerReverb/zita_ref1b_values.dsp.





























































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//import("all.lib");
import("maxmsp.lib");

//import("common.lib");
import("classic6.lib");

//import("revgui.lib");
import("zita_ref1.lib");
import("zita_ref1.gui");
import("zita_ref1.defaults");



/* klingt der _sim-lfo_ wirklich genau so gut?
sinusi=library("../rdk.lib").sinusi(freq,phase);
zitaLFO(i)=sinusi(ZT_GUI_SinusFreqHz,i*.125 )*(ZT_GUI_SinusDepth)+1.0;
  ZT_GUI_SinusFreqHz=1;
  ZT_SinusFreqHz=1;
  ZT_GUI_SinusDepth=0.01;
  ZT_SinusDepth=0.01;
*/

process = //zt.zita_distrib2(8):
  //zt.zita_rev_fdn(zt.f1,zt.f2,zt.t60dc,zt.t60m,zt.fsmax)
  //zitaCore
  //:ze.reflevel(zt.N)
  //:dir.eq82
  //:ze.lexicon_trick(zt.N)
  //:bus(2)
  par(i,8,ze.apdelay(i)/(SR/1000.0))
;




zitaCore=((bus(2*zt.N):>ze.fbdelaylines(zt.N):ze.allpass_combs(zt.N))
      ~(zt.feedbackmatrix(zt.N):cl.wdn(zt.N,zt.delayfilters(zt.N,zt.freqs,zt.durs),ZE_GUI_FLTON)
      :cl.wdn(zt.N,ze.reverbtime(zt.N),(1-(ZE_GUI_FLTON)))));

ze = environment{
  
///step 1: main loop
reverbtime(N) = par(i,N,*(ZE_GUI_MAINFB)) ;
///step 2.0: change delay to fdelay
fbdelaylines(zt.N)=par(i,zt.N,(fdelay(zt.maxfbdelay(i),(ze.fbdelay(i)))));
///step 2.1: change *g to UI
allpass_combs(N)=par(i,zt.N,(allpass_fcomb(zt.maxapdelay(i),ze.apdelay(i),ZE_GUI_APG(i)))) with {
  
  allpass_fcomb(maxdel,N,aN) = (+ <: fdelay(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : + ;//filters.lib
  }; 
///step 3: change delay(i) lenths to reflect SIM
apdelay(i)=sim.ssq(i+1)*gui.ZE_GUI_APPERCENT*SR/1000.0; //samples //rename ssq reflection
fbdelay(i)=sim.ssq(i+1)*SR/1000.0;

///step 4: change delay(i) lenths to reflect SIM
reflevel(N) = par(i,N,*(reflectionlevel(i)));
reflectionlevel(i) = sim.D0/(sim.ref(i+1)) *(ZE_GUI_ERCOMPRESSION) + makeup ;
 makeup = 1 - ZE_GUI_ERCOMPRESSION ;

///step 5: apply the lexicon trick
lexicon_trick(N)=bus(N)<:bus(2*N):(reva,refb):bus(4):>bus(2)
with {
  reva=bus(N):>bus(2):par(i,2,*(ZE_GUI_OUTLEVEL(1)));
  refb=bus(N):>bus(2):par(i,2,@(ZE_GUI_OUTDELAY)):par(i,2,*(ZE_GUI_OUTLEVEL(2)));
  };

};

  //apdelay(i) = SR/1000.*(apdelay_ms(i)) *zitaLFO(i) ; //ff_del
  //tdelay_ms(i) = reflectiondelay_ms(i) - (1-(APDELAY_PERCENT(i))) ; //fdn_del
  //                                     ^BUG?: * intended?
  //apdelay_ms(i) = reflectiondelay_ms(i) * APDELAY_PERCENT(i) ; 

my_apdelay(i)=sim.ssq(i+1)*gui.ZT_GUI_APPERCENT*SR/1000.0;
my_tdelay(i)=sim.ssq(i+1)*SR/1000.0;//bug wie oben ///samples



/*
revb=bus(8):>bus(2):par(i,2,*(ZT_GUI_L1));
ref8=//pot(8,1):
  bus(8):>bus(2):par(i,2,@(ZT_GUI_DX)):par(i,2,*(ZT_GUI_L2));

ch=8;
pot(n,j) = par(i,n,cl.panpot(ZTMX_PAN(i+1,j)));

//some GUI. todo: rename param
ZT_GUI_DX = nentry("[0]ZT_DX",ZT_DX,0,4000,1);
ZT_GUI_L2 = nentry("[0]ZT_L2",ZT_L2,-1,1,0.001);
ZT_GUI_L1 = nentry("[0]ZT_L1",ZT_L1,-1,1,0.001);
*/

//import lit. from old/effect.lib:
zt = environment {
  
  zita_rev_fdn(f1,f2,t60dc,t60m,fsmax) =
  ((bus(2*N) :> allpass_combs(N) : feedbackmatrix(N)) ~
   (delayfilters(N,freqs,durs) : fbdelaylines(N)));

  N = 8;

  // Delay-line lengths in seconds:
  apdelays = (0.020346, 0.024421, 0.031604, 0.027333, 0.022904,
              0.029291, 0.013458, 0.019123); // feedforward delays in seconds
  tdelays = ( 0.153129, 0.210389, 0.127837, 0.256891, 0.174713,
              0.192303, 0.125000, 0.219991); // total delays in seconds
///step 2.0: replace delay lengths with values from source image model (SIM)
  tdelay(i) = floor(0.5 + SR*take(i+1,tdelays)); // samples
  apdelay(i) = floor(0.5 + SR*take(i+1,apdelays));
  //tdelay(i) = my_tdelay(i);//floor(0.5 + SR*take(i+1,tdelays)); // samples
  //apdelay(i) = my_apdelay(i);//floor(0.5 + SR*take(i+1,apdelays));
///------------------------------------------------------------------------
  fbdelay(i) = tdelay(i) - apdelay(i);
  // NOTE: Since SR is not bounded at compile time, we can't use it to
  // allocate delay lines; hence, the fsmax parameter:
  tdelaymaxfs(i) = floor(0.5 + fsmax*take(i+1,tdelays));
  apdelaymaxfs(i) = floor(0.5 + fsmax*take(i+1,apdelays));
  fbdelaymaxfs(i) = tdelaymaxfs(i) - apdelaymaxfs(i);
  nextpow2(x) = ceil(log(x)/log(2.0));
  maxapdelay(i) = int(2.0^max(1.0,nextpow2(apdelaymaxfs(i))));
  maxfbdelay(i) = int(2.0^max(1.0,nextpow2(fbdelaymaxfs(i))));

  apcoeff(i) = select2(i&1,0.6,-0.6);  // allpass comb-filter coefficient
///step 3.0: replace g* with gui
  allpass_combs(N) =
    par(i,N,(allpass_comb(maxapdelay(i),apdelay(i),apcoeff(i)))); 
    //par(i,N,(allpass_comb(maxapdelay(i),apdelay(i),(gui.AP_G(i)*(-1))))); 
///------------------------------------------------^^^^^^^-----
  fbdelaylines(N) = par(i,N,(delay(maxfbdelay(i),(fbdelay(i)))));
  freqs = (f1,f2); durs = (t60dc,t60m);
  delayfilters(N,freqs,durs) = par(i,N,filter(i,freqs,durs));
  feedbackmatrix(N) = hadamard(N); // math.lib

  staynormal = 10.0^(-20); // let signals decay well below LSB, but not to zero

  special_lowpass(g,f) = smooth(p) with {
    // unity-dc-gain lowpass needs gain g at frequency f => quadratic formula:
    p = mbo2 - sqrt(max(0,mbo2*mbo2 - 1.0)); // other solution is unstable
    mbo2 = (1.0 - gs*c)/(1.0 - gs); // NOTE: must ensure |g|<1 (t60m finite)
    gs = g*g;
    c = cos(2.0*PI*f/float(SR));
  };

  filter(i,freqs,durs) = lowshelf_lowpass(i)/sqrt(float(N))+staynormal
  with {
    lowshelf_lowpass(i) = gM*low_shelf1_l(g0/gM,f(1)):special_lowpass(gM,f(2));
    low_shelf1_l(G0,fx,x) = x + (G0-1)*lowpass(1,fx,x); // filter.lib
    g0 = g(0,i);
    gM = g(1,i);
    f(k) = take(k,freqs);
    dur(j) = take(j+1,durs);
    n60(j) = dur(j)*SR; // decay time in samples
    g(j,i) = exp(-3.0*log(10.0)*tdelay(i)/n60(j));
  };
  
  // Stereo input delay used by zita_rev1 in both stereo and ambisonics mode:
  zita_in_delay(rdel) = zita_delay_mono(rdel), zita_delay_mono(rdel) with {
    zita_delay_mono(rdel) = delay(8192,SR*rdel*0.001) * 0.3;
  };

  // Stereo input mapping used by zita_rev1 in both stereo and ambisonics mode:
  zita_distrib2(N) = _,_ <: fanflip(N) with {
     fanflip(4) = _,_,*(-1),*(-1);
     fanflip(N) = fanflip(N/2),fanflip(N/2);
  };

  /* not used here
  //--------------------------- zita_rev_fdn_demo ------------------------------
  // zita_rev_fdn_demo = zita_rev_fdn (above) + basic GUI
  //
  // USAGE:
  //   bus(8) : zita_rev_fdn_demo(f1,f2,t60dc,t60m,fsmax) : bus(8)
  //
  // WHERE
  //   (args and references as for zita_rev_fdn above)

  zita_rev_fdn_demo = zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
  with {
    fsmax = 48000.0;
    fdn_group(x) = hgroup(
      "Zita_Rev Internal FDN Reverb [tooltip: ~ Zita_Rev's internal 8x8 Feedback Delay Network (FDN) & Schroeder allpass-comb reverberator.  See Faust's effect.lib for documentation and references]",x);
    t60dc = fdn_group(vslider("[1] Low RT60 [unit:s] [style:knob]
      [style:knob]
      [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
      3, 1, 8, 0.1));
    f1 = fdn_group(vslider("[2] LF X [unit:Hz] [style:knob] [scale:log]
      [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
      200, 50, 1000, 1));
    t60m = fdn_group(vslider("[3] Mid RT60 [unit:s] [style:knob] [scale:log]
      [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
      2, 1, 8, 0.1));
    f2 = fdn_group(vslider("[4] HF Damping [unit:Hz] [style:knob] [scale:log]
      [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
      6000, 1500, 0.49*fsmax, 1));
  };
  */

  //---------------------------- zita_rev1_stereo ---------------------------
  // Extend zita_rev_fdn to include zita_rev1 input/output mapping in stereo mode.
  //
  // USAGE:
  //   _,_ : zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax) : _,_
  //
  // WHERE
  //   rdel  = delay (in ms) before reverberation begins (e.g., 0 to ~100 ms)
  //   (remaining args and refs as for zita_rev_fdn above)

  zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax) =
     zita_in_delay(rdel)
   : zita_distrib2(N)
   : zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
   : output2(N)
  with {
   N = 8;
   output2(N) = outmix(N) : *(t1),*(t1);
   t1 = 0.37; // zita-rev1 linearly ramps from 0 to t1 over one buffer
   outmix(4) = !,butterfly(2),!; // probably the result of some experimenting!
   outmix(N) = outmix(N/2),par(i,N/2,!);
  };

  /* not used here
  //----------------------------- zita_rev1_ambi ---------------------------
  // Extend zita_rev_fdn to include zita_rev1 input/output mapping in
  // "ambisonics mode", as provided in the Linux C++ version.
  //
  // USAGE:
  //   _,_ : zita_rev1_ambi(rgxyz,rdel,f1,f2,t60dc,t60m,fsmax) : _,_,_,_
  //
  // WHERE
  //   rgxyz = relative gain of lanes 1,4,2 to lane 0 in output (e.g., -9 to 9)
  //   (remaining args and references as for zita_rev1_stereo above)

  zita_rev1_ambi(rgxyz,rdel,f1,f2,t60dc,t60m,fsmax) =
     zita_in_delay(rdel)
   : zita_distrib2(N)
   : zita_rev_fdn(f1,f2,t60dc,t60m,fsmax)
   : output4(N) // ambisonics mode
  with {
    N=8;
    output4(N) = select4 : *(t0),*(t1),*(t1),*(t1);
    select4 = _,_,_,!,_,!,!,! : _,_,cross with { cross(x,y) = y,x; };
    t0 = 1.0/sqrt(2.0);
    t1 = t0 * 10.0^(0.05 * rgxyz);
  };
  */
  
  //---------------------------------- zita_rev1 ------------------------------
  // Example GUI for zita_rev1_stereo (mostly following the Linux zita-rev1 GUI).
  //
  // Only the dry/wet and output level parameters are "dezippered" here.  If
  // parameters are to be varied in real time, use "smooth(0.999)" or the like
  // in the same way.
  //
  // REFERENCE:
  //   http://www.kokkinizita.net/linuxaudio/zita-rev1-doc/quickguide.html
  //
  // DEPENDENCIES:
  //   filter.lib (peak_eq_rm)

  zita_rev1(x,y) = zita_rev1_stereo(rdel,f1,f2,t60dc,t60m,fsmax,x,y)
            : out_eq : dry_wet(x,y) : out_level;
  //with {

    fsmax = 48000.0;  // highest sampling rate that will be used

    fdn_group(x) = hgroup(
      "[0] Zita_Rev1 [tooltip: ~ ZITA REV1 FEEDBACK DELAY NETWORK (FDN) & SCHROEDER ALLPASS-COMB REVERBERATOR (8x8). See Faust's effect.lib for documentation and references]", x);

    in_group(x) = fdn_group(hgroup("[1] Input", x));

    rdel = in_group(vslider("[1] In Delay [unit:ms] [style:knob]
                    [tooltip: Delay in ms before reverberation begins]",
                    60,20,100,1));

    freq_group(x) = fdn_group(hgroup("[2] Decay Times in Bands (see tooltips)", x));

    f1 = freq_group(vslider("[1] LF X [unit:Hz] [style:knob] [scale:log]
         [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
         200, 50, 1000, 1));

    t60dc = freq_group(vslider("[2] Low RT60 [unit:s] [style:knob] [scale:log]
            [style:knob] [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
            3, 1, 8, 0.1));

    t60m = freq_group(vslider("[3] Mid RT60 [unit:s] [style:knob] [scale:log]
            [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
            2, 1, 8, 0.1));

    f2 = freq_group(vslider("[4] HF Damping [unit:Hz] [style:knob] [scale:log]
         [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
         6000, 1500, 0.49*fsmax, 1));

    out_eq = pareq_stereo(eq1f,eq1l,eq1q) : pareq_stereo(eq2f,eq2l,eq2q);
  // Zolzer style peaking eq (not used in zita-rev1) (filter.lib):
  // pareq_stereo(eqf,eql,Q) = peak_eq(eql,eqf,eqf/Q), peak_eq(eql,eqf,eqf/Q);
  // Regalia-Mitra peaking eq with "Q" hard-wired near sqrt(g)/2 (filter.lib):
    pareq_stereo(eqf,eql,Q) = peak_eq_rm(eql,eqf,tpbt), peak_eq_rm(eql,eqf,tpbt)
    with {
      tpbt = wcT/sqrt(max(0,g)); // tan(PI*B/SR), B bw in Hz (Q^2 ~ g/4)
      wcT = 2*PI*eqf/SR;  // peak frequency in rad/sample
      g = db2linear(eql); // peak gain
    };

    eq1_group(x) = fdn_group(hgroup("[3] RM Peaking Equalizer 1", x));

    eq1f = eq1_group(vslider("[1] Eq1 Freq [unit:Hz] [style:knob] [scale:log]
         [tooltip: Center-frequency of second-order Regalia-Mitra peaking equalizer section 1]",
         315, 40, 2500, 1));

    eq1l = eq1_group(vslider("[2] Eq1 Level [unit:dB] [style:knob]
         [tooltip: Peak level in dB of second-order Regalia-Mitra peaking equalizer section 1]",
         0, -15, 15, 0.1));

    eq1q = eq1_group(vslider("[3] Eq1 Q [style:knob]
         [tooltip: Q = centerFrequency/bandwidth of second-order peaking equalizer section 1]",
         3, 0.1, 10, 0.1));

    eq2_group(x) = fdn_group(hgroup("[4] RM Peaking Equalizer 2", x));

    eq2f = eq2_group(vslider("[1] Eq2 Freq [unit:Hz] [style:knob] [scale:log]
         [tooltip: Center-frequency of second-order Regalia-Mitra peaking equalizer section 2]",
         1500, 160, 10000, 1));

    eq2l = eq2_group(vslider("[2] Eq2 Level [unit:dB] [style:knob]
         [tooltip: Peak level in dB of second-order Regalia-Mitra peaking equalizer section 2]",
         0, -15, 15, 0.1));

    eq2q = eq2_group(vslider("[3] Eq2 Q [style:knob]
         [tooltip: Q = centerFrequency/bandwidth of second-order peaking equalizer section 2]",
         3, 0.1, 10, 0.1));

    out_group(x)  = fdn_group(hgroup("[5] Output", x));

    dry_wet(x,y) = *(wet) + dry*x, *(wet) + dry*y with {
      wet = 0.5*(drywet+1.0);
      dry = 1.0-wet;
    };

    drywet = out_group(vslider("[1] Dry/Wet Mix [style:knob]
         [tooltip: -1 = dry, 1 = wet]",
         0, -1.0, 1.0, 0.01)) : smooth(0.999);

    out_level = *(gain),*(gain);

    gain = out_group(vslider("[2] Level [unit:dB] [style:knob]
      [tooltip: Output scale factor]", -20, -70, 40, 0.1))
      : db2linear : smooth(0.999);

  //};
};

Added SchlemmerReverb/zita_ref1c.dsp.













































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//import("all.lib");
import("maxmsp.lib");

//import("common.lib");
import("classic6.lib");

//import("revgui.lib");
import("zita_ref1.lib");
import("zita_ref1.gui");
import("zita_ref1.defaults");

///Extending Zita Reverb with Virtual Room Acoustics 
//Life coding/sound processing and modification of the famous zita reverb by fons adriaensen.

//---------------------------------------------------------------------------------------
re=library("effect.lib"); // doesn't work because with {} is used for 'member' functions.
//---------------------------------------------------------------------------------------



/* klingt der _sim-lfo_ wirklich genau so gut?
sinusi=library("../rdk.lib").sinusi(freq,phase);
zitaLFO(i)=sinusi(ZT_GUI_SinusFreqHz,i*.125 )*(ZT_GUI_SinusDepth)+1.0;
  ZT_GUI_SinusFreqHz=1;
  ZT_SinusFreqHz=1;
  ZT_GUI_SinusDepth=0.01;
  ZT_SinusDepth=0.01;
*/

process = zt.zita_distrib2(8):
  //zt.zita_rev_fdn(zt.f1,zt.f2,zt.t60dc,zt.t60m,zt.fsmax)
  zitaCore
  :ze.reflevel(zt.N)
  :dir.eq82
  :ze.lexicon_trick(zt.N)
  :bus(2)
;

zitaCore=((bus(2*zt.N):>ze.fbdelaylines(zt.N):ze.allpass_combs(zt.N))
      ~(zt.feedbackmatrix(zt.N):cl.wdn(zt.N,zt.delayfilters(zt.N,zt.freqs,zt.durs),ZE_GUI_FLTON)
      :cl.wdn(zt.N,ze.reverbtime(zt.N),(1-(ZE_GUI_FLTON)))));

ze = environment{
  
///step 1: main loop
reverbtime(N) = par(i,N,*(ZE_GUI_MAINFB)) ;
///step 2.0: change delay to fdelay
fbdelaylines(zt.N)=par(i,zt.N,(fdelay(zt.maxfbdelay(i),(ze.fbdelay(i)))));
///step 2.1: change *g to UI
allpass_combs(N)=par(i,zt.N,(allpass_fcomb(zt.maxapdelay(i),ze.apdelay(i),ZE_GUI_APG(i)))) with {
  
  allpass_fcomb(maxdel,N,aN) = (+ <: fdelay(maxdel,N-1),*(aN)) ~ *(-aN) : mem,_ : + ;//filters.lib
  }; 
///step 3: change delay(i) lenths to reflect SIM
apdelay(i)=sim.ssq(i+1)*gui.ZE_GUI_APPERCENT*SR/1000.0; //samples //rename ssq reflection
fbdelay(i)=sim.ssq(i+1)*SR/1000.0;

///step 4: change delay(i) lenths to reflect SIM
reflevel(N) = par(i,N,*(reflectionlevel(i)));
reflectionlevel(i) = sim.D0/(sim.ref(i+1)) *(ZE_GUI_ERCOMPRESSION) + makeup ;
 makeup = 1 - ZE_GUI_ERCOMPRESSION ;

///step 5: apply the lexicon trick
lexicon_trick(N)=bus(N)<:bus(2*N):(reva,refb):bus(4):>bus(2)
with {
  reva=bus(N):>bus(2):par(i,2,*(ZE_GUI_OUTLEVEL(1)));
  refb=bus(N):>bus(2):par(i,2,@(ZE_GUI_OUTDELAY)):par(i,2,*(ZE_GUI_OUTLEVEL(2)));
  };

};

Added zita_extended/zita_tripledat_values-presets/lex.



























>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
1 zita_ref0//GUTS/ER_ctl/Reverb_In//DIR_WD
0.222 zita_ref0/RT0
128 zita_ref0/ZT_DX
-0.5 zita_ref0/ZT_L2
0.5 zita_ref0/LR
0.17 zita_ref0/DISTANCE
0.62 zita_ref0/APDELAY_PERCENT
0.62 zita_ref0/AP_G
1 zita_ref0/ER_COMPRESSION_FACTOR
1.32 zita_ref0/ROOMSIZE
0.007 zita_ref0/rdk.sinusDepth
0.91 zita_ref0/rdk.sinusFreqHz

Added zita_extended/zita_tripledat_values-presets/lex-dennon.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1 zita_ref0//GUTS/ER_ctl/Reverb_In//DIR_WD

0.222 zita_ref0/RT0

128 zita_ref0/ZT_DX

0.3 zita_ref0/ZT_L1

-0.5 zita_ref0/ZT_L2
0.5 zita_ref0/LR
0.17 zita_ref0/DISTANCE
0.62 zita_ref0/APDELAY_PERCENT

0.62 zita_ref0/AP_G

1 zita_ref0/ER_COMPRESSION_FACTOR
1.32 zita_ref0/ROOMSIZE
0.007 zita_ref0/rdk.sinusDepth
0.91 zita_ref0/rdk.sinusFreqHz

Added zita_extended/zita_tripledat_values-presets/small-room.





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0.26 zita_ref0//GUTS/ER_ctl/Reverb_In//DIR_WD
0.173 zita_ref0/RT0
128 zita_ref0/ZT_DX
0.244 zita_ref0/ZT_L1
-0.3 zita_ref0/ZT_L2
0.5 zita_ref0/LR
0.25 zita_ref0/DISTANCE
0.62 zita_ref0/APDELAY_PERCENT
0.62 zita_ref0/AP_G
0 zita_ref0/ER_COMPRESSION_FACTOR
0.74 zita_ref0/ROOMSIZE
0.008 zita_ref0/rdk.sinusDepth
0.91 zita_ref0/rdk.sinusFreqHz

Added zita_extended/zita_tripledat_values-presets/snare003.



>
1
../../zita_extended/zita_tripledat-presets/snare003

Added zita_extended/zita_tripledat_values.dsp.









































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import("../rdk.lib") ; 

N = 8;
fsmax = 48000.0;
maxapdelay(i) = 1<<16 ;
maxtdelay(i) = 1<<16 ;
SPEED_OF_SOUND = 343 ; // [m/s]

zitaM = _ <: zita_distrib2(1) : redZita :> _ ;
zitaST = _,_ : zita_distrib2(N) : redZita :> par(i,2,*(WET)) ;

//choose decay law
decaylaw(a) = if(SEL_DECAY==1, g1(a), if(SEL_DECAY==2, g2(a), g0(a))) ;
g0y(delaylength_in_samps) = RT(0) ; //none
g1y(delaylength_in_samps) = pow(pow (0.001, (1.0 / (44100 *RT(1)))),delaylength_in_samps) ; //log decay
g2y(delaylength_in_samps) = RT(2)*10/(delaylength_in_samps*1000./SR*.343+(RT(2)*10)) ; //reflection law (distance) 1/x
g2x(delaylength_in_meter) = RT(2)*direct_m/(delaylength_in_meter+(RT(2)*direct_m)) ; //reflection law

RT(0) 				= hslider("[0]RT0",0, 0,1.2,.001) ;
RT(1) 				= hslider("[0]RT1",2, 0,30,.001) ;
RT(2) 				= hslider("[0]RT2",5, 0,1000,.001) ;
alldelays(i) = 0 : seq(i,N,+(betrag(i))) ;

totaldelay_samps(i) = reflectiondelay_ms(i) *SR/1000. ;
n60 = t60m*SR; // decay time in samples
//mfb(i) = exp(-3.0*log(10.0)*totaldelay_samps(i)/n60);
mfb(i) = g0y(i) 
//g2x(betrag(i))
;//*direct_m/alldelays(N) ; //g2x(betrag(i)) ;

//---
process = //0 : seq(i,N,+(betrag(i)))//g0(0),gM(0),totaldelay_samps(0),reflectiondelay_ms(0),betrag(0),direct_m;//
//filtero(0) ;//
par(i,8,apdelay_ms(i))
//wetwet(zitaST , 2, directpathrev, EFFECTPATHREV) 
; //par(i,8,mfb(i)) ;//filter(1,freqs,durs) ;//
 directpathrev = 1 - (EFFECTPATHREV) ;
 
 		//g0(i) = exp(-3.0*log(10.0)*totaldelay_samps(i)/(t60dc*SR));
		//gM(i) = exp(-3.0*log(10.0)*totaldelay_samps(i)/(t60m*SR));
		//totaldelay_samps(i) = reflectiondelay_ms(i) *SR/1000. ; 
 
//--


zitaLFO(i) = rdk[ sinlfo = rdk.sinusi(rdk.sinusFreqHz, i*.125 ) *(rdk.sinusDepth) ; ].sinlfo +1. ; 

zitaCore  = ((bus(2*N) :> allpass_combs(N) : tdelay(N)  				) ~ (feedbackmatrix(N) : reverbtime(N)    )) ;
//
redZita   = ((bus(2*N) :> allpass_combs(N) : tdelay(N)  				) ~ (feedbackmatrix(N) : reverbtime(N)    )) : reflevel(N) ;
//redZita = ((bus(2*N) :> allpass_combs(N) : tdelay(N)					) ~ (feedbackmatrix(N) : par(i,N,*(dist)) )) : par(i,N,*(reflectio
  reflevel(N) = par(i,N,*(reflectionlevel(i))) ;
  
  //delayfilters(N) = par(i,N,filtero(i)); //
  
  reverbtime(N) = par(i,N,*(mfb(i))) ;

  allpass_combs(N) = par(i,N,(rdk.ap1(maxapdelay(i),apdelay(i),-AP_G(i)))); 
  tdelay(N) = par(i,N,(fdelay(maxtdelay(i),(tdelay_ms(i)*SR/1000.))));    
  feedbackmatrix(N) = hadamard(N) ; // math.lib
  
  apdelay(i) = SR/1000.*(apdelay_ms(i)) *zitaLFO(i) ; 
  tdelay_ms(i) = reflectiondelay_ms(i) - (1-(APDELAY_PERCENT(i))) ; 
  apdelay_ms(i) = reflectiondelay_ms(i) * APDELAY_PERCENT(i) ; 
  
  dist = (MAINFB) *(1.1-(DISTANCE*0.4)); 
  //(reflectiondelay_ms(i)*.343)/ (MAINFB + (reflectiondelay_ms(i)*.343)) ;
  //g(j,i) = exp(-3.0*log(10.0)*tdelay(i)/n60(j));
  //g = exp(-3.0*log(10.0)*tdelay_ms(N)*1000./n60seconds);

  
/*** room model *****************

room <L,B,H> ,(s)ender, (r)eceiver

		   front

	width < B >
	   ^ +------+  ^
	  42 ¦ (s)  ¦ (L)
		 ¦______¦  e 
   left  ¦      ¦  n right
		 ¦  (r) ¦  g
		 ¦      ¦  t
	   0 +------+  h
		 0     19                
		   rear
		   
*********************************/ 
/*
L = 42 ; B = 19 ; H = 16 ;
Ls = 33 ; Bs = 11 ; Hs = 3 ; //sender
Lr = 23 ; Br = 5 ; Hr = 1 ; //receiver
*/

L = 42 *(ROOMSIZE); 
B = 19 *(ROOMSIZE); 
H = 16 *(ROOMSIZE);

Ls = 33  *(ROOMSIZE); 
Bs = 11  *(ROOMSIZE); 
Hs = 3 ; //sender

Lr = (Ls-1)*DISTANCE ; 
Br = (B)*(LR) ;
Hr = 1 ; //receiver 

// source image models
ssq(0) = Ls 	, -Bs 		, Hs ; //left 
ssq(1) = Ls 	, 2*B-Bs 	, Hs ; //right
ssq(2) = Ls 	, -Bs 		, 2*H-Hs ; //left + ceiling
ssq(3) = Ls 	, 2*B-Bs 	, 2*H-Hs ; //right + ceiling
ssq(4) = 2*L-Ls , -Bs 		, Hs ; //left + front
ssq(5) = 2*L-Ls , 2*B-Bs 	, Hs ; //right + front
ssq(6) = -Ls , -Bs 		, 2*H-Hs ; //left + ceiling + rear
ssq(7) = -Ls , 2*B-Bs 	, 2*H-Hs ; //right + ceiling + rear

vector(i) = ssq(i), (-Lr,-Br,-Hr) :> bus(3) ; 

betrag(i) = vector(i) : par(i,3,quadrat) : threesum : sqrt ;
 quadrat(x) = x*x ;
 threesum = +,_ : + ; 

reflectiondelay_ms(i) = ((betrag(i) - direct_m) / SPEED_OF_SOUND) *1000 ;
reflectionlevel(i) = direct_m/(betrag(i)) *(ERCOMPRESSION) + makeup ;
 makeup = 1 - ERCOMPRESSION ;

direct_m = (Ls-Lr), (Bs-Br), (Hs-Hr) : par(i,3,quadrat) : threesum : sqrt ;

// filtersection ---
  staynormal = 10.0^(-20); // let signals decay well below LSB, but not to zero
  
  filtero(i) = lowshelf_lowpass(i)/3. /*sqrt(float(N))*/ +staynormal with {

    lowshelf_lowpass(i) = /*gM(i) */ low_shelf1_l(g0(i)/gM(i), f1) : special_lowpass(gM(i),f2) with {
		
		g0(i) = exp(-3.0*log(10.0)*totaldelay_samps(7)/(t60dc*SR));
		gM(i) = exp(-3.0*log(10.0)*totaldelay_samps(7)/(t60m*SR));
		totaldelay_samps(i) = reflectiondelay_ms(i) *SR/1000. ;  
    
		low_shelf1_l(G0,fx,x) = x + (G0-1)*lowpass(1,fx,x); // filter.lib
		
		special_lowpass(g,f) = smooth(p) with {
		// unity-dc-gain lowpass needs gain g at frequency f => quadratic formula:
		p = mbo2 - sqrt(max(0,mbo2*mbo2 - 1.0)); // other solution is unstable
		mbo2 = (1.0 - gs*c)/(1.0 - gs); // NOTE: must ensure |g|<1 (t60m finite)
		gs = g*g;
		c = cos(2.0*PI*f/float(SR));
		};	
	};
  };

// filtersection end ---



//ap-gain
//ap_gain(i) = (tdelay_ms(i) + (direct_m/343.)/1000.) / ((tdelay_ms(i) + apdelay_ms(i) + (direct_m/343.)/1000.));


//process = reflectiondelay_ms(0),reflectiondelay_ms(1),reflectiondelay_ms(2),reflectiondelay_ms(3),
 //reflectionlevel(0),reflectionlevel(1),reflectionlevel(2),reflectionlevel(3) ;

//--- UI ---
wetwet(fx,n,directpath,effectpath) = bus(n) <: bus(2*n) : (fx : par(i,n,*(effectpath))), par(i,n,*(directpath)) :> bus(n) ;

LR					= hslider("[10]LR",0.5,.1,.9,.01) ;
DISTANCE			= hslider("[11]DISTANCE",0.5,.05,1,.01) ;//: smooth(.999) ;
MAINFB	 			= hslider("[12]RT",0,0,.33,.01) ;
//-1) *100 + 100 ;//distance law //*((1/(DISTANCE*10))*3 +0.6) *(DISTANCE) ;
APDELAY_PERCENT(i) 	= hslider("[13]APDELAY_PERCENT",0.46 ,0,1,.01) ;
AP_G(i) 			= hslider("[15]AP_G",0.63 ,0,.9,.01) ;//1-(APDELAY_PERCENT(i)) ; 
WET					= 2^(hslider("[6]WET(dB)",0,-60,6,.1)/6) *(DISTANCE:max(.4)) *8;
ERCOMPRESSION		= hslider("[17]ER COMPRESSION FACTOR",.66,0,1,.01) ;	
ROOMSIZE			= hslider("[19]ROOMSIZE",1,0.2,20,.01) ;//: smooth(.999) ;
EFFECTPATHREV 		= hslider("[20]dry<->wet",0.5,0,1,.01) ;

//redZitaGUI = redZita(f1,f2,t60dc,t60m,fsmax) //effect.lib
//with {
  //fsmax = 48000.0;
  fdn_group(x) = hgroup(
    "Zita_Rev [tooltip: ~ 8x8 Feedback Delay Network (FDN) & Schroeder allpass-comb reverberator. ]",x);
  t60dc = fdn_group(vslider("[1] Low RT60 [unit:s] [style:knob]
    [style:knob]
    [tooltip: T60 = time (in seconds) to decay 60dB in low-frequency band]",
    8, 1, 8, 0.1));
  f1 = fdn_group(vslider("[2] LF X [unit:Hz] [style:knob]
    [tooltip: Crossover frequency (Hz) separating low and middle frequencies]",
    200, 50, 1000, 1));
  t60m = fdn_group(vslider("[3] Mid RT60 [unit:s] [style:knob]
    [tooltip: T60 = time (in seconds) to decay 60dB in middle band]",
    8, 1, 8, 0.1));
  f2 = fdn_group(vslider("[4] HF Damping [unit:Hz] [style:knob]
    [tooltip: Frequency (Hz) at which the high-frequency T60 is half the middle-band's T60]",
    22000, 1500, 0.49*fsmax, 1));
//};