2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "JackTimedDriver.h"
22 #include "JackEngineControl.h"
24 #include "JackCompilerDeps.h"
32 int JackTimedDriver::FirstCycle(jack_time_t cur_time_usec
)
34 fAnchorTimeUsec
= cur_time_usec
;
35 return int((double(fEngineControl
->fBufferSize
) * 1000000) / double(fEngineControl
->fSampleRate
));
38 int JackTimedDriver::CurrentCycle(jack_time_t cur_time_usec
)
40 return int(((double(fCycleCount
) * double(fEngineControl
->fBufferSize
) * 1000000.) / double(fEngineControl
->fSampleRate
)) - (cur_time_usec
- fAnchorTimeUsec
));
43 int JackTimedDriver::Start()
46 return JackAudioDriver::Start();
49 void JackTimedDriver::ProcessWait()
51 jack_time_t cur_time_usec
= GetMicroSeconds();
54 if (fCycleCount
++ == 0) {
55 wait_time_usec
= FirstCycle(cur_time_usec
);
57 wait_time_usec
= CurrentCycle(cur_time_usec
);
60 if (wait_time_usec
< 0) {
61 NotifyXRun(cur_time_usec
, float(cur_time_usec
- fBeginDateUst
));
64 jack_error("JackTimedDriver::Process XRun = %ld usec", (cur_time_usec
- fBeginDateUst
));
67 //jack_log("JackTimedDriver::Process wait_time = %d", wait_time_usec);
68 JackSleep(wait_time_usec
);
71 int JackWaiterDriver::ProcessNull()
73 JackDriver::CycleTakeBeginTime();
75 // Graph processing without Read/Write
76 if (fEngineControl
->fSyncMode
) {
82 // Keep end cycle time
83 JackDriver::CycleTakeEndTime();