Commit f786e831 authored by sletz's avatar sletz
Browse files

Correct timing in drivers : frame time has to be incremented before Read.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2357 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 834f9674
......@@ -20,10 +20,14 @@ Fernando Lopez-Lezcano
Jackdmp changes log
---------------------------
2008-05-27 Stephane Letz <letz@grame.fr>
* Correct timing in drivers : frame time has to be incremented before Read.
2008-05-26 Stephane Letz <letz@grame.fr>
* 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 <letz@grame.fr>
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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; r<str->jack.nports; ++r) {
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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();
}
......
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment