Created
March 18, 2024 13:18
-
-
Save sletz/dbafd738bdefbb7a5762d8f4227fe4f5 to your computer and use it in GitHub Desktop.
Faust organ voice in Cmajor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------------------------------------------------ | |
name: "organ" | |
Code generated with Faust 2.72.10 (https://faust.grame.fr) | |
Compilation options: -lang cmajor-poly -ec -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0 | |
------------------------------------------------------------ */ | |
namespace faust | |
{ | |
processor mydsp | |
{ | |
input event float32 event_freq [[ name: "freq", group: "/v:organ/freq", min: 2e+01f, max: 5e+03f, init: 4.4e+02f, step: 1.0f, meta_unit0: "Hz" ]]; | |
input event float32 event_gain [[ name: "gain", group: "/v:organ/gain", min: 0.0f, max: 1e+01f, init: 0.5f, step: 0.01f ]]; | |
input event float32 event_gate [[ name: "gate", group: "/v:organ/gate", text: "off|on", boolean ]]; | |
input event float32 event_pan [[ name: "pan", group: "/v:organ/pan", min: 0.0f, max: 1.0f, init: 0.5f, step: 0.01f ]]; | |
input event float32 event_volume [[ name: "volume", group: "/v:organ/volume", min: 0.0f, max: 1.0f, init: 0.5f, step: 0.01f ]]; | |
output stream float32 output0; | |
output stream float32 output1; | |
float32 fHslider0; | |
float32 fSlow0; | |
float32 fHslider1; | |
float32 fSlow1; | |
float32 fSlow2; | |
float32 fButton0; | |
float32 fHslider2; | |
float32 fSlow3; | |
float32[2] fRec0; | |
int32 fSampleRate; | |
float32 fConst1; | |
float32 fHslider3; | |
float32 fSlow4; | |
float32 fSlow5; | |
float32[2] fRec1; | |
float32 fConst2; | |
float32 fSlow6; | |
float32[2] fRec2; | |
float32 fConst3; | |
float32 fSlow7; | |
float32[2] fRec3; | |
float32 fSlow8; | |
bool fUpdated; | |
// freq [init = 4.4e+02f, min = 2e+01f, max = 5e+03f, step = 1.0f] | |
event event_freq (float32 val) { fUpdated ||= (fHslider3 != val); fHslider3 = val; } | |
// gain [init = 0.5f, min = 0.0f, max = 1e+01f, step = 0.01f] | |
event event_gain (float32 val) { fUpdated ||= (fHslider2 != val); fHslider2 = val; } | |
// gate | |
event event_gate (float32 val) { fUpdated ||= (fButton0 != val); fButton0 = val; } | |
// pan [init = 0.5f, min = 0.0f, max = 1.0f, step = 0.01f] | |
event event_pan (float32 val) { fUpdated ||= (fHslider1 != val); fHslider1 = val; } | |
// volume [init = 0.5f, min = 0.0f, max = 1.0f, step = 0.01f] | |
event event_volume (float32 val) { fUpdated ||= (fHslider0 != val); fHslider0 = val; } | |
float32 copysign(float32 x, float32 y) { return abs(x) * ((y < 0.0f) ? -1.0f : 1.0f); } | |
float32 round(float32 x) { return float32(roundToInt(x)); } | |
int getNumInputs() { return 0; } | |
int getNumOuputs() { return 2; } | |
void classInit (int sample_rate) | |
{ | |
} | |
void instanceConstants (int sample_rate) | |
{ | |
fSampleRate = sample_rate; | |
float32 fConst0 = min (1.92e+05f, max (0.0f, float32 (fSampleRate))); | |
fConst1 = 1.0f / fConst0; | |
fConst2 = 2.0f / fConst0; | |
fConst3 = 3.0f / fConst0; | |
} | |
void instanceResetUserInterface() | |
{ | |
fUpdated = true; | |
fHslider0 = 0.5f; | |
fHslider1 = 0.5f; | |
fButton0 = 0.0f; | |
fHslider2 = 0.5f; | |
fHslider3 = 4.4e+02f; | |
} | |
void instanceClear() | |
{ | |
for (int32 l0 = 0; l0 < 2; l0 = l0 + 1) { | |
fRec0.at (l0) = 0.0f; | |
} | |
for (int32 l1 = 0; l1 < 2; l1 = l1 + 1) { | |
fRec1.at (l1) = 0.0f; | |
} | |
for (int32 l2 = 0; l2 < 2; l2 = l2 + 1) { | |
fRec2.at (l2) = 0.0f; | |
} | |
for (int32 l3 = 0; l3 < 2; l3 = l3 + 1) { | |
fRec3.at (l3) = 0.0f; | |
} | |
} | |
void init() | |
{ | |
let sample_rate = int(processor.frequency); | |
// classInit is not called here since the tables are actually not shared between instances | |
instanceInit (sample_rate); | |
} | |
void instanceInit (int sample_rate) | |
{ | |
// classInit has to be called for each instance since the tables are actually not shared between instances | |
classInit (sample_rate); | |
instanceConstants (sample_rate); | |
instanceResetUserInterface(); | |
instanceClear(); | |
} | |
void control() | |
{ | |
fSlow0 = fHslider0; | |
fSlow1 = fHslider1; | |
fSlow2 = fSlow0 * (1.0f - fSlow1); | |
fSlow3 = 0.0005f * fButton0 * fHslider2; | |
fSlow4 = fHslider3; | |
fSlow5 = fConst1 * fSlow4; | |
fSlow6 = fConst2 * fSlow4; | |
fSlow7 = fConst3 * fSlow4; | |
fSlow8 = fSlow1 * fSlow0; | |
} | |
void main() | |
{ | |
// DSP loop running forever... | |
loop | |
{ | |
if (fUpdated) { fUpdated = false; control(); } | |
// Computes one sample | |
fRec0[0] = fSlow3 + 0.9995f * fRec0[1]; | |
fRec1[0] = fmod (fSlow5 + fRec1[1], 1.0f); | |
fRec2[0] = fmod (fSlow6 + fRec2[1], 1.0f); | |
fRec3[0] = fmod (fSlow7 + fRec3[1], 1.0f); | |
float32 fTemp0 = fRec0[0] * (sin (6.2831855f * fRec1[0]) + 0.5f * sin (6.2831855f * fRec2[0]) + 0.25f * sin (6.2831855f * fRec3[0])); | |
output0 <- fSlow2 * fTemp0; | |
output1 <- fSlow8 * fTemp0; | |
fRec0[1] = fRec0[0]; | |
fRec1[1] = fRec1[0]; | |
fRec2[1] = fRec2[0]; | |
fRec3[1] = fRec3[0]; | |
// Moves all streams forward by one 'tick' | |
advance(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment