1 // generated from file '../src/LV2/faust/compressor.dsp' by dsp2cc:
2 // Code generated with Faust (https://faust.grame.fr)
3 
4 
5 namespace compressor {
6 
7 class Dsp: public PluginLV2 {
8 private:
9 	uint32_t fSampleRate;
10 	FAUSTFLOAT fEntry0;
11 	FAUSTFLOAT	*fEntry0_;
12 	FAUSTFLOAT fEntry1;
13 	FAUSTFLOAT	*fEntry1_;
14 	double fConst1;
15 	FAUSTFLOAT fHslider0;
16 	FAUSTFLOAT	*fHslider0_;
17 	double fConst2;
18 	double fConst3;
19 	double fRec1[2];
20 	FAUSTFLOAT fHslider1;
21 	FAUSTFLOAT	*fHslider1_;
22 	double fRec0[2];
23 	FAUSTFLOAT fEntry2;
24 	FAUSTFLOAT	*fEntry2_;
25 
26 	void connect(uint32_t port,void* data);
27 	void clear_state_f();
28 	void init(uint32_t sample_rate);
29 	void compute(int count, FAUSTFLOAT *input0, FAUSTFLOAT *output0);
30 
31 	static void clear_state_f_static(PluginLV2*);
32 	static void init_static(uint32_t sample_rate, PluginLV2*);
33 	static void compute_static(int count, FAUSTFLOAT *input0, FAUSTFLOAT *output0, PluginLV2*);
34 	static void del_instance(PluginLV2 *p);
35 	static void connect_static(uint32_t port,void* data, PluginLV2 *p);
36 public:
37 	Dsp();
38 	~Dsp();
39 };
40 
41 
42 
Dsp()43 Dsp::Dsp()
44 	: PluginLV2() {
45 	version = PLUGINLV2_VERSION;
46 	id = "compressor";
47 	name = N_("Compressor");
48 	mono_audio = compute_static;
49 	stereo_audio = 0;
50 	set_samplerate = init_static;
51 	activate_plugin = 0;
52 	connect_ports = connect_static;
53 	clear_state = clear_state_f_static;
54 	delete_instance = del_instance;
55 }
56 
~Dsp()57 Dsp::~Dsp() {
58 }
59 
clear_state_f()60 inline void Dsp::clear_state_f()
61 {
62 	for (int l0 = 0; (l0 < 2); l0 = (l0 + 1)) fRec1[l0] = 0.0;
63 	for (int l1 = 0; (l1 < 2); l1 = (l1 + 1)) fRec0[l1] = 0.0;
64 }
65 
clear_state_f_static(PluginLV2 * p)66 void Dsp::clear_state_f_static(PluginLV2 *p)
67 {
68 	static_cast<Dsp*>(p)->clear_state_f();
69 }
70 
init(uint32_t sample_rate)71 inline void Dsp::init(uint32_t sample_rate)
72 {
73 	fSampleRate = sample_rate;
74 	double fConst0 = std::min<double>(192000.0, std::max<double>(1.0, double(fSampleRate)));
75 	fConst1 = (1.0 / fConst0);
76 	fConst2 = std::exp((0.0 - (10.0 / fConst0)));
77 	fConst3 = (1.0 - fConst2);
78 	clear_state_f();
79 }
80 
init_static(uint32_t sample_rate,PluginLV2 * p)81 void Dsp::init_static(uint32_t sample_rate, PluginLV2 *p)
82 {
83 	static_cast<Dsp*>(p)->init(sample_rate);
84 }
85 
compute(int count,FAUSTFLOAT * input0,FAUSTFLOAT * output0)86 void always_inline Dsp::compute(int count, FAUSTFLOAT *input0, FAUSTFLOAT *output0)
87 {
88 #define fEntry0 (*fEntry0_)
89 #define fEntry1 (*fEntry1_)
90 #define fHslider0 (*fHslider0_)
91 #define fHslider1 (*fHslider1_)
92 #define fEntry2 (*fEntry2_)
93 	double fSlow0 = (1.0 - double(fEntry0));
94 	double fSlow1 = (0.050000000000000003 * fSlow0);
95 	double fSlow2 = double(fEntry1);
96 	double fSlow3 = std::exp((0.0 - (fConst1 / std::max<double>(fConst1, double(fHslider0)))));
97 	double fSlow4 = std::exp((0.0 - (fConst1 / std::max<double>(fConst1, double(fHslider1)))));
98 	double fSlow5 = double(fEntry2);
99 	double fSlow6 = (1.0 / (fSlow2 + 0.001));
100 	for (int i0 = 0; (i0 < count); i0 = (i0 + 1)) {
101 		double fTemp0 = double(input0[i0]);
102 		fRec1[0] = ((fConst2 * fRec1[1]) + (fConst3 * std::fabs((fTemp0 + 9.9999999999999995e-21))));
103 		double fTemp1 = ((fSlow3 * double((fRec0[1] < fRec1[0]))) + (fSlow4 * double((fRec0[1] >= fRec1[0]))));
104 		fRec0[0] = ((fRec0[1] * fTemp1) + (fRec1[0] * (1.0 - fTemp1)));
105 		double fTemp2 = std::max<double>(0.0, (fSlow2 + ((20.0 * std::log10(std::max<double>(2.2250738585072014e-308, fRec0[0]))) - fSlow5)));
106 		double fTemp3 = std::min<double>(1.0, std::max<double>(0.0, (fSlow6 * fTemp2)));
107 		output0[i0] = FAUSTFLOAT((fTemp0 * std::pow(10.0, (fSlow1 * ((fTemp2 * fTemp3) / (1.0 - (fSlow0 * fTemp3)))))));
108 		fRec1[1] = fRec1[0];
109 		fRec0[1] = fRec0[0];
110 	}
111 #undef fEntry0
112 #undef fEntry1
113 #undef fHslider0
114 #undef fHslider1
115 #undef fEntry2
116 }
117 
compute_static(int count,FAUSTFLOAT * input0,FAUSTFLOAT * output0,PluginLV2 * p)118 void __rt_func Dsp::compute_static(int count, FAUSTFLOAT *input0, FAUSTFLOAT *output0, PluginLV2 *p)
119 {
120 	static_cast<Dsp*>(p)->compute(count, input0, output0);
121 }
122 
123 
connect(uint32_t port,void * data)124 void Dsp::connect(uint32_t port,void* data)
125 {
126 	switch ((PortIndex)port)
127 	{
128 	case ATTACK:
129 		fHslider0_ = (float*)data; // , 0.002, 0.0, 1.0, 0.001
130 		break;
131 	case RELEASE:
132 		fHslider1_ = (float*)data; // , 0.5, 0.0, 10.0, 0.01
133 		break;
134 	case KNEE:
135 		fEntry1_ = (float*)data; // , 3.0, 0.0, 20.0, 0.10000000000000001
136 		break;
137 	case RATIO:
138 		fEntry0_ = (float*)data; // , 2.0, 1.0, 20.0, 0.10000000000000001
139 		break;
140 	case THRESHOLD:
141 		fEntry2_ = (float*)data; // , -20.0, -96.0, 10.0, 0.10000000000000001
142 		break;
143 	default:
144 		break;
145 	}
146 }
147 
connect_static(uint32_t port,void * data,PluginLV2 * p)148 void Dsp::connect_static(uint32_t port,void* data, PluginLV2 *p)
149 {
150 	static_cast<Dsp*>(p)->connect(port, data);
151 }
152 
153 
plugin()154 PluginLV2 *plugin() {
155 	return new Dsp();
156 }
157 
del_instance(PluginLV2 * p)158 void Dsp::del_instance(PluginLV2 *p)
159 {
160 	delete static_cast<Dsp*>(p);
161 }
162 
163 /*
164 typedef enum
165 {
166    ATTACK,
167    KNEE,
168    RATIO,
169    RELEASE,
170    THRESHOLD,
171 } PortIndex;
172 */
173 
174 } // end namespace compressor
175