diff --git a/Makefile b/Makefile index 28965ad..6796329 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,7 @@ FLAGS += -Idep/include CFLAGS += CXXFLAGS += -LDFLAGS += - +LDFLAGS += SOURCES += src/Prototype.cpp DISTRIBUTABLES += res examples @@ -14,8 +13,8 @@ DISTRIBUTABLES += $(wildcard LICENSE*) include $(RACK_DIR)/arch.mk DUKTAPE ?= 0 -QUICKJS ?= 1 -LUAJIT ?= 1 +QUICKJS ?= 0 +LUAJIT ?= 0 PYTHON ?= 0 SUPERCOLLIDER ?= 0 VULT ?= 1 @@ -212,7 +211,6 @@ FLAGS += -Idep/vult DEPS += $(vult) endif - # LibPD ifeq ($(LIBPD), 1) libpd := dep/lib/libpd.a @@ -249,4 +247,14 @@ endif endif +# Faust +ifeq ($(FAUST), 1) +SOURCES += src/FaustEngine.cpp +FLAGS += -I/use/local/include +LDFLAGS += -L/usr/local/lib -lfaust +DEPS += $(faust) +OBJECTS += $(faust) +FAUST_MAKE_FLAGS += prefix="$(DEP_PATH)" +endif + include $(RACK_DIR)/plugin.mk diff --git a/src/FaustEngine.cpp b/src/FaustEngine.cpp new file mode 100644 index 0000000..4c51b27 --- /dev/null +++ b/src/FaustEngine.cpp @@ -0,0 +1,84 @@ +#include "ScriptEngine.hpp" + +#include +#include + +class FaustEngine : public ScriptEngine { + + public: + + FaustEngine():fFactory(nullptr), fDSP(nullptr), fInputs(nullptr), fOutputs(nullptr) + {} + + ~FaustEngine() + { + delete [] fInputs; + delete [] fOutputs; + delete fDSP; + deleteDSPFactory(fFactory); + } + + std::string getEngineName() override + { + return "Faust"; + } + + 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"); + return -1; + } else { + display("Compiling finished"); + } + + fDSP = fFactory->createDSPInstance(); + if (!fDSP) { + display("Cannot create Faust instance"); + return -1; + } else { + display("Creating DSP"); + } + + fInputs = new FAUSTFLOAT*[fDSP->getNumInputs()]; + fOutputs = new FAUSTFLOAT*[fDSP->getNumOutputs()]; + + setFrameDivider(1); + setBufferSize(64); + + // TODO + //ProcessBlock* block = getProcessBlock(); + fDSP->init(44100); + return 0; + } + + int process() override + { + ProcessBlock* block = getProcessBlock(); + + for (int chan = 0; chan < fDSP->getNumInputs(); chan++) { + fInputs[chan] = block->inputs[chan]; + } + for (int chan = 0; chan < fDSP->getNumOutputs(); chan++) { + fOutputs[chan] = block->outputs[chan]; + } + + fDSP->compute(block->bufferSize, fInputs, fOutputs); + return 0; + } + + private: + llvm_dsp_factory* fFactory; + llvm_dsp* fDSP; + FAUSTFLOAT** fInputs; + FAUSTFLOAT** fOutputs; +}; + +__attribute__((constructor(1000))) +static void constructor() { + addScriptEngine("dsp"); +}