Created
August 11, 2023 06:37
-
-
Save sletz/a7eeba9257bb222362d9ae88039a4c2a to your computer and use it in GitHub Desktop.
Faust vumeter in C++ and codebox
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
Faust code: process = vbargraph("val", -1, 1); | |
get compiled to this C++: | |
class mydsp : public dsp { | |
private: | |
FAUSTFLOAT fVbargraph0; | |
int fSampleRate; | |
public: | |
mydsp() {} | |
void metadata(Meta* m) { | |
m->declare("author", "Grame"); | |
m->declare("compile_options", "-lang cpp -ct 1 -es 1 -mcd 16 -single -ftz 0"); | |
m->declare("copyright", "(c)GRAME 2006"); | |
m->declare("filename", "vumeter.dsp"); | |
m->declare("license", "BSD"); | |
m->declare("name", "vumeter"); | |
m->declare("version", "1.0"); | |
} | |
virtual int getNumInputs() { | |
return 1; | |
} | |
virtual int getNumOutputs() { | |
return 1; | |
} | |
static void classInit(int sample_rate) { | |
} | |
virtual void instanceConstants(int sample_rate) { | |
fSampleRate = sample_rate; | |
} | |
virtual void instanceResetUserInterface() { | |
} | |
virtual void instanceClear() { | |
} | |
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("vumeter"); | |
ui_interface->addVerticalBargraph("val", &fVbargraph0, FAUSTFLOAT(-1.0f), FAUSTFLOAT(1.0f)); | |
ui_interface->closeBox(); | |
} | |
virtual void compute(int count, FAUSTFLOAT** RESTRICT inputs, FAUSTFLOAT** RESTRICT outputs) { | |
FAUSTFLOAT* input0 = inputs[0]; | |
FAUSTFLOAT* output0 = outputs[0]; | |
for (int i0 = 0; i0 < count; i0 = i0 + 1) { | |
fVbargraph0 = FAUSTFLOAT(float(input0[i0])); | |
output0[i0] = FAUSTFLOAT(fVbargraph0); | |
} | |
} | |
}; | |
with the "output control" fVbargraph0 which is written at each sample, and the last value only is kept and can be looked | |
once by block rate in the fVbargraph0 variable. | |
Compilation in codebox currently gives: | |
// Params | |
@param({min: -1.0f, max: 1.0f}) val = 0; | |
// Globals | |
// Fields | |
@state fVbargraph0_cb : number = 0; | |
@state fSampleRate_cb : Int = 0; | |
@state fUpdated : Int = 0; | |
// Init | |
function dspsetup() { | |
fUpdated = true; | |
fSampleRate_cb = samplerate(); | |
} | |
// Control | |
function control() { | |
} | |
// Update parameters | |
function update(val) { | |
if (fUpdated) { fUpdated = false; control(); } | |
} | |
// Compute one frame | |
function compute(i0) { | |
input0_cb = i0; | |
fVbargraph0_cb = input0_cb; | |
output0_cb = fVbargraph0_cb; | |
return [output0_cb]; | |
} | |
// Update parameters | |
update(val); | |
// Compute one frame | |
outputs = compute(in1); | |
// Write the outputs | |
out1 = outputs[0]; | |
And I would need to add: | |
val = fVbargraph0_cb in the compute(..) function and I would like to "output" val as a control rate value out | |
from the codebox code. Is that possible ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment