Jack2 1.9.12

JackTimedDriver.cpp
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4
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.
9
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.
14
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.
18
19 */
20
21 #include "JackTimedDriver.h"
22 #include "JackEngineControl.h"
23 #include "JackTime.h"
24 #include "JackCompilerDeps.h"
25 #include <iostream>
26 #include <unistd.h>
27 #include <math.h>
28
29 namespace Jack
30 {
31
32 int JackTimedDriver::FirstCycle(jack_time_t cur_time_usec)
33 {
34 fAnchorTimeUsec = cur_time_usec;
35 return int((double(fEngineControl->fBufferSize) * 1000000) / double(fEngineControl->fSampleRate));
36 }
37
38 int JackTimedDriver::CurrentCycle(jack_time_t cur_time_usec)
39 {
40 return int(((double(fCycleCount) * double(fEngineControl->fBufferSize) * 1000000.) / double(fEngineControl->fSampleRate)) - (cur_time_usec - fAnchorTimeUsec));
41 }
42
43 int JackTimedDriver::Start()
44 {
45 fCycleCount = 0;
46 return JackAudioDriver::Start();
47 }
48
49 void JackTimedDriver::ProcessWait()
50 {
51 jack_time_t cur_time_usec = GetMicroSeconds();
52 int wait_time_usec;
53
54 if (fCycleCount++ == 0) {
55 wait_time_usec = FirstCycle(cur_time_usec);
56 } else {
57 wait_time_usec = CurrentCycle(cur_time_usec);
58 }
59
60 if (wait_time_usec < 0) {
61 NotifyXRun(cur_time_usec, float(cur_time_usec - fBeginDateUst));
62 fCycleCount = 0;
63 wait_time_usec = 0;
64 jack_error("JackTimedDriver::Process XRun = %ld usec", (cur_time_usec - fBeginDateUst));
65 }
66
67 //jack_log("JackTimedDriver::Process wait_time = %d", wait_time_usec);
68 JackSleep(wait_time_usec);
69 }
70
71 int JackWaiterDriver::ProcessNull()
72 {
73 JackDriver::CycleTakeBeginTime();
74
75 // Graph processing without Read/Write
76 if (fEngineControl->fSyncMode) {
77 ProcessGraphSync();
78 } else {
79 ProcessGraphAsync();
80 }
81
82 // Keep end cycle time
83 JackDriver::CycleTakeEndTime();
84
85 ProcessWait();
86 return 0;
87 }
88
89 void JackRestarterDriver::SetRestartDriver(JackDriver* driver)
90 {
91 fRestartDriver = driver;
92 }
93
94 int JackRestarterDriver::RestartWait()
95 {
96 if (!fRestartDriver) {
97 jack_error("JackRestartedDriver::RestartWait driver not set");
98 return -1;
99 }
100 return fRestartDriver->Start();
101 }
102
103 } // end of namespace
jack_error
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:92
Jack::JackRestarterDriver::SetRestartDriver
void SetRestartDriver(JackDriver *driver)
Definition: JackTimedDriver.cpp:89
Jack::JackDriver
Definition: JackDriver.h:127
Jack::JackRestarterDriver::RestartWait
int RestartWait()
Definition: JackTimedDriver.cpp:94