namespace gx_distortion {
// generated from file '../src/faust/gx_distortion.dsp'

int 	iVec0[2];
FAUSTFLOAT 	fslider0;
double 	fRec0[2];
double 	fConst0;
double 	fConst1;
double 	fConst2;
FAUSTFLOAT 	fentry0;
double 	fConst3;
FAUSTFLOAT 	fentry1;
FAUSTFLOAT 	fentry2;
double 	fConst4;
double 	fConst5;
double 	fConst6;
double 	fConst7;
double 	fConst8;
double 	fConst9;
double 	fConst10;
double 	fConst11;
double 	fConst12;
double 	fRec10[2];
FAUSTFLOAT 	fslider1;
int 	IOTA;
double 	fVec1[4096];
FAUSTFLOAT 	fslider2;
double 	fRec11[2];
FAUSTFLOAT 	fcheckbox0;
double 	fRec9[3];
double 	fVec2[2];
double 	fConst13;
double 	fConst14;
double 	fRec8[2];
double 	fRec7[2];
double 	fRec6[3];
double 	fVec3[2];
double 	fRec5[2];
double 	fRec4[3];
double 	fVec4[2];
double 	fRec3[2];
double 	fRec2[3];
FAUSTFLOAT 	fslider3;
FAUSTFLOAT 	fslider4;
FAUSTFLOAT 	fslider5;
FAUSTFLOAT 	fslider6;
double 	fRec12[2];
double 	fRec14[2];
double 	fRec13[3];
FAUSTFLOAT 	fslider7;
FAUSTFLOAT 	fslider8;
double 	fRec15[2];
double 	fRec18[2];
double 	fRec17[3];
double 	fRec16[3];
FAUSTFLOAT 	fslider9;
FAUSTFLOAT 	fslider10;
double 	fRec19[2];
double 	fRec23[2];
double 	fRec22[3];
double 	fRec21[3];
double 	fRec20[3];
FAUSTFLOAT 	fslider11;
FAUSTFLOAT 	fslider12;
double 	fRec24[2];
double 	fVec5[2];
double 	fConst15;
double 	fRec1[2];
int	fSamplingFreq;

void init(int samplingFreq)
{
	fSamplingFreq = samplingFreq;
	for (int i=0; i<2; i++) iVec0[i] = 0;
	for (int i=0; i<2; i++) fRec0[i] = 0;
	fConst0 = (1.0 / tan((20517.741620594938 / fSamplingFreq)));
	fConst1 = (1 + fConst0);
	fConst2 = (0 - ((1 - fConst0) / fConst1));
	fConst3 = (3.141592653589793 / fSamplingFreq);
	fConst4 = (1.0 / tan((97.38937226128358 / fSamplingFreq)));
	fConst5 = (1 + fConst4);
	fConst6 = (0 - ((1 - fConst4) / fConst5));
	fConst7 = tan((47123.8898038469 / fSamplingFreq));
	fConst8 = (2 * (1 - (1.0 / faustpower<2>(fConst7))));
	fConst9 = (1.0 / fConst7);
	fConst10 = (1 + ((fConst9 - 1.414213562373095) / fConst7));
	fConst11 = (1 + ((1.414213562373095 + fConst9) / fConst7));
	fConst12 = (1.0 / fConst11);
	for (int i=0; i<2; i++) fRec10[i] = 0;
	IOTA = 0;
	for (int i=0; i<4096; i++) fVec1[i] = 0;
	for (int i=0; i<2; i++) fRec11[i] = 0;
	for (int i=0; i<3; i++) fRec9[i] = 0;
	for (int i=0; i<2; i++) fVec2[i] = 0;
	fConst13 = (0 - fConst4);
	fConst14 = (1.0 / (fConst5 * fConst11));
	for (int i=0; i<2; i++) fRec8[i] = 0;
	for (int i=0; i<2; i++) fRec7[i] = 0;
	for (int i=0; i<3; i++) fRec6[i] = 0;
	for (int i=0; i<2; i++) fVec3[i] = 0;
	for (int i=0; i<2; i++) fRec5[i] = 0;
	for (int i=0; i<3; i++) fRec4[i] = 0;
	for (int i=0; i<2; i++) fVec4[i] = 0;
	for (int i=0; i<2; i++) fRec3[i] = 0;
	for (int i=0; i<3; i++) fRec2[i] = 0;
	for (int i=0; i<2; i++) fRec12[i] = 0;
	for (int i=0; i<2; i++) fRec14[i] = 0;
	for (int i=0; i<3; i++) fRec13[i] = 0;
	for (int i=0; i<2; i++) fRec15[i] = 0;
	for (int i=0; i<2; i++) fRec18[i] = 0;
	for (int i=0; i<3; i++) fRec17[i] = 0;
	for (int i=0; i<3; i++) fRec16[i] = 0;
	for (int i=0; i<2; i++) fRec19[i] = 0;
	for (int i=0; i<2; i++) fRec23[i] = 0;
	for (int i=0; i<3; i++) fRec22[i] = 0;
	for (int i=0; i<3; i++) fRec21[i] = 0;
	for (int i=0; i<3; i++) fRec20[i] = 0;
	for (int i=0; i<2; i++) fRec24[i] = 0;
	for (int i=0; i<2; i++) fVec5[i] = 0;
	fConst15 = (1.0 / fConst1);
	for (int i=0; i<2; i++) fRec1[i] = 0;
}

void compute(int count, float *input0, float *output0)
{
	double 	fSlow0 = (0.0010000000000000009 * pow(10,(0.05 * (fslider0 - 10))));
	double 	fSlow1 = tan((fConst3 * fentry0));
	double 	fSlow2 = (1.0 / faustpower<2>(fSlow1));
	double 	fSlow3 = (2 * (1 - fSlow2));
	double 	fSlow4 = (1.0 / fSlow1);
	double 	fSlow5 = (1 + ((fSlow4 - 1.0000000000000004) / fSlow1));
	double 	fSlow6 = (1 + ((fSlow4 + 1.0000000000000004) / fSlow1));
	double 	fSlow7 = (1.0 / fSlow6);
	double 	fSlow8 = (1 + fSlow4);
	double 	fSlow9 = (0 - ((1 - fSlow4) / fSlow8));
	double 	fSlow10 = tan((fConst3 * fentry1));
	double 	fSlow11 = (1.0 / faustpower<2>(fSlow10));
	double 	fSlow12 = (2 * (1 - fSlow11));
	double 	fSlow13 = (1.0 / fSlow10);
	double 	fSlow14 = (1 + ((fSlow13 - 1.0000000000000004) / fSlow10));
	double 	fSlow15 = (1 + ((fSlow13 + 1.0000000000000004) / fSlow10));
	double 	fSlow16 = (1.0 / fSlow15);
	double 	fSlow17 = (1 + fSlow13);
	double 	fSlow18 = (0 - ((1 - fSlow13) / fSlow17));
	double 	fSlow19 = tan((fConst3 * fentry2));
	double 	fSlow20 = (1.0 / faustpower<2>(fSlow19));
	double 	fSlow21 = (2 * (1 - fSlow20));
	double 	fSlow22 = (1.0 / fSlow19);
	double 	fSlow23 = (1 + ((fSlow22 - 1.0000000000000004) / fSlow19));
	double 	fSlow24 = (1 + ((1.0000000000000004 + fSlow22) / fSlow19));
	double 	fSlow25 = (1.0 / fSlow24);
	double 	fSlow26 = (1 + fSlow22);
	double 	fSlow27 = (0 - ((1 - fSlow22) / fSlow26));
	double 	fSlow28 = (1.0 - fslider1);
	double 	fSlow29 = fslider2;
	int 	iSlow30 = int((int((fSlow29 - 1)) & 4095));
	int 	iSlow31 = int((int(fSlow29) & 4095));
	int 	iSlow32 = int(fcheckbox0);
	double 	fSlow33 = (1.0 / fSlow26);
	double 	fSlow34 = (1.0 / fSlow17);
	double 	fSlow35 = (1.0 / (fSlow1 * fSlow15));
	double 	fSlow36 = (0 - fSlow4);
	double 	fSlow37 = (1.0 / fSlow8);
	double 	fSlow38 = (2 * (0 - fSlow2));
	double 	fSlow39 = fslider4;
	double 	fSlow40 = (pow(1e+01,(2 * (fSlow39 * fslider3))) / fSlow6);
	double 	fSlow41 = fslider5;
	double 	fSlow42 = (0.0010000000000000009 * pow(10,(0.05 * (fslider6 - 10))));
	double 	fSlow43 = (pow(1e+01,(2 * (fSlow39 * fslider7))) / fSlow6);
	double 	fSlow44 = (0.0010000000000000009 * pow(10,(0.05 * (fslider8 - 10))));
	double 	fSlow45 = (1 + ((fSlow4 - 1.0) / fSlow1));
	double 	fSlow46 = (1.0 / (1 + ((1.0 + fSlow4) / fSlow1)));
	double 	fSlow47 = (1.0 / (fSlow10 * fSlow24));
	double 	fSlow48 = (0 - fSlow13);
	double 	fSlow49 = (2 * (0 - fSlow11));
	double 	fSlow50 = pow(1e+01,(2 * (fSlow39 * fslider9)));
	double 	fSlow51 = (0.0010000000000000009 * pow(10,(0.05 * (fslider10 - 10))));
	double 	fSlow52 = (1 + ((fSlow13 - 1.0) / fSlow10));
	double 	fSlow53 = (1.0 / (1 + ((1.0 + fSlow13) / fSlow10)));
	double 	fSlow54 = (0 - fSlow22);
	double 	fSlow55 = (2 * (0 - fSlow20));
	double 	fSlow56 = pow(1e+01,(2 * (fSlow39 * fslider11)));
	double 	fSlow57 = (0.0010000000000000009 * pow(10,(0.05 * (fslider12 - 10))));
	for (int i=0; i<count; i++) {
		iVec0[0] = 1;
		fRec0[0] = (fSlow0 + (0.999 * fRec0[1]));
		fRec10[0] = ((1e-20 * (1 - iVec0[1])) - fRec10[1]);
		double fTemp0 = (double)input0[i];
		double fTemp1 = (fTemp0 + (fSlow28 * fRec11[1]));
		fVec1[IOTA&4095] = fTemp1;
		fRec11[0] = (0.5 * (fVec1[(IOTA-iSlow31)&4095] + fVec1[(IOTA-iSlow30)&4095]));
		fRec9[0] = ((((iSlow32)?fRec11[0]:fTemp0) + fRec10[0]) - (fConst12 * ((fConst10 * fRec9[2]) + (fConst8 * fRec9[1]))));
		double fTemp2 = (fRec9[2] + (fRec9[0] + (2 * fRec9[1])));
		fVec2[0] = fTemp2;
		fRec8[0] = ((fConst14 * ((fConst13 * fVec2[1]) + (fConst4 * fVec2[0]))) + (fConst6 * fRec8[1]));
		fRec7[0] = ((fSlow33 * (fRec8[0] + fRec8[1])) + (fSlow27 * fRec7[1]));
		fRec6[0] = (fRec7[0] - (fSlow25 * ((fSlow23 * fRec6[2]) + (fSlow21 * fRec6[1]))));
		double fTemp3 = (fRec6[2] + (fRec6[0] + (2 * fRec6[1])));
		double fTemp4 = (fSlow25 * fTemp3);
		fVec3[0] = fTemp4;
		fRec5[0] = ((fSlow34 * (fVec3[0] + fVec3[1])) + (fSlow18 * fRec5[1]));
		fRec4[0] = (fRec5[0] - (fSlow16 * ((fSlow14 * fRec4[2]) + (fSlow12 * fRec4[1]))));
		double fTemp5 = (fRec4[2] + (fRec4[0] + (2 * fRec4[1])));
		double fTemp6 = (fSlow16 * fTemp5);
		fVec4[0] = fTemp6;
		fRec3[0] = ((fSlow37 * ((fSlow36 * fVec4[1]) + (fSlow35 * fTemp5))) + (fSlow9 * fRec3[1]));
		fRec2[0] = (fRec3[0] - (fSlow7 * ((fSlow5 * fRec2[2]) + (fSlow3 * fRec2[1]))));
		double fTemp7 = max(-1, min(1, (fSlow41 + (fSlow40 * (((fSlow2 * fRec2[0]) + (fSlow38 * fRec2[1])) + (fSlow2 * fRec2[2]))))));
		fRec12[0] = (fSlow42 + (0.999 * fRec12[1]));
		fRec14[0] = ((fSlow37 * (fVec4[0] + fVec4[1])) + (fSlow9 * fRec14[1]));
		fRec13[0] = (fRec14[0] - (fSlow7 * ((fSlow5 * fRec13[2]) + (fSlow3 * fRec13[1]))));
		double fTemp8 = max(-1, min(1, (fSlow41 + (fSlow43 * (fRec13[2] + (fRec13[0] + (2 * fRec13[1])))))));
		fRec15[0] = (fSlow44 + (0.999 * fRec15[1]));
		double fTemp9 = (fSlow3 * fRec16[1]);
		fRec18[0] = ((fSlow34 * ((fSlow48 * fVec3[1]) + (fSlow47 * fTemp3))) + (fSlow18 * fRec18[1]));
		fRec17[0] = (fRec18[0] - (fSlow16 * ((fSlow14 * fRec17[2]) + (fSlow12 * fRec17[1]))));
		fRec16[0] = ((fSlow16 * (((fSlow11 * fRec17[0]) + (fSlow49 * fRec17[1])) + (fSlow11 * fRec17[2]))) - (fSlow46 * ((fSlow45 * fRec16[2]) + fTemp9)));
		double fTemp10 = max(-1, min(1, (fSlow41 + (fSlow50 * (fRec16[2] + (fSlow46 * (fTemp9 + (fSlow45 * fRec16[0]))))))));
		fRec19[0] = (fSlow51 + (0.999 * fRec19[1]));
		double fTemp11 = (fSlow3 * fRec20[1]);
		double fTemp12 = (fSlow12 * fRec21[1]);
		fRec23[0] = ((fSlow33 * ((fSlow54 * fRec8[1]) + (fSlow22 * fRec8[0]))) + (fSlow27 * fRec23[1]));
		fRec22[0] = (fRec23[0] - (fSlow25 * ((fSlow23 * fRec22[2]) + (fSlow21 * fRec22[1]))));
		fRec21[0] = ((fSlow25 * (((fSlow20 * fRec22[0]) + (fSlow55 * fRec22[1])) + (fSlow20 * fRec22[2]))) - (fSlow53 * ((fSlow52 * fRec21[2]) + fTemp12)));
		fRec20[0] = ((fRec21[2] + (fSlow53 * (fTemp12 + (fSlow52 * fRec21[0])))) - (fSlow46 * ((fSlow45 * fRec20[2]) + fTemp11)));
		double fTemp13 = max(-1, min(1, (fSlow41 + (fSlow56 * (fRec20[2] + (fSlow46 * (fTemp11 + (fSlow45 * fRec20[0]))))))));
		fRec24[0] = (fSlow57 + (0.999 * fRec24[1]));
		double fTemp14 = (((fRec24[0] * fTemp13) * (1 - (0.3333333333333333 * faustpower<2>(fTemp13)))) + (((fRec19[0] * fTemp10) * (1 - (0.3333333333333333 * faustpower<2>(fTemp10)))) + (((fRec15[0] * fTemp8) * (1 - (0.3333333333333333 * faustpower<2>(fTemp8)))) + ((fRec12[0] * fTemp7) * (1 - (0.3333333333333333 * faustpower<2>(fTemp7)))))));
		fVec5[0] = fTemp14;
		fRec1[0] = ((fConst15 * (fVec5[0] + fVec5[1])) + (fConst2 * fRec1[1]));
		output0[i] = (FAUSTFLOAT)(fRec1[0] * fRec0[0]);
		// post processing
		fRec1[1] = fRec1[0];
		fVec5[1] = fVec5[0];
		fRec24[1] = fRec24[0];
		fRec20[2] = fRec20[1]; fRec20[1] = fRec20[0];
		fRec21[2] = fRec21[1]; fRec21[1] = fRec21[0];
		fRec22[2] = fRec22[1]; fRec22[1] = fRec22[0];
		fRec23[1] = fRec23[0];
		fRec19[1] = fRec19[0];
		fRec16[2] = fRec16[1]; fRec16[1] = fRec16[0];
		fRec17[2] = fRec17[1]; fRec17[1] = fRec17[0];
		fRec18[1] = fRec18[0];
		fRec15[1] = fRec15[0];
		fRec13[2] = fRec13[1]; fRec13[1] = fRec13[0];
		fRec14[1] = fRec14[0];
		fRec12[1] = fRec12[0];
		fRec2[2] = fRec2[1]; fRec2[1] = fRec2[0];
		fRec3[1] = fRec3[0];
		fVec4[1] = fVec4[0];
		fRec4[2] = fRec4[1]; fRec4[1] = fRec4[0];
		fRec5[1] = fRec5[0];
		fVec3[1] = fVec3[0];
		fRec6[2] = fRec6[1]; fRec6[1] = fRec6[0];
		fRec7[1] = fRec7[0];
		fRec8[1] = fRec8[0];
		fVec2[1] = fVec2[0];
		fRec9[2] = fRec9[1]; fRec9[1] = fRec9[0];
		fRec11[1] = fRec11[0];
		IOTA = IOTA+1;
		fRec10[1] = fRec10[0];
		fRec0[1] = fRec0[0];
		iVec0[1] = iVec0[0];
	}
}

static struct RegisterParams { RegisterParams(); } RegisterParams;
RegisterParams::RegisterParams()
{
	registerVar("gx_distortion.high_gain","","S","",&fslider12, 1e+01, -1e+01, 2e+01, 0.1);
	registerVar("gx_distortion.high_drive","","S","",&fslider11, 1.0, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.middle_h_gain","","S","",&fslider10, 1e+01, -1e+01, 2e+01, 0.1);
	registerVar("gx_distortion.resonator.on_off","resonat","B","",&fcheckbox0, 0.0, 0.0, 1.0, 1.0);
	registerVar("gx_distortion.split_middle_freq","","S","",&fentry1, 6.5e+02, 6e+02, 1.25e+03, 1e+01);
	registerVar("gx_distortion.split_low_freq","","S","",&fentry0, 2.5e+02, 2e+01, 6e+02, 1e+01);
	registerVar("gx_distortion.split_high_freq","","S","",&fentry2, 1.25e+03, 1.25e+03, 1.2e+04, 1e+01);
	registerVar("gx_distortion.low_drive","","S","",&fslider7, 1.0, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.middle_l_gain","","S","",&fslider6, 1e+01, -1e+01, 2e+01, 0.1);
	registerVar("gx_distortion.level","","S","",&fslider5, 0.01, 0.0, 0.5, 0.01);
	registerVar("gx_distortion.drive","","S","",&fslider4, 0.64, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.middle_l_drive","","S","",&fslider3, 1.0, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.vibrato","","S","",&fslider2, 1.0, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.trigger","","S","",&fslider1, 0.12, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.gain","","S","",&fslider0, 2.0, -1e+01, 1e+01, 0.1);
	registerVar("gx_distortion.middle_h_drive","","S","",&fslider9, 1.0, 0.0, 1.0, 0.01);
	registerVar("gx_distortion.low_gain","","S","",&fslider8, 1e+01, -1e+01, 2e+01, 0.1);
	registerInit("gx_distortion", init);
}

} // end namespace gx_distortion
