git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4481 0c269be4-1314-0410-8aa9-9f06e86f4224tags/1.9.8
| @@ -35,6 +35,18 @@ Chris Caudle | |||
| Jackdmp changes log | |||
| --------------------------- | |||
| 2011-07-08 Stephane Letz <letz@grame.fr> | |||
| * NetJack2 now only send data on network for connected ports. | |||
| 2011-07-03 Stephane Letz <letz@grame.fr> | |||
| * More debug code in JackMMCSS class. | |||
| 2011-07-03 Stephane Letz <letz@grame.fr> | |||
| * -l in JackCoreAudioDriver now display devices names and then quit. | |||
| 2011-07-01 Stephane Letz <letz@grame.fr> | |||
| * Fix bugs in JackNetAdapter. | |||
| @@ -127,6 +127,7 @@ extern "C" | |||
| unsigned long buffer_size); | |||
| EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *); | |||
| EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t); | |||
| EXPORT void * jack_port_get_buffer_nulled(jack_port_t *, jack_nframes_t); | |||
| EXPORT const char* jack_port_name(const jack_port_t *port); | |||
| EXPORT const char* jack_port_short_name(const jack_port_t *port); | |||
| EXPORT int jack_port_flags(const jack_port_t *port); | |||
| @@ -349,6 +350,22 @@ EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames) | |||
| } | |||
| } | |||
| EXPORT void* jack_port_get_buffer_nulled(jack_port_t* port, jack_nframes_t frames) | |||
| { | |||
| #ifdef __CLIENTDEBUG__ | |||
| JackGlobals::CheckContext("jack_port_get_buffer"); | |||
| #endif | |||
| uintptr_t port_aux = (uintptr_t)port; | |||
| jack_port_id_t myport = (jack_port_id_t)port_aux; | |||
| if (!CheckPort(myport)) { | |||
| jack_error("jack_port_get_buffer called with an incorrect port %ld", myport); | |||
| return NULL; | |||
| } else { | |||
| JackGraphManager* manager = GetGraphManager(); | |||
| return (manager ? manager->GetBuffer(myport, frames, true) : NULL); | |||
| } | |||
| } | |||
| EXPORT const char* jack_port_name(const jack_port_t* port) | |||
| { | |||
| #ifdef __CLIENTDEBUG__ | |||
| @@ -41,12 +41,22 @@ namespace Jack | |||
| // Always clear output | |||
| for (int i = 0; i < adapter->fAudioAdapter->GetInputs(); i++) { | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| inputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer_nulled(adapter->fCapturePortList[i], frames); | |||
| 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_default_audio_sample_t*)jack_port_get_buffer_nulled(adapter->fPlaybackPortList[i], frames); | |||
| #else | |||
| outputBuffer[i] = (jack_default_audio_sample_t*)jack_port_get_buffer(adapter->fPlaybackPortList[i], frames); | |||
| #endif | |||
| } | |||
| adapter->fAudioAdapter->PullAndPush(inputBuffer, outputBuffer, frames); | |||
| @@ -34,9 +34,9 @@ namespace Jack | |||
| { | |||
| private: | |||
| 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 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); | |||
| jack_port_t** fCapturePortList; | |||
| jack_port_t** fPlaybackPortList; | |||
| @@ -396,24 +396,24 @@ void JackAudioDriver::WaitUntilNextCycle() | |||
| JackSleep(wait_time_usec); | |||
| } | |||
| jack_default_audio_sample_t* JackAudioDriver::GetInputBuffer(int port_index) | |||
| jack_default_audio_sample_t* JackAudioDriver::GetInputBuffer(int port_index, bool nulled) | |||
| { | |||
| return fCapturePortList[port_index] | |||
| ? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize) | |||
| ? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fCapturePortList[port_index], fEngineControl->fBufferSize, nulled) | |||
| : NULL; | |||
| } | |||
| jack_default_audio_sample_t* JackAudioDriver::GetOutputBuffer(int port_index) | |||
| jack_default_audio_sample_t* JackAudioDriver::GetOutputBuffer(int port_index, bool nulled) | |||
| { | |||
| return fPlaybackPortList[port_index] | |||
| ? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize) | |||
| ? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fPlaybackPortList[port_index], fEngineControl->fBufferSize, nulled) | |||
| : NULL; | |||
| } | |||
| jack_default_audio_sample_t* JackAudioDriver::GetMonitorBuffer(int port_index) | |||
| jack_default_audio_sample_t* JackAudioDriver::GetMonitorBuffer(int port_index, bool nulled) | |||
| { | |||
| return fPlaybackPortList[port_index] | |||
| ? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[port_index], fEngineControl->fBufferSize) | |||
| ? (jack_default_audio_sample_t*)fGraphManager->GetBuffer(fMonitorPortList[port_index], fEngineControl->fBufferSize, nulled) | |||
| : NULL; | |||
| } | |||
| @@ -59,9 +59,9 @@ 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); | |||
| jack_default_audio_sample_t* GetOutputBuffer(int port_index); | |||
| jack_default_audio_sample_t* GetMonitorBuffer(int port_index); | |||
| 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); | |||
| void HandleLatencyCallback(int status); | |||
| void UpdateLatencies(); | |||
| @@ -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) | |||
| void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buffer_size, bool nulled) | |||
| { | |||
| AssertPort(port_index); | |||
| AssertBufferSize(buffer_size); | |||
| @@ -191,7 +191,7 @@ void* JackGraphManager::GetBuffer(jack_port_id_t port_index, jack_nframes_t buff | |||
| // No connections : return a zero-filled buffer | |||
| if (len == 0) { | |||
| port->ClearBuffer(buffer_size); | |||
| return port->GetBuffer(); | |||
| return (nulled) ? NULL : port->GetBuffer(); | |||
| // One connection | |||
| } else if (len == 1) { | |||
| @@ -791,9 +791,9 @@ const char** JackGraphManager::GetConnections(jack_port_id_t port_index) | |||
| next_index = GetCurrentIndex(); | |||
| } while (cur_index != next_index); // Until a coherent state has been read | |||
| if (res[0]) { // at least one connection | |||
| if (res[0]) { // At least one connection | |||
| return res; | |||
| } else { // empty array, should return NULL | |||
| } else { // Empty array, should return NULL | |||
| free(res); | |||
| return NULL; | |||
| } | |||
| @@ -874,10 +874,10 @@ const char** JackGraphManager::GetPorts(const char* port_name_pattern, const cha | |||
| next_index = GetCurrentIndex(); | |||
| } while (cur_index != next_index); // Until a coherent state has been read | |||
| if (res[0]) { // at least one port | |||
| if (res[0]) { // At least one port | |||
| return res; | |||
| } else { | |||
| free(res); // empty array, should return NULL | |||
| free(res); // Empty array, should return NULL | |||
| return NULL; | |||
| } | |||
| } | |||
| @@ -113,7 +113,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); | |||
| void* GetBuffer(jack_port_id_t port_index, jack_nframes_t frames, bool nulled = false); | |||
| // Activation management | |||
| void RunCurrentGraph(); | |||
| @@ -59,13 +59,14 @@ namespace Jack | |||
| for (node = params; node; node = jack_slist_next(node)) | |||
| { | |||
| param = (const jack_driver_param_t*) node->data; | |||
| switch (param->character) | |||
| { | |||
| switch (param->character) { | |||
| case 'a' : | |||
| if (strlen(param->value.str) < 32) | |||
| if (strlen(param->value.str) < 32) { | |||
| strcpy(fMulticastIP, param->value.str); | |||
| else | |||
| } else { | |||
| jack_error("Can't use multicast address %s, using default %s", param->value.ui, DEFAULT_MULTICAST_IP); | |||
| } | |||
| break; | |||
| case 'p' : | |||
| fSocket.SetPort(param->value.ui); | |||
| @@ -94,14 +95,15 @@ namespace Jack | |||
| break; | |||
| #endif | |||
| case 'm' : | |||
| if (strcmp(param->value.str, "normal") == 0) | |||
| if (strcmp(param->value.str, "normal") == 0) { | |||
| fParams.fNetworkMode = 'n'; | |||
| else if (strcmp(param->value.str, "slow") == 0) | |||
| } else if (strcmp(param->value.str, "slow") == 0) { | |||
| fParams.fNetworkMode = 's'; | |||
| else if (strcmp(param->value.str, "fast") == 0) | |||
| } else if (strcmp(param->value.str, "fast") == 0) { | |||
| fParams.fNetworkMode = 'f'; | |||
| else | |||
| } else { | |||
| jack_error("Unknown network mode, using 'normal' mode."); | |||
| } | |||
| break; | |||
| case 'q': | |||
| fQuality = param->value.ui; | |||
| @@ -124,28 +124,28 @@ namespace Jack | |||
| SaveConnections(); | |||
| FreePorts(); | |||
| //new loading, but existing socket, restart the driver | |||
| // New loading, but existing socket, restart the driver | |||
| if (fSocket.IsSocket()) { | |||
| jack_info("Restarting driver..."); | |||
| FreeAll(); | |||
| } | |||
| //set the parameters to send | |||
| // Set the parameters to send | |||
| fParams.fSendAudioChannels = fCaptureChannels; | |||
| fParams.fReturnAudioChannels = fPlaybackChannels; | |||
| fParams.fSlaveSyncMode = fEngineControl->fSyncMode; | |||
| //display some additional infos | |||
| // Display some additional infos | |||
| jack_info("NetDriver started in %s mode %s Master's transport sync.", | |||
| (fParams.fSlaveSyncMode) ? "sync" : "async", (fParams.fTransportSync) ? "with" : "without"); | |||
| //init network | |||
| // Init network | |||
| if (!JackNetSlaveInterface::Init()) { | |||
| jack_error("Starting network fails..."); | |||
| return false; | |||
| } | |||
| //set global parameters | |||
| // Set global parameters | |||
| if (!SetParams()) { | |||
| jack_error("SetParams error..."); | |||
| return false; | |||
| @@ -155,7 +155,7 @@ namespace Jack | |||
| fCaptureChannels = fParams.fSendAudioChannels; | |||
| fPlaybackChannels = fParams.fReturnAudioChannels; | |||
| //allocate midi ports lists | |||
| // Allocate midi ports lists | |||
| fMidiCapturePortList = new jack_port_id_t [fParams.fSendMidiChannels]; | |||
| fMidiPlaybackPortList = new jack_port_id_t [fParams.fReturnMidiChannels]; | |||
| @@ -169,19 +169,19 @@ namespace Jack | |||
| fMidiPlaybackPortList[midi_port_index] = 0; | |||
| } | |||
| //register jack ports | |||
| // Register jack ports | |||
| if (AllocPorts() != 0) { | |||
| jack_error("Can't allocate ports."); | |||
| return false; | |||
| } | |||
| //init done, display parameters | |||
| // Init done, display parameters | |||
| SessionParamsDisplay(&fParams); | |||
| //monitor | |||
| // Monitor | |||
| #ifdef JACK_MONITOR | |||
| string plot_name; | |||
| //NetTimeMon | |||
| // NetTimeMon | |||
| plot_name = string(fParams.fName); | |||
| plot_name += string("_slave"); | |||
| plot_name += (fEngineControl->fSyncMode) ? string("_sync") : string("_async"); | |||
| @@ -215,14 +215,14 @@ namespace Jack | |||
| }; | |||
| fNetTimeMon->SetPlotFile(net_time_mon_options, 2, net_time_mon_fields, 5); | |||
| #endif | |||
| //driver parametering | |||
| // Driver parametering | |||
| JackAudioDriver::SetBufferSize(fParams.fPeriodSize); | |||
| JackAudioDriver::SetSampleRate(fParams.fSampleRate); | |||
| JackDriver::NotifyBufferSize(fParams.fPeriodSize); | |||
| JackDriver::NotifySampleRate(fParams.fSampleRate); | |||
| //transport engine parametering | |||
| // Transport engine parametering | |||
| fEngineControl->fTransport.SetNetworkSync(fParams.fTransportSync); | |||
| RestoreConnections(); | |||
| @@ -413,25 +413,7 @@ namespace Jack | |||
| const char** connections; | |||
| fConnections.clear(); | |||
| for (int i = 0; i < fCaptureChannels; ++i) { | |||
| if (fCapturePortList[i] && (connections = fGraphManager->GetConnections(fCapturePortList[i])) != 0) { | |||
| for (int j = 0; connections[j]; j++) { | |||
| fConnections.push_back(make_pair(fGraphManager->GetPort(fCapturePortList[i])->GetName(), connections[j])); | |||
| jack_info("Save connection: %s %s", fGraphManager->GetPort(fCapturePortList[i])->GetName(), connections[j]); | |||
| } | |||
| free(connections); | |||
| } | |||
| } | |||
| for (int i = 0; i < fPlaybackChannels; ++i) { | |||
| if (fPlaybackPortList[i] && (connections = fGraphManager->GetConnections(fPlaybackPortList[i])) != 0) { | |||
| for (int j = 0; connections[j]; j++) { | |||
| fConnections.push_back(make_pair(connections[j], fGraphManager->GetPort(fPlaybackPortList[i])->GetName())); | |||
| jack_info("Save connection: %s %s", connections[j], fGraphManager->GetPort(fPlaybackPortList[i])->GetName()); | |||
| } | |||
| free(connections); | |||
| } | |||
| } | |||
| JackAudioDriver::SaveConnections(); | |||
| for (int i = 0; i < fParams.fSendMidiChannels; ++i) { | |||
| if (fCapturePortList[i] && (connections = fGraphManager->GetConnections(fMidiCapturePortList[i])) != 0) { | |||
| @@ -546,7 +528,11 @@ namespace Jack | |||
| for (midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++) | |||
| fNetMidiCaptureBuffer->SetBuffer(midi_port_index, GetMidiInputBuffer(midi_port_index)); | |||
| for (audio_port_index = 0; audio_port_index < fParams.fSendAudioChannels; audio_port_index++) | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| fNetAudioCaptureBuffer->SetBuffer(audio_port_index, GetInputBuffer(audio_port_index, true)); | |||
| #else | |||
| fNetAudioCaptureBuffer->SetBuffer(audio_port_index, GetInputBuffer(audio_port_index)); | |||
| #endif | |||
| #ifdef JACK_MONITOR | |||
| fNetTimeMon->New(); | |||
| @@ -589,9 +575,13 @@ namespace Jack | |||
| //buffers | |||
| for (midi_port_index = 0; midi_port_index < fParams.fReturnMidiChannels; midi_port_index++) | |||
| fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, GetMidiOutputBuffer (midi_port_index)); | |||
| fNetMidiPlaybackBuffer->SetBuffer(midi_port_index, GetMidiOutputBuffer(midi_port_index)); | |||
| for (audio_port_index = 0; audio_port_index < fPlaybackChannels; audio_port_index++) | |||
| fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer (audio_port_index)); | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer(audio_port_index, true)); | |||
| #else | |||
| fNetAudioPlaybackBuffer->SetBuffer(audio_port_index, GetOutputBuffer(audio_port_index)); | |||
| #endif | |||
| #ifdef JACK_MONITOR | |||
| fNetTimeMon->Add(((float) (GetMicroSeconds() - fRcvSyncUst) / (float)fEngineControl->fPeriodUsecs) * 100.f); | |||
| @@ -92,12 +92,12 @@ namespace Jack | |||
| return true; | |||
| } | |||
| int SetBufferSize ( jack_nframes_t buffer_size ) | |||
| int SetBufferSize(jack_nframes_t buffer_size) | |||
| { | |||
| return -1; | |||
| } | |||
| int SetSampleRate ( jack_nframes_t sample_rate ) | |||
| int SetSampleRate(jack_nframes_t sample_rate) | |||
| { | |||
| return -1; | |||
| } | |||
| @@ -455,8 +455,9 @@ namespace Jack | |||
| for (subproc = 0; subproc < fTxHeader.fNumPacket; subproc++) { | |||
| fTxHeader.fSubCycle = subproc; | |||
| fTxHeader.fIsLastPckt = (subproc == (fTxHeader.fNumPacket - 1)) ? 1 : 0; | |||
| fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioCaptureBuffer->RenderToNetwork(subproc, data_size); | |||
| fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioCaptureBuffer->RenderToNetwork(subproc, data_size, fTxHeader.fActivePorts); | |||
| memcpy(fTxBuffer, &fTxHeader, HEADER_SIZE); | |||
| //PacketHeaderDisplay(&fTxHeader); | |||
| if (Send(fTxHeader.fPacketSize, 0) == SOCKET_ERROR) | |||
| return SOCKET_ERROR; | |||
| } | |||
| @@ -570,7 +571,8 @@ namespace Jack | |||
| fRxHeader.fCycle = rx_head->fCycle; | |||
| fRxHeader.fSubCycle = rx_head->fSubCycle; | |||
| fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; | |||
| fNetAudioPlaybackBuffer->RenderFromNetwork(rx_head->fCycle, rx_head->fSubCycle, rx_bytes - HEADER_SIZE); | |||
| fRxHeader.fActivePorts = rx_head->fActivePorts; | |||
| fNetAudioPlaybackBuffer->RenderFromNetwork(rx_head->fCycle, rx_head->fSubCycle, rx_bytes - HEADER_SIZE, fRxHeader.fActivePorts); | |||
| // Last audio packet is received, so finish rendering... | |||
| if (fRxHeader.fIsLastPckt) | |||
| fNetAudioPlaybackBuffer->RenderToJackPorts(); | |||
| @@ -962,7 +964,8 @@ namespace Jack | |||
| fRxHeader.fCycle = rx_head->fCycle; | |||
| fRxHeader.fSubCycle = rx_head->fSubCycle; | |||
| fRxHeader.fIsLastPckt = rx_head->fIsLastPckt; | |||
| fNetAudioCaptureBuffer->RenderFromNetwork(rx_head->fCycle, rx_head->fSubCycle, rx_bytes - HEADER_SIZE); | |||
| fRxHeader.fActivePorts = rx_head->fActivePorts; | |||
| fNetAudioCaptureBuffer->RenderFromNetwork(rx_head->fCycle, rx_head->fSubCycle, rx_bytes - HEADER_SIZE, fRxHeader.fActivePorts); | |||
| // Last audio packet is received, so finish rendering... | |||
| if (fRxHeader.fIsLastPckt) | |||
| fNetAudioCaptureBuffer->RenderToJackPorts(); | |||
| @@ -1028,8 +1031,9 @@ namespace Jack | |||
| for (subproc = 0; subproc < fTxHeader.fNumPacket; subproc++) { | |||
| fTxHeader.fSubCycle = subproc; | |||
| fTxHeader.fIsLastPckt = (subproc == (fTxHeader.fNumPacket - 1)) ? 1 : 0; | |||
| fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioPlaybackBuffer->RenderToNetwork(subproc, data_size); | |||
| fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioPlaybackBuffer->RenderToNetwork(subproc, data_size, fTxHeader.fActivePorts); | |||
| memcpy(fTxBuffer, &fTxHeader, HEADER_SIZE); | |||
| //PacketHeaderDisplay(&fTxHeader); | |||
| if (Send(fTxHeader.fPacketSize, 0) == SOCKET_ERROR) | |||
| return SOCKET_ERROR; | |||
| } | |||
| @@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| using namespace std; | |||
| namespace Jack | |||
| { | |||
| //JackNetMaster****************************************************************************************************** | |||
| @@ -428,9 +429,19 @@ namespace Jack | |||
| fParams.fPeriodSize))); | |||
| } | |||
| for (int port_index = 0; port_index < fParams.fSendAudioChannels; port_index++) { | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| fNetAudioCaptureBuffer->SetBuffer(port_index, | |||
| static_cast<sample_t*>(jack_port_get_buffer_nulled(fAudioCapturePorts[port_index], | |||
| fParams.fPeriodSize))); | |||
| #else | |||
| fNetAudioCaptureBuffer->SetBuffer(port_index, | |||
| static_cast<sample_t*>(jack_port_get_buffer(fAudioCapturePorts[port_index], | |||
| fParams.fPeriodSize))); | |||
| #endif | |||
| } | |||
| for (int port_index = 0; port_index < fParams.fReturnMidiChannels; port_index++) { | |||
| fNetMidiPlaybackBuffer->SetBuffer(port_index, | |||
| @@ -438,9 +449,18 @@ namespace Jack | |||
| fParams.fPeriodSize))); | |||
| } | |||
| for (int port_index = 0; port_index < fParams.fReturnAudioChannels; port_index++) { | |||
| /* | |||
| */ | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| fNetAudioPlaybackBuffer->SetBuffer(port_index, | |||
| static_cast<sample_t*>(jack_port_get_buffer_nulled(fAudioPlaybackPorts[port_index], | |||
| fParams.fPeriodSize))); | |||
| #else | |||
| fNetAudioPlaybackBuffer->SetBuffer(port_index, | |||
| static_cast<sample_t*>(jack_port_get_buffer(fAudioPlaybackPorts[port_index], | |||
| fParams.fPeriodSize))); | |||
| #endif | |||
| } | |||
| if (IsSynched()) { // only send if connection is "synched" | |||
| @@ -133,13 +133,13 @@ namespace Jack | |||
| void NetMidiBuffer::DisplayEvents() | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| { | |||
| for (uint event = 0; event < fPortBuffer[port_index]->event_count; event++) | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| for (uint event = 0; event < fPortBuffer[port_index]->event_count; event++) { | |||
| if (fPortBuffer[port_index]->IsValid()) | |||
| jack_info("port %d : midi event %u/%u -> time : %u, size : %u", | |||
| port_index + 1, event + 1, fPortBuffer[port_index]->event_count, | |||
| fPortBuffer[port_index]->events[event].time, fPortBuffer[port_index]->events[event].size); | |||
| } | |||
| } | |||
| } | |||
| @@ -147,8 +147,8 @@ namespace Jack | |||
| { | |||
| int pos = 0; | |||
| size_t copy_size; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| char* write_pos = fBuffer + pos; | |||
| copy_size = sizeof(JackMidiBuffer) + fPortBuffer[port_index]->event_count * sizeof(JackMidiEvent); | |||
| memcpy(fBuffer + pos, fPortBuffer[port_index], copy_size); | |||
| @@ -167,8 +167,8 @@ namespace Jack | |||
| { | |||
| int pos = 0; | |||
| int copy_size; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(fBuffer + pos); | |||
| MidiBufferNToH(midi_buffer, midi_buffer); | |||
| copy_size = sizeof(JackMidiBuffer) + reinterpret_cast<JackMidiBuffer*>(fBuffer + pos)->event_count * sizeof(JackMidiEvent); | |||
| @@ -181,17 +181,17 @@ namespace Jack | |||
| return pos; | |||
| } | |||
| int NetMidiBuffer::RenderFromNetwork(int subcycle, size_t copy_size) | |||
| int NetMidiBuffer::RenderFromNetwork(int sub_cycle, size_t copy_size) | |||
| { | |||
| memcpy(fBuffer + subcycle * fMaxPcktSize, fNetBuffer, copy_size); | |||
| memcpy(fBuffer + sub_cycle * fMaxPcktSize, fNetBuffer, copy_size); | |||
| return copy_size; | |||
| } | |||
| int NetMidiBuffer::RenderToNetwork(int subcycle, size_t total_size) | |||
| int NetMidiBuffer::RenderToNetwork(int sub_cycle, size_t total_size) | |||
| { | |||
| int size = total_size - subcycle * fMaxPcktSize; | |||
| int size = total_size - sub_cycle * fMaxPcktSize; | |||
| int copy_size = (size <= fMaxPcktSize) ? size : fMaxPcktSize; | |||
| memcpy(fNetBuffer, fBuffer + subcycle * fMaxPcktSize, copy_size); | |||
| memcpy(fNetBuffer, fBuffer + sub_cycle * fMaxPcktSize, copy_size); | |||
| return copy_size; | |||
| } | |||
| @@ -219,25 +219,25 @@ namespace Jack | |||
| return fPortBuffer.GetBuffer(index); | |||
| } | |||
| int NetFloatAudioBuffer::RenderFromJackPorts () | |||
| int NetFloatAudioBuffer::RenderFromJackPorts() | |||
| { | |||
| return fPortBuffer.RenderFromJackPorts(); | |||
| } | |||
| int NetFloatAudioBuffer::RenderToJackPorts () | |||
| int NetFloatAudioBuffer::RenderToJackPorts() | |||
| { | |||
| return fPortBuffer.RenderToJackPorts(); | |||
| } | |||
| //network<->buffer | |||
| int NetFloatAudioBuffer::RenderFromNetwork(int cycle, int subcycle, size_t copy_size) | |||
| int NetFloatAudioBuffer::RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) | |||
| { | |||
| return fPortBuffer.RenderFromNetwork(fNetBuffer, cycle, subcycle, copy_size); | |||
| return fPortBuffer.RenderFromNetwork(fNetBuffer, cycle, sub_cycle, copy_size, port_num); | |||
| } | |||
| int NetFloatAudioBuffer::RenderToNetwork (int subcycle, size_t total_size) | |||
| int NetFloatAudioBuffer::RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num) | |||
| { | |||
| return fPortBuffer.RenderToNetwork(fNetBuffer, subcycle, total_size); | |||
| return fPortBuffer.RenderToNetwork(fNetBuffer, sub_cycle, total_size, port_num); | |||
| } | |||
| // Celt audio buffer ********************************************************************************* | |||
| @@ -443,36 +443,36 @@ namespace Jack | |||
| } | |||
| //network<->buffer | |||
| int NetCeltAudioBuffer::RenderFromNetwork(int cycle, int subcycle, size_t copy_size) | |||
| int NetCeltAudioBuffer::RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) | |||
| { | |||
| if (subcycle == fNumPackets - 1) { | |||
| if (sub_cycle == fNumPackets - 1) { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize); | |||
| memcpy(fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize); | |||
| } else { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| memcpy(fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| } | |||
| if (subcycle != fLastSubCycle + 1) | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, subcycle); | |||
| if (sub_cycle != fLastSubCycle + 1) | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, sub_cycle); | |||
| fLastSubCycle = subcycle; | |||
| fLastSubCycle = sub_cycle; | |||
| return copy_size; | |||
| } | |||
| int NetCeltAudioBuffer::RenderToNetwork(int subcycle, size_t total_size) | |||
| int NetCeltAudioBuffer::RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num) | |||
| { | |||
| if (subcycle == fNumPackets - 1) { | |||
| port_num = fNPorts; | |||
| if (sub_cycle == fNumPackets - 1) { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fLastSubPeriodBytesSize); | |||
| memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fLastSubPeriodBytesSize); | |||
| return fNPorts * fLastSubPeriodBytesSize; | |||
| } else { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fCompressedBuffer[port_index] + sub_cycle * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| return fNPorts * fSubPeriodBytesSize; | |||
| } | |||
| return fNPorts * fSubPeriodBytesSize; | |||
| } | |||
| #endif | |||
| @@ -577,32 +577,34 @@ namespace Jack | |||
| } | |||
| //network<->buffer | |||
| int NetIntAudioBuffer::RenderFromNetwork(int cycle, int subcycle, size_t copy_size) | |||
| int NetIntAudioBuffer::RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) | |||
| { | |||
| if (subcycle == fNumPackets - 1) { | |||
| if (sub_cycle == fNumPackets - 1) { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fIntBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize); | |||
| memcpy(fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize); | |||
| } else { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fIntBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| memcpy(fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| } | |||
| if (subcycle != fLastSubCycle + 1) | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, subcycle); | |||
| if (sub_cycle != fLastSubCycle + 1) | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, sub_cycle); | |||
| fLastSubCycle = subcycle; | |||
| fLastSubCycle = sub_cycle; | |||
| return copy_size; | |||
| } | |||
| int NetIntAudioBuffer::RenderToNetwork(int subcycle, size_t total_size) | |||
| int NetIntAudioBuffer::RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num) | |||
| { | |||
| if (subcycle == fNumPackets - 1) { | |||
| port_num = fNPorts; | |||
| if (sub_cycle == fNumPackets - 1) { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fIntBuffer[port_index] + subcycle * fSubPeriodSize, fLastSubPeriodBytesSize); | |||
| memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fLastSubPeriodBytesSize); | |||
| return fNPorts * fLastSubPeriodBytesSize; | |||
| } else { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fIntBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize); | |||
| memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fIntBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize); | |||
| return fNPorts * fSubPeriodBytesSize; | |||
| } | |||
| } | |||
| @@ -644,17 +646,17 @@ namespace Jack | |||
| return fJackPortBuffer[index]; | |||
| } | |||
| void NetBufferedAudioBuffer::RenderFromJackPorts (int subcycle) | |||
| void NetBufferedAudioBuffer::RenderFromJackPorts (int sub_cycle) | |||
| { | |||
| fPortBuffer[0].RenderFromJackPorts(fNetBuffer, subcycle); // Always use first buffer... | |||
| fPortBuffer[0].RenderFromJackPorts(fNetBuffer, sub_cycle); // Always use first buffer... | |||
| } | |||
| void NetBufferedAudioBuffer::RenderToJackPorts (int cycle, int subcycle) | |||
| void NetBufferedAudioBuffer::RenderToJackPorts (int cycle, int sub_cycle) | |||
| { | |||
| if (cycle < fMaxCycle) { | |||
| jack_info("Wrong order fCycle %d subcycle %d fMaxCycle %d", cycle, subcycle, fMaxCycle); | |||
| jack_info("Wrong order fCycle %d sub_cycle %d fMaxCycle %d", cycle, sub_cycle, fMaxCycle); | |||
| } | |||
| fPortBuffer[cycle % AUDIO_BUFFER_SIZE].RenderToJackPorts(fNetBuffer, subcycle); | |||
| fPortBuffer[cycle % AUDIO_BUFFER_SIZE].RenderToJackPorts(fNetBuffer, sub_cycle); | |||
| } | |||
| void NetBufferedAudioBuffer::FinishRenderToJackPorts (int cycle) | |||
| @@ -833,7 +835,9 @@ namespace Jack | |||
| jack_info("ID : %u", header->fID); | |||
| jack_info("Cycle : %u", header->fCycle); | |||
| jack_info("SubCycle : %u", header->fSubCycle); | |||
| jack_info("Active ports : %u", header->fActivePorts); | |||
| jack_info("DATA packets : %u", header->fNumPacket); | |||
| jack_info("DATA size : %u", header->fPacketSize); | |||
| jack_info("Last packet : '%s'", (header->fIsLastPckt) ? "yes" : "no"); | |||
| jack_info("Bitdepth : %s", bitdepth); | |||
| jack_info("**********************************************"); | |||
| @@ -31,14 +31,19 @@ using namespace std; | |||
| #ifndef htonll | |||
| #ifdef __BIG_ENDIAN__ | |||
| #define htonll(x) (x) | |||
| #define ntohll(x) (x) | |||
| #define htonll(x) (x) | |||
| #define ntohll(x) (x) | |||
| #else | |||
| #define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl(x >> 32)) | |||
| #define ntohll(x) ((((uint64_t)ntohl(x)) << 32) + ntohl(x >> 32)) | |||
| #define htonll(x) ((((uint64_t)htonl(x)) << 32) + htonl(x >> 32)) | |||
| #define ntohll(x) ((((uint64_t)ntohl(x)) << 32) + ntohl(x >> 32)) | |||
| #endif | |||
| #endif | |||
| #define MASTER_PROTOCOL 3 | |||
| #define SLAVE_PROTOCOL 3 | |||
| #define OPTIMIZED_PROTOCOL | |||
| namespace Jack | |||
| { | |||
| typedef struct _session_params session_params_t; | |||
| @@ -74,9 +79,6 @@ namespace Jack | |||
| are kept in LITTLE_ENDIAN format (to avoid 2 conversions in the more common LITTLE_ENDIAN <==> LITTLE_ENDIAN connection case). | |||
| */ | |||
| #define MASTER_PROTOCOL 2 | |||
| #define SLAVE_PROTOCOL 2 | |||
| struct _session_params | |||
| { | |||
| char fPacketType[7]; //packet type ('param') | |||
| @@ -167,6 +169,7 @@ namespace Jack | |||
| uint32_t fID; //unique ID of the slave | |||
| uint32_t fNumPacket; //number of data packets of the cycle | |||
| uint32_t fPacketSize; //packet size in bytes | |||
| uint32_t fActivePorts; //number of active ports | |||
| uint32_t fCycle; //process cycle counter | |||
| uint32_t fSubCycle; //midi/audio subcycle counter | |||
| uint32_t fIsLastPckt; //is it the last packet of a given cycle ('y' or 'n') | |||
| @@ -253,8 +256,8 @@ namespace Jack | |||
| int RenderToJackPorts(); | |||
| //network<->buffer | |||
| int RenderFromNetwork(int subcycle, size_t copy_size); | |||
| int RenderToNetwork(int subcycle, size_t total_size); | |||
| int RenderFromNetwork(int sub_cycle, size_t copy_size); | |||
| int RenderToNetwork(int sub_cycle, size_t total_size); | |||
| void SetBuffer(int index, JackMidiBuffer* buffer); | |||
| JackMidiBuffer* GetBuffer(int index); | |||
| @@ -285,8 +288,8 @@ namespace Jack | |||
| virtual int RenderToJackPorts() = 0; | |||
| //network<->buffer | |||
| virtual int RenderFromNetwork(int cycle, int subcycle, size_t copy_size) = 0; | |||
| virtual int RenderToNetwork(int subcycle, size_t total_size) = 0; | |||
| virtual int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) = 0; | |||
| virtual int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num) = 0; | |||
| virtual void SetBuffer(int index, sample_t* buffer) = 0; | |||
| virtual sample_t* GetBuffer(int index) = 0; | |||
| @@ -308,6 +311,7 @@ namespace Jack | |||
| 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 | |||
| @@ -319,12 +323,14 @@ namespace Jack | |||
| fNPorts = nports; | |||
| fPeriodSize = params->fPeriodSize; | |||
| fPacketSize = params->fMtu - sizeof(packet_header_t); | |||
| if (params->fSendAudioChannels == 0 && params->fReturnAudioChannels == 0) { | |||
| fSubPeriodSize = params->fPeriodSize; | |||
| } else { | |||
| jack_nframes_t period = (int) powf(2.f,(int)(log(float((params->fMtu - sizeof(packet_header_t))) | |||
| jack_nframes_t period = (int) powf(2.f,(int)(log(float(fPacketSize) | |||
| / (max(params->fReturnAudioChannels, params->fSendAudioChannels) * sizeof(sample_t))) / log(2.))); | |||
| fSubPeriodSize = (period > params->fPeriodSize) ? params->fPeriodSize : period; | |||
| fSubPeriodSize = (period > fPeriodSize) ? fPeriodSize : period; | |||
| } | |||
| fSubPeriodBytesSize = fSubPeriodSize * sizeof(sample_t); | |||
| @@ -339,8 +345,10 @@ namespace Jack | |||
| fLastSubCycle = -1; | |||
| } | |||
| int GetNumPackets() | |||
| virtual int GetNumPackets() | |||
| { | |||
| jack_info("GetNumPackets packet = %d fPeriodSize = %d fSubPeriodSize = %d fSubPeriodBytesSize = %d", | |||
| fPeriodSize / fSubPeriodSize, fPeriodSize, fSubPeriodSize, fSubPeriodBytesSize); | |||
| return fPeriodSize / fSubPeriodSize; | |||
| } | |||
| @@ -404,76 +412,79 @@ namespace Jack | |||
| return dat2.f; | |||
| } | |||
| int RenderFromJackPorts() | |||
| virtual int RenderFromJackPorts() | |||
| { | |||
| return fNPorts * fSubPeriodBytesSize; // in bytes | |||
| } | |||
| int RenderToJackPorts() | |||
| virtual int RenderToJackPorts() | |||
| { | |||
| return fPeriodSize * sizeof(sample_t); // in bytes TODO | |||
| } | |||
| //network<->buffer | |||
| int RenderFromNetwork(char* net_buffer, int cycle, int subcycle, size_t copy_size) | |||
| virtual int RenderFromNetwork(char* net_buffer, int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| float* src = (float*)(net_buffer + port_index * fSubPeriodBytesSize); | |||
| float* dst = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize); | |||
| float* dst = (float*)(fPortBuffer[port_index] + sub_cycle * fSubPeriodSize); | |||
| for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) { | |||
| dst[sample] = SwapFloat(src[sample]); | |||
| } | |||
| } | |||
| if (subcycle != fLastSubCycle + 1) { | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, subcycle); | |||
| if (sub_cycle != fLastSubCycle + 1) { | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, sub_cycle); | |||
| } | |||
| fLastSubCycle = subcycle; | |||
| fLastSubCycle = sub_cycle; | |||
| return copy_size; | |||
| } | |||
| int RenderToNetwork(char* net_buffer, int subcycle, size_t total_size) | |||
| virtual int RenderToNetwork(char* net_buffer, int sub_cycle, size_t total_size, uint32_t& port_num) | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| float* src = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize); | |||
| float* src = (float*)(fPortBuffer[port_index] + sub_cycle * fSubPeriodSize); | |||
| float* dst = (float*)(net_buffer + port_index * fSubPeriodBytesSize); | |||
| for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) { | |||
| dst[sample] = SwapFloat(src[sample]); | |||
| } | |||
| } | |||
| port_num = fNPorts; | |||
| return fNPorts * fSubPeriodBytesSize; | |||
| } | |||
| #else | |||
| int RenderFromJackPorts() | |||
| virtual int RenderFromJackPorts() | |||
| { | |||
| return fNPorts * fSubPeriodBytesSize; // in bytes | |||
| } | |||
| int RenderToJackPorts() | |||
| virtual int RenderToJackPorts() | |||
| { | |||
| fLastSubCycle = -1; | |||
| return fPeriodSize * sizeof(sample_t); // in bytes; TODO | |||
| } | |||
| //network<->buffer | |||
| int RenderFromNetwork(char* net_buffer, int cycle, int subcycle, size_t copy_size) | |||
| //network<->buffer | |||
| virtual int RenderFromNetwork(char* net_buffer, int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(fPortBuffer[port_index] + subcycle * fSubPeriodSize, net_buffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| if (subcycle != fLastSubCycle + 1) { | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, subcycle); | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| memcpy(fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, net_buffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); | |||
| } | |||
| if (sub_cycle != fLastSubCycle + 1) { | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, sub_cycle); | |||
| } | |||
| fLastSubCycle = subcycle; | |||
| fLastSubCycle = sub_cycle; | |||
| return copy_size; | |||
| } | |||
| int RenderToNetwork(char* net_buffer,int subcycle, size_t total_size) | |||
| virtual int RenderToNetwork(char* net_buffer, int sub_cycle, size_t total_size, uint32_t& port_num) | |||
| { | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) | |||
| memcpy(net_buffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize); | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| memcpy(net_buffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize); | |||
| } | |||
| port_num = fNPorts; | |||
| return fNPorts * fSubPeriodBytesSize; | |||
| } | |||
| @@ -481,6 +492,91 @@ namespace Jack | |||
| }; | |||
| struct JackOptimizedPortList : JackPortList { | |||
| JackOptimizedPortList(session_params_t* params, uint32_t nports) | |||
| :JackPortList(params, nports) | |||
| {} | |||
| int GetNumPackets() | |||
| { | |||
| // Count active ports | |||
| int active_ports = 0; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| if (fPortBuffer[port_index]) active_ports++; | |||
| } | |||
| if (active_ports == 0) { | |||
| fSubPeriodSize = fPeriodSize; | |||
| } else { | |||
| jack_nframes_t period = (int) powf(2.f, (int)(log(float(fPacketSize) / (active_ports * sizeof(sample_t))) / log(2.))); | |||
| fSubPeriodSize = (period > fPeriodSize) ? fPeriodSize : period; | |||
| } | |||
| fSubPeriodBytesSize = fSubPeriodSize * sizeof(sample_t) + sizeof(uint32_t); // The port number in coded on 4 bytes | |||
| return fPeriodSize / fSubPeriodSize; // At least one packet... | |||
| } | |||
| #ifdef __BIG_ENDIAN__ | |||
| // TODO | |||
| #else | |||
| //network<->buffer | |||
| virtual int RenderFromNetwork(char* net_buffer, int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) | |||
| { | |||
| /// Setup rendering parameters | |||
| int sub_period_size, sub_period_bytes_size; | |||
| if (port_num == 0) { | |||
| sub_period_size = fPeriodSize; | |||
| } else { | |||
| jack_nframes_t period = (int) powf(2.f, (int)(log(float(fPacketSize) / (port_num * sizeof(sample_t))) / log(2.))); | |||
| sub_period_size = (period > fPeriodSize) ? fPeriodSize : period; | |||
| } | |||
| sub_period_bytes_size = sub_period_size * sizeof(sample_t) + sizeof(uint32_t); // The port number in coded on 4 bytes | |||
| if (sub_cycle == 0) { // Cleanup all JACK ports | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| memset(fPortBuffer[port_index], 0, fPeriodSize * sizeof(sample_t)); | |||
| } | |||
| } | |||
| for (uint32_t port_index = 0; port_index < port_num; port_index++) { | |||
| // Only copy to active ports : get the active port number then audio data | |||
| int* active_port_address = (int*)(net_buffer + port_index * sub_period_bytes_size); | |||
| int active_port = (int)(*active_port_address); | |||
| memcpy(fPortBuffer[active_port] + sub_cycle * sub_period_size, (char*)(active_port_address + 1), sub_period_bytes_size - sizeof(int)); | |||
| } | |||
| if (sub_cycle != fLastSubCycle + 1) { | |||
| jack_error("Packet(s) missing from... %d %d", fLastSubCycle, sub_cycle); | |||
| } | |||
| fLastSubCycle = sub_cycle; | |||
| return copy_size; | |||
| } | |||
| virtual int RenderToNetwork(char* net_buffer,int sub_cycle, size_t total_size, uint32_t& port_num) | |||
| { | |||
| port_num = 0; | |||
| for (int port_index = 0; port_index < fNPorts; port_index++) { | |||
| // Only copy from active ports : set the active port number then audio data | |||
| if (fPortBuffer[port_index]) { | |||
| int* active_port_address = (int*)(net_buffer + port_num * fSubPeriodBytesSize); | |||
| *active_port_address = port_index; | |||
| memcpy((char*)(active_port_address + 1), fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize - sizeof(uint32_t)); | |||
| port_num++; | |||
| } | |||
| } | |||
| return port_num * fSubPeriodBytesSize; | |||
| } | |||
| #endif | |||
| }; | |||
| struct JackPortListAllocate : public JackPortList { | |||
| JackPortListAllocate() | |||
| @@ -524,7 +620,11 @@ namespace Jack | |||
| { | |||
| private: | |||
| #ifdef OPTIMIZED_PROTOCOL | |||
| JackOptimizedPortList fPortBuffer; | |||
| #else | |||
| JackPortList fPortBuffer; | |||
| #endif | |||
| char* fNetBuffer; | |||
| public: | |||
| @@ -554,8 +654,8 @@ namespace Jack | |||
| sample_t* GetBuffer(int index); | |||
| //network<->buffer | |||
| int RenderFromNetwork(int cycle, int subcycle, size_t copy_size); | |||
| int RenderToNetwork(int subcycle, size_t total_size); | |||
| int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num); | |||
| int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num); | |||
| }; | |||
| #if HAVE_CELT | |||
| @@ -581,10 +681,9 @@ namespace Jack | |||
| sample_t** fPortBuffer; | |||
| char* fNetBuffer; | |||
| unsigned char ** fCompressedBuffer; | |||
| unsigned char** fCompressedBuffer; | |||
| int fNPorts; | |||
| int fLastSubCycle; | |||
| void FreeCelt(); | |||
| @@ -599,7 +698,6 @@ namespace Jack | |||
| // cycle duration in sec | |||
| float GetCycleDuration(); | |||
| int GetNumPackets(); | |||
| void SetBuffer(int index, sample_t* buffer); | |||
| @@ -610,8 +708,8 @@ namespace Jack | |||
| int RenderToJackPorts(); | |||
| //network<->buffer | |||
| int RenderFromNetwork(int cycle, int subcycle, size_t copy_size); | |||
| int RenderToNetwork(int subcycle, size_t total_size); | |||
| int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num); | |||
| int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num); | |||
| }; | |||
| #endif | |||
| @@ -637,7 +735,6 @@ namespace Jack | |||
| short ** fIntBuffer; | |||
| int fNPorts; | |||
| int fLastSubCycle; | |||
| public: | |||
| @@ -650,7 +747,6 @@ namespace Jack | |||
| // cycle duration in sec | |||
| float GetCycleDuration(); | |||
| int GetNumPackets(); | |||
| void SetBuffer(int index, sample_t* buffer); | |||
| @@ -661,8 +757,8 @@ namespace Jack | |||
| int RenderToJackPorts(); | |||
| //network<->buffer | |||
| int RenderFromNetwork(int cycle, int subcycle, size_t copy_size); | |||
| int RenderToNetwork(int subcycle, size_t total_size); | |||
| int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num); | |||
| int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num); | |||
| }; | |||
| @@ -692,17 +788,17 @@ namespace Jack | |||
| } | |||
| //jack<->buffer | |||
| int RenderFromJackPorts(int subcycle); | |||
| int RenderToJackPorts(int cycle, int subcycle); | |||
| int RenderFromJackPorts(int sub_cycle); | |||
| int RenderToJackPorts(int cycle, int sub_cycle); | |||
| //void FinishRenderToJackPorts(int cycle); | |||
| //network<->buffer | |||
| int RenderFromNetwork(int subcycle, size_t copy_size) | |||
| int RenderFromNetwork(int sub_cycle, size_t copy_size) | |||
| { | |||
| // TODO | |||
| return 0; | |||
| } | |||
| int RenderToNetwork(int subcycle, size_t total_size) | |||
| int RenderToNetwork(int sub_cycle, size_t total_size) | |||
| { | |||
| // TODO | |||
| return 0; | |||
| @@ -735,6 +735,7 @@ int jack_port_unregister (jack_client_t *, jack_port_t *) JACK_OPTIONAL_WEAK_EXP | |||
| * Port buffers have to be retrieved in each callback for proper functionning. | |||
| */ | |||
| void * jack_port_get_buffer (jack_port_t *, jack_nframes_t) JACK_OPTIONAL_WEAK_EXPORT; | |||
| void * jack_port_get_buffer_nulled(jack_port_t* port, jack_nframes_t frames) JACK_OPTIONAL_WEAK_EXPORT; | |||
| /** | |||
| * @return the full name of the jack_port_t (including the @a | |||
| @@ -165,7 +165,7 @@ static OSStatus DisplayDeviceNames() | |||
| if (err != noErr) | |||
| return err; | |||
| jack_info("Device name = \'%s\', internal_name = \'%s\' (to be used as -C, -P, or -d parameter)", device_name, internal_name); | |||
| jack_info("Device name = \'%s\', internal name = \'%s\' (to be used as -C, -P, or -d parameter)", device_name, internal_name); | |||
| } | |||
| return noErr; | |||