//----------------------------------------------------------
// name: "table2"
//
// 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:
	class SIG0 {
	  private:
		int fSampleRate;
		// Recursion delay iVeeec2 is of type kMonoDelay
		// While its definition is of type kZeroDelay
		int 	iVeeec2State; // Mono Delay
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			iVeeec2State = 0;
		}
		void fill(int count, int output[]) {
			int 	iVeeec2;
			int fullcount = count;
			for (int index = 0; index < fullcount; index += 32) {
				int count = min(32, fullcount-index);
				iVeeec2 = iVeeec2State;
				for (int i=0; i<count; i++) {
					iVeeec2 = (iVeeec2 + 1);
					output[i] = iVeeec2;
				}
				iVeeec2State = iVeeec2;
				output += 32;
			}
		}
	};


	class SIG1 {
	  private:
		int fSampleRate;
		// Recursion delay fVeeec6 is of type kMonoDelay
		// While its definition is of type kZeroDelay
		float 	fVeeec6State; // Mono Delay
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			fVeeec6State = 0;
		}
		void fill(int count, float output[]) {
			float 	fVeeec6;
			int fullcount = count;
			for (int index = 0; index < fullcount; index += 32) {
				int count = min(32, fullcount-index);
				fVeeec6 = fVeeec6State;
				for (int i=0; i<count; i++) {
					fVeeec6 = (fVeeec6 + 0.1f);
					output[i] = fVeeec6;
				}
				fVeeec6State = fVeeec6;
				output += 32;
			}
		}
	};


	class SIG2 {
	  private:
		int fSampleRate;
		static int 	iWave1[7];
		int 	idxiWave1;
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			idxiWave1 = 0;
		}
		void fill(int count, int output[]) {
			int fullcount = count;
			for (int index = 0; index < fullcount; index += 32) {
				int count = min(32, fullcount-index);
				for (int i=0; i<count; i++) {
					output[i] = iWave1[idxiWave1];
					// post processing
					idxiWave1 = (idxiWave1 + 1) % 7;
				}
				output += 32;
			}
		}
	};


	class SIG3 {
	  private:
		int fSampleRate;
		static float 	fWave3[7];
		int 	idxfWave3;
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			idxfWave3 = 0;
		}
		void fill(int count, float output[]) {
			int fullcount = count;
			for (int index = 0; index < fullcount; index += 32) {
				int count = min(32, fullcount-index);
				for (int i=0; i<count; i++) {
					output[i] = fWave3[idxfWave3];
					// post processing
					idxfWave3 = (idxfWave3 + 1) % 7;
				}
				output += 32;
			}
		}
	};


	// Recursion delay iVeeec0 is of type kMonoDelay
	// While its definition is of type kZeroDelay
	int 	iVeeec0State; // Mono Delay
	int 	itbl0[10];
	// Recursion delay fVeeec4 is of type kMonoDelay
	// While its definition is of type kZeroDelay
	float 	fVeeec4State; // Mono Delay
	float 	ftbl1[7];
	static int 	iWave0[7];
	int 	idxiWave0;
	int 	itbl2[10];
	static float 	fWave2[7];
	int 	idxfWave2;
	float 	ftbl3[7];
	int fSampleRate;

  public:
	virtual void metadata(Meta* m) { 
		m->declare("filename", "table2.dsp");
		m->declare("name", "table2");
	}

	virtual int getNumInputs() { return 0; }
	virtual int getNumOutputs() { return 4; }
	static void classInit(int sample_rate) {
	}
	virtual void instanceConstants(int sample_rate) {
		fSampleRate = sample_rate;
		SIG0 sig0;
		sig0.init(sample_rate);
		sig0.fill(10,itbl0);
		SIG1 sig1;
		sig1.init(sample_rate);
		sig1.fill(7,ftbl1);
		idxiWave0 = 0;
		SIG2 sig2;
		sig2.init(sample_rate);
		sig2.fill(10,itbl2);
		idxfWave2 = 0;
		SIG3 sig3;
		sig3.init(sample_rate);
		sig3.fill(7,ftbl3);
	}
	virtual void instanceResetUserInterface() {
	}
	virtual void instanceClear() {
		iVeeec0State = 0;
		fVeeec4State = 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("table2");
		ui_interface->closeBox();
	}
	virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
		int 	iVeeec0;
		float 	fVeeec4;
		int fullcount = count;
		for (int index = 0; index < fullcount; index += 32) {
			int count = min(32, fullcount-index);
			FAUSTFLOAT* output0 = &output[0][index]; // Zone 3
			FAUSTFLOAT* output1 = &output[1][index]; // Zone 3
			FAUSTFLOAT* output2 = &output[2][index]; // Zone 3
			FAUSTFLOAT* output3 = &output[3][index]; // Zone 3
			iVeeec0 = iVeeec0State;
			fVeeec4 = fVeeec4State;
			for (int i=0; i<count; i++) {
				iVeeec0 = (iVeeec0 + 1);
				int 	iTemp0 = iVeeec0; // step: 7
				itbl0[((iTemp0 + 1) % 10)] = (2 * iTemp0);
				fVeeec4 = (fVeeec4 + 0.1f);
				float 	fTemp1 = fVeeec4; // step: 26
				ftbl1[int(fmodf((fTemp1 + 1.0f),7.0f))] = (1.24f * fTemp1);
				int 	iTemp2 = iWave0[idxiWave0]; // step: 49
				itbl2[((iTemp2 + 1) % 10)] = int((1.24f * float(iTemp2)));
				float 	fTemp3 = fWave2[idxfWave2]; // step: 72
				ftbl3[int(fmodf((fTemp3 + 1.0f),7.0f))] = (1.24f * fTemp3);
				output0[i] = (FAUSTFLOAT)(itbl0[((iTemp0 + 2) % 10)]);  // Zone Exec Code
				output1[i] = (FAUSTFLOAT)(ftbl1[int(fmodf((fTemp1 + 2.0f),7.0f))]);  // Zone Exec Code
				output2[i] = (FAUSTFLOAT)(itbl2[((iTemp2 + 2) % 10)]);  // Zone Exec Code
				output3[i] = (FAUSTFLOAT)(ftbl3[int(fmodf((fTemp3 + 2.0f),7.0f))]);  // Zone Exec Code
				// post processing
				idxfWave2 = (idxfWave2 + 1) % 7;
				idxiWave0 = (idxiWave0 + 1) % 7;
			}
			iVeeec0State = iVeeec0;
			fVeeec4State = fVeeec4;
		}
	}
};


int 	mydsp::iWave0[7] = {1,2,3,7,4,8,1};
int 	mydsp::SIG2::iWave1[7] = {1,2,3,7,4,8,1};
float 	mydsp::fWave2[7] = {1.4f,2.1f,3.8f,7.12f,4.9f,8.9f,1.2f};
float 	mydsp::SIG3::fWave3[7] = {1.4f,2.1f,3.8f,7.12f,4.9f,8.9f,1.2f};
