ref: fd272a818645bf34eb7479ecb2467f81396506a0
parent: d9e5685ee0dad00198fa1792c5666ea782848553
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jan 15 10:13:34 EST 2020
regenerate using faust v2.20.2
--- a/gen.sh
+++ b/gen.sh
@@ -4,10 +4,11 @@
for i in *.dsp; do
class=$(grep -o declare.*name.* $i | head -1 | sed 's/^[^"]*//g;s/[^A-Za-z0-9]//g')
test -z "$class" && echo "$i: name not set in metadata" && exit 1
+ out=$(echo $i | sed 's/dsp$/c/')
+ faust -lang c -a arch.c -cn $class $@ $i -o "$out"
# in C () is not the same as (void) so fix it
- # mark "dsp", "samplingFreq", and "inputs" args as USED
- faust -lang c -a arch.c -cn $class $@ $i -o /dev/stdout \
- | sed 's/new\([^(]*\)() /new\1(void) /' \
- | sed 's/'$class'[A-Z0-9]*\* dsp.*{/&\n\tUSED(dsp);/g' \
- | sed 's/ \(samplingFreq\|inputs\).*{/&\n\tUSED(\1);/g' > `echo $i | sed 's/dsp$/c/'`
+ sed 's/new\([^(]*\)() /new\1(void) /' -i "$out"
+ # mark "dsp", "sample_rate", and "inputs" args as USED
+ sed 's/'$class'[A-Z0-9]*\* dsp.*{/&\n\tUSED(dsp);/g' -i "$out"
+ sed 's/ \(sample_rate\|inputs\).*{/&\n\tUSED(\1);/g' -i "$out"
done
--- a/kick_drum.c
+++ b/kick_drum.c
@@ -1,7 +1,7 @@
/* ------------------------------------------------------------
name: "Kick Drum"
-Code generated with Faust 2.5.23 (https://faust.grame.fr)
-Compilation options: c, -scal -ftz 0
+Code generated with Faust 2.20.2 (https://faust.grame.fr)
+Compilation options: -lang c -scal -ftz 0
------------------------------------------------------------ */
#ifndef __KickDrum_H__
@@ -20,7 +20,6 @@
#define FAUSTFLOAT float
#endif
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -28,14 +27,11 @@
#include <math.h>
#include <stdlib.h>
-
typedef struct {
-
int iRec0[2];
-
} KickDrumSIG0;
-static KickDrumSIG0* newKickDrumSIG0(void) { return (KickDrumSIG0*)malloc(sizeof(KickDrumSIG0)); }
+static KickDrumSIG0* newKickDrumSIG0(void) { return (KickDrumSIG0*)calloc(1, sizeof(KickDrumSIG0)); }
static void deleteKickDrumSIG0(KickDrumSIG0* dsp) {
USED(dsp); free(dsp); }
@@ -42,30 +38,26 @@
int getNumInputsKickDrumSIG0(KickDrumSIG0* dsp) {
USED(dsp);
return 0;
-
}
int getNumOutputsKickDrumSIG0(KickDrumSIG0* dsp) {
USED(dsp);
return 1;
-
}
int getInputRateKickDrumSIG0(KickDrumSIG0* dsp, int channel) {
USED(dsp);
int rate;
- switch (channel) {
+ switch ((channel)) {
default: {
rate = -1;
break;
}
-
}
return rate;
-
}
int getOutputRateKickDrumSIG0(KickDrumSIG0* dsp, int channel) {
USED(dsp);
int rate;
- switch (channel) {
+ switch ((channel)) {
case 0: {
rate = 0;
break;
@@ -74,14 +66,12 @@
rate = -1;
break;
}
-
}
return rate;
-
}
-static void instanceInitKickDrumSIG0(KickDrumSIG0* dsp, int samplingFreq) {
- USED(samplingFreq);
+static void instanceInitKickDrumSIG0(KickDrumSIG0* dsp, int sample_rate) {
+ USED(sample_rate);
USED(dsp);
/* C99 loop */
{
@@ -88,14 +78,11 @@
int l0;
for (l0 = 0; (l0 < 2); l0 = (l0 + 1)) {
dsp->iRec0[l0] = 0;
-
}
-
}
-
}
-static void fillKickDrumSIG0(KickDrumSIG0* dsp, int count, float* output) {
+static void fillKickDrumSIG0(KickDrumSIG0* dsp, int count, float* table) {
USED(dsp);
/* C99 loop */
{
@@ -102,14 +89,11 @@
int i;
for (i = 0; (i < count); i = (i + 1)) {
dsp->iRec0[0] = (dsp->iRec0[1] + 1);
- output[i] = sinf((9.58738019e-05f * (float)(dsp->iRec0[0] + -1)));
+ table[i] = sinf((9.58738019e-05f * (float)(dsp->iRec0[0] + -1)));
dsp->iRec0[1] = dsp->iRec0[0];
-
}
-
}
-
-};
+}
static float ftbl0KickDrumSIG0[65536];
@@ -122,11 +106,10 @@
#endif
typedef struct {
-
FAUSTFLOAT fHslider0;
FAUSTFLOAT fButton0;
float fVec0[2];
- int fSamplingFreq;
+ int fSampleRate;
float fConst0;
float fConst1;
FAUSTFLOAT fHslider1;
@@ -133,22 +116,15 @@
FAUSTFLOAT fHslider2;
FAUSTFLOAT fCheckbox0;
FAUSTFLOAT fHslider3;
+ int iRec2[2];
FAUSTFLOAT fHslider4;
- float fVec1[2];
- float fRec2[2];
- float fConst2;
float fRec1[2];
FAUSTFLOAT fHslider5;
- float fRec3[2];
FAUSTFLOAT fHslider6;
- FAUSTFLOAT fHslider7;
- float fRec5[2];
- float fRec4[2];
-
} KickDrum;
KickDrum* newKickDrum(void) {
- KickDrum* dsp = (KickDrum*)malloc(sizeof(KickDrum));
+ KickDrum* dsp = (KickDrum*)calloc(1, sizeof(KickDrum));
return dsp;
}
@@ -159,13 +135,14 @@
void metadataKickDrum(MetaGlue* m) {
m->declare(m->metaInterface, "basics.lib/name", "Faust Basic Element Library");
- m->declare(m->metaInterface, "basics.lib/version", "0.0");
+ m->declare(m->metaInterface, "basics.lib/version", "0.1");
+ m->declare(m->metaInterface, "envelopes.lib/ar:author", "Yann Orlarey, Stéphane Letz");
m->declare(m->metaInterface, "envelopes.lib/author", "GRAME");
m->declare(m->metaInterface, "envelopes.lib/copyright", "GRAME");
m->declare(m->metaInterface, "envelopes.lib/license", "LGPL with exception");
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, "filename", "kick_drum.dsp");
m->declare(m->metaInterface, "group", "Synthesis");
m->declare(m->metaInterface, "maths.lib/author", "GRAME");
m->declare(m->metaInterface, "maths.lib/copyright", "GRAME");
@@ -178,35 +155,33 @@
}
int getSampleRateKickDrum(KickDrum* dsp) {
- USED(dsp); return dsp->fSamplingFreq; }
+ USED(dsp);
+ return dsp->fSampleRate;
+}
int getNumInputsKickDrum(KickDrum* dsp) {
USED(dsp);
return 0;
-
}
int getNumOutputsKickDrum(KickDrum* dsp) {
USED(dsp);
return 1;
-
}
int getInputRateKickDrum(KickDrum* dsp, int channel) {
USED(dsp);
int rate;
- switch (channel) {
+ switch ((channel)) {
default: {
rate = -1;
break;
}
-
}
return rate;
-
}
int getOutputRateKickDrum(KickDrum* dsp, int channel) {
USED(dsp);
int rate;
- switch (channel) {
+ switch ((channel)) {
case 0: {
rate = 1;
break;
@@ -215,19 +190,16 @@
rate = -1;
break;
}
-
}
return rate;
-
}
-void classInitKickDrum(int samplingFreq) {
- USED(samplingFreq);
+void classInitKickDrum(int sample_rate) {
+ USED(sample_rate);
KickDrumSIG0* sig0 = newKickDrumSIG0();
- instanceInitKickDrumSIG0(sig0, samplingFreq);
+ instanceInitKickDrumSIG0(sig0, sample_rate);
fillKickDrumSIG0(sig0, 65536, ftbl0KickDrumSIG0);
deleteKickDrumSIG0(sig0);
-
}
void instanceResetUserInterfaceKickDrum(KickDrum* dsp) {
@@ -235,14 +207,12 @@
dsp->fHslider0 = (FAUSTFLOAT)1.0f;
dsp->fButton0 = (FAUSTFLOAT)0.0f;
dsp->fHslider1 = (FAUSTFLOAT)100.0f;
- dsp->fHslider2 = (FAUSTFLOAT)200.0f;
+ dsp->fHslider2 = (FAUSTFLOAT)-5.0f;
dsp->fCheckbox0 = (FAUSTFLOAT)0.0f;
dsp->fHslider3 = (FAUSTFLOAT)0.001f;
dsp->fHslider4 = (FAUSTFLOAT)0.001f;
dsp->fHslider5 = (FAUSTFLOAT)0.001f;
dsp->fHslider6 = (FAUSTFLOAT)0.001f;
- dsp->fHslider7 = (FAUSTFLOAT)0.01f;
-
}
void instanceClearKickDrum(KickDrum* dsp) {
@@ -252,90 +222,45 @@
int l1;
for (l1 = 0; (l1 < 2); l1 = (l1 + 1)) {
dsp->fVec0[l1] = 0.0f;
-
}
-
}
/* C99 loop */
{
int l2;
for (l2 = 0; (l2 < 2); l2 = (l2 + 1)) {
- dsp->fVec1[l2] = 0.0f;
-
+ dsp->iRec2[l2] = 0;
}
-
}
/* C99 loop */
{
int l3;
for (l3 = 0; (l3 < 2); l3 = (l3 + 1)) {
- dsp->fRec2[l3] = 0.0f;
-
+ dsp->fRec1[l3] = 0.0f;
}
-
}
- /* C99 loop */
- {
- int l4;
- for (l4 = 0; (l4 < 2); l4 = (l4 + 1)) {
- dsp->fRec1[l4] = 0.0f;
-
- }
-
- }
- /* C99 loop */
- {
- int l5;
- for (l5 = 0; (l5 < 2); l5 = (l5 + 1)) {
- dsp->fRec3[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;
-
- }
-
- }
-
}
-void instanceConstantsKickDrum(KickDrum* dsp, int samplingFreq) {
- USED(samplingFreq);
+void instanceConstantsKickDrum(KickDrum* dsp, int sample_rate) {
+ USED(sample_rate);
USED(dsp);
- dsp->fSamplingFreq = samplingFreq;
- dsp->fConst0 = min(192000.0f, max(1.0f, (float)dsp->fSamplingFreq));
+ dsp->fSampleRate = sample_rate;
+ dsp->fConst0 = min(192000.0f, max(1.0f, (float)dsp->fSampleRate));
dsp->fConst1 = (1.0f / dsp->fConst0);
- dsp->fConst2 = (1.0f / dsp->fConst0);
-
}
-void instanceInitKickDrum(KickDrum* dsp, int samplingFreq) {
- USED(samplingFreq);
+void instanceInitKickDrum(KickDrum* dsp, int sample_rate) {
+ USED(sample_rate);
USED(dsp);
- instanceConstantsKickDrum(dsp, samplingFreq);
+ instanceConstantsKickDrum(dsp, sample_rate);
instanceResetUserInterfaceKickDrum(dsp);
instanceClearKickDrum(dsp);
}
-void initKickDrum(KickDrum* dsp, int samplingFreq) {
- USED(samplingFreq);
+void initKickDrum(KickDrum* dsp, int sample_rate) {
+ USED(sample_rate);
USED(dsp);
- classInitKickDrum(samplingFreq);
- instanceInitKickDrum(dsp, samplingFreq);
+ classInitKickDrum(sample_rate);
+ instanceInitKickDrum(dsp, sample_rate);
}
void buildUserInterfaceKickDrum(KickDrum* dsp, UIGlue* ui_interface) {
@@ -344,21 +269,18 @@
ui_interface->openVerticalBox(ui_interface->uiInterface, "A");
ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider1, "0", "");
ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider1, "unit", "Hz");
- ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Frequency", &dsp->fHslider1, 100.0f, 10.0f, 400.0f, 5.0f);
- ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider6, "1", "");
- ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider6, "unit", "s");
- ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Attack", &dsp->fHslider6, 0.00100000005f, 9.99999975e-06f, 0.200000003f, 0.00100000005f);
- ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider7, "2", "");
- ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider7, "unit", "s");
- ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Delay", &dsp->fHslider7, 0.00999999978f, 9.99999975e-06f, 1.0f, 0.00100000005f);
- ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider5, "3", "");
+ ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Frequency", &dsp->fHslider1, 100.0f, 5.0f, 200.0f, 1.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, "Release", &dsp->fHslider5, 0.00100000005f, 9.99999975e-06f, 1.0f, 0.00100000005f);
+ 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, "3", "");
+ ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider6, "unit", "s");
+ ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Release", &dsp->fHslider6, 0.00100000005f, 9.99999975e-06f, 1.0f, 0.00100000005f);
ui_interface->closeBox(ui_interface->uiInterface);
ui_interface->openVerticalBox(ui_interface->uiInterface, "B");
ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider2, "0", "");
ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider2, "unit", "Hz");
- ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Frequency", &dsp->fHslider2, 200.0f, -400.0f, 400.0f, 5.0f);
+ ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Frequency", &dsp->fHslider2, -5.0f, -5.0f, 200.0f, 5.0f);
ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider3, "1", "");
ui_interface->declare(ui_interface->uiInterface, &dsp->fHslider3, "unit", "s");
ui_interface->addHorizontalSlider(ui_interface->uiInterface, "Attack", &dsp->fHslider3, 0.00100000005f, 9.99999975e-06f, 0.200000003f, 0.00100000005f);
@@ -376,7 +298,6 @@
ui_interface->addButton(ui_interface->uiInterface, "Gate", &dsp->fButton0);
ui_interface->closeBox(ui_interface->uiInterface);
ui_interface->closeBox(ui_interface->uiInterface);
-
}
void computeKickDrum(KickDrum* dsp, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {
@@ -387,59 +308,33 @@
float fSlow1 = (float)dsp->fButton0;
float fSlow2 = (float)dsp->fHslider1;
float fSlow3 = ((float)dsp->fHslider2 * (float)dsp->fCheckbox0);
- float fSlow4 = (float)dsp->fHslider3;
- float fSlow5 = (fSlow4 + (float)dsp->fHslider4);
- float fSlow6 = (dsp->fConst0 * fSlow5);
- float fSlow7 = (dsp->fConst0 * fSlow4);
- float fSlow8 = (1.0f / (0.0f - (dsp->fConst0 * (fSlow4 - fSlow5))));
- float fSlow9 = (dsp->fConst2 / fSlow4);
- int iSlow10 = (fSlow1 > 0.0f);
- int iSlow11 = (iSlow10 > 0);
- float fSlow12 = (float)dsp->fHslider5;
- float fSlow13 = (dsp->fConst0 * fSlow12);
- int iSlow14 = ((fSlow1 == 0.0f) > 0);
- float fSlow15 = (float)dsp->fHslider6;
- float fSlow16 = (fSlow15 + (float)dsp->fHslider7);
- float fSlow17 = (dsp->fConst0 * fSlow16);
- float fSlow18 = (dsp->fConst0 * fSlow15);
- float fSlow19 = (9.99999997e-07f * fSlow1);
- float fSlow20 = ((fSlow19 + -1.0f) / (0.0f - (dsp->fConst0 * (fSlow15 - fSlow16))));
- float fSlow21 = (dsp->fConst2 / fSlow15);
- float fSlow22 = (dsp->fConst2 / fSlow12);
+ float fSlow4 = max(1.0f, (dsp->fConst0 * (float)dsp->fHslider3));
+ float fSlow5 = (1.0f / fSlow4);
+ float fSlow6 = (1.0f / max(1.0f, (dsp->fConst0 * (float)dsp->fHslider4)));
+ float fSlow7 = max(1.0f, (dsp->fConst0 * (float)dsp->fHslider5));
+ float fSlow8 = (1.0f / fSlow7);
+ float fSlow9 = (1.0f / max(1.0f, (dsp->fConst0 * (float)dsp->fHslider6)));
/* C99 loop */
{
int i;
for (i = 0; (i < count); i = (i + 1)) {
dsp->fVec0[0] = fSlow1;
- int iTemp0 = (((fSlow1 - dsp->fVec0[1]) > 0.0f) > 0);
- dsp->fVec1[0] = fSlow5;
- dsp->fRec2[0] = (iTemp0?0.0f:min(fSlow6, ((dsp->fRec2[1] + (dsp->fConst0 * (fSlow5 - dsp->fVec1[1]))) + 1.0f)));
- int iTemp1 = (dsp->fRec2[0] < fSlow7);
- float fTemp2 = ((dsp->fRec1[1] * (float)(1 - iTemp0)) + (dsp->fConst1 * (fSlow2 + (fSlow3 * (iTemp1?((dsp->fRec2[0] < 0.0f)?0.0f:(iTemp1?(fSlow9 * dsp->fRec2[0]):1.0f)):((dsp->fRec2[0] < fSlow6)?((fSlow8 * (0.0f - (dsp->fRec2[0] - fSlow7))) + 1.0f):0.0f))))));
+ int iTemp0 = (fSlow1 > dsp->fVec0[1]);
+ dsp->iRec2[0] = (iTemp0 + ((fSlow1 <= dsp->fVec0[1]) * (dsp->iRec2[1] + (dsp->iRec2[1] > 0))));
+ float fTemp1 = (float)dsp->iRec2[0];
+ float fTemp2 = ((dsp->fRec1[1] * (1.0f - (float)(iTemp0 > 0))) + (dsp->fConst1 * (fSlow2 + (fSlow3 * max(0.0f, min((fSlow5 * fTemp1), (1.0f - (fSlow6 * (fTemp1 - fSlow4)))))))));
dsp->fRec1[0] = (fTemp2 - floorf(fTemp2));
- dsp->fRec3[0] = (iSlow11?0.0f:min(fSlow13, (dsp->fRec3[1] + 1.0f)));
- dsp->fRec5[0] = (iSlow14?0.0f:min(fSlow17, (dsp->fRec5[1] + 1.0f)));
- int iTemp3 = (dsp->fRec5[0] < fSlow18);
- dsp->fRec4[0] = (iSlow10?((float)iSlow10 * (iTemp3?((dsp->fRec5[0] < 0.0f)?0.0f:(iTemp3?(fSlow21 * dsp->fRec5[0]):1.0f)):((dsp->fRec5[0] < fSlow17)?((fSlow20 * (dsp->fRec5[0] - fSlow18)) + 1.0f):fSlow19))):dsp->fRec4[1]);
- output0[i] = (FAUSTFLOAT)(fSlow0 * (ftbl0KickDrumSIG0[(int)(65536.0f * dsp->fRec1[0])] * ((dsp->fRec3[0] < 0.0f)?dsp->fRec4[0]:((dsp->fRec3[0] < fSlow13)?(dsp->fRec4[0] + (fSlow22 * (dsp->fRec3[0] * (0.0f - dsp->fRec4[0])))):0.0f))));
+ output0[i] = (FAUSTFLOAT)(fSlow0 * (ftbl0KickDrumSIG0[(int)(65536.0f * dsp->fRec1[0])] * max(0.0f, min((fSlow8 * fTemp1), ((fSlow9 * (fSlow7 - fTemp1)) + 1.0f)))));
dsp->fVec0[1] = dsp->fVec0[0];
- dsp->fVec1[1] = dsp->fVec1[0];
- dsp->fRec2[1] = dsp->fRec2[0];
+ dsp->iRec2[1] = dsp->iRec2[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];
-
}
-
}
-
}
#ifdef __cplusplus
}
#endif
-
#define DSP KickDrum
--- a/kick_drum.dsp
+++ b/kick_drum.dsp
@@ -3,15 +3,14 @@
declare group "Synthesis";
import("stdfaust.lib");
-aFreq = hslider("v:A/[0]Frequency[unit:Hz]", 100, 10, 400, 5);
+aFreq = hslider("v:A/[0]Frequency[unit:Hz]", 100, 5, 200, 1);
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[unit:Hz]", 200, -400, 400, 5);
+bFreq = checkbox("v:B/[3]Enable") * hslider("v:B/[0]Frequency[unit:Hz]", -5, -5, 200, 5);
gain = hslider("v:Control/[0]Gain[style:knob]", 1, 0, 1, 0.01);
gate = button("v:Control/[1]Gate");
-process = os.hs_oscsin(aFreq + bFreq*en.ar(bA, bR, gate), gate : ba.impulsify) * gain * en.adsr(aA, aD, 0.000001, aR, gate);
+process = os.hs_oscsin(aFreq + bFreq*en.ar(bA, bR, gate), gate : ba.impulsify) * gain * en.ar(aA, aR, gate);