1declare id "12AU7 feedback"; // in amp tube ba.selector
2declare name "12AU7 feedback";
3declare samplerate "96000";
4
5import("stdfaust.lib");
6import("guitarix.lib");
7
8/****************************************************************
9 ** Tube Preamp Emulation stage 1 - 2
10 *   12AU7 feedback
11 */
12
13val(x) = valve.vt(dist, q(x), x)
14with {
15    dist =  40.1;
16    q(x) = lp1tm1(x) * 1 - lp2tm1(x) * 1.02 - 1.0 : clip(-1,-0.01);
17    lp(a) = *(1 - a) : + ~ *(a);
18    lp1tm1 = abs <: lp(0.9999), _ : max;
19    avgs = lp1tm1 : avg;
20    avg_size = ma.SR/9;
21    avg(x) = x - de.delay1s(avg_size,x) : + ~ _ : /(avg_size);
22    lp2tm1 = avgs : lp(0.999);
23};
24
25tubeax(preamp,gain1) =  hgroup("stage1", stage1) :
26          hgroup("stage2", stage2)
27          with {
28
29    stage1 = tubestage130_10(TB_12AU7_68k,86.0,2700.0,1.257240) : - ~ tubestage130_10(TB_12AU7_250k,132.0,1500.0,0.776162) : *(preamp):
30    fi.lowpass(1,6531.0) : tubestage130_10(TB_12AU7_250k,132.0,1500.0,0.776162): + ~ tubestage130_10(TB_12AU7_250k,194.0,820.0,0.445487) ;
31    stage2 = fi.lowpass(1,6531.0) : tubestage130_10(TB_12AU7_250k,194.0,820.0,0.445487) : *(gain1);
32
33} ;
34
35process = val : component("gxdistortion.dsp").dist1(drive,wet_dry) : tubeax(preamp,gain1) with {
36    drive = ampctrl.drive;
37    wet_dry = ampctrl.wet_dry;
38    preamp = ampctrl.preamp;
39    gain1 = ampctrl.gain1;
40/*
41    drive = vslider(".gxdistortion.drive[alias]",0.35, 0, 1, 0.01);
42    wet_dry = vslider(".gxdistortion.wet_dry[alias]",  100, 0, 100, 1) : /(100) : smoothi(0.999);
43    preamp =  vslider(".amp2.stage1.Pregain[alias]",0,-20,20,0.1) : ba.db2linear : smoothi(0.999);
44    gain1 = vslider(".amp2.stage2.gain1[alias]", 6, -20.0, 20.0, 0.1) : ba.db2linear : smoothi(0.999);
45*/
46} ;
47