//----------------------------------------------------------
// name: "constant"
//
// Code generated with Faust 2.81.0 (https://faust.grame.fr)
//----------------------------------------------------------

/* link with  */
#include <math.h>
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif 


#ifndef FAUSTCLASS 
#define FAUSTCLASS mydsp
#endif

class mydsp : public dsp {
  private:
	float 	fConst0; // step: 6
	float 	fConst1; // step: 7
	int 	iConst2; // step: 14
	float 	fVec0State; // Single Delay
	float 	fVec1State[2]; // Copy Delay
	float 	fVec2State[4]; // Copy Delay
	int 	iConst3; // step: 23
	int 	iConst4; // step: 28
	int 	iConst5; // step: 30
	int fSampleRate;

  public:
	virtual void metadata(Meta* m) { 
		m->declare("basics_lib_name", "Faust Basic Element Library");
		m->declare("basics_lib_version", "0.1");
		m->declare("compilation_options", "-single -scal -e t1.dsp -o t1_exp.dsp");
		m->declare("filename", "constant.dsp");
		m->declare("library_path", "/usr/local/share/faust/stdfaust.lib");
		m->declare("maths_lib_author", "GRAME");
		m->declare("maths_lib_copyright", "GRAME");
		m->declare("maths_lib_license", "LGPL with exception");
		m->declare("maths_lib_name", "Faust Math Library");
		m->declare("maths_lib_version", "2.3");
		m->declare("name", "constant");
		m->declare("platform_lib_name", "Generic Platform Library");
		m->declare("platform_lib_version", "0.1");
	}

	virtual int getNumInputs() { return 1; }
	virtual int getNumOutputs() { return 1; }
	static void classInit(int sample_rate) {
	}
	virtual void instanceConstants(int sample_rate) {
		fSampleRate = sample_rate;
		fConst0 = min(1.92e+05f, max(1.0f, float(fSampleRate))); // step: 6
		fConst1 = (1.0f / fConst0); // step: 7
		iConst2 = (int(floorf((0.25f * fConst0))) % 2); // step: 14
		iConst3 = (int(floorf(fConst0)) % 2); // step: 23
		iConst4 = (int(floorf((0.5f * fConst0))) % 2); // step: 28
		iConst5 = (iConst3 + (2 * iConst4)); // step: 30
	}
	virtual void instanceResetUserInterface() {
	}
	virtual void instanceClear() {
		fVec0State = 0;
		for (int j = 0; j < 2; j++) { fVec1State[j] = 0; }
		for (int j = 0; j < 4; j++) { fVec2State[j] = 0; }
	}
	virtual void init(int sample_rate) {
		classInit(sample_rate);
		instanceInit(sample_rate);
	}
	virtual void instanceInit(int sample_rate) {
		instanceConstants(sample_rate);
		instanceResetUserInterface();
		instanceClear();
	}
	virtual mydsp* clone() {
		return new mydsp();
	}
	virtual int getSampleRate() {
		return fSampleRate;
	}
	virtual void buildUserInterface(UI* ui_interface) {
		ui_interface->openVerticalBox("constant");
		ui_interface->closeBox();
	}
	virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
		float 	fVec0[2];
		float 	fVec1[3];
		float 	fVec2[5];
		int fullcount = count;
		for (int index = 0; index < fullcount; index += 32) {
			int count = min(32, fullcount-index);
			FAUSTFLOAT* input0 = &input[0][index]; // Zone 3
			FAUSTFLOAT* output0 = &output[0][index]; // Zone 3
			fVec0[1] = fVec0State;
			fVec1[1] = fVec1State[0];
			fVec1[2] = fVec1State[1];
			fVec2[1] = fVec2State[0];
			fVec2[2] = fVec2State[1];
			fVec2[3] = fVec2State[2];
			fVec2[4] = fVec2State[3];
			for (int i=0; i<count; i++) {
				float 	fTemp0 = (float)input0[i]; // step: 15
				fVec0[0] = fTemp0;
				float 	fTemp1 = (fVec0[0] + fVec0[1]); // step: 18
				fVec1[0] = fTemp1;
				fVec2[0] = (fVec1[0] + fVec1[2]);
				output0[i] = (FAUSTFLOAT)((fConst1 * ((((0) ? fVec0[0] : ((iConst3) ? fVec0[0] : 0.0f)) + ((iConst4) ? fVec1[iConst3] : 0.0f)) + ((iConst2) ? fVec2[iConst5] : 0.0f))));  // Zone Exec Code
				// post processing
				fVec2[4] = fVec2[3];
				fVec2[3] = fVec2[2];
				fVec2[2] = fVec2[1];
				fVec2[1] = fVec2[0];
				fVec1[2] = fVec1[1];
				fVec1[1] = fVec1[0];
				fVec0[1] = fVec0[0];
			}
			fVec0State = fVec0[1];
			fVec1State[0] = fVec1[1];
			fVec1State[1] = fVec1[2];
			fVec2State[0] = fVec2[1];
			fVec2State[1] = fVec2[2];
			fVec2State[2] = fVec2[3];
			fVec2State[3] = fVec2[4];
		}
	}
};


