//----------------------------------------------------------
// name: "osc_enable"
//
// 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, float 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] = sinf((9.58738e-05f * float((iVeeec2 + -1))));
				}
				iVeeec2State = iVeeec2;
				output += 32;
			}
		}
	};


	static float 	fWave0[13];
	int 	idxfWave0;
	float 	fTempPerm0;
	float 	fConst0; // step: 20
	float 	fTempPerm1;
	// Recursion delay fVeeec0 is of type kSingleDelay
	// While its definition is of type kZeroDelay
	float 	fVeeec0State; // Single Delay
	static float 	ftbl0[65536];
	float 	fTempPerm2;
	float 	fTempPerm3;
	int fSampleRate;

  public:
	virtual void metadata(Meta* m) { 
		m->declare("filename", "osc_enable.dsp");
		m->declare("math.lib/author", "GRAME");
		m->declare("math.lib/copyright", "GRAME");
		m->declare("math.lib/deprecated", "This library is deprecated and is not maintained anymore. It will be removed in August 2017.");
		m->declare("math.lib/license", "LGPL with exception");
		m->declare("math.lib/name", "Math Library");
		m->declare("math.lib/version", "1.0");
		m->declare("music.lib/author", "GRAME");
		m->declare("music.lib/copyright", "GRAME");
		m->declare("music.lib/license", "LGPL with exception");
		m->declare("music.lib/name", "Music Library");
		m->declare("music.lib/version", "1.0");
		m->declare("name", "osc_enable");
	}

	virtual int getNumInputs() { return 0; }
	virtual int getNumOutputs() { return 5; }
	static void classInit(int sample_rate) {
		SIG0 sig0;
		sig0.init(sample_rate);
		sig0.fill(65536,ftbl0);
	}
	virtual void instanceConstants(int sample_rate) {
		fSampleRate = sample_rate;
		idxfWave0 = 0;
		fTempPerm0 = 0;
		fConst0 = (4e+02f / min(1.92e+05f, max(1.0f, float(fSampleRate)))); // step: 20
		fTempPerm1 = 0;
		fTempPerm2 = 0;
		fTempPerm3 = 0;
	}
	virtual void instanceResetUserInterface() {
	}
	virtual void instanceClear() {
		fVeeec0State = 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("osc_enable");
		ui_interface->closeBox();
	}
	virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
		float 	fTemp2 = fTempPerm0;
		float 	fTemp3 = fTempPerm1;
		float 	fVeeec0[2];
		float 	fTemp4 = fTempPerm2;
		float 	fTemp5 = fTempPerm3;
		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
			FAUSTFLOAT* output4 = &output[4][index]; // Zone 3
			fVeeec0[1] = fVeeec0State;
			for (int i=0; i<count; i++) {
				float 	fTemp0 = fWave0[idxfWave0]; // step: 6
				int 	iTemp1 = (fTemp0 != 0.0f); // step: 7
				if (iTemp1) {
					fTemp2 = powf(fTemp0,2.0f);
					fTemp3 = fVeeec0[1];
					fVeeec0[0] = (fConst0 + (fTemp3 - floorf((fConst0 + fTemp3))));
					fTemp4 = ftbl0[max(0, min(int((65536.0f * fVeeec0[0])), 65535))];
					fTemp5 = (fTemp0 * fTemp4);
				}
				output0[i] = (FAUSTFLOAT)(fTemp0);  // Zone Exec Code
				output1[i] = (FAUSTFLOAT)(fTemp4);  // Zone Exec Code
				output2[i] = (FAUSTFLOAT)(fTemp5);  // Zone Exec Code
				output3[i] = (FAUSTFLOAT)(fTemp0);  // Zone Exec Code
				output4[i] = (FAUSTFLOAT)(fTemp2);  // Zone Exec Code
				// post processing
				fVeeec0[1] = fVeeec0[0];
				idxfWave0 = (idxfWave0 + 1) % 13;
			}
			fVeeec0State = fVeeec0[1];
		}
		fTempPerm0 = fTemp2;
		fTempPerm1 = fTemp3;
		fTempPerm2 = fTemp4;
		fTempPerm3 = fTemp5;
	}
};


float 	mydsp::fWave0[13] = {1.0f,0.5f,0.0f,0.0f,0.0f,0.0f,-0.5f,-1.0f,-0.5f,0.0f,0.0f,0.0f,0.0f};
float 	mydsp::ftbl0[65536];
