Browse Source

Fix for NetJack2.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4504 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.9.8
sletz 14 years ago
parent
commit
b8c47e5967
3 changed files with 88 additions and 95 deletions
  1. +0
    -7
      common/JackNetAPI.cpp
  2. +19
    -19
      example-clients/netslave.c
  3. +69
    -69
      macosx/iphone/freeverb.mm

+ 0
- 7
common/JackNetAPI.cpp View File

@@ -35,13 +35,6 @@ extern "C"


#define MASTER_NAME_SIZE 256 #define MASTER_NAME_SIZE 256


enum JackNetMode {

JackFastMode = 'f',
JackNormalMode = 'n',
JackSlowMode = 's',
};

enum JackNetEncoder { enum JackNetEncoder {


JackFloatEncoder = 0, JackFloatEncoder = 0,


+ 19
- 19
example-clients/netslave.c View File

@@ -1,6 +1,6 @@
/* /*
Copyright (C) 2009 Grame Copyright (C) 2009 Grame
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
@@ -55,18 +55,18 @@ static void net_shutdown(void* data)
} }


static int net_process(jack_nframes_t buffer_size, static int net_process(jack_nframes_t buffer_size,
int audio_input,
float** audio_input_buffer,
int audio_input,
float** audio_input_buffer,
int midi_input, int midi_input,
void** midi_input_buffer, void** midi_input_buffer,
int audio_output, int audio_output,
float** audio_output_buffer,
int midi_output,
void** midi_output_buffer,
float** audio_output_buffer,
int midi_output,
void** midi_output_buffer,
void* data) void* data)
{ {
int i; int i;
// Copy input to output // Copy input to output
for (i = 0; i < audio_input; i++) { for (i = 0; i < audio_input; i++) {
memcpy(audio_output_buffer[i], audio_input_buffer[i], buffer_size * sizeof(float)); memcpy(audio_output_buffer[i], audio_input_buffer[i], buffer_size * sizeof(float));
@@ -84,7 +84,7 @@ main (int argc, char *argv[])
const char *options = "C:P:a:p:"; const char *options = "C:P:a:p:";
int option_index; int option_index;
int opt; int opt;
struct option long_options[] = struct option long_options[] =
{ {
{"audio input", 1, 0, 'C'}, {"audio input", 1, 0, 'C'},
@@ -93,36 +93,36 @@ main (int argc, char *argv[])
{"port", 1, 0, 'p'}, {"port", 1, 0, 'p'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) { while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
switch (opt) { switch (opt) {
case 'C': case 'C':
audio_input = atoi(optarg); audio_input = atoi(optarg);
break; break;
case 'P': case 'P':
audio_output = atoi(optarg); audio_output = atoi(optarg);
break; break;
case 'a': case 'a':
multicast_ip = strdup(optarg); multicast_ip = strdup(optarg);
break; break;
case 'p': case 'p':
port = atoi(optarg); port = atoi(optarg);
break; break;
case 'h': case 'h':
usage(); usage();
return -1; return -1;
} }
} }


jack_slave_t request = { audio_input, audio_output, 0, 0, DEFAULT_MTU, -1, JackSlowMode };
jack_slave_t request = { audio_input, audio_output, 0, 0, DEFAULT_MTU, -1, 2 };
jack_master_t result; jack_master_t result;
printf("Waiting for a master...\n"); printf("Waiting for a master...\n");


if ((net = jack_net_slave_open(DEFAULT_MULTICAST_IP, DEFAULT_PORT, "net_slave", &request, &result)) == 0) { if ((net = jack_net_slave_open(DEFAULT_MULTICAST_IP, DEFAULT_PORT, "net_slave", &request, &result)) == 0) {
@@ -139,7 +139,7 @@ main (int argc, char *argv[])
fprintf(stderr, "Cannot sactivate client\n"); fprintf(stderr, "Cannot sactivate client\n");
return 1; return 1;
} }
/* install a signal handler to properly quits jack client */ /* install a signal handler to properly quits jack client */
#ifdef WIN32 #ifdef WIN32
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
@@ -160,7 +160,7 @@ main (int argc, char *argv[])
sleep(1); sleep(1);
#endif #endif
}; };
// Wait for application end // Wait for application end
jack_net_slave_deactivate(net); jack_net_slave_deactivate(net);
jack_net_slave_close(net); jack_net_slave_close(net);


+ 69
- 69
macosx/iphone/freeverb.mm View File

@@ -25,7 +25,7 @@
#include <pwd.h> #include <pwd.h>
#include <sys/types.h> #include <sys/types.h>
#include <assert.h> #include <assert.h>
#include <pthread.h>
#include <pthread.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <libgen.h> #include <libgen.h>
#include <jack/net.h> #include <jack/net.h>
@@ -52,7 +52,7 @@ using namespace std;
#define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000) #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
#endif #endif
#else #else
#define AVOIDDENORMALS
#define AVOIDDENORMALS
#endif #endif


//#define BENCHMARKMODE //#define BENCHMARKMODE
@@ -61,7 +61,7 @@ struct Meta : map<const char*, const char*>
{ {
void declare (const char* key, const char* value) { (*this)[key]=value; } void declare (const char* key, const char* value) { (*this)[key]=value; }
}; };


#define max(x,y) (((x)>(y)) ? (x) : (y)) #define max(x,y) (((x)>(y)) ? (x) : (y))
#define min(x,y) (((x)<(y)) ? (x) : (y)) #define min(x,y) (((x)<(y)) ? (x) : (y))
@@ -91,37 +91,37 @@ class UI
{ {
bool fStopped; bool fStopped;
public: public:
UI() : fStopped(false) {} UI() : fStopped(false) {}
virtual ~UI() {} virtual ~UI() {}
// -- active widgets // -- active widgets
virtual void addButton(const char* label, float* zone) = 0; virtual void addButton(const char* label, float* zone) = 0;
virtual void addToggleButton(const char* label, float* zone) = 0; virtual void addToggleButton(const char* label, float* zone) = 0;
virtual void addCheckButton(const char* label, float* zone) = 0; virtual void addCheckButton(const char* label, float* zone) = 0;
virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0; virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0; virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0; virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0;
// -- passive widgets // -- passive widgets
virtual void addNumDisplay(const char* label, float* zone, int precision) = 0; virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0; virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0; virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0; virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;
// -- frames and labels // -- frames and labels
virtual void openFrameBox(const char* label) = 0; virtual void openFrameBox(const char* label) = 0;
virtual void openTabBox(const char* label) = 0; virtual void openTabBox(const char* label) = 0;
virtual void openHorizontalBox(const char* label) = 0; virtual void openHorizontalBox(const char* label) = 0;
virtual void openVerticalBox(const char* label) = 0; virtual void openVerticalBox(const char* label) = 0;
virtual void closeBox() = 0; virtual void closeBox() = 0;
virtual void show() = 0; virtual void show() = 0;
virtual void run() = 0; virtual void run() = 0;
void stop() { fStopped = true; } void stop() { fStopped = true; }
bool stopped() { return fStopped; } bool stopped() { return fStopped; }


@@ -132,24 +132,24 @@ struct param {
float* fZone; float fMin; float fMax; float* fZone; float fMin; float fMax;
param(float* z, float a, float b) : fZone(z), fMin(a), fMax(b) {} param(float* z, float a, float b) : fZone(z), fMin(a), fMax(b) {}
}; };
class CMDUI : public UI class CMDUI : public UI
{ {
int fArgc; int fArgc;
char** fArgv; char** fArgv;
stack<string> fPrefix; stack<string> fPrefix;
map<string, param> fKeyParam; map<string, param> fKeyParam;
void addOption(const char* label, float* zone, float min, float max) void addOption(const char* label, float* zone, float min, float max)
{ {
string fullname = fPrefix.top() + label; string fullname = fPrefix.top() + label;
fKeyParam.insert(make_pair(fullname, param(zone, min, max))); fKeyParam.insert(make_pair(fullname, param(zone, min, max)));
} }
void openAnyBox(const char* label) void openAnyBox(const char* label)
{ {
string prefix; string prefix;
if (label && label[0]) { if (label && label[0]) {
prefix = fPrefix.top() + "-" + label; prefix = fPrefix.top() + "-" + label;
} else { } else {
@@ -157,21 +157,21 @@ class CMDUI : public UI
} }
fPrefix.push(prefix); fPrefix.push(prefix);
} }
public: public:
CMDUI(int argc, char *argv[]) : UI(), fArgc(argc), fArgv(argv) { fPrefix.push("--"); } CMDUI(int argc, char *argv[]) : UI(), fArgc(argc), fArgv(argv) { fPrefix.push("--"); }
virtual ~CMDUI() {} virtual ~CMDUI() {}
virtual void addButton(const char* label, float* zone) {}; virtual void addButton(const char* label, float* zone) {};
virtual void addToggleButton(const char* label, float* zone) {}; virtual void addToggleButton(const char* label, float* zone) {};
virtual void addCheckButton(const char* label, float* zone) {}; virtual void addCheckButton(const char* label, float* zone) {};
virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step)
{ {
addOption(label,zone,min,max); addOption(label,zone,min,max);
} }
virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step)
{ {
addOption(label,zone,min,max); addOption(label,zone,min,max);
@@ -181,9 +181,9 @@ public:
{ {
addOption(label,zone,min,max); addOption(label,zone,min,max);
} }
// -- passive widgets // -- passive widgets
virtual void addNumDisplay(const char* label, float* zone, int precision) {} virtual void addNumDisplay(const char* label, float* zone, int precision) {}
virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {} virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {}
virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {} virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {}
@@ -193,11 +193,11 @@ public:
virtual void openTabBox(const char* label) { openAnyBox(label); } virtual void openTabBox(const char* label) { openAnyBox(label); }
virtual void openHorizontalBox(const char* label) { openAnyBox(label); } virtual void openHorizontalBox(const char* label) { openAnyBox(label); }
virtual void openVerticalBox(const char* label) { openAnyBox(label); } virtual void openVerticalBox(const char* label) { openAnyBox(label); }
virtual void closeBox() { fPrefix.pop(); } virtual void closeBox() { fPrefix.pop(); }
virtual void show() {} virtual void show() {}
virtual void run()
virtual void run()
{ {
char c; char c;
printf("Type 'q' to quit\n"); printf("Type 'q' to quit\n");
@@ -205,8 +205,8 @@ public:
sleep(1); sleep(1);
} }
} }
void print()
void print()
{ {
map<string, param>::iterator i; map<string, param>::iterator i;
cout << fArgc << "\n"; cout << fArgc << "\n";
@@ -215,13 +215,13 @@ public:
cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] "; cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] ";
} }
} }
void process_command() void process_command()
{ {
map<string, param>::iterator p; map<string, param>::iterator p;
for (int i = 1; i < fArgc; i++) { for (int i = 1; i < fArgc; i++) {
if (fArgv[i][0] == '-') { if (fArgv[i][0] == '-') {
p = fKeyParam.find(fArgv[i]);
p = fKeyParam.find(fArgv[i]);
if (p == fKeyParam.end()) { if (p == fKeyParam.end()) {
cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n"; cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
print(); print();
@@ -233,13 +233,13 @@ public:
} }
} }
} }
void process_init() void process_init()
{ {
map<string, param>::iterator p; map<string, param>::iterator p;
for (int i = 1; i < fArgc; i++) { for (int i = 1; i < fArgc; i++) {
if (fArgv[i][0] == '-') { if (fArgv[i][0] == '-') {
p = fKeyParam.find(fArgv[i]);
p = fKeyParam.find(fArgv[i]);
if (p == fKeyParam.end()) { if (p == fKeyParam.end()) {
cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n"; cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
exit(1); exit(1);
@@ -256,14 +256,14 @@ public:
//---------------------------------------------------------------- //----------------------------------------------------------------
// Signal processor definition // Signal processor definition
//---------------------------------------------------------------- //----------------------------------------------------------------
class dsp { class dsp {
protected: protected:
int fSamplingFreq; int fSamplingFreq;
public: public:
dsp() {} dsp() {}
virtual ~dsp() {} virtual ~dsp() {}
virtual int getNumInputs() = 0; virtual int getNumInputs() = 0;
virtual int getNumOutputs() = 0; virtual int getNumOutputs() = 0;
virtual void buildUserInterface(UI* interface) = 0; virtual void buildUserInterface(UI* interface) = 0;
@@ -271,12 +271,12 @@ class dsp {
virtual void compute(int len, float** inputs, float** outputs) = 0; virtual void compute(int len, float** inputs, float** outputs) = 0;
virtual void conclude() {} virtual void conclude() {}
}; };


//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// FAUST generated code // FAUST generated code
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------


class mydsp : public dsp { class mydsp : public dsp {
private: private:
@@ -349,7 +349,7 @@ class mydsp : public dsp {
float fVec23[256]; float fVec23[256];
float fRec24[2]; float fRec24[2];
public: public:
static void metadata(Meta* m) {
static void metadata(Meta* m) {
m->declare("name", "freeverb"); m->declare("name", "freeverb");
m->declare("version", "1.0"); m->declare("version", "1.0");
m->declare("author", "Grame"); m->declare("author", "Grame");
@@ -580,8 +580,8 @@ class mydsp : public dsp {
}; };




mydsp DSP; mydsp DSP;




@@ -601,7 +601,7 @@ int gNumInChans;
int gNumOutChans; int gNumOutChans;


//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Jack Callbacks
// Jack Callbacks
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------


static void net_shutdown(void *) static void net_shutdown(void *)
@@ -633,7 +633,7 @@ void printstats()
low = hi = tot = (stops[KSKIP] - starts[KSKIP]); low = hi = tot = (stops[KSKIP] - starts[KSKIP]);


if (mesure < KMESURE) { if (mesure < KMESURE) {
for (int i = KSKIP+1; i<mesure; i++) { for (int i = KSKIP+1; i<mesure; i++) {
unsigned long long int m = stops[i] - starts[i]; unsigned long long int m = stops[i] - starts[i];
if (m<low) low = m; if (m<low) low = m;
@@ -643,7 +643,7 @@ void printstats()
cout << low << ' ' << tot/(mesure-KSKIP) << ' ' << hi << endl; cout << low << ' ' << tot/(mesure-KSKIP) << ' ' << hi << endl;


} else { } else {
for (int i = KSKIP+1; i<KMESURE; i++) { for (int i = KSKIP+1; i<KMESURE; i++) {
unsigned long long int m = stops[i] - starts[i]; unsigned long long int m = stops[i] - starts[i];
if (m<low) low = m; if (m<low) low = m;
@@ -652,7 +652,7 @@ void printstats()
} }
cout << low << ' ' << tot/(KMESURE-KSKIP) << ' ' << hi << endl; cout << low << ' ' << tot/(KMESURE-KSKIP) << ' ' << hi << endl;


}
}
} }


#else #else
@@ -663,20 +663,20 @@ void printstats()
#endif #endif


static int net_process(jack_nframes_t buffer_size, static int net_process(jack_nframes_t buffer_size,
int audio_input,
float** audio_input_buffer,
int audio_input,
float** audio_input_buffer,
int midi_input, int midi_input,
void** midi_input_buffer, void** midi_input_buffer,
int audio_output, int audio_output,
float** audio_output_buffer,
int midi_output,
void** midi_output_buffer,
float** audio_output_buffer,
int midi_output,
void** midi_output_buffer,
void* data) void* data)
{ {
AVOIDDENORMALS; AVOIDDENORMALS;
STARTMESURE STARTMESURE
DSP.compute(buffer_size, audio_input_buffer, audio_output_buffer); DSP.compute(buffer_size, audio_input_buffer, audio_output_buffer);
STOPMESURE
STOPMESURE
return 0; return 0;
} }


@@ -687,68 +687,68 @@ static int net_process(jack_nframes_t buffer_size,


******************************************************************************* *******************************************************************************
*******************************************************************************/ *******************************************************************************/
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// MAIN // MAIN
//------------------------------------------------------------------------- //-------------------------------------------------------------------------




#define TEST_MASTER "194.5.49.5" #define TEST_MASTER "194.5.49.5"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
UI* interface = new CMDUI(argc, argv); UI* interface = new CMDUI(argc, argv);
jack_net_slave_t* net; jack_net_slave_t* net;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//Jack::JackAudioQueueAdapter audio(2, 2, 1024, 44100, NULL); //Jack::JackAudioQueueAdapter audio(2, 2, 1024, 44100, NULL);
gNumInChans = DSP.getNumInputs(); gNumInChans = DSP.getNumInputs();
gNumOutChans = DSP.getNumOutputs(); gNumOutChans = DSP.getNumOutputs();
jack_slave_t request = { gNumInChans, gNumOutChans, 0, 0, DEFAULT_MTU, -1, JackSlowMode };
jack_slave_t request = { gNumInChans, gNumOutChans, 0, 0, DEFAULT_MTU, -1, 2 };
jack_master_t result; jack_master_t result;
printf("Network\n"); printf("Network\n");
//if (audio.Open() < 0) { //if (audio.Open() < 0) {
// fprintf(stderr, "Cannot open audio\n"); // fprintf(stderr, "Cannot open audio\n");
// return 1; // return 1;
//} //}
//audio.Start(); //audio.Start();
// Hang around forever... // Hang around forever...
//while(1) CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.25, false); //while(1) CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.25, false);
if ((net = jack_net_slave_open(TEST_MASTER, DEFAULT_PORT, "iPhone", &request, &result)) == 0) { if ((net = jack_net_slave_open(TEST_MASTER, DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
fprintf(stderr, "jack remote server not running ?\n"); fprintf(stderr, "jack remote server not running ?\n");
return 1; return 1;
} }
jack_set_net_slave_process_callback(net, net_process, NULL); jack_set_net_slave_process_callback(net, net_process, NULL);
// We want to restart (that is "wait for available master" again) // We want to restart (that is "wait for available master" again)
//jack_set_net_shutdown_callback(net, net_shutdown, 0); //jack_set_net_shutdown_callback(net, net_shutdown, 0);
DSP.init(result.sample_rate); DSP.init(result.sample_rate);
DSP.buildUserInterface(interface); DSP.buildUserInterface(interface);
if (jack_net_slave_activate(net) != 0) { if (jack_net_slave_activate(net) != 0) {
fprintf(stderr, "cannot activate net"); fprintf(stderr, "cannot activate net");
return 1; return 1;
} }
int retVal = UIApplicationMain(argc, argv, nil, nil); int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release]; [pool release];
// Wait for application end // Wait for application end
jack_net_slave_deactivate(net); jack_net_slave_deactivate(net);
jack_net_slave_close(net); jack_net_slave_close(net);
//if (audio.Close() < 0) { //if (audio.Close() < 0) {
// fprintf(stderr, "Cannot close audio\n"); // fprintf(stderr, "Cannot close audio\n");
//} //}
return retVal; return retVal;
} }

Loading…
Cancel
Save