diff --git a/ChangeLog b/ChangeLog index 7be8e615..86c71d16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,10 +20,14 @@ Fernando Lopez-Lezcano Jackdmp changes log --------------------------- +2008-05-27 Stephane Letz + + * Correct timing in drivers : frame time has to be incremented before Read. + 2008-05-26 Stephane Letz - * Merge control branch. - * Cleanup example clients : use jack_client_open and install a proper 'quit' signal handler. + * Merge control branch. + * Cleanup example clients : use jack_client_open and install a proper 'quit' signal handler. 2008-05-24 Stephane Letz diff --git a/common/JackDummyDriver.cpp b/common/JackDummyDriver.cpp index 8ea3dd90..42773636 100644 --- a/common/JackDummyDriver.cpp +++ b/common/JackDummyDriver.cpp @@ -61,6 +61,7 @@ int JackDummyDriver::Open(jack_nframes_t nframes, int JackDummyDriver::Process() { fLastWaitUst = GetMicroSeconds(); // Take callback date here + fEngineControl->CycleIncTime(fLastWaitUst); JackAudioDriver::Process(); usleep(std::max(0L, long(fWaitTime - (GetMicroSeconds() - fLastWaitUst)))); return 0; diff --git a/common/JackEngineControl.cpp b/common/JackEngineControl.cpp index df0d414f..405a80d2 100644 --- a/common/JackEngineControl.cpp +++ b/common/JackEngineControl.cpp @@ -27,14 +27,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. namespace Jack { +void JackEngineControl::CycleIncTime(jack_time_t callback_usecs) +{ + // Timer + fFrameTimer.IncFrameTime(fBufferSize, callback_usecs, fPeriodUsecs); +} + void JackEngineControl::CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs) { // Transport fTransport.CycleBegin(fSampleRate, callback_usecs); - // Timer - fFrameTimer.IncFrameTime(fBufferSize, callback_usecs, fPeriodUsecs); - // Timing GetTimeMeasure(table, manager, callback_usecs); CalcCPULoad(table, manager); diff --git a/common/JackEngineControl.h b/common/JackEngineControl.h index 1e321c93..ced24488 100644 --- a/common/JackEngineControl.h +++ b/common/JackEngineControl.h @@ -138,6 +138,7 @@ struct JackEngineControl : public JackShmMem {} // Cycle + void CycleIncTime(jack_time_t callback_usecs); void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs); void CycleEnd(JackClientInterface** table); diff --git a/linux/alsa/JackAlsaDriver.cpp b/linux/alsa/JackAlsaDriver.cpp index 78b1257d..eca1a6d4 100644 --- a/linux/alsa/JackAlsaDriver.cpp +++ b/linux/alsa/JackAlsaDriver.cpp @@ -45,7 +45,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "hdsp.h" #include "ice1712.h" #include "usx2y.h" - #include "generic.h" #include "memops.h" @@ -1209,7 +1208,7 @@ JackAlsaDriver::alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed timersub(&now, &tstamp, &diff); *delayed_usecs = diff.tv_sec * 1000000.0 + diff.tv_usec; - // steph: utiliser une version TR + // steph: TODO use a RT version jack_error("\n\n**** alsa_pcm: xrun of at least %.3f msecs\n\n", *delayed_usecs / 1000.0); } @@ -2293,6 +2292,9 @@ int JackAlsaDriver::Read() if (nframes != fEngineControl->fBufferSize) jack_log("JackAlsaDriver::Read nframes = %ld", nframes); + + // Has to be done before read + fEngineControl->CycleIncTime(fLastWaitUst); return alsa_driver_read((alsa_driver_t *)fDriver, fEngineControl->fBufferSize); } diff --git a/linux/alsa/alsa_rawmidi.c b/linux/alsa/alsa_rawmidi.c index 9c329187..fbc82958 100644 --- a/linux/alsa/alsa_rawmidi.c +++ b/linux/alsa/alsa_rawmidi.c @@ -768,6 +768,7 @@ void jack_process(midi_stream_t *str, jack_nframes_t nframes) { int r, w; process_jack_t proc; + jack_nframes_t cur_frames; if (!str->owner->keep_walking) return; @@ -775,6 +776,13 @@ void jack_process(midi_stream_t *str, jack_nframes_t nframes) proc.midi = str->owner; proc.nframes = nframes; proc.frame_time = jack_last_frame_time(proc.midi->client); + cur_frames = jack_frame_time(proc.midi->client); + int periods_diff = cur_frames - proc.frame_time; + if (periods_diff < proc.nframes) { + int periods_lost = periods_diff / proc.nframes; + proc.frame_time += periods_lost * proc.nframes; + debug_log("xrun detected: %d periods lost", periods_lost); + } // process existing ports for (r=0, w=0; rjack.nports; ++r) { diff --git a/linux/firewire/JackFFADODriver.cpp b/linux/firewire/JackFFADODriver.cpp index 7c57bd59..59228eb7 100644 --- a/linux/firewire/JackFFADODriver.cpp +++ b/linux/firewire/JackFFADODriver.cpp @@ -745,6 +745,9 @@ int JackFFADODriver::Read() if (nframes != fEngineControl->fBufferSize) jack_log("JackFFADODriver::Read nframes = %ld", nframes); + + // Has to be done before read + fEngineControl->CycleIncTime(fLastWaitUst); printExit(); return ffado_driver_read((ffado_driver_t *)fDriver, fEngineControl->fBufferSize); diff --git a/linux/freebob/JackFreebobDriver.cpp b/linux/freebob/JackFreebobDriver.cpp index 17cc1ec9..923c1a61 100644 --- a/linux/freebob/JackFreebobDriver.cpp +++ b/linux/freebob/JackFreebobDriver.cpp @@ -261,7 +261,7 @@ JackFreebobDriver::SetBufferSize (jack_nframes_t nframes) printError("Buffer size change requested but not supported!!!"); /* - driver->period_size = nframes; + driver->period_size = nframes; driver->period_usecs = (jack_time_t) floor ((((float) nframes) / driver->sample_rate) * 1000000.0f); @@ -870,7 +870,7 @@ int JackFreebobDriver::Read() /* we detected an xrun and restarted: notify * clients about the delay. */ - jack_log("FreeBoB XRun "); + jack_log("FreeBoB XRun"); NotifyXRun(fLastWaitUst, fDelayedUsecs); return -1; } @@ -878,7 +878,9 @@ int JackFreebobDriver::Read() if (nframes != fEngineControl->fBufferSize) jack_log("JackFreebobDriver::Read nframes = %ld", nframes); - //return engine->run_cycle (engine, nframes, delayed_usecs); + // Has to be done before read + fEngineControl->CycleIncTime(fLastWaitUst); + printExit(); return freebob_driver_read((freebob_driver_t *)fDriver, fEngineControl->fBufferSize); } diff --git a/macosx/JackCoreAudioDriver.cpp b/macosx/JackCoreAudioDriver.cpp index 7753a588..818a5ba4 100644 --- a/macosx/JackCoreAudioDriver.cpp +++ b/macosx/JackCoreAudioDriver.cpp @@ -173,6 +173,7 @@ OSStatus JackCoreAudioDriver::Render(void *inRefCon, driver->fActionFags = ioActionFlags; driver->fCurrentTime = (AudioTimeStamp *)inTimeStamp; driver->fDriverOutputData = ioData; + driver->fEngineControl->CycleIncTime(driver->fLastWaitUst); return driver->Process(); } diff --git a/windows/JackPortAudioDriver.cpp b/windows/JackPortAudioDriver.cpp index 40f82f9a..206c5e28 100644 --- a/windows/JackPortAudioDriver.cpp +++ b/windows/JackPortAudioDriver.cpp @@ -223,6 +223,7 @@ int JackPortAudioDriver::Render(const void* inputBuffer, void* outputBuffer, driver->fOutputBuffer = (float**)outputBuffer; // Setup threadded based log function set_threaded_log_function(); + driver->fEngineControl->CycleIncTime(driver->fLastWaitUst); return (driver->Process() == 0) ? paContinue : paAbort; }