diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index 337afe84..3cb0f56f 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -46,25 +46,20 @@ int JackAudioDriver::SetBufferSize(jack_nframes_t buffer_size) // Update engine and graph manager state fEngineControl->fBufferSize = buffer_size; fGraphManager->SetBufferSize(buffer_size); - fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec - if (!fEngineControl->fTimeOut) { - fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); - } - + + fEngineControl->UpdateTimeOut(); UpdateLatencies(); - // Redirect on slaves drivers... + // Redirected on slaves drivers... return JackDriver::SetBufferSize(buffer_size); } 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) { - fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); - } + fEngineControl->UpdateTimeOut(); + // Redirected on slaves drivers... return JackDriver::SetSampleRate(sample_rate); } diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index 19889549..4e0cbbc3 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -129,10 +129,7 @@ int JackDriver::Open(bool capturing, strcpy(fCaptureDriverName, capture_driver_name); strcpy(fPlaybackDriverName, playback_driver_name); - fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec - if (!fEngineControl->fTimeOut) { - fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); - } + fEngineControl->UpdateTimeOut(); fGraphManager->DirectConnect(fClientControl.fRefNum, fClientControl.fRefNum); // Connect driver to itself for "sync" mode SetupDriverSync(fClientControl.fRefNum, false); @@ -183,10 +180,7 @@ int JackDriver::Open(jack_nframes_t buffer_size, strcpy(fCaptureDriverName, capture_driver_name); strcpy(fPlaybackDriverName, playback_driver_name); - fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec - if (!fEngineControl->fTimeOut) { - fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs); - } + fEngineControl->UpdateTimeOut(); fGraphManager->SetBufferSize(buffer_size); fGraphManager->DirectConnect(fClientControl.fRefNum, fClientControl.fRefNum); // Connect driver to itself for "sync" mode diff --git a/common/JackDriver.h b/common/JackDriver.h index 4f230ebe..3cc564b8 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -176,7 +176,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface void CycleTakeEndTime(); void SetupDriverSync(int ref, bool freewheel); - + void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver void NotifyBufferSize(jack_nframes_t buffer_size); // BufferSize notification sent by the driver void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index dbd48c05..042444e0 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -163,8 +163,9 @@ void JackEngine::ProcessNext(jack_time_t cur_cycle_begin) void JackEngine::ProcessCurrent(jack_time_t cur_cycle_begin) { - if (cur_cycle_begin < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs) // Signal XRun only for the first failing cycle + if (cur_cycle_begin < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs) { // Signal XRun only for the first failing cycle CheckXRun(cur_cycle_begin); + } fGraphManager->RunCurrentGraph(); } @@ -265,10 +266,12 @@ void JackEngine::NotifyClient(int refnum, int event, int sync, const char* messa Important for internal clients : unlock before calling the notification callbacks. */ bool res = Unlock(); - if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, message, value1, value2) < 0) + if (client->ClientNotify(refnum, client->GetClientControl()->fName, event, sync, message, value1, value2) < 0) { jack_error("NotifyClient fails name = %s event = %ld val1 = %ld val2 = %ld", client->GetClientControl()->fName, event, value1, value2); - if (res) + } + if (res) { Lock(); + } } else { jack_log("JackEngine::NotifyClient: no callback for event = %ld", event); @@ -508,13 +511,15 @@ bool JackEngine::ClientCheckName(const char* name) { for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (strcmp(client->GetClientControl()->fName, name) == 0)) + if (client && (strcmp(client->GetClientControl()->fName, name) == 0)) { return true; + } } for (std::map::iterator i = fReservationMap.begin(); i != fReservationMap.end(); i++) { - if (i->second == name) + if (i->second == name) { return true; + } } return false; @@ -527,8 +532,9 @@ int JackEngine::GetNewUUID() void JackEngine::EnsureUUID(int uuid) { - if (uuid > fMaxUUID) - fMaxUUID = uuid+1; + if (uuid > fMaxUUID) { + fMaxUUID = uuid + 1; + } for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; @@ -542,8 +548,9 @@ int JackEngine::GetClientPID(const char* name) { for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (strcmp(client->GetClientControl()->fName, name) == 0)) + if (client && (strcmp(client->GetClientControl()->fName, name) == 0)) { return client->GetClientControl()->fPID; + } } return 0; @@ -553,8 +560,9 @@ int JackEngine::GetClientRefNum(const char* name) { for (int i = 0; i < CLIENT_NUM; i++) { JackClientInterface* client = fClientTable[i]; - if (client && (strcmp(client->GetClientControl()->fName, name) == 0)) + if (client && (strcmp(client->GetClientControl()->fName, name) == 0)) { return client->GetClientControl()->fRefNum; + } } return -1; diff --git a/common/JackEngineControl.h b/common/JackEngineControl.h index 7e168708..87263150 100644 --- a/common/JackEngineControl.h +++ b/common/JackEngineControl.h @@ -124,6 +124,14 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem ~JackEngineControl() {} + + void UpdateTimeOut() + { + fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize); // In microsec + if (!(fTimeOut && fTimeOutUsecs > 2 * fPeriodUsecs)) { + fTimeOutUsecs = 2 * fPeriodUsecs; + } + } // Cycle void CycleIncTime(jack_time_t callback_usecs) diff --git a/common/JackMidiDriver.cpp b/common/JackMidiDriver.cpp index de5f295d..db707853 100644 --- a/common/JackMidiDriver.cpp +++ b/common/JackMidiDriver.cpp @@ -136,6 +136,8 @@ int JackMidiDriver::SetBufferSize(jack_nframes_t buffer_size) int JackMidiDriver::ProcessReadSync() { int res = 0; + + jack_log("JackMidiDriver::ProcessReadSync"); // Read input buffers for the current cycle if (Read() < 0) { @@ -154,6 +156,8 @@ int JackMidiDriver::ProcessReadSync() int JackMidiDriver::ProcessWriteSync() { int res = 0; + + jack_log("JackMidiDriver::ProcessWriteSync"); if (SuspendRefNum() < 0) { jack_error("JackMidiDriver::ProcessWriteSync: SuspendRefNum error"); @@ -172,6 +176,8 @@ int JackMidiDriver::ProcessWriteSync() int JackMidiDriver::ProcessReadAsync() { int res = 0; + + jack_log("JackMidiDriver::ProcessReadAsync"); // Read input buffers for the current cycle if (Read() < 0) { @@ -195,6 +201,7 @@ int JackMidiDriver::ProcessReadAsync() int JackMidiDriver::ProcessWriteAsync() { +jack_log("JackMidiDriver::ProcessWriteAsync"); return 0; }