//----------------------------------------------------------
// name: "waveform4"
//
// 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;
		static int 	iWave0[7];
		int 	idxiWave0;
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			idxiWave0 = 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] = iWave0[idxiWave0];
					// post processing
					idxiWave0 = (idxiWave0 + 1) % 7;
				}
				output += 32;
			}
		}
	};


	class SIG1 {
	  private:
		int fSampleRate;
		static float 	fWave1[7];
		int 	idxfWave1;
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			idxfWave1 = 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] = fWave1[idxfWave1];
					// post processing
					idxfWave1 = (idxfWave1 + 1) % 7;
				}
				output += 32;
			}
		}
	};


	// Recursion delay iVeeec0 is of type kMonoDelay
	// While its definition is of type kZeroDelay
	int 	iVeeec0State; // Mono Delay
	static int 	itbl0[7];
	static float 	ftbl1[7];
	int fSampleRate;

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

	virtual int getNumInputs() { return 0; }
	virtual int getNumOutputs() { return 2; }
	static void classInit(int sample_rate) {
		SIG0 sig0;
		sig0.init(sample_rate);
		sig0.fill(7,itbl0);
		SIG1 sig1;
		sig1.init(sample_rate);
		sig1.fill(7,ftbl1);
	}
	virtual void instanceConstants(int sample_rate) {
		fSampleRate = sample_rate;
	}
	virtual void instanceResetUserInterface() {
	}
	virtual void instanceClear() {
		iVeeec0State = 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("waveform4");
		ui_interface->closeBox();
	}
	virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
		int 	iVeeec0;
		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
			iVeeec0 = iVeeec0State;
			for (int i=0; i<count; i++) {
				iVeeec0 = ((iVeeec0 + 3) % 7);
				int 	iTemp0 = max(0, min(iVeeec0, 6)); // step: 12
				output0[i] = (FAUSTFLOAT)(itbl0[iTemp0]);  // Zone Exec Code
				output1[i] = (FAUSTFLOAT)(ftbl1[iTemp0]);  // Zone Exec Code
			}
			iVeeec0State = iVeeec0;
		}
	}
};


int 	mydsp::SIG0::iWave0[7] = {10,20,30,40,50,60,70};
int 	mydsp::itbl0[7];
float 	mydsp::SIG1::fWave1[7] = {1.1f,2.2f,3.3f,4.4f,5.5f,6.6f,7.7f};
float 	mydsp::ftbl1[7];
