//----------------------------------------------------------
// name: "table"
//
// 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 iVeeec4 is of type kMonoDelay
		// While its definition is of type kZeroDelay
		int 	iVeeec4State; // Mono Delay
		// Recursion delay fVeeec2 is of type kCopyDelay
		// While its definition is of type kZeroDelay
		float 	fVeeec2State[3]; // Copy Delay
	  public:
		int getNumInputs() { return 0; }
		int getNumOutputs() { return 1; }
		void init(int sample_rate) {
			fSampleRate = sample_rate;
			iVeeec4State = 0;
			for (int j = 0; j < 3; j++) { fVeeec2State[j] = 0; }
		}
		void fill(int count, float output[]) {
			int 	iVeeec4;
			float 	fVeeec2[4];
			int fullcount = count;
			for (int index = 0; index < fullcount; index += 32) {
				int count = min(32, fullcount-index);
				iVeeec4 = iVeeec4State;
				fVeeec2[1] = fVeeec2State[0];
				fVeeec2[2] = fVeeec2State[1];
				fVeeec2[3] = fVeeec2State[2];
				for (int i=0; i<count; i++) {
					float 	fTemp1 = fVeeec2[2]; // step: 29
					float 	fTemp2 = fVeeec2[3]; // step: 32
					iVeeec4 = ((1103515245 * iVeeec4) + 12345);
					float 	fTemp3 = fVeeec2[1]; // step: 46
					fVeeec2[0] = (((0.5221894f * fTemp2) + ((4.656613e-10f * float(iVeeec4)) + (2.494956f * fTemp3))) - (2.0172658f * fTemp1));
					output[i] = (((0.049922034f * fVeeec2[0]) + (0.0506127f * fTemp1)) - ((0.095993534f * fTemp3) + (0.004408786f * fTemp2)));
					// post processing
					fVeeec2[3] = fVeeec2[2];
					fVeeec2[2] = fVeeec2[1];
					fVeeec2[1] = fVeeec2[0];
				}
				iVeeec4State = iVeeec4;
				fVeeec2State[0] = fVeeec2[1];
				fVeeec2State[1] = fVeeec2[2];
				fVeeec2State[2] = fVeeec2[3];
				output += 32;
			}
		}
	};


	FAUSTFLOAT 	fslider0;
	float 	fConst0; // step: 10
	// Recursion delay fVeeec0 is of type kSingleDelay
	// While its definition is of type kZeroDelay
	float 	fVeeec0State; // Single Delay
	static float 	ftbl0[65536];
	int fSampleRate;

  public:
	virtual void metadata(Meta* m) { 
		m->declare("compilation_options", "-single -scal -e table.dsp -o table.dsp");
		m->declare("filename", "table.dsp");
		m->declare("filters_lib_fir_author", "Julius O. Smith III");
		m->declare("filters_lib_fir_copyright", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
		m->declare("filters_lib_fir_license", "MIT-style STK-4.3 license");
		m->declare("filters_lib_iir_author", "Julius O. Smith III");
		m->declare("filters_lib_iir_copyright", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
		m->declare("filters_lib_iir_license", "MIT-style STK-4.3 license");
		m->declare("filters_lib_lowpass0_highpass1", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
		m->declare("filters_lib_name", "Faust Filters Library");
		m->declare("filters_lib_version", "0.3");
		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", "table");
		m->declare("noises_lib_name", "Faust Noise Generator Library");
		m->declare("noises_lib_version", "0.0");
		m->declare("oscillators_lib_name", "Faust Oscillator Library");
		m->declare("oscillators_lib_version", "0.1");
		m->declare("platform_lib_name", "Generic Platform Library");
		m->declare("platform_lib_version", "0.1");
	}

	virtual int getNumInputs() { return 0; }
	virtual int getNumOutputs() { return 2; }
	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;
		fConst0 = (1.0f / min(1.92e+05f, max(1.0f, float(fSampleRate)))); // step: 10
	}
	virtual void instanceResetUserInterface() {
		fslider0 = 4.4e+02f;
	}
	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("table");
		ui_interface->addHorizontalSlider("freq", &fslider0, 4.4e+02f, 5e+01f, 2e+03f, 0.01f);
		ui_interface->closeBox();
	}
	virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
		float 	fSlow0 = (fConst0 * float(fslider0)); // step: 11
		float 	fVeeec0[2];
		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
			fVeeec0[1] = fVeeec0State;
			for (int i=0; i<count; i++) {
				float 	fTemp0 = fVeeec0[1]; // step: 13
				fVeeec0[0] = (fSlow0 + (fTemp0 - floorf((fSlow0 + fTemp0))));
				float 	fTemp4 = ftbl0[max(0, min(int((65536.0f * fVeeec0[0])), 65535))]; // step: 64
				output0[i] = (FAUSTFLOAT)(fTemp4);  // Zone Exec Code
				output1[i] = (FAUSTFLOAT)(fTemp4);  // Zone Exec Code
				// post processing
				fVeeec0[1] = fVeeec0[0];
			}
			fVeeec0State = fVeeec0[1];
		}
	}
};


float 	mydsp::ftbl0[65536];
