Skip to content

Commit

Permalink
Add an example in signal-tester.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Mar 31, 2024
1 parent 81cf3d7 commit 7cb4e75
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 91 deletions.
2 changes: 1 addition & 1 deletion tools/benchmark/box-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static void test4()
}
}

int main(int argc, const char* argv[])
int main(int argc, char* argv[])
{
test1();
test2();
Expand Down
85 changes: 29 additions & 56 deletions tools/benchmark/box-tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@

using namespace std;

// Run a DSP with a GUI
static void runAudio(dsp* dsp, const char* name, int argc, char* argv[])
{
// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)name, &argc, &argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
}

/**
* Return the current runtime sample rate.
*
Expand Down Expand Up @@ -425,7 +446,7 @@ static void test20()
*/

// Using the LLVM backend.
static void test21(int argc, const char* argv[])
static void test21(int argc, char* argv[])
{
cout << "test21\n";
string error_msg;
Expand All @@ -446,23 +467,7 @@ static void test21(int argc, const char* argv[])
if (factory) {
dsp* dsp = factory->createDSPInstance();
assert(dsp);

// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)"Organ", &argc, (char***)&argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
runAudio(dsp, "Organ", argc, argv);
delete dsp;
deleteDSPFactory(factory);
} else {
Expand All @@ -471,7 +476,7 @@ static void test21(int argc, const char* argv[])
}

// Using the Interpreter backend.
static void test22(int argc, const char* argv[])
static void test22(int argc, char* argv[])
{
cout << "test22\n";
string error_msg;
Expand All @@ -492,23 +497,7 @@ static void test22(int argc, const char* argv[])
if (factory) {
dsp* dsp = factory->createDSPInstance();
assert(dsp);

// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)"Organ", &argc, (char***)&argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
runAudio(dsp, "Organ", argc, argv);
delete dsp;
deleteInterpreterDSPFactory(factory);
} else {
Expand All @@ -517,7 +506,7 @@ static void test22(int argc, const char* argv[])
}

// Using the Interpreter backend.
static void test23(int argc, const char* argv[])
static void test23(int argc, char* argv[])
{
cout << "test23\n";
interpreter_dsp_factory* factory = nullptr;
Expand Down Expand Up @@ -573,23 +562,7 @@ static void test23(int argc, const char* argv[])
if (factory) {
dsp* dsp = factory->createDSPInstance();
assert(dsp);

// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)"Organ", &argc, (char***)&argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
runAudio(dsp, "Organ", argc, argv);
delete dsp;
deleteInterpreterDSPFactory(factory);
} else {
Expand All @@ -612,7 +585,7 @@ static void test23(int argc, const char* argv[])
*/

// Simple polyphonic DSP.
static void test24(int argc, const char* argv[])
static void test24(int argc, char* argv[])
{
cout << "test24\n";
interpreter_dsp_factory* factory = nullptr;
Expand Down Expand Up @@ -743,7 +716,7 @@ static void test26()
list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;

int main(int argc, const char* argv[])
int main(int argc, char* argv[])
{
test0();
test1();
Expand Down
105 changes: 71 additions & 34 deletions tools/benchmark/signal-tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@

using namespace std;

// Run a DSP with a GUI
static void runAudio(dsp* dsp, const char* name, int argc, char* argv[])
{
// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)name, &argc, &argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
}

/**
* Return the current runtime sample rate.
Expand Down Expand Up @@ -675,30 +695,60 @@ static void test22(int argc, char* argv[])
if (factory) {
dsp* dsp = factory->createDSPInstance();
assert(dsp);

// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)"Organ", &argc, &argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
runAudio(dsp, "Organ", argc, argv);
delete dsp;
deleteDSPFactory(factory);
} else {
cerr << "Cannot create factory" << error_msg << endl;
}
}

static void test22bis(int argc, char* argv[])
{
cout << "test22\n";
string error_msg;
llvm_dsp_factory* factory1 = nullptr;
llvm_dsp_factory* factory2 = nullptr;

createLibContext();
{
{
tvec signals;
signals.push_back(osc(sigVSlider("h:Oscillator/Freq1", sigReal(300), sigReal(100), sigReal(2000), sigReal(0.01))));
signals.push_back(osc(sigVSlider("h:Oscillator/Freq2", sigReal(500), sigReal(100), sigReal(2000), sigReal(0.01))));
factory1 = createDSPFactoryFromSignals("FaustDSP1", signals, 0, nullptr, "", error_msg);
}

{
tvec signals;
signals.push_back(osc(sigVSlider("h:Oscillator/Foo1", sigReal(200), sigReal(100), sigReal(2000), sigReal(0.01))));
signals.push_back(osc(sigVSlider("h:Oscillator/Foo2", sigReal(700), sigReal(100), sigReal(2000), sigReal(0.01))));
factory2 = createDSPFactoryFromSignals("FaustDSP2", signals, 0, nullptr, "", error_msg);
}
}
destroyLibContext();

// The factories can be used outside of the createLibContext/destroyLibContext scope
if (factory1 && factory2) {
{
dsp* dsp = factory1->createDSPInstance();
assert(dsp);
runAudio(dsp, "Organ1", argc, argv);
delete dsp;
}
{
dsp* dsp = factory2->createDSPInstance();
assert(dsp);
runAudio(dsp, "Organ2", argc, argv);
delete dsp;
}
deleteDSPFactory(factory1);
deleteDSPFactory(factory2);
} else {
cerr << "Cannot create factories" << error_msg << endl;
}
}

// Using the Interpreter backend.
static void test23(int argc, char* argv[])
{
Expand All @@ -720,23 +770,7 @@ static void test23(int argc, char* argv[])
if (factory) {
dsp* dsp = factory->createDSPInstance();
assert(dsp);

// Allocate audio driver
jackaudio audio;
audio.init("Test", dsp);

// Create GUI
GTKUI gtk_ui = GTKUI((char*)"Organ", &argc, &argv);
dsp->buildUserInterface(&gtk_ui);

// Start real-time processing
audio.start();

// Start GUI
gtk_ui.run();

// Cleanup
audio.stop();
runAudio(dsp, "Organ", argc, argv);
delete dsp;
deleteInterpreterDSPFactory(factory);
} else {
Expand Down Expand Up @@ -900,6 +934,9 @@ int main(int argc, char* argv[])
// Test with audio, GUI and LLVM backend
test22(argc, argv);

// Test with audio, GUI and LLVM backend and 2 factories/DSP
test22bis(argc, argv);

// Test with audio, GUI and Interp backend
test23(argc, argv);

Expand Down

0 comments on commit 7cb4e75

Please sign in to comment.