git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4517 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.8
| @@ -317,8 +317,11 @@ namespace Jack | |||
| switch (fParams.fSampleEncoder) { | |||
| case JackFloatEncoder: | |||
| #ifdef NEW_FLOAT_CONVERTER | |||
| fNetAudioCaptureBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fSendAudioChannels, fTxData); | |||
| #else | |||
| fNetAudioCaptureBuffer = new NetFloatAudioBuffer(&fParams, fParams.fSendAudioChannels, fTxData); | |||
| //fNetAudioCaptureBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fSendAudioChannels, fTxData); | |||
| #endif | |||
| break; | |||
| case JackIntEncoder: | |||
| @@ -340,8 +343,11 @@ namespace Jack | |||
| switch (fParams.fSampleEncoder) { | |||
| case JackFloatEncoder: | |||
| #ifdef NEW_FLOAT_CONVERTER | |||
| fNetAudioPlaybackBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fReturnAudioChannels, fRxData); | |||
| #else | |||
| fNetAudioPlaybackBuffer = new NetFloatAudioBuffer(&fParams, fParams.fReturnAudioChannels, fRxData); | |||
| //fNetAudioPlaybackBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fReturnAudioChannels, fRxData); | |||
| #endif | |||
| break; | |||
| case JackIntEncoder: | |||
| @@ -825,8 +831,11 @@ namespace Jack | |||
| switch (fParams.fSampleEncoder) { | |||
| case JackFloatEncoder: | |||
| #ifdef NEW_FLOAT_CONVERTER | |||
| fNetAudioCaptureBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fSendAudioChannels, fRxData); | |||
| #else | |||
| fNetAudioCaptureBuffer = new NetFloatAudioBuffer(&fParams, fParams.fSendAudioChannels, fRxData); | |||
| //fNetAudioCaptureBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fSendAudioChannels, fRxData); | |||
| #endif | |||
| break; | |||
| case JackIntEncoder: | |||
| @@ -848,8 +857,11 @@ namespace Jack | |||
| switch (fParams.fSampleEncoder) { | |||
| case JackFloatEncoder: | |||
| #ifdef NEW_FLOAT_CONVERTER | |||
| fNetAudioPlaybackBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fReturnAudioChannels, fTxData); | |||
| #else | |||
| fNetAudioPlaybackBuffer = new NetFloatAudioBuffer(&fParams, fParams.fReturnAudioChannels, fTxData); | |||
| //fNetAudioPlaybackBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fReturnAudioChannels, fTxData); | |||
| #endif | |||
| break; | |||
| case JackIntEncoder: | |||
| @@ -32,13 +32,15 @@ namespace Jack | |||
| #define SLAVE_SETUP_RETRY 5 | |||
| #define MANAGER_INIT_TIMEOUT 2000000 // in usec | |||
| #define MASTER_INIT_TIMEOUT 1000000 // in usec | |||
| #define MASTER_INIT_TIMEOUT 1000000 // in usec | |||
| #define SLAVE_INIT_TIMEOUT 1000000 // in usec | |||
| #define NETWORK_MAX_LATENCY 20 | |||
| #define NEW_FLOAT_CONVERTER | |||
| /** | |||
| \Brief This class describes the basic Net Interface, used by both master and slave | |||
| \Brief This class describes the basic Net Interface, used by both master and slave. | |||
| */ | |||
| class SERVER_EXPORT JackNetInterface | |||
| @@ -66,7 +68,7 @@ namespace Jack | |||
| char* fTxData; | |||
| char* fRxData; | |||
| // jack buffers | |||
| // JACK buffers | |||
| NetMidiBuffer* fNetMidiCaptureBuffer; | |||
| NetMidiBuffer* fNetMidiPlaybackBuffer; | |||
| NetAudioBuffer* fNetAudioCaptureBuffer; | |||
| @@ -413,6 +413,7 @@ namespace Jack | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| if ((intptr_t)fNetAudioCaptureBuffer->GetBuffer(audio_port_index) == -1) { | |||
| jack_info("Process fNetAudioCaptureBuffer %d", jack_port_connected(fAudioCapturePorts[audio_port_index])); | |||
| // Port is connected on other side... | |||
| fNetAudioCaptureBuffer->SetBuffer(audio_port_index, | |||
| ((jack_port_connected(fAudioCapturePorts[audio_port_index]) > 0) | |||
| @@ -201,17 +201,47 @@ namespace Jack | |||
| // net audio buffer ********************************************************************************* | |||
| NetAudioBuffer::NetAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer) | |||
| { | |||
| fNPorts = nports; | |||
| fNetBuffer = net_buffer; | |||
| fPortBuffer = new sample_t* [fNPorts]; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = (sample_t*)-1; | |||
| } | |||
| } | |||
| NetAudioBuffer::~NetAudioBuffer() | |||
| { | |||
| delete [] fPortBuffer; | |||
| } | |||
| void NetAudioBuffer::SetBuffer(int index, sample_t* buffer) | |||
| { | |||
| //jack_info("NetAudioBuffer::SetBuffer %d %x", index, buffer); | |||
| fPortBuffer[index] = buffer; | |||
| } | |||
| sample_t* NetAudioBuffer::GetBuffer(int index) | |||
| { | |||
| return fPortBuffer[index]; | |||
| } | |||
| //network<->buffer | |||
| void NetAudioBuffer::ActivePortsToNetwork(uint32_t& port_num) | |||
| void NetAudioBuffer::ActivePortsToNetwork(char* net_buffer, uint32_t& port_num) | |||
| { | |||
| // Init active port count | |||
| port_num = 0; | |||
| short* active_port_address = (short*)fNetBuffer; | |||
| short* active_port_address = (short*)net_buffer; | |||
| //jack_info("ActivePortsToNetwork %d", fNPorts); | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| //jack_info("ActivePortsToNetwork %d", port_index); | |||
| // Write the active port number | |||
| if (fPortBuffer[port_index]) { | |||
| //jack_info("ActivePortsToNetwork OK %d", port_index); | |||
| *active_port_address = port_index; | |||
| active_port_address++; | |||
| port_num++; | |||
| @@ -220,9 +250,9 @@ namespace Jack | |||
| } | |||
| } | |||
| void NetAudioBuffer::ActivePortsFromNetwork(uint32_t port_num) | |||
| void NetAudioBuffer::ActivePortsFromNetwork(char* net_buffer, uint32_t port_num) | |||
| { | |||
| short* active_port_address = (short*)fNetBuffer; | |||
| short* active_port_address = (short*)net_buffer; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = NULL; | |||
| @@ -241,10 +271,8 @@ namespace Jack | |||
| // Float | |||
| NetFloatAudioBuffer::NetFloatAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer) | |||
| : NetAudioBuffer(), fPortBuffer1(params, nports) | |||
| { | |||
| fNetBuffer = net_buffer; | |||
| } | |||
| : NetAudioBuffer(params, nports, net_buffer), fPortBuffer1(params, nports) | |||
| {} | |||
| NetFloatAudioBuffer::~NetFloatAudioBuffer() | |||
| {} | |||
| @@ -256,6 +284,7 @@ namespace Jack | |||
| void NetFloatAudioBuffer::SetBuffer(int index, sample_t* buffer) | |||
| { | |||
| jack_info("NetAudioBuffer::SetBuffer %d %x", index, buffer); | |||
| fPortBuffer1.SetBuffer(index, buffer); | |||
| } | |||
| @@ -298,11 +327,8 @@ namespace Jack | |||
| // New | |||
| NetFloatAudioBuffer1::NetFloatAudioBuffer1(session_params_t* params, uint32_t nports, char* net_buffer) | |||
| : NetAudioBuffer() | |||
| : NetAudioBuffer(params, nports, net_buffer) | |||
| { | |||
| fNetBuffer = net_buffer; | |||
| fNPorts = nports; | |||
| fPeriodSize = params->fPeriodSize; | |||
| fPacketSize = params->fMtu - sizeof(packet_header_t); | |||
| @@ -329,20 +355,7 @@ namespace Jack | |||
| } | |||
| NetFloatAudioBuffer1::~NetFloatAudioBuffer1() | |||
| { | |||
| delete [] fPortBuffer; | |||
| } | |||
| void NetFloatAudioBuffer1::SetBuffer(int index, sample_t* buffer) | |||
| { | |||
| //jack_info("NetFloatAudioBuffer1::SetBuffer %d %x", index, buffer); | |||
| fPortBuffer[index] = buffer; | |||
| } | |||
| sample_t* NetFloatAudioBuffer1::GetBuffer(int index) | |||
| { | |||
| return fPortBuffer[index]; | |||
| } | |||
| {} | |||
| // needed size in bytes for an entire cycle | |||
| size_t NetFloatAudioBuffer1::GetCycleSize() | |||
| @@ -436,7 +449,7 @@ namespace Jack | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| // Only copy from active ports : write the active port number then audio data | |||
| if (fPortBuffer[port_index]) { | |||
| jack_info("NetFloatAudioBuffer1::RenderToNetwork %d", port_index); | |||
| //jack_info("NetFloatAudioBuffer1::RenderToNetwork %d", port_index); | |||
| uint32_t* active_port_address = (uint32_t*)(fNetBuffer + port_num * fSubPeriodBytesSize); | |||
| *active_port_address = port_index; | |||
| memcpy((char*)(active_port_address + 1), fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize - sizeof(uint32_t)); | |||
| @@ -447,46 +460,6 @@ namespace Jack | |||
| return port_num * fSubPeriodBytesSize; | |||
| } | |||
| //network<->buffer | |||
| /* | |||
| void NetFloatAudioBuffer1::ActivePortsToNetwork(uint32_t& port_num) | |||
| { | |||
| // Init active port count | |||
| port_num = 0; | |||
| short* active_port_address = (short*)fNetBuffer; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| // Write the active port number | |||
| if (fPortBuffer[port_index]) { | |||
| *active_port_address = port_index; | |||
| active_port_address++; | |||
| port_num++; | |||
| assert(port_num < 512); | |||
| } | |||
| } | |||
| } | |||
| void NetFloatAudioBuffer1::ActivePortsFromNetwork(uint32_t port_num) | |||
| { | |||
| short* active_port_address = (short*)fNetBuffer; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = NULL; | |||
| } | |||
| for (uint port_index = 0; port_index < port_num; port_index++) { | |||
| // Use -1 when port is actually connected on other side | |||
| if (*active_port_address >= 0 && *active_port_address < fNPorts) { | |||
| fPortBuffer[*active_port_address] = (sample_t*)-1; | |||
| } else { | |||
| jack_error("ActivePortsFromNetwork: incorrect port = %d", *active_port_address); | |||
| } | |||
| active_port_address++; | |||
| } | |||
| } | |||
| */ | |||
| // Celt audio buffer ********************************************************************************* | |||
| #if HAVE_CELT | |||
| @@ -495,11 +468,10 @@ namespace Jack | |||
| #define KPS_DIV 8 | |||
| NetCeltAudioBuffer::NetCeltAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer, int kbps) | |||
| :NetAudioBuffer(params, nports, net_buffer) | |||
| { | |||
| int res1, res2; | |||
| fNetBuffer = net_buffer; | |||
| fNPorts = nports; | |||
| fPeriodSize = params->fPeriodSize; | |||
| fCeltMode = new CELTMode *[fNPorts]; | |||
| @@ -556,11 +528,6 @@ namespace Jack | |||
| #endif | |||
| } | |||
| fPortBuffer = new sample_t* [fNPorts]; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = NULL; | |||
| } | |||
| fCompressedSizeByte = (kbps * params->fPeriodSize * 1024) / (params->fSampleRate * 8); | |||
| fCompressedBuffer = new unsigned char* [fNPorts]; | |||
| @@ -603,7 +570,6 @@ namespace Jack | |||
| } | |||
| delete [] fCompressedBuffer; | |||
| delete [] fPortBuffer; | |||
| } | |||
| void NetCeltAudioBuffer::FreeCelt() | |||
| @@ -640,18 +606,6 @@ namespace Jack | |||
| return fNumPackets; | |||
| } | |||
| void NetCeltAudioBuffer::SetBuffer(int index, sample_t* buffer) | |||
| { | |||
| assert(fPortBuffer); | |||
| fPortBuffer[index] = buffer; | |||
| } | |||
| sample_t* NetCeltAudioBuffer::GetBuffer(int index) | |||
| { | |||
| assert(fPortBuffer); | |||
| return fPortBuffer[index]; | |||
| } | |||
| void NetCeltAudioBuffer::RenderFromJackPorts() | |||
| { | |||
| float floatbuf[fPeriodSize]; | |||
| @@ -732,17 +686,11 @@ namespace Jack | |||
| #endif | |||
| NetIntAudioBuffer::NetIntAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer) | |||
| : NetAudioBuffer(params, nports, net_buffer) | |||
| { | |||
| int res1, res2; | |||
| fNPorts = nports; | |||
| fPeriodSize = params->fPeriodSize; | |||
| fNetBuffer = net_buffer; | |||
| fPortBuffer = new sample_t* [fNPorts]; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| fPortBuffer[port_index] = NULL; | |||
| } | |||
| fIntBuffer = new short* [fNPorts]; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| @@ -782,7 +730,6 @@ namespace Jack | |||
| } | |||
| delete [] fIntBuffer; | |||
| delete [] fPortBuffer; | |||
| } | |||
| size_t NetIntAudioBuffer::GetCycleSize() | |||
| @@ -800,16 +747,6 @@ namespace Jack | |||
| return fNumPackets; | |||
| } | |||
| void NetIntAudioBuffer::SetBuffer(int index, sample_t* buffer) | |||
| { | |||
| fPortBuffer[index] = buffer; | |||
| } | |||
| sample_t* NetIntAudioBuffer::GetBuffer(int index) | |||
| { | |||
| return fPortBuffer[index]; | |||
| } | |||
| void NetIntAudioBuffer::RenderFromJackPorts() | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| @@ -282,10 +282,8 @@ namespace Jack | |||
| public: | |||
| NetAudioBuffer() | |||
| {} | |||
| virtual ~NetAudioBuffer() | |||
| {} | |||
| NetAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer); | |||
| virtual ~NetAudioBuffer(); | |||
| // needed syze in bytes ofr an entire cycle | |||
| virtual size_t GetCycleSize() = 0; | |||
| @@ -295,23 +293,19 @@ namespace Jack | |||
| virtual int GetNumPackets() = 0; | |||
| virtual void SetBuffer(int index, sample_t* buffer); | |||
| virtual sample_t* GetBuffer(int index); | |||
| //jack<->buffer | |||
| virtual void RenderFromJackPorts() = 0; | |||
| virtual void RenderToJackPorts() = 0; | |||
| //network<->buffer | |||
| virtual int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) = 0; | |||
| virtual void ActivePortsFromNetwork(char* net_buffer, uint32_t port_num) {} | |||
| virtual int RenderToNetwork(int sub_cycle, uint32_t& port_num) = 0; | |||
| virtual void ActivePortsToNetwork(char* net_buffer, uint32_t& port_num) {} | |||
| virtual void SetBuffer(int index, sample_t* buffer) = 0; | |||
| virtual sample_t* GetBuffer(int index) = 0; | |||
| virtual void ActivePortsToNetwork(uint32_t& port_num); | |||
| virtual void ActivePortsFromNetwork(uint32_t port_num); | |||
| virtual void ActivePortsToNetwork(char* net_buffer, uint32_t& port_num); | |||
| virtual void ActivePortsFromNetwork(char* net_buffer, uint32_t port_num); | |||
| }; | |||
| @@ -707,14 +701,16 @@ namespace Jack | |||
| void RenderFromJackPorts(); | |||
| void RenderToJackPorts(); | |||
| void SetBuffer(int index, sample_t* buffer); | |||
| sample_t* GetBuffer(int index); | |||
| //network<->buffer | |||
| int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num); | |||
| void ActivePortsFromNetwork(char* net_buffer, uint32_t port_num); | |||
| int RenderToNetwork(int sub_cycle, uint32_t& ort_num); | |||
| void ActivePortsFromNetwork(char* net_buffer, uint32_t port_num); | |||
| void ActivePortsToNetwork(char* net_buffer, uint32_t& port_num); | |||
| }; | |||
| @@ -726,14 +722,10 @@ namespace Jack | |||
| jack_nframes_t fPeriodSize; | |||
| jack_nframes_t fSubPeriodSize; | |||
| size_t fSubPeriodBytesSize; | |||
| //sample_t** fPortBuffer; | |||
| int fPacketSize; | |||
| //int fNPorts; | |||
| size_t fCycleSize; // needed size in bytes for an entire cycle | |||
| float fCycleDuration; // in sec | |||
| //int fLastSubCycle; | |||
| public: | |||
| NetFloatAudioBuffer1(session_params_t* params, uint32_t nports, char* net_buffer); | |||
| @@ -747,9 +739,6 @@ namespace Jack | |||
| int GetNumPackets(); | |||
| void SetBuffer(int index, sample_t* buffer); | |||
| sample_t* GetBuffer(int index); | |||
| virtual void RenderFromJackPorts() | |||
| {} | |||
| @@ -763,12 +752,6 @@ namespace Jack | |||
| int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num); | |||
| int RenderToNetwork(int sub_cycle, uint32_t& port_num); | |||
| /* | |||
| void ActivePortsToNetwork(uint32_t& port_num); | |||
| void ActivePortsFromNetwork(uint32_t port_num); | |||
| */ | |||
| }; | |||
| #if HAVE_CELT | |||
| @@ -793,7 +776,6 @@ namespace Jack | |||
| size_t fSubPeriodBytesSize; | |||
| size_t fLastSubPeriodBytesSize; | |||
| //sample_t** fPortBuffer; | |||
| unsigned char** fCompressedBuffer; | |||
| void FreeCelt(); | |||
| @@ -810,9 +792,6 @@ namespace Jack | |||
| float GetCycleDuration(); | |||
| int GetNumPackets(); | |||
| void SetBuffer(int index, sample_t* buffer); | |||
| sample_t* GetBuffer(int index); | |||
| //jack<->buffer | |||
| void RenderFromJackPorts(); | |||
| void RenderToJackPorts(); | |||
| @@ -842,7 +821,6 @@ namespace Jack | |||
| size_t fLastSubPeriodSize; | |||
| size_t fLastSubPeriodBytesSize; | |||
| //sample_t** fPortBuffer; | |||
| short** fIntBuffer; | |||
| public: | |||
| @@ -857,9 +835,6 @@ namespace Jack | |||
| float GetCycleDuration(); | |||
| int GetNumPackets(); | |||
| void SetBuffer(int index, sample_t* buffer); | |||
| sample_t* GetBuffer(int index); | |||
| //jack<->buffer | |||
| void RenderFromJackPorts(); | |||
| void RenderToJackPorts(); | |||
| @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) | |||
| jack_on_shutdown(client, jack_shutdown, 0); | |||
| if (just_print_bufsize) { | |||
| fprintf(stdout, "%d %d\n", jack_get_buffer_size(client), jack_get_sample_rate(client)); | |||
| fprintf(stdout, "buffer size = %d sample rate = %d\n", jack_get_buffer_size(client), jack_get_sample_rate(client)); | |||
| rc=0; | |||
| } | |||
| else | |||
| @@ -94,12 +94,14 @@ process_audio (jack_nframes_t nframes) | |||
| offset += frames_left; | |||
| } | |||
| /* | |||
| jack_nframes_t cur_time = jack_frame_time(client); | |||
| jack_time_t cur_micro_time = jack_get_time(); | |||
| printf("jack_frame_timed %lld micro %lld delta %d\n", cur_time, (cur_micro_time - last_micro_time), cur_time - last_time); | |||
| last_time = cur_time; | |||
| last_micro_time = cur_micro_time; | |||
| */ | |||
| } | |||
| static int | |||