Browse Source

Add FaustEngine.

faust
Stephane Letz Andrew Belt 4 years ago
parent
commit
4136ec6f24
2 changed files with 97 additions and 5 deletions
  1. +13
    -5
      Makefile
  2. +84
    -0
      src/FaustEngine.cpp

+ 13
- 5
Makefile View File

@@ -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

+ 84
- 0
src/FaustEngine.cpp View File

@@ -0,0 +1,84 @@
#include "ScriptEngine.hpp"

#include <faust/dsp/llvm-dsp.h>
#include <iostream>

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<FaustEngine>("dsp");
}

Loading…
Cancel
Save