|
|
@@ -3,6 +3,8 @@ |
|
|
|
#include <faust/dsp/llvm-dsp.h> |
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
#define kBufferSize 64 |
|
|
|
|
|
|
|
class FaustEngine : public ScriptEngine { |
|
|
|
|
|
|
|
public: |
|
|
@@ -25,40 +27,41 @@ class FaustEngine : public ScriptEngine { |
|
|
|
|
|
|
|
int run(const std::string& path, const std::string& script) override |
|
|
|
{ |
|
|
|
display("Compiling..."); |
|
|
|
|
|
|
|
std::string error_msg; |
|
|
|
fFactory = createDSPFactoryFromString("FaustDSP", script, 0, NULL, "", error_msg, -1); |
|
|
|
if (!fFactory) { |
|
|
|
display("Cannot create Faust factory"); |
|
|
|
display("ERROR: cannot create Faust factory !"); |
|
|
|
return -1; |
|
|
|
} else { |
|
|
|
display("Compiling finished"); |
|
|
|
display("Compiling factory finished"); |
|
|
|
} |
|
|
|
|
|
|
|
fDSP = fFactory->createDSPInstance(); |
|
|
|
if (!fDSP) { |
|
|
|
display("Cannot create Faust instance"); |
|
|
|
display("ERROR: cannot create Faust instance !"); |
|
|
|
return -1; |
|
|
|
} else { |
|
|
|
display("Creating DSP"); |
|
|
|
display("Created DSP"); |
|
|
|
} |
|
|
|
|
|
|
|
fInputs = new FAUSTFLOAT*[fDSP->getNumInputs()]; |
|
|
|
fOutputs = new FAUSTFLOAT*[fDSP->getNumOutputs()]; |
|
|
|
// Prepare inputs/ouputs |
|
|
|
if (fDSP->getNumInputs() > 6) { |
|
|
|
display("ERROR: DSP has " + std::to_string(fDSP->getNumInputs()) + " inputs !"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
setFrameDivider(1); |
|
|
|
setBufferSize(64); |
|
|
|
if (fDSP->getNumOutputs() > 6) { |
|
|
|
display("ERROR: DSP has " + std::to_string(fDSP->getNumInputs()) + " outputs !"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO |
|
|
|
//ProcessBlock* block = getProcessBlock(); |
|
|
|
fDSP->init(44100); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int process() override |
|
|
|
{ |
|
|
|
setFrameDivider(1); |
|
|
|
setBufferSize(kBufferSize); |
|
|
|
|
|
|
|
// Prepare buffers for process |
|
|
|
ProcessBlock* block = getProcessBlock(); |
|
|
|
fInputs = new FAUSTFLOAT*[fDSP->getNumInputs()]; |
|
|
|
fOutputs = new FAUSTFLOAT*[fDSP->getNumOutputs()]; |
|
|
|
|
|
|
|
for (int chan = 0; chan < fDSP->getNumInputs(); chan++) { |
|
|
|
fInputs[chan] = block->inputs[chan]; |
|
|
@@ -67,7 +70,18 @@ class FaustEngine : public ScriptEngine { |
|
|
|
fOutputs[chan] = block->outputs[chan]; |
|
|
|
} |
|
|
|
|
|
|
|
fDSP->compute(block->bufferSize, fInputs, fOutputs); |
|
|
|
// Init DSP with default SR |
|
|
|
fDSP->init(44100); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int process() override |
|
|
|
{ |
|
|
|
// Possibly update SR |
|
|
|
if (getProcessBlock()->sampleRate != fDSP->getSampleRate()) { |
|
|
|
fDSP->init(getProcessBlock()->sampleRate); |
|
|
|
} |
|
|
|
fDSP->compute(kBufferSize, fInputs, fOutputs); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|