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

enum JackNetMode {

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

enum JackNetEncoder {

JackFloatEncoder = 0,


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

@@ -1,6 +1,6 @@
/*
Copyright (C) 2009 Grame
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
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,
int audio_input,
float** audio_input_buffer,
int audio_input,
float** audio_input_buffer,
int midi_input,
void** midi_input_buffer,
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)
{
int i;
// Copy input to output
for (i = 0; i < audio_input; i++) {
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:";
int option_index;
int opt;
struct option long_options[] =
{
{"audio input", 1, 0, 'C'},
@@ -93,36 +93,36 @@ main (int argc, char *argv[])
{"port", 1, 0, 'p'},
{0, 0, 0, 0}
};
while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
switch (opt) {
case 'C':
audio_input = atoi(optarg);
break;
case 'P':
audio_output = atoi(optarg);
break;
case 'a':
multicast_ip = strdup(optarg);
break;
case 'p':
port = atoi(optarg);
break;
case 'h':
usage();
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;
printf("Waiting for a master...\n");

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");
return 1;
}
/* install a signal handler to properly quits jack client */
#ifdef WIN32
signal(SIGINT, signal_handler);
@@ -160,7 +160,7 @@ main (int argc, char *argv[])
sleep(1);
#endif
};
// Wait for application end
jack_net_slave_deactivate(net);
jack_net_slave_close(net);


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

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

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

#define max(x,y) (((x)>(y)) ? (x) : (y))
#define min(x,y) (((x)<(y)) ? (x) : (y))
@@ -91,37 +91,37 @@ class UI
{
bool fStopped;
public:
UI() : fStopped(false) {}
virtual ~UI() {}
// -- active widgets
virtual void addButton(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 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 addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0;
// -- passive widgets
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 addHorizontalBargraph(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
virtual void openFrameBox(const char* label) = 0;
virtual void openTabBox(const char* label) = 0;
virtual void openHorizontalBox(const char* label) = 0;
virtual void openVerticalBox(const char* label) = 0;
virtual void closeBox() = 0;
virtual void show() = 0;
virtual void run() = 0;
void stop() { fStopped = true; }
bool stopped() { return fStopped; }

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

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

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


mydsp DSP;


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

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

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

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

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

}
}
}

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

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,
void** midi_input_buffer,
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)
{
AVOIDDENORMALS;
STARTMESURE
DSP.compute(buffer_size, audio_input_buffer, audio_output_buffer);
STOPMESURE
STOPMESURE
return 0;
}

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

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


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

Loading…
Cancel
Save