Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Aug 29, 2023
1 parent 8b4aea0 commit eb49e96
Show file tree
Hide file tree
Showing 2 changed files with 364 additions and 155 deletions.
166 changes: 63 additions & 103 deletions architecture/faust/dsp/faust-dynamic-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,34 @@ architecture section is not modified.
#include "faust/gui/JSONUI.h"
#include "faust/gui/APIUI.h"
#include "faust/dsp/llvm-dsp.h"

#if defined(_WIN32)

#define STRDUP _strdup
#include "faust/audio/audio.h"

#if COREAUDIO_DRIVER
#include "faust/audio/coreaudio-dsp.h"
#elif IOS_DRIVER
#include "faust/audio/coreaudio-ios-dsp.h"
#elif ANDROID_DRIVER
#include "faust/audio/oboe-dsp.h"
#elif ALSA_DRIVER
#include "faust/audio/alsa-dsp.h"
#elif JACK_DRIVER
#include "faust/audio/jack-dsp.h"
#elif PORTAUDIO_DRIVER
#include "faust/audio/portaudio-dsp.h"
#endif

#elif defined(__APPLE__)
#if SOUNDFILE
#include "faust/gui/SoundUI.h"
#endif

#if defined(_WIN32)
#define STRDUP _strdup
#elif defined(__APPLE__)
#define STRDUP strdup
#if defined(TARGET_OS_IPHONE)
#include "faust/audio/coreaudio-ios-dsp"
#else
#include "faust/audio/coreaudio-dsp.h"
#endif

#elif defined(__linux__)

#define STRDUP strdup
#if defined(ANDROID)
#include "faust/audio/android-dsp.h"
#else
#include "faust/audio/alsa-dsp.h"
#endif

#endif

#if defined(_WIN32) || defined(__APPLE__) || defined(__linux__)
#define HAS_JACK 1
#endif

#if HAS_JACK
#include "faust/audio/jack-dsp.h"
#endif

#if !defined(LLVM_DSP)

/**************************BEGIN USER SECTION **************************/
Expand Down Expand Up @@ -98,6 +92,9 @@ struct dsp_aux {

#ifdef LLVM_DSP
llvm_dsp_factory* fFactory;
#endif
#if SOUNDFILE
SoundUI* fSoundInterface;
#endif
dsp* fDSP;
audio* fDriver;
Expand All @@ -106,34 +103,14 @@ struct dsp_aux {

#ifdef LLVM_DSP
dsp_aux(const char* name_app,
const char* dsp_content,
const char* argv,
const char* dsp_content,
int argc,
const char* argv[],
const char* target,
int opt_level)
:fDriver(0)
:fDriver(nullptr)
{
int argc1 = 0;
const char* argv1[64];
stringstream os(argv);
string token;

// Allocate parameters
while (os >> token) {
argv1[argc1++] = STRDUP(token.c_str());
}

#ifdef _WIN32
argv1[argc1++] = STRDUP("-l");
argv1[argc1++] = STRDUP("llvm_math.ll");
#endif

fFactory = createDSPFactoryFromString(name_app, dsp_content, argc1, argv1, "", gLastError, opt_level);

// Free parameters
for (int i = 0; i < argc1; i++) {
free((void*)argv1[i]);
}

fFactory = createDSPFactoryFromString(name_app, dsp_content, argc, argv, "", gLastError, opt_level);
if (fFactory) {
fDSP = fFactory->createDSPInstance();
createJSON(name_app);
Expand All @@ -142,7 +119,7 @@ struct dsp_aux {
}
}
#else
dsp_aux():fDriver(0)
dsp_aux():fDriver(nullptr)
{
fDSP = new mydsp();
createJSON("dummy_dsp");
Expand All @@ -159,6 +136,9 @@ struct dsp_aux {
#ifdef LLVM_DSP
deleteDSPFactory(fFactory);
#endif
#if SOUNDFILE
delete fSoundInterface;
#endif
}

void createJSON(const string& name_app)
Expand All @@ -170,65 +150,68 @@ struct dsp_aux {
fJSON = json.JSON();
}

bool init2(const char* name, int sr, int bsize, int renderer)
bool init(const char* name, int sr, int bsize, int renderer)
{
switch (renderer) {
#ifdef HAS_JACK
#ifdef JACK_DRIVER
case kJackRenderer:
fDriver = new jackaudio();
break;
#endif

#ifdef _WIN32
#ifdef PORTAUDIO_DRIVER
case kPortAudioRenderer:
fDriver = new portaudio(sr, bsize);
break;
#endif

#ifdef __APPLE__
#if defined(TARGET_OS_IPHONE)
#ifdef COREAUDIO_DRIVER
case kCoreAudioRenderer:
fDriver = new coreaudio(sr, bsize);
break;
#else
#endif

#ifdef COREAUDIO_DRIVER
case kiOSRenderer:
fDriver = new iosaudio(sr, bsize);
break;
#endif
#endif

#ifdef __linux__
#if defined(ANDROID)
#ifdef ANDROID_DRIVER
case kAndroidRenderer:
fDriver = new androidaudio(sr, bsize);
break;
#else
#endif

#ifdef ALSA_DRIVER
case kAlsaRenderer:
fDriver = new alsaaudio(sr, bsize);
break;
#endif
#endif

};

if (fDriver) {
fDriver->init(name, fDSP);
fDSP->buildUserInterface(&fParams);
#if SOUNDFILE
// Use bundle path
fSoundInterface = new SoundUI(SoundUI::getBinaryPath(), -1, nullptr);
#endif
return true;
} else {
return false;
}
}

virtual int getNumInputs() { return fDSP->getNumInputs(); }
virtual int getNumOutputs() { return fDSP->getNumOutputs(); }
int getNumInputs() { return fDSP->getNumInputs(); }
int getNumOutputs() { return fDSP->getNumOutputs(); }

};

#if HAS_JACK
#if JACK_DRIVER
static audio* createDriver()
{
return new jackaudio(0, 0);
return new jackaudio();
}

static jackaudio* getJackDriver(dsp* dsp_ext)
Expand All @@ -246,7 +229,7 @@ extern "C"

int getNumInputsDsp(dsp* dsp_ext)
{
#if HAS_JACK
#if JACK_DRIVER
if (dsp_ext) {
return reinterpret_cast<dsp_aux*>(dsp_ext)->getNumInputs();
} else {
Expand All @@ -265,7 +248,7 @@ extern "C"

int getNumOutputsDsp(dsp* dsp_ext)
{
#if HAS_JACK
#if JACK_DRIVER
if (dsp_ext) {
return reinterpret_cast<dsp_aux*>(dsp_ext)->getNumOutputs();
} else {
Expand All @@ -284,7 +267,7 @@ extern "C"

void connectDsp(dsp* dsp1_ext, dsp* dsp2_ext, int src, int dst)
{
#if HAS_JACK
#if JACK_DRIVER
jackaudio* driver1 = getJackDriver(dsp1_ext);
jackaudio* driver2 = getJackDriver(dsp2_ext);
if (driver1 == nullptr && driver2 == nullptr) return;
Expand All @@ -304,7 +287,7 @@ extern "C"

void disconnectDsp(dsp* dsp1_ext, dsp* dsp2_ext, int src, int dst)
{
#if HAS_JACK
#if JACK_DRIVER
jackaudio* driver1 = getJackDriver(dsp1_ext);
jackaudio* driver2 = getJackDriver(dsp2_ext);
if (driver1 == nullptr && driver2 == nullptr) return;
Expand All @@ -324,7 +307,7 @@ extern "C"

bool isConnectedDsp(dsp* dsp1_ext, dsp* dsp2_ext, int src, int dst)
{
#if HAS_JACK
#if JACK_DRIVER
jackaudio* driver1 = getJackDriver(dsp1_ext);
jackaudio* driver2 = getJackDriver(dsp2_ext);
if (driver1 == nullptr && driver2 == nullptr) false;
Expand All @@ -339,51 +322,28 @@ extern "C"
// Connection test between Dsp
return driver1->isConnected(driver2, src, dst, false);
}
#else
return false;
#endif
}

dsp* create2Dsp(const char* name_app, const char* dsp_content, const char* argv, const char* target, int opt_level)
dsp* createDsp(const char* name_app, const char* dsp_content,int argc, const char* argv[], const char* target, int opt_level)
{
#ifdef LLVM_DSP
try {
return reinterpret_cast<dsp*>(new dsp_aux(name_app, dsp_content, argv, target, opt_level));
return reinterpret_cast<dsp*>(new dsp_aux(name_app, dsp_content, argc, argv, target, opt_level));
} catch (...) {
cerr << "Cannot create DSP\n";
}
#endif
return 0;
}

dsp* create1Dsp(const char* name_app, const char* dsp_content)
{
#ifdef LLVM_DSP
return create2Dsp(name_app, dsp_content, "", "", 3);
#else
return 0;
#endif
}

dsp* create3Dsp()
{
#ifdef LLVM_DSP
return 0;
#else
return reinterpret_cast<dsp*>(new dsp_aux());
#endif
return nullptr;
}

const char* getLastError() { return gLastError.c_str(); }

bool init2Dsp(dsp* dsp_ext, const char* name, int sr, int bsize, int renderer)
{
return reinterpret_cast<dsp_aux*>(dsp_ext)->init2(name, sr, bsize, renderer);
}

bool init1Dsp(dsp* dsp, const char* name)
bool initDsp(dsp* dsp_ext, const char* name, int sr, int bsize, int renderer)
{
return init2Dsp(dsp, name, -1, 512, kJackRenderer);
//return init2(dsp, name, 44100, 2048, kPortAudioRenderer);
//return init2(dsp, name, 44100, 512, kCoreAudioRenderer);
return reinterpret_cast<dsp_aux*>(dsp_ext)->init(name, sr, bsize, renderer);
}

void destroyDsp(dsp* dsp_ext)
Expand Down
Loading

0 comments on commit eb49e96

Please sign in to comment.