shithub: neindaw

Download patch

ref: d83563a5ff7b654ce35011bcea875c1e681537bb
parent: 49765cee0852763c1703d04ea5a867ea7f880bf2
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Jan 12 13:57:19 EST 2020

kick drum: rename/rearrange controls and remove the gate button

--- a/kick_drum.c
+++ b/kick_drum.c
@@ -123,26 +123,23 @@
 
 typedef struct {
 	
+	int iVec0[2];
 	int fSamplingFreq;
 	float fConst0;
 	float fConst1;
-	FAUSTFLOAT fVslider0;
-	FAUSTFLOAT fVslider1;
+	FAUSTFLOAT fHslider0;
+	FAUSTFLOAT fHslider1;
 	FAUSTFLOAT fCheckbox0;
-	FAUSTFLOAT fButton0;
-	float fVec0[2];
-	FAUSTFLOAT fVslider2;
-	FAUSTFLOAT fVslider3;
+	FAUSTFLOAT fHslider2;
+	FAUSTFLOAT fHslider3;
 	float fVec1[2];
 	float fRec2[2];
 	float fConst2;
 	float fRec1[2];
-	FAUSTFLOAT fVslider4;
-	float fRec3[2];
-	FAUSTFLOAT fVslider5;
-	FAUSTFLOAT fVslider6;
+	FAUSTFLOAT fHslider4;
+	FAUSTFLOAT fHslider5;
+	FAUSTFLOAT fHslider6;
 	float fRec5[2];
-	float fRec4[2];
 	
 } KickDrum;
 
@@ -165,7 +162,7 @@
 	m->declare(m->metaInterface, "envelopes.lib/name", "Faust Envelope Library");
 	m->declare(m->metaInterface, "envelopes.lib/version", "0.0");
 	m->declare(m->metaInterface, "filename", "kick_drum");
-	m->declare(m->metaInterface, "group", "synthesis");
+	m->declare(m->metaInterface, "group", "Synthesis");
 	m->declare(m->metaInterface, "maths.lib/author", "GRAME");
 	m->declare(m->metaInterface, "maths.lib/copyright", "GRAME");
 	m->declare(m->metaInterface, "maths.lib/license", "LGPL with exception");
@@ -235,15 +232,14 @@
 
 void instanceResetUserInterfaceKickDrum(KickDrum* dsp) {
 	USED(dsp);
-	dsp->fVslider0 = (FAUSTFLOAT)100.0f;
-	dsp->fVslider1 = (FAUSTFLOAT)200.0f;
+	dsp->fHslider0 = (FAUSTFLOAT)100.0f;
+	dsp->fHslider1 = (FAUSTFLOAT)200.0f;
 	dsp->fCheckbox0 = (FAUSTFLOAT)0.0f;
-	dsp->fButton0 = (FAUSTFLOAT)0.0f;
-	dsp->fVslider2 = (FAUSTFLOAT)0.001f;
-	dsp->fVslider3 = (FAUSTFLOAT)0.001f;
-	dsp->fVslider4 = (FAUSTFLOAT)0.001f;
-	dsp->fVslider5 = (FAUSTFLOAT)0.001f;
-	dsp->fVslider6 = (FAUSTFLOAT)0.01f;
+	dsp->fHslider2 = (FAUSTFLOAT)0.001f;
+	dsp->fHslider3 = (FAUSTFLOAT)0.001f;
+	dsp->fHslider4 = (FAUSTFLOAT)0.001f;
+	dsp->fHslider5 = (FAUSTFLOAT)0.001f;
+	dsp->fHslider6 = (FAUSTFLOAT)0.01f;
 	
 }
 
@@ -253,7 +249,7 @@
 	{
 		int l1;
 		for (l1 = 0; (l1 < 2); l1 = (l1 + 1)) {
-			dsp->fVec0[l1] = 0.0f;
+			dsp->iVec0[l1] = 0;
 			
 		}
 		
@@ -289,29 +285,11 @@
 	{
 		int l5;
 		for (l5 = 0; (l5 < 2); l5 = (l5 + 1)) {
-			dsp->fRec3[l5] = 0.0f;
+			dsp->fRec5[l5] = 0.0f;
 			
 		}
 		
 	}
-	/* C99 loop */
-	{
-		int l6;
-		for (l6 = 0; (l6 < 2); l6 = (l6 + 1)) {
-			dsp->fRec5[l6] = 0.0f;
-			
-		}
-		
-	}
-	/* C99 loop */
-	{
-		int l7;
-		for (l7 = 0; (l7 < 2); l7 = (l7 + 1)) {
-			dsp->fRec4[l7] = 0.0f;
-			
-		}
-		
-	}
 	
 }
 
@@ -343,37 +321,33 @@
 void buildUserInterfaceKickDrum(KickDrum* dsp, UIGlue* ui_interface) {
 	USED(dsp);
 	ui_interface->openVerticalBox(ui_interface->uiInterface, "Kick Drum");
-	ui_interface->openHorizontalBox(ui_interface->uiInterface, "a");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider0, "0", "");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider0, "unit", "Hz");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "frequency", &dsp->fVslider0, 100.0f, 10.0f, 400.0f, 5.0f);
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider5, "1", "");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider5, "unit", "s");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "attack", &dsp->fVslider5, 0.00100000005f, 9.99999975e-06f, 0.200000003f, 0.00100000005f);
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider6, "2", "");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider6, "unit", "s");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "delay", &dsp->fVslider6, 0.00999999978f, 9.99999975e-06f, 1.0f, 0.00100000005f);
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider4, "3", "");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider4, "unit", "s");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "release", &dsp->fVslider4, 0.00100000005f, 9.99999975e-06f, 1.0f, 0.00100000005f);
+	ui_interface->openVerticalBox(ui_interface->uiInterface, "A");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider0, "0", "");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider0, "unit", "Hz");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Frequency", &dsp->fHslider0, 100.0f, 10.0f, 400.0f, 5.0f);
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider5, "1", "");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider5, "unit", "s");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Attack", &dsp->fHslider5, 0.00100000005f, 9.99999975e-06f, 0.200000003f, 0.00100000005f);
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider6, "2", "");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider6, "unit", "s");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Delay", &dsp->fHslider6, 0.00999999978f, 9.99999975e-06f, 1.0f, 0.00100000005f);
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider4, "3", "");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider4, "unit", "s");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Release", &dsp->fHslider4, 0.00100000005f, 9.99999975e-06f, 1.0f, 0.00100000005f);
 	ui_interface->closeBox(ui_interface->uiInterface);
-	ui_interface->openHorizontalBox(ui_interface->uiInterface, "b");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider2, "0", "");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider2, "unit", "s");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "attack", &dsp->fVslider2, 0.00100000005f, 9.99999975e-06f, 0.200000003f, 0.00100000005f);
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider1, "1", "");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "frequency", &dsp->fVslider1, 200.0f, -400.0f, 400.0f, 5.0f);
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider3, "2", "");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fVslider3, "unit", "s");
-	ui_interface->addVerticalSlider(ui_interface->uiInterface, "release", &dsp->fVslider3, 0.00100000005f, 9.99999975e-06f, 1.0f, 0.00100000005f);
+	ui_interface->openVerticalBox(ui_interface->uiInterface, "B");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider1, "0", "");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Frequency", &dsp->fHslider1, 200.0f, -400.0f, 400.0f, 5.0f);
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider2, "1", "");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider2, "unit", "s");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Attack", &dsp->fHslider2, 0.00100000005f, 9.99999975e-06f, 0.200000003f, 0.00100000005f);
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider3, "2", "");
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider3, "unit", "s");
+	ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Release", &dsp->fHslider3, 0.00100000005f, 9.99999975e-06f, 1.0f, 0.00100000005f);
+	ui_interface->declare(ui_interface->uiInterface, &dsp->fCheckbox0, "3", "");
+	ui_interface->addCheckButton(ui_interface->uiInterface, "Enable", &dsp->fCheckbox0);
 	ui_interface->closeBox(ui_interface->uiInterface);
-	ui_interface->openHorizontalBox(ui_interface->uiInterface, "control");
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fButton0, "0", "");
-	ui_interface->addButton(ui_interface->uiInterface, "gate", &dsp->fButton0);
-	ui_interface->declare(ui_interface->uiInterface, &dsp->fCheckbox0, "1", "");
-	ui_interface->addCheckButton(ui_interface->uiInterface, "b enable", &dsp->fCheckbox0);
 	ui_interface->closeBox(ui_interface->uiInterface);
-	ui_interface->closeBox(ui_interface->uiInterface);
 	
 }
 
@@ -382,50 +356,43 @@
 	USED(dsp);
 	FAUSTFLOAT* input0 = inputs[0];
 	FAUSTFLOAT* output0 = outputs[0];
-	float fSlow0 = (float)dsp->fVslider0;
-	float fSlow1 = ((float)dsp->fVslider1 * (float)dsp->fCheckbox0);
-	float fSlow2 = (float)dsp->fButton0;
-	float fSlow3 = (float)dsp->fVslider2;
-	float fSlow4 = (fSlow3 + (float)dsp->fVslider3);
-	float fSlow5 = (dsp->fConst0 * fSlow4);
-	float fSlow6 = (dsp->fConst0 * fSlow3);
-	float fSlow7 = (1.0f / (0.0f - (dsp->fConst0 * (fSlow3 - fSlow4))));
-	float fSlow8 = (dsp->fConst2 / fSlow3);
-	int iSlow9 = (fSlow2 > 0.0f);
-	int iSlow10 = (iSlow9 > 0);
-	float fSlow11 = (float)dsp->fVslider4;
+	float fSlow0 = (float)dsp->fHslider0;
+	float fSlow1 = ((float)dsp->fHslider1 * (float)dsp->fCheckbox0);
+	float fSlow2 = (float)dsp->fHslider2;
+	float fSlow3 = (fSlow2 + (float)dsp->fHslider3);
+	float fSlow4 = (dsp->fConst0 * fSlow3);
+	float fSlow5 = (dsp->fConst0 * fSlow2);
+	float fSlow6 = (1.0f / (0.0f - (dsp->fConst0 * (fSlow2 - fSlow3))));
+	float fSlow7 = (dsp->fConst2 / fSlow2);
+	float fSlow8 = (float)dsp->fHslider4;
+	float fSlow9 = (dsp->fConst0 * fSlow8);
+	float fSlow10 = (float)dsp->fHslider5;
+	float fSlow11 = (fSlow10 + (float)dsp->fHslider6);
 	float fSlow12 = (dsp->fConst0 * fSlow11);
-	int iSlow13 = ((fSlow2 == 0.0f) > 0);
-	float fSlow14 = (float)dsp->fVslider5;
-	float fSlow15 = (fSlow14 + (float)dsp->fVslider6);
-	float fSlow16 = (dsp->fConst0 * fSlow15);
-	float fSlow17 = (dsp->fConst0 * fSlow14);
-	float fSlow18 = (9.99999997e-07f * fSlow2);
-	float fSlow19 = ((fSlow18 + -1.0f) / (0.0f - (dsp->fConst0 * (fSlow14 - fSlow15))));
-	float fSlow20 = (dsp->fConst2 / fSlow14);
-	float fSlow21 = (dsp->fConst2 / fSlow11);
+	float fSlow13 = (dsp->fConst0 * fSlow10);
+	float fSlow14 = (1.0f / (0.0f - (dsp->fConst0 * (fSlow10 - fSlow11))));
+	float fSlow15 = (dsp->fConst2 / fSlow10);
+	float fSlow16 = (dsp->fConst2 / fSlow8);
 	/* C99 loop */
 	{
 		int i;
 		for (i = 0; (i < count); i = (i + 1)) {
-			dsp->fVec0[0] = fSlow2;
-			dsp->fVec1[0] = fSlow4;
-			dsp->fRec2[0] = ((((fSlow2 - dsp->fVec0[1]) > 0.0f) > 0)?0.0f:min(fSlow5, ((dsp->fRec2[1] + (dsp->fConst0 * (fSlow4 - dsp->fVec1[1]))) + 1.0f)));
-			int iTemp0 = (dsp->fRec2[0] < fSlow6);
-			float fTemp1 = ((dsp->fRec1[1] * (float)(1 - ((float)input0[i] > 0.0f))) + (dsp->fConst1 * (fSlow0 + (fSlow1 * (iTemp0?((dsp->fRec2[0] < 0.0f)?0.0f:(iTemp0?(fSlow8 * dsp->fRec2[0]):1.0f)):((dsp->fRec2[0] < fSlow5)?((fSlow7 * (0.0f - (dsp->fRec2[0] - fSlow6))) + 1.0f):0.0f))))));
+			dsp->iVec0[0] = 1;
+			dsp->fVec1[0] = fSlow3;
+			dsp->fRec2[0] = ((((1 - dsp->iVec0[1]) > 0) > 0)?0.0f:min(fSlow4, ((dsp->fRec2[1] + (dsp->fConst0 * (fSlow3 - dsp->fVec1[1]))) + 1.0f)));
+			int iTemp0 = (dsp->fRec2[0] < fSlow5);
+			float fTemp1 = ((dsp->fRec1[1] * (float)(1 - ((float)input0[i] > 0.0f))) + (dsp->fConst1 * (fSlow0 + (fSlow1 * (iTemp0?((dsp->fRec2[0] < 0.0f)?0.0f:(iTemp0?(fSlow7 * dsp->fRec2[0]):1.0f)):((dsp->fRec2[0] < fSlow4)?((fSlow6 * (0.0f - (dsp->fRec2[0] - fSlow5))) + 1.0f):0.0f))))));
 			dsp->fRec1[0] = (fTemp1 - floorf(fTemp1));
-			dsp->fRec3[0] = (iSlow10?0.0f:min(fSlow12, (dsp->fRec3[1] + 1.0f)));
-			dsp->fRec5[0] = (iSlow13?0.0f:min(fSlow16, (dsp->fRec5[1] + 1.0f)));
-			int iTemp2 = (dsp->fRec5[0] < fSlow17);
-			dsp->fRec4[0] = (iSlow9?((float)iSlow9 * (iTemp2?((dsp->fRec5[0] < 0.0f)?0.0f:(iTemp2?(fSlow20 * dsp->fRec5[0]):1.0f)):((dsp->fRec5[0] < fSlow16)?((fSlow19 * (dsp->fRec5[0] - fSlow17)) + 1.0f):fSlow18))):dsp->fRec4[1]);
-			output0[i] = (FAUSTFLOAT)(ftbl0KickDrumSIG0[(int)(65536.0f * dsp->fRec1[0])] * ((dsp->fRec3[0] < 0.0f)?dsp->fRec4[0]:((dsp->fRec3[0] < fSlow12)?(dsp->fRec4[0] + (fSlow21 * (dsp->fRec3[0] * (0.0f - dsp->fRec4[0])))):0.0f)));
-			dsp->fVec0[1] = dsp->fVec0[0];
+			int iRec3 = 0;
+			dsp->fRec5[0] = min(fSlow12, (dsp->fRec5[1] + 1.0f));
+			int iTemp2 = (dsp->fRec5[0] < fSlow13);
+			float fRec4 = (iTemp2?((dsp->fRec5[0] < 0.0f)?0.0f:(iTemp2?(fSlow15 * dsp->fRec5[0]):1.0f)):((dsp->fRec5[0] < fSlow12)?((fSlow14 * (0.0f - (0.999998987f * (dsp->fRec5[0] - fSlow13)))) + 1.0f):9.99999997e-07f));
+			output0[i] = (FAUSTFLOAT)(ftbl0KickDrumSIG0[(int)(65536.0f * dsp->fRec1[0])] * ((iRec3 < 0)?fRec4:(((float)iRec3 < fSlow9)?(fRec4 + (fSlow16 * ((float)iRec3 * (0.0f - fRec4)))):0.0f)));
+			dsp->iVec0[1] = dsp->iVec0[0];
 			dsp->fVec1[1] = dsp->fVec1[0];
 			dsp->fRec2[1] = dsp->fRec2[0];
 			dsp->fRec1[1] = dsp->fRec1[0];
-			dsp->fRec3[1] = dsp->fRec3[0];
 			dsp->fRec5[1] = dsp->fRec5[0];
-			dsp->fRec4[1] = dsp->fRec4[0];
 			
 		}
 		
--- a/kick_drum.dsp
+++ b/kick_drum.dsp
@@ -1,15 +1,14 @@
 // Simple kick drum
 declare name "Kick Drum";
-declare group "synthesis";
+declare group "Synthesis";
 import("stdfaust.lib");
 
-aFreq = vslider("h:a/[0]frequency[unit:Hz]", 100, 10, 400, 5);
-aA = vslider("h:a/[1]attack[unit:s]", 0.001, 0.00001, 0.2, 0.001);
-aD = vslider("h:a/[2]delay[unit:s]", 0.01, 0.00001, 1.0, 0.001);
-aR = vslider("h:a/[3]release[unit:s]", 0.001, 0.00001, 1.0, 0.001);
-bA = vslider("h:b/[0]attack[unit:s]", 0.001, 0.00001, 0.2, 0.001);
-bFreq = checkbox("h:control/[1]b enable") * vslider("h:b/[1]frequency", 200, -400, 400, 5);
-bR = vslider("h:b/[2]release[unit:s]", 0.001, 0.00001, 1, 0.001);
-gate = button("h:control/[0]gate");
+aFreq = hslider("v:A/[0]Frequency[unit:Hz]", 100, 10, 400, 5);
+aA = hslider("v:A/[1]Attack[unit:s]", 0.001, 0.00001, 0.2, 0.001);
+aD = hslider("v:A/[2]Delay[unit:s]", 0.01, 0.00001, 1.0, 0.001);
+aR = hslider("v:A/[3]Release[unit:s]", 0.001, 0.00001, 1.0, 0.001);
+bA = hslider("v:B/[1]Attack[unit:s]", 0.001, 0.00001, 0.2, 0.001);
+bR = hslider("v:B/[2]Release[unit:s]", 0.001, 0.00001, 1, 0.001);
+bFreq = checkbox("v:B/[3]Enable") * hslider("v:B/[0]Frequency", 200, -400, 400, 5);
 
-process = os.hs_oscsin(aFreq + bFreq*en.ar(bA, bR, gate)) * en.adsr(aA, aD, 0.000001, aR, gate);
+process = os.hs_oscsin(aFreq + bFreq*en.ar(bA, bR, 1)) * en.adsr(aA, aD, 0.000001, aR, 1.0);