Browse Source

NetJack2 code cleanup.

tags/1.9.8
Stephane Letz 13 years ago
parent
commit
734e450924
49 changed files with 1650 additions and 1255 deletions
  1. +151
    -135
      common/JackAudioAdapter.cpp
  2. +6
    -2
      common/JackAudioAdapter.h
  3. +25
    -16
      common/JackAudioAdapterInterface.cpp
  4. +43
    -38
      common/JackAudioAdapterInterface.h
  5. +56
    -46
      common/JackAudioDriver.cpp
  6. +14
    -13
      common/JackAudioDriver.h
  7. +14
    -14
      common/JackDriver.cpp
  8. +57
    -57
      common/JackDriverLoader.cpp
  9. +4
    -4
      common/JackDriverLoader.h
  10. +13
    -1
      common/JackDummyDriver.h
  11. +4
    -8
      common/JackGraphManager.cpp
  12. +1
    -1
      common/JackGraphManager.h
  13. +2
    -1
      common/JackLibSampleRateResampler.cpp
  14. +0
    -10
      common/JackMidiDriver.cpp
  15. +0
    -3
      common/JackMidiDriver.h
  16. +33
    -21
      common/JackNetAPI.cpp
  17. +52
    -34
      common/JackNetAdapter.cpp
  18. +1
    -1
      common/JackNetAdapter.h
  19. +45
    -34
      common/JackNetDriver.cpp
  20. +2
    -9
      common/JackNetDriver.h
  21. +119
    -124
      common/JackNetOneDriver.cpp
  22. +4
    -6
      common/JackNetOneDriver.h
  23. +3
    -2
      common/JackResampler.cpp
  24. +11
    -11
      common/JackThreadedDriver.cpp
  25. +35
    -32
      common/JackTimedDriver.cpp
  26. +23
    -9
      common/JackTimedDriver.h
  27. +3
    -3
      common/JackWaitThreadedDriver.cpp
  28. +2
    -2
      common/JackWaitThreadedDriver.h
  29. +2
    -4
      common/jack/session.h
  30. +1
    -1
      common/jack/thread.h
  31. +30
    -34
      example-clients/cpu_load.c
  32. +4
    -4
      example-clients/netmaster.c
  33. +4
    -4
      example-clients/netslave.c
  34. +31
    -31
      example-clients/wait.c
  35. +2
    -2
      linux/alsa/JackAlsaAdapter.cpp
  36. +13
    -5
      macosx/Jackdmp.xcodeproj/project.pbxproj
  37. +217
    -48
      macosx/coreaudio/JackCoreAudioAdapter.cpp
  38. +18
    -7
      macosx/coreaudio/JackCoreAudioAdapter.h
  39. +108
    -40
      macosx/coreaudio/JackCoreAudioDriver.cpp
  40. +2
    -1
      macosx/coreaudio/JackCoreAudioDriver.h
  41. +114
    -97
      posix/JackNetUnixSocket.cpp
  42. +21
    -19
      posix/JackNetUnixSocket.h
  43. +2
    -2
      solaris/oss/JackOSSAdapter.cpp
  44. +33
    -33
      tests/iodelay.cpp
  45. +2
    -2
      windows/portaudio/JackPortAudioAdapter.cpp
  46. +97
    -100
      windows/portaudio/JackPortAudioDevices.cpp
  47. +6
    -2
      windows/portaudio/JackPortAudioDevices.h
  48. +219
    -181
      windows/portaudio/JackPortAudioDriver.cpp
  49. +1
    -1
      windows/portaudio/JackPortAudioDriver.h

+ 151
- 135
common/JackAudioAdapter.cpp View File

@@ -32,172 +32,188 @@ using namespace std;
namespace Jack
{

//static methods ***********************************************************
int JackAudioAdapter::Process (jack_nframes_t frames, void* arg)
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*>(arg);
jack_default_audio_sample_t* inputBuffer[adapter->fAudioAdapter->GetInputs()];
jack_default_audio_sample_t* outputBuffer[adapter->fAudioAdapter->GetOutputs()];

// Always clear output
for (int i = 0; i < adapter->fAudioAdapter->GetInputs(); i++) {
#ifdef OPTIMIZED_PROTOCOL
inputBuffer[i] = (jack_port_connected(adapter->fCapturePortList[i]) > 0)
? (jack_default_audio_sample_t*)(adapter->fCapturePortList[i], frames)
: NULL;
if (inputBuffer[i]) {
memset(inputBuffer[i], 0, frames * sizeof(jack_default_audio_sample_t));
}
#else
inputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fCapturePortList[i], frames);
memset(inputBuffer[i], 0, frames * sizeof(jack_default_audio_sample_t));
#endif
}

for (int i = 0; i < adapter->fAudioAdapter->GetOutputs(); i++) {
#ifdef OPTIMIZED_PROTOCOL
outputBuffer[i] = (jack_port_connected(fAudioCapturePorts[audio_port_index] > 0)
? (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fPlaybackPortList[i], frames)
: NULL;
#else
outputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fPlaybackPortList[i], frames);
#endif
}

adapter->fAudioAdapter->PullAndPush(inputBuffer, outputBuffer, frames);
return 0;
int JackAudioAdapter::Process(jack_nframes_t frames, void* arg)
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*>(arg);
jack_default_audio_sample_t* inputBuffer[adapter->fAudioAdapter->GetInputs()];
jack_default_audio_sample_t* outputBuffer[adapter->fAudioAdapter->GetOutputs()];

// Always clear output
for (int i = 0; i < adapter->fAudioAdapter->GetInputs(); i++) {
inputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fCapturePortList[i], frames);
memset(inputBuffer[i], 0, frames * sizeof(jack_default_audio_sample_t));
}

int JackAudioAdapter::BufferSize ( jack_nframes_t buffer_size, void* arg )
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*> ( arg );
adapter->Reset();
adapter->fAudioAdapter->SetHostBufferSize ( buffer_size );
return 0;
for (int i = 0; i < adapter->fAudioAdapter->GetOutputs(); i++) {
outputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fPlaybackPortList[i], frames);
}

int JackAudioAdapter::SampleRate ( jack_nframes_t sample_rate, void* arg )
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*> ( arg );
adapter->Reset();
adapter->fAudioAdapter->SetHostSampleRate ( sample_rate );
return 0;
}
adapter->fAudioAdapter->PullAndPush(inputBuffer, outputBuffer, frames);
return 0;
}

int JackAudioAdapter::BufferSize(jack_nframes_t buffer_size, void* arg)
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*>(arg);
adapter->Reset();
adapter->fAudioAdapter->SetHostBufferSize(buffer_size);
return 0;
}

//JackAudioAdapter *********************************************************
int JackAudioAdapter::SampleRate(jack_nframes_t sample_rate, void* arg)
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*>(arg);
adapter->Reset();
adapter->fAudioAdapter->SetHostSampleRate(sample_rate);
return 0;
}

JackAudioAdapter::JackAudioAdapter (jack_client_t* jack_client, JackAudioAdapterInterface* audio_io, const JSList* params, bool system)
:fJackClient(jack_client), fAudioAdapter(audio_io)
{
const JSList* node;
const jack_driver_param_t* param;
fAutoConnect = false;
void JackAudioAdapter::Latency(jack_latency_callback_mode_t mode, void* arg)
{
JackAudioAdapter* adapter = static_cast<JackAudioAdapter*>(arg);

for (node = params; node; node = jack_slist_next(node)) {
param = (const jack_driver_param_t*) node->data;
switch (param->character) {
case 'c':
fAutoConnect = true;
break;
}
if (mode == JackCaptureLatency) {
for (int i = 0; i < adapter->fAudioAdapter->GetInputs(); i++) {
jack_latency_range_t range;
range.min = range.max = adapter->fAudioAdapter->GetInputLatency(i);
jack_port_set_latency_range(adapter->fCapturePortList[i], JackCaptureLatency, &range);
}

} else {
for (int i = 0; i < adapter->fAudioAdapter->GetOutputs(); i++) {
jack_latency_range_t range;
range.min = range.max = adapter->fAudioAdapter->GetOutputLatency(i);
jack_port_set_latency_range(adapter->fPlaybackPortList[i], JackPlaybackLatency, &range);
}
}
}

JackAudioAdapter::~JackAudioAdapter()
{
// When called, Close has already been used for the client, thus ports are already unregistered.
delete fAudioAdapter;
JackAudioAdapter::JackAudioAdapter(jack_client_t* client, JackAudioAdapterInterface* audio_io, const JSList* params)
:fClient(client), fAudioAdapter(audio_io)
{
const JSList* node;
const jack_driver_param_t* param;
fAutoConnect = false;

for (node = params; node; node = jack_slist_next(node)) {
param = (const jack_driver_param_t*)node->data;
switch (param->character) {
case 'c':
fAutoConnect = true;
break;
}
}
}

void JackAudioAdapter::FreePorts()
{
for (int i = 0; i < fAudioAdapter->GetInputs(); i++ )
if ( fCapturePortList[i] )
jack_port_unregister ( fJackClient, fCapturePortList[i] );
for (int i = 0; i < fAudioAdapter->GetOutputs(); i++ )
if ( fPlaybackPortList[i] )
jack_port_unregister ( fJackClient, fPlaybackPortList[i] );
JackAudioAdapter::~JackAudioAdapter()
{
// When called, Close has already been used for the client, thus ports are already unregistered.
delete fAudioAdapter;
}

delete[] fCapturePortList;
delete[] fPlaybackPortList;
void JackAudioAdapter::FreePorts()
{
for (int i = 0; i < fAudioAdapter->GetInputs(); i++) {
if (fCapturePortList[i]) {
jack_port_unregister(fClient, fCapturePortList[i]);
}
}
for (int i = 0; i < fAudioAdapter->GetOutputs(); i++) {
if (fPlaybackPortList[i]) {
jack_port_unregister(fClient, fPlaybackPortList[i]);
}
}

void JackAudioAdapter::ConnectPorts()
{
const char **ports;
delete[] fCapturePortList;
delete[] fPlaybackPortList;
}

ports = jack_get_ports(fJackClient, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
if (ports != NULL) {
for (int i = 0; i < fAudioAdapter->GetInputs() && ports[i]; i++) {
jack_connect(fJackClient, jack_port_name(fCapturePortList[i]), ports[i]);
}
free(ports);
}
void JackAudioAdapter::ConnectPorts()
{
const char** ports;

ports = jack_get_ports(fJackClient, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
if (ports != NULL) {
for (int i = 0; i < fAudioAdapter->GetOutputs() && ports[i]; i++) {
jack_connect(fJackClient, ports[i], jack_port_name(fPlaybackPortList[i]));
}
free(ports);
ports = jack_get_ports(fClient, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
if (ports != NULL) {
for (int i = 0; i < fAudioAdapter->GetInputs() && ports[i]; i++) {
jack_connect(fClient,jack_port_name(fCapturePortList[i]), ports[i]);
}
jack_free(ports);
}

void JackAudioAdapter::Reset()
{
fAudioAdapter->Reset();
ports = jack_get_ports(fClient, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
if (ports != NULL) {
for (int i = 0; i < fAudioAdapter->GetOutputs() && ports[i]; i++) {
jack_connect(fClient, ports[i], jack_port_name(fPlaybackPortList[i]));
}
jack_free(ports);
}
}

int JackAudioAdapter::Open()
{
char name[32];
jack_log("JackAudioAdapter::Open fCaptureChannels %d fPlaybackChannels %d", fAudioAdapter->GetInputs(), fAudioAdapter->GetOutputs());
fAudioAdapter->Create();
void JackAudioAdapter::Reset()
{
fAudioAdapter->Reset();
}

//jack ports
fCapturePortList = new jack_port_t*[fAudioAdapter->GetInputs()];
fPlaybackPortList = new jack_port_t*[fAudioAdapter->GetOutputs()];
int JackAudioAdapter::Open()
{
char name[32];
jack_log("JackAudioAdapter::Open fCaptureChannels %d fPlaybackChannels %d", fAudioAdapter->GetInputs(), fAudioAdapter->GetOutputs());
fAudioAdapter->Create();

for (int i = 0; i < fAudioAdapter->GetInputs(); i++) {
sprintf(name, "capture_%d", i + 1);
if ((fCapturePortList[i] = jack_port_register(fJackClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) == NULL)
goto fail;
}
//jack ports
fCapturePortList = new jack_port_t*[fAudioAdapter->GetInputs()];
fPlaybackPortList = new jack_port_t*[fAudioAdapter->GetOutputs()];

for (int i = 0; i < fAudioAdapter->GetOutputs(); i++) {
sprintf(name, "playback_%d", i + 1);
if ((fPlaybackPortList[i] = jack_port_register(fJackClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)) == NULL)
goto fail;
for (int i = 0; i < fAudioAdapter->GetInputs(); i++) {
sprintf(name, "capture_%d", i + 1);
if ((fCapturePortList[i] = jack_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, CaptureDriverFlags, 0)) == NULL) {
goto fail;
}
}

//callbacks and activation
if (jack_set_process_callback(fJackClient, Process, this) < 0)
goto fail;
if (jack_set_buffer_size_callback(fJackClient, BufferSize, this) < 0)
for (int i = 0; i < fAudioAdapter->GetOutputs(); i++) {
sprintf(name, "playback_%d", i + 1);
if ((fPlaybackPortList[i] = jack_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, PlaybackDriverFlags, 0)) == NULL) {
goto fail;
if (jack_set_sample_rate_callback(fJackClient, SampleRate, this) < 0)
goto fail;
if (jack_activate(fJackClient) < 0)
goto fail;

if (fAutoConnect)
ConnectPorts();

// Ring buffers are now allocated..
return fAudioAdapter->Open();
return 0;
}
}

fail:
FreePorts();
fAudioAdapter->Destroy();
return -1;
//callbacks and activation
if (jack_set_process_callback(fClient, Process, this) < 0) {
goto fail;
}
if (jack_set_buffer_size_callback(fClient, BufferSize, this) < 0) {
goto fail;
}
if (jack_set_sample_rate_callback(fClient, SampleRate, this) < 0) {
goto fail;
}
if (jack_set_latency_callback(fClient, Latency, this) < 0) {
goto fail;
}
if (jack_activate(fClient) < 0) {
goto fail;
}

int JackAudioAdapter::Close()
{
fAudioAdapter->Close();
fAudioAdapter->Destroy();
return 0;
if (fAutoConnect) {
ConnectPorts();
}

// Ring buffers are now allocated...
return fAudioAdapter->Open();
return 0;

fail:
FreePorts();
fAudioAdapter->Destroy();
return -1;
}

int JackAudioAdapter::Close()
{
fAudioAdapter->Close();
fAudioAdapter->Destroy();
return 0;
}

} //namespace

+ 6
- 2
common/JackAudioAdapter.h View File

@@ -37,11 +37,12 @@ namespace Jack
static int Process(jack_nframes_t, void* arg);
static int BufferSize(jack_nframes_t buffer_size, void* arg);
static int SampleRate(jack_nframes_t sample_rate, void* arg);
static void Latency(jack_latency_callback_mode_t mode, void* arg);

jack_port_t** fCapturePortList;
jack_port_t** fPlaybackPortList;

jack_client_t* fJackClient;
jack_client_t* fClient;
JackAudioAdapterInterface* fAudioAdapter;
bool fAutoConnect;

@@ -51,7 +52,7 @@ namespace Jack

public:

JackAudioAdapter(jack_client_t* jack_client, JackAudioAdapterInterface* audio_io, const JSList* params = NULL, bool system = false);
JackAudioAdapter(jack_client_t* client, JackAudioAdapterInterface* audio_io, const JSList* params = NULL);
~JackAudioAdapter();

int Open();
@@ -60,4 +61,7 @@ namespace Jack

}

#define CaptureDriverFlags static_cast<JackPortFlags>(JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal)
#define PlaybackDriverFlags static_cast<JackPortFlags>(JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal)

#endif

+ 25
- 16
common/JackAudioAdapterInterface.cpp View File

@@ -49,8 +49,7 @@ namespace Jack
FILE* file = fopen("JackAudioAdapter.log", "w");

int max = (fCount) % TABLE_MAX - 1;
for (int i = 1; i < max; i++)
{
for (int i = 1; i < max; i++) {
fprintf(file, "%d \t %d \t %d \t %f \t %f \t %d \t %d \n",
fTable[i].delta, fTable[i].time1, fTable[i].time2,
fTable[i].r1, fTable[i].r2, fTable[i].pos1, fTable[i].pos2);
@@ -158,21 +157,25 @@ namespace Jack

void JackAudioAdapterInterface::AdaptRingBufferSize()
{
if (fHostBufferSize > fAdaptedBufferSize)
if (fHostBufferSize > fAdaptedBufferSize) {
fRingbufferCurSize = 4 * fHostBufferSize;
else
} else {
fRingbufferCurSize = 4 * fAdaptedBufferSize;
}
}

void JackAudioAdapterInterface::ResetRingBuffers()
{
if (fRingbufferCurSize > DEFAULT_RB_SIZE)
if (fRingbufferCurSize > DEFAULT_RB_SIZE) {
fRingbufferCurSize = DEFAULT_RB_SIZE;
}

for (int i = 0; i < fCaptureChannels; i++)
for (int i = 0; i < fCaptureChannels; i++) {
fCaptureRingBuffer[i]->Reset(fRingbufferCurSize);
for (int i = 0; i < fPlaybackChannels; i++)
}
for (int i = 0; i < fPlaybackChannels; i++) {
fPlaybackRingBuffer[i]->Reset(fRingbufferCurSize);
}
}

void JackAudioAdapterInterface::Reset()
@@ -195,8 +198,9 @@ namespace Jack
AdaptRingBufferSize();
jack_info("Ringbuffer automatic adaptative mode size = %d frames", fRingbufferCurSize);
} else {
if (fRingbufferCurSize > DEFAULT_RB_SIZE)
if (fRingbufferCurSize > DEFAULT_RB_SIZE) {
fRingbufferCurSize = DEFAULT_RB_SIZE;
}
jack_info("Fixed ringbuffer size = %d frames", fRingbufferCurSize);
}

@@ -209,19 +213,23 @@ namespace Jack
fPlaybackRingBuffer[i]->Reset(fRingbufferCurSize);
}

if (fCaptureChannels > 0)
if (fCaptureChannels > 0) {
jack_log("ReadSpace = %ld", fCaptureRingBuffer[0]->ReadSpace());
if (fPlaybackChannels > 0)
}
if (fPlaybackChannels > 0) {
jack_log("WriteSpace = %ld", fPlaybackRingBuffer[0]->WriteSpace());
}
}
#endif

void JackAudioAdapterInterface::Destroy()
{
for (int i = 0; i < fCaptureChannels; i++ )
delete ( fCaptureRingBuffer[i] );
for (int i = 0; i < fPlaybackChannels; i++ )
delete ( fPlaybackRingBuffer[i] );
for (int i = 0; i < fCaptureChannels; i++) {
delete(fCaptureRingBuffer[i]);
}
for (int i = 0; i < fPlaybackChannels; i++) {
delete (fPlaybackRingBuffer[i]);
}

delete[] fCaptureRingBuffer;
delete[] fPlaybackRingBuffer;
@@ -238,10 +246,11 @@ namespace Jack
double ratio = 1;

// TODO : done like this just to avoid crash when input only or output only...
if (fCaptureChannels > 0)
if (fCaptureChannels > 0) {
ratio = fPIControler.GetRatio(fCaptureRingBuffer[0]->GetError() - delta_frames);
else if (fPlaybackChannels > 0)
} else if (fPlaybackChannels > 0) {
ratio = fPIControler.GetRatio(fPlaybackRingBuffer[0]->GetError() - delta_frames);
}

#ifdef JACK_MONITOR
if (fCaptureRingBuffer && fCaptureRingBuffer[0] != NULL)


+ 43
- 38
common/JackAudioAdapterInterface.h View File

@@ -49,7 +49,7 @@ namespace Jack
Measure fTable[TABLE_MAX];
int fCount;

MeasureTable() :fCount ( 0 )
MeasureTable() :fCount(0)
{}

void Write(int time1, int time2, float r1, float r2, int pos1, int pos2);
@@ -102,13 +102,13 @@ namespace Jack

public:

JackAudioAdapterInterface ( jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE):
fCaptureChannels ( 0 ),
fPlaybackChannels ( 0 ),
fHostBufferSize ( buffer_size ),
fHostSampleRate ( sample_rate ),
fAdaptedBufferSize ( buffer_size),
fAdaptedSampleRate ( sample_rate ),
JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE):
fCaptureChannels(0),
fPlaybackChannels(0),
fHostBufferSize(buffer_size),
fHostSampleRate(sample_rate),
fAdaptedBufferSize(buffer_size),
fAdaptedSampleRate(sample_rate),
fPIControler(sample_rate / sample_rate, 256),
fCaptureRingBuffer(NULL), fPlaybackRingBuffer(NULL),
fQuality(0),
@@ -117,23 +117,23 @@ namespace Jack
fRunning(false),
fAdaptative(true)
{}
JackAudioAdapterInterface ( jack_nframes_t host_buffer_size,
JackAudioAdapterInterface(jack_nframes_t host_buffer_size,
jack_nframes_t host_sample_rate,
jack_nframes_t adapted_buffer_size,
jack_nframes_t adapted_sample_rate,
jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE ) :
fCaptureChannels ( 0 ),
fPlaybackChannels ( 0 ),
fHostBufferSize ( host_buffer_size ),
fHostSampleRate ( host_sample_rate ),
fAdaptedBufferSize ( adapted_buffer_size),
fAdaptedSampleRate ( adapted_sample_rate ),
fPIControler(host_sample_rate / host_sample_rate, 256),
fQuality(0),
fRingbufferCurSize(ring_buffer_size),
fPullAndPushTime(0),
fRunning(false),
fAdaptative(true)
jack_nframes_t ring_buffer_size = DEFAULT_ADAPTATIVE_SIZE) :
fCaptureChannels(0),
fPlaybackChannels(0),
fHostBufferSize(host_buffer_size),
fHostSampleRate(host_sample_rate),
fAdaptedBufferSize(adapted_buffer_size),
fAdaptedSampleRate(adapted_sample_rate),
fPIControler(host_sample_rate / host_sample_rate, 256),
fQuality(0),
fRingbufferCurSize(ring_buffer_size),
fPullAndPushTime(0),
fRunning(false),
fAdaptative(true)
{}

virtual ~JackAudioAdapterInterface()
@@ -154,59 +154,61 @@ namespace Jack
return 0;
}

virtual int SetHostBufferSize ( jack_nframes_t buffer_size )
virtual int SetHostBufferSize(jack_nframes_t buffer_size)
{
fHostBufferSize = buffer_size;
if (fAdaptative)
if (fAdaptative) {
AdaptRingBufferSize();
}
return 0;
}

virtual int SetAdaptedBufferSize ( jack_nframes_t buffer_size )
virtual int SetAdaptedBufferSize(jack_nframes_t buffer_size)
{
fAdaptedBufferSize = buffer_size;
if (fAdaptative)
if (fAdaptative) {
AdaptRingBufferSize();
}
return 0;
}

virtual int SetBufferSize ( jack_nframes_t buffer_size )
virtual int SetBufferSize(jack_nframes_t buffer_size)
{
SetHostBufferSize ( buffer_size );
SetAdaptedBufferSize ( buffer_size );
SetHostBufferSize(buffer_size);
SetAdaptedBufferSize(buffer_size);
return 0;
}

virtual int SetHostSampleRate ( jack_nframes_t sample_rate )
virtual int SetHostSampleRate(jack_nframes_t sample_rate)
{
fHostSampleRate = sample_rate;
fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate));
return 0;
}

virtual int SetAdaptedSampleRate ( jack_nframes_t sample_rate )
virtual int SetAdaptedSampleRate(jack_nframes_t sample_rate)
{
fAdaptedSampleRate = sample_rate;
fPIControler.Init(double(fHostSampleRate) / double(fAdaptedSampleRate));
return 0;
}

virtual int SetSampleRate ( jack_nframes_t sample_rate )
virtual int SetSampleRate(jack_nframes_t sample_rate)
{
SetHostSampleRate ( sample_rate );
SetAdaptedSampleRate ( sample_rate );
SetHostSampleRate(sample_rate);
SetAdaptedSampleRate(sample_rate);
return 0;
}

void SetInputs ( int inputs )
void SetInputs(int inputs)
{
jack_log ( "JackAudioAdapterInterface::SetInputs %d", inputs );
jack_log("JackAudioAdapterInterface::SetInputs %d", inputs);
fCaptureChannels = inputs;
}

void SetOutputs ( int outputs )
void SetOutputs(int outputs)
{
jack_log ( "JackAudioAdapterInterface::SetOutputs %d", outputs );
jack_log("JackAudioAdapterInterface::SetOutputs %d", outputs);
fPlaybackChannels = outputs;
}

@@ -222,6 +224,9 @@ namespace Jack
return fPlaybackChannels;
}

virtual int GetInputLatency(int port_index) { return 0; }
virtual int GetOutputLatency(int port_index) { return 0; }

int PushAndPull(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);
int PullAndPush(jack_default_audio_sample_t** inputBuffer, jack_default_audio_sample_t** outputBuffer, unsigned int frames);



+ 56
- 46
common/JackAudioDriver.cpp View File

@@ -50,8 +50,9 @@ int JackAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
fEngineControl->fBufferSize = buffer_size;
fGraphManager->SetBufferSize(buffer_size);
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
if (!fEngineControl->fTimeOut) {
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
}

UpdateLatencies();

@@ -63,8 +64,9 @@ int JackAudioDriver::SetSampleRate(jack_nframes_t sample_rate)
{
fEngineControl->fSampleRate = sample_rate;
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
if (!fEngineControl->fTimeOut) {
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
}

return JackDriver::SetSampleRate(sample_rate);
}
@@ -87,7 +89,8 @@ int JackAudioDriver::Open(jack_nframes_t buffer_size,
memset(fCapturePortList, 0, sizeof(jack_port_id_t) * DRIVER_PORT_NUM);
memset(fPlaybackPortList, 0, sizeof(jack_port_id_t) * DRIVER_PORT_NUM);
memset(fMonitorPortList, 0, sizeof(jack_port_id_t) * DRIVER_PORT_NUM);
return JackDriver::Open(buffer_size, samplerate, capturing, playing, inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency);
return JackDriver::Open(buffer_size, samplerate, capturing, playing, inchannels, outchannels,
monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency);
}

int JackAudioDriver::Open(bool capturing,
@@ -106,26 +109,32 @@ int JackAudioDriver::Open(bool capturing,
memset(fCapturePortList, 0, sizeof(jack_port_id_t) * DRIVER_PORT_NUM);
memset(fPlaybackPortList, 0, sizeof(jack_port_id_t) * DRIVER_PORT_NUM);
memset(fMonitorPortList, 0, sizeof(jack_port_id_t) * DRIVER_PORT_NUM);
return JackDriver::Open(capturing, playing, inchannels, outchannels, monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency);
return JackDriver::Open(capturing, playing, inchannels, outchannels,
monitor, capture_driver_name, playback_driver_name, capture_latency, playback_latency);
}

void JackAudioDriver::UpdateLatencies()
{
jack_latency_range_t range;
jack_latency_range_t input_range;
jack_latency_range_t output_range;
jack_latency_range_t monitor_range;

for (int i = 0; i < fCaptureChannels; i++) {
range.max = range.min = fEngineControl->fBufferSize;
fGraphManager->GetPort(fCapturePortList[i])->SetLatencyRange(JackCaptureLatency, &range);
input_range.max = input_range.min = fEngineControl->fBufferSize + fCaptureLatency;
fGraphManager->GetPort(fCapturePortList[i])->SetLatencyRange(JackCaptureLatency, &input_range);
}

for (int i = 0; i < fPlaybackChannels; i++) {
if (! fEngineControl->fSyncMode) {
range.max = range.min = fEngineControl->fBufferSize * 2;
output_range.max = output_range.min = fPlaybackLatency;
if (fEngineControl->fSyncMode) {
output_range.max = output_range.min += fEngineControl->fBufferSize;
} else {
output_range.max = output_range.min += fEngineControl->fBufferSize * 2;
}
fGraphManager->GetPort(fPlaybackPortList[i])->SetLatencyRange(JackPlaybackLatency, &range);
fGraphManager->GetPort(fPlaybackPortList[i])->SetLatencyRange(JackPlaybackLatency, &output_range);
if (fWithMonitorPorts) {
range.min = range.max = fEngineControl->fBufferSize;
fGraphManager->GetPort(fMonitorPortList[i])->SetLatencyRange(JackCaptureLatency, &range);
monitor_range.min = monitor_range.max = fEngineControl->fBufferSize;
fGraphManager->GetPort(fMonitorPortList[i])->SetLatencyRange(JackCaptureLatency, &monitor_range);
}
}
}
@@ -220,6 +229,16 @@ int JackAudioDriver::Process()
return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync();
}

void JackAudioDriver::ProcessGraphAsync()
{
// Process graph
if (fIsMaster) {
ProcessGraphAsyncMaster();
} else {
ProcessGraphAsyncSlave();
}
}

/*
The driver ASYNC mode: output buffers computed at the *previous cycle* are used, the server does not
synchronize to the end of client graph execution.
@@ -240,17 +259,30 @@ int JackAudioDriver::ProcessAsync()
}

// Process graph
if (fIsMaster) {
ProcessGraphAsyncMaster();
} else {
ProcessGraphAsyncSlave();
}
ProcessGraphAsync();

// Keep end cycle time
JackDriver::CycleTakeEndTime();
return 0;
}

void JackAudioDriver::ProcessGraphSync()
{
// Process graph
if (fIsMaster) {
if (ProcessGraphSyncMaster() < 0) {
//jack_error("JackAudioDriver::ProcessSync: process error, skip cycle...");
//goto end;
}
} else {
if (ProcessGraphSyncSlave() < 0) {
//jack_error("JackAudioDriver::ProcessSync: process error, skip cycle...");
//goto end;
}
}
}


/*
The driver SYNC mode: the server does synchronize to the end of client graph execution,
if graph process succeed, output buffers computed at the *current cycle* are used.
@@ -265,17 +297,7 @@ int JackAudioDriver::ProcessSync()
}

// Process graph
if (fIsMaster) {
if (ProcessGraphSyncMaster() < 0) {
//jack_error("JackAudioDriver::ProcessSync: process error, skip cycle...");
//goto end;
}
} else {
if (ProcessGraphSyncSlave() < 0) {
//jack_error("JackAudioDriver::ProcessSync: process error, skip cycle...");
//goto end;
}
}
ProcessGraphSync();

// Write output buffers from the current cycle
if (Write() < 0) {
@@ -283,8 +305,6 @@ int JackAudioDriver::ProcessSync()
return -1;
}

end:

// Keep end cycle time
JackDriver::CycleTakeEndTime();
return 0;
@@ -371,34 +391,24 @@ int JackAudioDriver::Stop()
return res;
}

/*
void JackAudioDriver::WaitUntilNextCycle()
{
int wait_time_usec = (int((float(fEngineControl->fBufferSize) / (float(fEngineControl->fSampleRate))) * 1000000.0f));
wait_time_usec = int(wait_time_usec - (GetMicroSeconds() - fBeginDateUst));
if (wait_time_usec > 0)
JackSleep(wait_time_usec);
}
*/

jack_default_audio_sample_t* JackAudioDriver::GetInputBuffer(int port_index, bool nulled)
jack_default_audio_sample_t* JackAudioDriver::GetInputBuffer(int port_index)
{
return fCapturePortList[port_index]
? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize, nulled)
? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize)
: NULL;
}

jack_default_audio_sample_t* JackAudioDriver::GetOutputBuffer(int port_index, bool nulled)
jack_default_audio_sample_t* JackAudioDriver::GetOutputBuffer(int port_index)
{
return fPlaybackPortList[port_index]
? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize, nulled)
? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize)
: NULL;
}

jack_default_audio_sample_t* JackAudioDriver::GetMonitorBuffer(int port_index, bool nulled)
jack_default_audio_sample_t* JackAudioDriver::GetMonitorBuffer(int port_index)
{
return fPlaybackPortList[port_index]
? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[port_index], fEngineControl->fBufferSize, nulled)
? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[port_index], fEngineControl->fBufferSize)
: NULL;
}



+ 14
- 13
common/JackAudioDriver.h View File

@@ -35,15 +35,6 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver

protected:

void ProcessGraphAsyncMaster();
void ProcessGraphAsyncSlave();

int ProcessGraphSyncMaster();
int ProcessGraphSyncSlave();

virtual int ProcessAsync();
virtual int ProcessSync();

int fCaptureChannels;
int fPlaybackChannels;

@@ -57,12 +48,22 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver

std::list<std::pair<std::string, std::string> > fConnections; // Connections list

jack_default_audio_sample_t* GetInputBuffer(int port_index, bool nulled = false);
jack_default_audio_sample_t* GetOutputBuffer(int port_index, bool nulled = false);
jack_default_audio_sample_t* GetMonitorBuffer(int port_index, bool nulled = false);
jack_default_audio_sample_t* GetInputBuffer(int port_index);
jack_default_audio_sample_t* GetOutputBuffer(int port_index);
jack_default_audio_sample_t* GetMonitorBuffer(int port_index);

void HandleLatencyCallback(int status);
void UpdateLatencies();
virtual void UpdateLatencies();

int ProcessAsync();
void ProcessGraphAsync();
void ProcessGraphAsyncMaster();
void ProcessGraphAsyncSlave();

int ProcessSync();
void ProcessGraphSync();
int ProcessGraphSyncMaster();
int ProcessGraphSyncSlave();

public:



+ 14
- 14
common/JackDriver.cpp View File

@@ -124,8 +124,9 @@ int JackDriver::Open(bool capturing,
strcpy(fPlaybackDriverName, playback_driver_name);

fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
if (!fEngineControl->fTimeOut) {
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
}

fGraphManager->DirectConnect(fClientControl.fRefNum, fClientControl.fRefNum); // Connect driver to itself for "sync" mode
SetupDriverSync(fClientControl.fRefNum, false);
@@ -177,8 +178,9 @@ int JackDriver::Open(jack_nframes_t buffer_size,
strcpy(fPlaybackDriverName, playback_driver_name);

fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
if (!fEngineControl->fTimeOut) {
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
}

fGraphManager->SetBufferSize(buffer_size);
fGraphManager->DirectConnect(fClientControl.fRefNum, fClientControl.fRefNum); // Connect driver to itself for "sync" mode
@@ -309,9 +311,9 @@ int JackDriver::ProcessReadSlaves()
list<JackDriverInterface*>::const_iterator it;
for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) {
JackDriverInterface* slave = *it;
if (slave->ProcessRead() < 0)
if (slave->ProcessRead() < 0) {
res = -1;
}
}
return res;
}
@@ -322,9 +324,9 @@ int JackDriver::ProcessWriteSlaves()
list<JackDriverInterface*>::const_iterator it;
for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) {
JackDriverInterface* slave = *it;
if (slave->ProcessWrite() < 0)
if (slave->ProcessWrite() < 0) {
res = -1;
}
}
return res;
}
@@ -387,10 +389,8 @@ int JackDriver::StartSlaves()
JackDriverInterface* slave = *it;
if (slave->Start() < 0) {
res = -1;

// XXX: We should attempt to stop all of the slaves that we've
// started here.

break;
}
}
@@ -403,8 +403,9 @@ int JackDriver::StopSlaves()
list<JackDriverInterface*>::const_iterator it;
for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) {
JackDriverInterface* slave = *it;
if (slave->Stop() < 0)
if (slave->Stop() < 0) {
res = -1;
}
}
return res;
}
@@ -417,14 +418,13 @@ bool JackDriver::IsFixedBufferSize()
int JackDriver::SetBufferSize(jack_nframes_t buffer_size)
{
int res = 0;

list<JackDriverInterface*>::const_iterator it;
for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) {
JackDriverInterface* slave = *it;
if (slave->SetBufferSize(buffer_size) < 0)
if (slave->SetBufferSize(buffer_size) < 0) {
res = -1;
}
}

return res;
}

@@ -434,8 +434,9 @@ int JackDriver::SetSampleRate(jack_nframes_t sample_rate)
list<JackDriverInterface*>::const_iterator it;
for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) {
JackDriverInterface* slave = *it;
if (slave->SetSampleRate(sample_rate) < 0)
if (slave->SetSampleRate(sample_rate) < 0) {
res = -1;
}
}
return res;
}
@@ -445,5 +446,4 @@ bool JackDriver::Initialize()
return true;
}


} // end of namespace

+ 57
- 57
common/JackDriverLoader.cpp View File

@@ -31,7 +31,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <dirent.h>
#endif

jack_driver_desc_t * jackctl_driver_get_desc(jackctl_driver_t * driver);
jack_driver_desc_t* jackctl_driver_get_desc(jackctl_driver_t * driver);

SERVER_EXPORT void jack_print_driver_options(jack_driver_desc_t* desc, FILE* file)
{
@@ -50,17 +50,18 @@ SERVER_EXPORT void jack_print_driver_options(jack_driver_desc_t* desc, FILE* fil
sprintf (arg_default, "%c", desc->params[i].value.c);
break;
case JackDriverParamString:
if (desc->params[i].value.str && strcmp (desc->params[i].value.str, "") != 0)
if (desc->params[i].value.str && strcmp (desc->params[i].value.str, "") != 0) {
sprintf (arg_default, "%s", desc->params[i].value.str);
else
} else {
sprintf (arg_default, "none");
}
break;
case JackDriverParamBool:
sprintf (arg_default, "%s", desc->params[i].value.i ? "true" : "false");
break;
}

fprintf (file, "\t-%c, --%s \t%s (default: %s)\n",
fprintf(file, "\t-%c, --%s \t%s (default: %s)\n",
desc->params[i].character,
desc->params[i].name,
desc->params[i].long_desc,
@@ -69,7 +70,7 @@ SERVER_EXPORT void jack_print_driver_options(jack_driver_desc_t* desc, FILE* fil
}

static void
jack_print_driver_param_usage (jack_driver_desc_t * desc, unsigned long param, FILE *file)
jack_print_driver_param_usage (jack_driver_desc_t* desc, unsigned long param, FILE *file)
{
fprintf (file, "Usage information for the '%s' parameter for driver '%s':\n",
desc->params[param].name, desc->name);
@@ -78,8 +79,8 @@ jack_print_driver_param_usage (jack_driver_desc_t * desc, unsigned long param, F

SERVER_EXPORT void jack_free_driver_params(JSList * driver_params)
{
JSList *node_ptr = driver_params;
JSList *next_node_ptr;
JSList*node_ptr = driver_params;
JSList*next_node_ptr;

while (node_ptr) {
next_node_ptr = node_ptr->next;
@@ -90,14 +91,14 @@ SERVER_EXPORT void jack_free_driver_params(JSList * driver_params)
}

SERVER_EXPORT int
jack_parse_driver_params(jack_driver_desc_t * desc, int argc, char* argv[], JSList ** param_ptr)
jack_parse_driver_params(jack_driver_desc_t* desc, int argc, char* argv[], JSList** param_ptr)
{
struct option * long_options;
char * options, * options_ptr;
char* options, * options_ptr;
unsigned long i;
int opt;
unsigned int param_index;
JSList * params = NULL;
JSList* params = NULL;
jack_driver_param_t * driver_param;

if (argc <= 1) {
@@ -192,11 +193,8 @@ jack_parse_driver_params(jack_driver_desc_t * desc, int argc, char* argv[], JSLi
strcasecmp("0", optarg) == 0 ||
strcasecmp("(null)", optarg) == 0 ) {
driver_param->value.i = false;

} else {

driver_param->value.i = true;

}
break;
}
@@ -214,31 +212,33 @@ jack_parse_driver_params(jack_driver_desc_t * desc, int argc, char* argv[], JSLi
free (options);
free (long_options);

if (param_ptr)
if (param_ptr) {
*param_ptr = params;
}
return 0;
}

SERVER_EXPORT int
jackctl_parse_driver_params(jackctl_driver *driver_ptr, int argc, char* argv[])
{
struct option * long_options;
char * options, * options_ptr;
struct option* long_options;
char* options, * options_ptr;
unsigned long i;
int opt;
JSList * node_ptr;
JSList* node_ptr;
jackctl_parameter_t * param = NULL;
union jackctl_parameter_value value;

if (argc <= 1)
if (argc <= 1) {
return 0;
}

const JSList * driver_params = jackctl_driver_get_parameters(driver_ptr);
if (driver_params == NULL)
const JSList* driver_params = jackctl_driver_get_parameters(driver_ptr);
if (driver_params == NULL) {
return 1;
}

jack_driver_desc_t * desc = jackctl_driver_get_desc(driver_ptr);
jack_driver_desc_t* desc = jackctl_driver_get_desc(driver_ptr);

/* check for help */
if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) {
@@ -352,14 +352,14 @@ jackctl_parse_driver_params(jackctl_driver *driver_ptr, int argc, char* argv[])
return 0;
}

jack_driver_desc_t *
jack_find_driver_descriptor (JSList * drivers, const char * name)
jack_driver_desc_t*
jack_find_driver_descriptor (JSList * drivers, const char* name)
{
jack_driver_desc_t * desc = 0;
JSList * node;
jack_driver_desc_t* desc = 0;
JSList* node;

for (node = drivers; node; node = jack_slist_next (node)) {
desc = (jack_driver_desc_t *) node->data;
desc = (jack_driver_desc_t*) node->data;

if (strcmp (desc->name, name) != 0) {
desc = NULL;
@@ -371,18 +371,18 @@ jack_find_driver_descriptor (JSList * drivers, const char * name)
return desc;
}

static jack_driver_desc_t *
jack_get_descriptor (JSList * drivers, const char * sofile, const char * symbol)
static jack_driver_desc_t*
jack_get_descriptor (JSList * drivers, const char* sofile, const char* symbol)
{
jack_driver_desc_t * descriptor, * other_descriptor;
jack_driver_desc_t* descriptor, * other_descriptor;
JackDriverDescFunction so_get_descriptor = NULL;
JSList * node;
JSList* node;
void * dlhandle;
char * filename;
char* filename;
#ifdef WIN32
int dlerr;
#else
const char * dlerr;
const char* dlerr;
#endif

int err;
@@ -410,7 +410,7 @@ jack_get_descriptor (JSList * drivers, const char * sofile, const char * symbol)
#endif
}

filename = (char *)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1);
filename = (char*)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1);
sprintf (filename, "%s/%s", driver_dir, sofile);

if ((dlhandle = LoadDriverModule(filename)) == NULL) {
@@ -458,7 +458,7 @@ jack_get_descriptor (JSList * drivers, const char * sofile, const char * symbol)

/* check it doesn't exist already */
for (node = drivers; node; node = jack_slist_next (node)) {
other_descriptor = (jack_driver_desc_t *) node->data;
other_descriptor = (jack_driver_desc_t*) node->data;

if (strcmp(descriptor->name, other_descriptor->name) == 0) {
jack_error("the drivers in '%s' and '%s' both have the name '%s'; using the first",
@@ -502,7 +502,7 @@ static bool check_symbol(const char* sofile, const char* symbol)
#endif
}

char* filename = (char *)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1);
char* filename = (char*)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1);
sprintf (filename, "%s/%s", driver_dir, sofile);

if ((dlhandle = LoadDriverModule(filename)) == NULL) {
@@ -524,14 +524,14 @@ static bool check_symbol(const char* sofile, const char* symbol)

JSList *
jack_drivers_load (JSList * drivers) {
char * driver_dir;
char* driver_dir;
char driver_dir_storage[512];
char dll_filename[512];
WIN32_FIND_DATA filedata;
HANDLE file;
const char * ptr = NULL;
JSList * driver_list = NULL;
jack_driver_desc_t * desc = NULL;
const char* ptr = NULL;
JSList* driver_list = NULL;
jack_driver_desc_t* desc = NULL;

if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
// for WIN32 ADDON_DIR is defined in JackConstants.h as relative path
@@ -601,10 +601,10 @@ JSList *
jack_drivers_load (JSList * drivers) {
struct dirent * dir_entry;
DIR * dir_stream;
const char * ptr;
const char* ptr;
int err;
JSList * driver_list = NULL;
jack_driver_desc_t * desc = NULL;
JSList* driver_list = NULL;
jack_driver_desc_t* desc = NULL;

const char* driver_dir;
if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
@@ -669,14 +669,14 @@ jack_drivers_load (JSList * drivers) {

JSList *
jack_internals_load (JSList * internals) {
char * driver_dir;
char* driver_dir;
char driver_dir_storage[512];
char dll_filename[512];
WIN32_FIND_DATA filedata;
HANDLE file;
const char * ptr = NULL;
JSList * driver_list = NULL;
jack_driver_desc_t * desc;
const char* ptr = NULL;
JSList* driver_list = NULL;
jack_driver_desc_t* desc;

if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
// for WIN32 ADDON_DIR is defined in JackConstants.h as relative path
@@ -742,10 +742,10 @@ JSList *
jack_internals_load (JSList * internals) {
struct dirent * dir_entry;
DIR * dir_stream;
const char * ptr;
const char* ptr;
int err;
JSList * driver_list = NULL;
jack_driver_desc_t * desc;
JSList* driver_list = NULL;
jack_driver_desc_t* desc;

const char* driver_dir;
if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
@@ -809,7 +809,7 @@ Jack::JackDriverClientInterface* JackDriverInfo::Open(jack_driver_desc_t* driver
#ifdef WIN32
int errstr;
#else
const char * errstr;
const char* errstr;
#endif

fHandle = LoadDriverModule (driver_desc->file);
@@ -852,7 +852,7 @@ JackDriverInfo::~JackDriverInfo()
}

SERVER_EXPORT
jack_driver_desc_t *
jack_driver_desc_t*
jack_driver_descriptor_construct(
const char * name,
jack_driver_type_t type,
@@ -861,7 +861,7 @@ jack_driver_descriptor_construct(
{
size_t name_len;
size_t description_len;
jack_driver_desc_t * desc_ptr;
jack_driver_desc_t* desc_ptr;

name_len = strlen(name);
description_len = strlen(description);
@@ -894,15 +894,15 @@ jack_driver_descriptor_construct(
SERVER_EXPORT
int
jack_driver_descriptor_add_parameter(
jack_driver_desc_t * desc_ptr,
jack_driver_desc_t* desc_ptr,
jack_driver_desc_filler_t * filler_ptr,
const char * name,
const char* name,
char character,
jack_driver_param_type_t type,
const jack_driver_param_value_t * value_ptr,
jack_driver_param_constraint_desc_t * constraint,
const char * short_desc,
const char * long_desc)
const char* short_desc,
const char* long_desc)
{
size_t name_len;
size_t short_desc_len;


+ 4
- 4
common/JackDriverLoader.h View File

@@ -27,7 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackDriver.h"
#include "JackSystemDeps.h"

typedef jack_driver_desc_t * (*JackDriverDescFunction) ();
typedef jack_driver_desc_t* (*JackDriverDescFunction) ();
typedef Jack::JackDriverClientInterface* (*driverInitialize) (Jack::JackLockedEngine*, Jack::JackSynchro*, const JSList*);

class SERVER_EXPORT JackDriverInfo
@@ -54,10 +54,10 @@ class SERVER_EXPORT JackDriverInfo

};

jack_driver_desc_t * jack_find_driver_descriptor(JSList * drivers, const char * name);
jack_driver_desc_t* jack_find_driver_descriptor(JSList* drivers, const char* name);

JSList * jack_drivers_load(JSList * drivers);
JSList * jack_internals_load(JSList * internals);
JSList* jack_drivers_load(JSList* drivers);
JSList* jack_internals_load(JSList* internals);

#ifdef __cplusplus
extern "C"


+ 13
- 1
common/JackDummyDriver.h View File

@@ -32,7 +32,7 @@ namespace Jack

class JackDummyDriver : public JackTimedDriver
{
public:

JackDummyDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
@@ -41,6 +41,18 @@ class JackDummyDriver : public JackTimedDriver
virtual ~JackDummyDriver()
{}

virtual int Process()
{
JackDriver::CycleTakeBeginTime();

if (JackAudioDriver::Process() < 0) {
return -1;
} else {
ProcessWait();
return 0;
}
}

};

} // end of namespace


+ 4
- 8
common/JackGraphManager.cpp View File

@@ -166,7 +166,7 @@ bool JackGraphManager::IsDirectConnection(int ref1, int ref2)
}

// RT
void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buffer_size, bool nulled)
void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buffer_size)
{
AssertPort(port_index);
AssertBufferSize(buffer_size);
@@ -184,17 +184,13 @@ void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buff

// Output port
if (port->fFlags & JackPortIsOutput) {
if (port->fTied != NO_PORT) {
return GetBuffer(port->fTied, buffer_size);
} else {
return (len == 0 && nulled) ? NULL : GetBuffer(port_index);
}
}
return (port->fTied != NO_PORT) ? GetBuffer(port->fTied, buffer_size) : GetBuffer(port_index);
}

// No connections : return a zero-filled buffer
if (len == 0) {
port->ClearBuffer(buffer_size);
return (nulled) ? NULL : port->GetBuffer();
return port->GetBuffer();

// One connection
} else if (len == 1) {


+ 1
- 1
common/JackGraphManager.h View File

@@ -114,7 +114,7 @@ class SERVER_EXPORT JackGraphManager : public JackShmMem, public JackAtomicState
int GetOutputRefNum(jack_port_id_t port_index);

// Buffer management
void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames, bool nulled = false);
void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames);

// Activation management
void RunCurrentGraph();


+ 2
- 1
common/JackLibSampleRateResampler.cpp View File

@@ -58,8 +58,9 @@ JackLibSampleRateResampler::JackLibSampleRateResampler(unsigned int quality)

int error;
fResampler = src_new(quality, 1, &error);
if (error != 0)
if (error != 0) {
jack_error("JackLibSampleRateResampler::JackLibSampleRateResampler err = %s", src_strerror(error));
}
}

JackLibSampleRateResampler::~JackLibSampleRateResampler()


+ 0
- 10
common/JackMidiDriver.cpp View File

@@ -110,16 +110,6 @@ int JackMidiDriver::Detach()
return 0;
}

int JackMidiDriver::Read()
{
return 0;
}

int JackMidiDriver::Write()
{
return 0;
}

void JackMidiDriver::UpdateLatencies()
{
jack_latency_range_t range;


+ 0
- 3
common/JackMidiDriver.h View File

@@ -77,9 +77,6 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver
virtual int Attach();
virtual int Detach();

virtual int Read();
virtual int Write();

};

} // end of namespace


+ 33
- 21
common/JackNetAPI.cpp View File

@@ -166,36 +166,36 @@ struct JackNetExtMaster : public JackNetMasterInterface {
{
// Init socket API (win32)
if (SocketAPIInit() < 0) {
fprintf(stderr, "Can't init Socket API, exiting...\n");
jack_error("Can't init Socket API, exiting...");
return -1;
}

// Request socket
if (fSocket.NewSocket() == SOCKET_ERROR) {
fprintf(stderr, "Can't create the network management input socket : %s\n", StrError(NET_ERROR_CODE));
jack_error("Can't create the network management input socket : %s", StrError(NET_ERROR_CODE));
return -1;
}

// Bind the socket to the local port
if (fSocket.Bind() == SOCKET_ERROR) {
fprintf(stderr, "Can't bind the network manager socket : %s\n", StrError(NET_ERROR_CODE));
jack_error("Can't bind the network manager socket : %s", StrError(NET_ERROR_CODE));
fSocket.Close();
return -1;
}

// Join multicast group
if (fSocket.JoinMCastGroup(fMulticastIP) == SOCKET_ERROR) {
fprintf(stderr, "Can't join multicast group : %s\n", StrError(NET_ERROR_CODE));
jack_error("Can't join multicast group : %s", StrError(NET_ERROR_CODE));
}

// Local loop
if (fSocket.SetLocalLoop() == SOCKET_ERROR) {
fprintf(stderr, "Can't set local loop : %s\n", StrError(NET_ERROR_CODE));
jack_error("Can't set local loop : %s", StrError(NET_ERROR_CODE));
}

// Set a timeout on the multicast receive (the thread can now be cancelled)
if (fSocket.SetTimeOut(MANAGER_INIT_TIMEOUT) == SOCKET_ERROR) {
fprintf(stderr, "Can't set timeout : %s\n", StrError(NET_ERROR_CODE));
jack_error("Can't set timeout : %s", StrError(NET_ERROR_CODE));
}

// Main loop, wait for data, deal with it and wait again
@@ -209,9 +209,9 @@ struct JackNetExtMaster : public JackNetMasterInterface {
SessionParamsNToH(&net_params, &fParams);

if ((rx_bytes == SOCKET_ERROR) && (fSocket.GetError() != NET_NO_DATA)) {
fprintf(stderr, "Error in receive : %s\n", StrError(NET_ERROR_CODE));
jack_error("Error in receive : %s", StrError(NET_ERROR_CODE));
if (++attempt == 10) {
fprintf(stderr, "Can't receive on the socket, exiting net manager.\n" );
jack_error("Can't receive on the socket, exiting net manager" );
goto error;
}
}
@@ -225,10 +225,10 @@ struct JackNetExtMaster : public JackNetMasterInterface {
SessionParamsDisplay(&fParams);
fRunning = false;
} else {
fprintf(stderr, "Can't init new net master...\n");
jack_error("Can't init new net master...");
goto error;
}
jack_info ( "Waiting for a slave..." );
jack_info("Waiting for a slave...");
break;

case KILL_MASTER:
@@ -259,7 +259,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
{
// Check MASTER <==> SLAVE network protocol coherency
if (fParams.fProtocolVersion != MASTER_PROTOCOL) {
fprintf(stderr, "Error : slave is running with a different protocol %s\n", fParams.fName);
jack_error("Error : slave is running with a different protocol %s", fParams.fName);
return -1;
}

@@ -465,7 +465,6 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
// Request parameters
assert(strlen(ip) < 32);
strcpy(fMulticastIP, ip);

fParams.fMtu = request->mtu;
fParams.fTransportSync = 0;
fParams.fSendAudioChannels = request->audio_input;
@@ -494,17 +493,25 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
int Open(jack_master_t* result)
{
if (fParams.fNetworkLatency > NETWORK_MAX_LATENCY) {
printf("Error : network latency is limited to %d\n", NETWORK_MAX_LATENCY);
jack_error("Error : network latency is limited to %d", NETWORK_MAX_LATENCY);
return -1;
}

// Init network connection
if (!JackNetSlaveInterface::InitConnection(fConnectTimeOut)) {
jack_error("Initing network fails...");
return -1;
}

// Finish connection...
if (!JackNetSlaveInterface::InitRendering()) {
jack_error("Starting network fails...");
return -1;
}

// Then set global parameters
if (!SetParams()) {
jack_error("SetParams error...");
return -1;
}

@@ -532,11 +539,19 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf

// Init network connection
if (!JackNetSlaveInterface::InitConnection(fConnectTimeOut)) {
jack_error("Initing network fails...");
return -1;
}

// Finish connection...
if (!JackNetSlaveInterface::InitRendering()) {
jack_error("Starting network fails...");
return -1;
}

// Then set global parameters
if (!SetParams()) {
jack_error("SetParams error...");
return -1;
}

@@ -630,8 +645,8 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
{
// Will do "something" on OSX only...
UInt64 period, constraint;
period = constraint = float(fParams.fPeriodSize) / float(fParams.fSampleRate) * 1000000;
UInt64 computation = JackTools::ComputationMicroSec(fParams.fPeriodSize);
period = constraint = UInt64(1000000000.f * (float(fParams.fPeriodSize) / float(fParams.fSampleRate)));
UInt64 computation = JackTools::ComputationMicroSec(fParams.fPeriodSize) * 1000;
fThread.SetParams(period, computation, constraint);

return (fThread.AcquireRealTime(80) == 0); // TODO: get a value from the server
@@ -713,11 +728,6 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf

int Start()
{
// Finish connection...
if (!JackNetSlaveInterface::InitRendering()) {
return -1;
}

return (fProcessCallback == 0) ? -1 : fThread.StartSync();
}

@@ -974,7 +984,8 @@ SERVER_EXPORT int jack_adapter_pull_and_push(jack_adapter_t* adapter, float** in
}


#ifdef MY_TARGET_OS_IPHONE
//#ifdef MY_TARGET_OS_IPHONE
#if 1

static void jack_format_and_log(int level, const char *prefix, const char *fmt, va_list ap)
{
@@ -1031,3 +1042,4 @@ SERVER_EXPORT void jack_log(const char *fmt, ...)
{}

#endif


+ 52
- 34
common/JackNetAdapter.cpp View File

@@ -35,9 +35,8 @@ namespace Jack
because we don't have full parametering right now, parameters will be parsed from the param list,
and then JackNetSlaveInterface will be filled with proper values.
*/

strcpy(fMulticastIP, DEFAULT_MULTICAST_IP);
uint port = DEFAULT_PORT;
char multicast_ip[32];
uint udp_port;
GetHostName(fParams.fName, JACK_CLIENT_NAME_SIZE);
fSocket.GetName(fParams.fSlaveNetName);
fParams.fMtu = DEFAULT_MTU;
@@ -52,7 +51,18 @@ namespace Jack
fParams.fSlaveSyncMode = 1;
fParams.fNetworkLatency = 2;
fParams.fSampleEncoder = JackFloatEncoder;
fJackClient = jack_client;
fClient = jack_client;

// Possibly use env variable
const char* default_udp_port = getenv("JACK_NETJACK_PORT");
udp_port = (default_udp_port) ? atoi(default_udp_port) : DEFAULT_PORT;

const char* default_multicast_ip = getenv("JACK_NETJACK_MULTICAST");
if (default_multicast_ip) {
strcpy(multicast_ip, default_multicast_ip);
} else {
strcpy(multicast_ip, DEFAULT_MULTICAST_IP);
}

//options parsing
const JSList* node;
@@ -63,14 +73,11 @@ namespace Jack

switch (param->character) {
case 'a' :
if (strlen(param->value.str) < 32) {
strcpy(fMulticastIP, param->value.str);
} else {
jack_error("Can't use multicast address %s, using default %s", param->value.ui, DEFAULT_MULTICAST_IP);
}
assert(strlen(param->value.str) < 32);
strcpy(multicast_ip, param->value.str);
break;
case 'p' :
fSocket.SetPort(param->value.ui);
udp_port = param->value.ui;
break;
case 'M' :
fParams.fMtu = param->value.i;
@@ -85,7 +92,7 @@ namespace Jack
strncpy(fParams.fName, param->value.str, JACK_CLIENT_NAME_SIZE);
break;
case 't' :
//fParams.fTransportSync = param->value.ui;
fParams.fTransportSync = param->value.ui;
break;
#if HAVE_CELT
case 'c':
@@ -112,9 +119,11 @@ namespace Jack
}
}

strcpy(fMulticastIP, multicast_ip);

// Set the socket parameters
fSocket.SetPort(port);
fSocket.SetAddress(fMulticastIP, port);
fSocket.SetPort(udp_port);
fSocket.SetAddress(fMulticastIP, udp_port);

// If not set, takes default
fParams.fSendAudioChannels = (send_audio == -1) ? 2 : send_audio;
@@ -136,13 +145,15 @@ namespace Jack
jack_log("JackNetAdapter::~JackNetAdapter");

if (fSoftCaptureBuffer) {
for (int port_index = 0; port_index < fCaptureChannels; port_index++)
for (int port_index = 0; port_index < fCaptureChannels; port_index++) {
delete[] fSoftCaptureBuffer[port_index];
}
delete[] fSoftCaptureBuffer;
}
if (fSoftPlaybackBuffer) {
for (int port_index = 0; port_index < fPlaybackChannels; port_index++)
for (int port_index = 0; port_index < fPlaybackChannels; port_index++) {
delete[] fSoftPlaybackBuffer[port_index];
}
delete[] fSoftPlaybackBuffer;
}
}
@@ -244,8 +255,9 @@ namespace Jack
try {
// Keep running even in case of error
while (fThread.GetStatus() == JackThread::kRunning)
if (Process() == SOCKET_ERROR)
if (Process() == SOCKET_ERROR) {
return false;
}
return false;
} catch (JackNetException& e) {
e.PrintMessage();
@@ -268,17 +280,17 @@ namespace Jack
//TODO : we need here to get the actual timebase master to eventually release it from its duty (see JackNetDriver)

//is there a new transport state ?
if (fSendTransportData.fNewState &&(fSendTransportData.fState != jack_transport_query(fJackClient, NULL))) {
if (fSendTransportData.fNewState &&(fSendTransportData.fState != jack_transport_query(fClient, NULL))) {
switch (fSendTransportData.fState)
{
case JackTransportStopped :
jack_transport_stop(fJackClient);
jack_transport_stop(fClient);
jack_info("NetMaster : transport stops");
break;

case JackTransportStarting :
jack_transport_reposition(fJackClient, &fSendTransportData.fPosition);
jack_transport_start(fJackClient);
jack_transport_reposition(fClient, &fSendTransportData.fPosition);
jack_transport_start(fClient);
jack_info("NetMaster : transport starts");
break;

@@ -314,13 +326,14 @@ namespace Jack
}

//update transport state and position
fReturnTransportData.fState = jack_transport_query(fJackClient, &fReturnTransportData.fPosition);
fReturnTransportData.fState = jack_transport_query(fClient, &fReturnTransportData.fPosition);

//is it a new state (that the master need to know...) ?
fReturnTransportData.fNewState = ((fReturnTransportData.fState != fLastTransportState) &&
(fReturnTransportData.fState != fSendTransportData.fState));
if (fReturnTransportData.fNewState)
if (fReturnTransportData.fNewState) {
jack_info("Sending transport state '%s'.", GetTransportState(fReturnTransportData.fState));
}
fLastTransportState = fReturnTransportData.fState;
}

@@ -329,8 +342,9 @@ namespace Jack
{
//don't return -1 in case of sync recv failure
//we need the process to continue for network error detection
if (SyncRecv() == SOCKET_ERROR)
if (SyncRecv() == SOCKET_ERROR) {
return 0;
}

DecodeSyncPacket();
return DataRecv();
@@ -340,8 +354,9 @@ namespace Jack
{
EncodeSyncPacket();

if (SyncSend() == SOCKET_ERROR)
if (SyncSend() == SOCKET_ERROR) {
return SOCKET_ERROR;
}

return DataSend();
}
@@ -351,15 +366,17 @@ namespace Jack
{
//read data from the network
//in case of fatal network error, stop the process
if (Read() == SOCKET_ERROR)
if (Read() == SOCKET_ERROR) {
return SOCKET_ERROR;
}

PushAndPull(fSoftCaptureBuffer, fSoftPlaybackBuffer, fAdaptedBufferSize);

//then write data to network
//in case of failure, stop process
if (Write() == SOCKET_ERROR)
if (Write() == SOCKET_ERROR) {
return SOCKET_ERROR;
}

return 0;
}
@@ -386,10 +403,10 @@ extern "C"
desc = jack_driver_descriptor_construct("netadapter", JackDriverNone, "netjack net <==> audio backend adapter", &filler);

strcpy(value.str, DEFAULT_MULTICAST_IP);
jack_driver_descriptor_add_parameter(desc, &filler, "multicast_ip", 'a', JackDriverParamString, &value, NULL, "Multicast Address", NULL);
jack_driver_descriptor_add_parameter(desc, &filler, "multicast-ip", 'a', JackDriverParamString, &value, NULL, "Multicast Address", NULL);

value.i = DEFAULT_PORT;
jack_driver_descriptor_add_parameter(desc, &filler, "udp_net_port", 'p', JackDriverParamInt, &value, NULL, "UDP port", NULL);
jack_driver_descriptor_add_parameter(desc, &filler, "udp-net-port", 'p', JackDriverParamInt, &value, NULL, "UDP port", NULL);

value.i = DEFAULT_MTU;
jack_driver_descriptor_add_parameter(desc, &filler, "mtu", 'M', JackDriverParamInt, &value, NULL, "MTU to the master", NULL);
@@ -406,7 +423,7 @@ extern "C"
strcpy(value.str, "'hostname'");
jack_driver_descriptor_add_parameter(desc, &filler, "client-name", 'n', JackDriverParamString, &value, NULL, "Name of the jack client", NULL);

value.ui = 1U;
value.ui = 0U;
jack_driver_descriptor_add_parameter(desc, &filler, "transport-sync", 't', JackDriverParamUInt, &value, NULL, "Sync transport with master's", NULL);

value.ui = 5U;
@@ -424,17 +441,17 @@ extern "C"
return desc;
}

SERVER_EXPORT int jack_internal_initialize(jack_client_t* jack_client, const JSList* params)
SERVER_EXPORT int jack_internal_initialize(jack_client_t* client, const JSList* params)
{
jack_log("Loading netadapter");

Jack::JackAudioAdapter* adapter;
jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);
jack_nframes_t buffer_size = jack_get_buffer_size(client);
jack_nframes_t sample_rate = jack_get_sample_rate(client);

try {

adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackNetAdapter(jack_client, buffer_size, sample_rate, params), params, false);
adapter = new Jack::JackAudioAdapter(client, new Jack::JackNetAdapter(client, buffer_size, sample_rate, params), params);
assert(adapter);

if (adapter->Open() == 0) {
@@ -458,8 +475,9 @@ extern "C"
jack_driver_desc_t* desc = jack_get_descriptor();

Jack::JackArgParser parser(load_init);
if (parser.GetArgc() > 0)
if (parser.GetArgc() > 0) {
parse_params = parser.ParseParams(desc, &params);
}

if (parse_params) {
res = jack_internal_initialize(jack_client, params);


+ 1
- 1
common/JackNetAdapter.h View File

@@ -38,7 +38,7 @@ namespace Jack
private:

//jack data
jack_client_t* fJackClient;
jack_client_t* fClient;

//transport data
int fLastTransportState;


+ 45
- 34
common/JackNetDriver.cpp View File

@@ -29,7 +29,7 @@ namespace Jack
JackNetDriver::JackNetDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
const char* ip, int udp_port, int mtu, int midi_input_ports, int midi_output_ports,
char* net_name, uint transport_sync, int network_latency, int celt_encoding)
: JackTimedDriver(name, alias, engine, table), JackNetSlaveInterface(ip, udp_port)
: JackWaiterDriver(name, alias, engine, table), JackNetSlaveInterface(ip, udp_port)
{
jack_log("JackNetDriver::JackNetDriver ip %s, port %d", ip, udp_port);

@@ -46,6 +46,7 @@ namespace Jack
fParams.fKBps = celt_encoding;
} else {
fParams.fSampleEncoder = JackFloatEncoder;
//fParams.fSampleEncoder = JackIntEncoder;
}
strcpy(fParams.fName, net_name);
fSocket.GetName(fParams.fSlaveNetName);
@@ -82,7 +83,7 @@ namespace Jack
}
#endif
FreeAll();
return JackTimedDriver::Close();
return JackWaiterDriver::Close();
}

// Attach and Detach are defined as empty methods: port allocation is done when driver actually start (that is in Init)
@@ -104,7 +105,7 @@ namespace Jack

bool JackNetDriver::Initialize()
{
jack_log("JackNetDriver::Initialize()");
jack_log("JackNetDriver::Initialize");
SaveConnections();
FreePorts();

@@ -233,22 +234,29 @@ namespace Jack
{
jack_log("JackNetDriver::AllocPorts fBufferSize = %ld fSampleRate = %ld", fEngineControl->fBufferSize, fEngineControl->fSampleRate);

/*
fNetAudioCaptureBuffer fNetAudioPlaybackBuffer
fSendAudioChannels fReturnAudioChannels

fCapturePortList fPlaybackPortList
fCaptureChannels ==> SLAVE ==> fPlaybackChannels
"capture_" "playback_"
*/

JackPort* port;
jack_port_id_t port_index;
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
unsigned long port_flags;
int audio_port_index;
int midi_port_index;
jack_latency_range_t range;

//audio
port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
for (audio_port_index = 0; audio_port_index < fCaptureChannels; audio_port_index++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, audio_port_index + 1);
snprintf(name, sizeof(name) - 1, "%s:capture_%d", fClientControl.fName, audio_port_index + 1);