Jack2
1.9.8
|
00001 /* 00002 Copyright (C) 2001 Paul Davis 00003 Copyright (C) 2004-2008 Grame 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 00019 */ 00020 00021 #include "JackTimedDriver.h" 00022 #include "JackEngineControl.h" 00023 #include "JackTime.h" 00024 #include "JackCompilerDeps.h" 00025 #include <iostream> 00026 #include <unistd.h> 00027 #include <math.h> 00028 00029 namespace Jack 00030 { 00031 00032 int JackTimedDriver::FirstCycle(jack_time_t cur_time_usec) 00033 { 00034 fAnchorTimeUsec = cur_time_usec; 00035 return int((double(fEngineControl->fBufferSize) * 1000000) / double(fEngineControl->fSampleRate)); 00036 } 00037 00038 int JackTimedDriver::CurrentCycle(jack_time_t cur_time_usec) 00039 { 00040 return int(((double(fCycleCount) * double(fEngineControl->fBufferSize) * 1000000.) / double(fEngineControl->fSampleRate)) - (cur_time_usec - fAnchorTimeUsec)); 00041 } 00042 00043 int JackTimedDriver::Start() 00044 { 00045 fCycleCount = 0; 00046 return JackAudioDriver::Start(); 00047 } 00048 00049 void JackTimedDriver::ProcessWait() 00050 { 00051 jack_time_t cur_time_usec = GetMicroSeconds(); 00052 int wait_time_usec; 00053 00054 if (fCycleCount++ == 0) { 00055 wait_time_usec = FirstCycle(cur_time_usec); 00056 } else { 00057 wait_time_usec = CurrentCycle(cur_time_usec); 00058 } 00059 00060 if (wait_time_usec < 0) { 00061 NotifyXRun(cur_time_usec, float(cur_time_usec - fBeginDateUst)); 00062 fCycleCount = 0; 00063 wait_time_usec = 0; 00064 jack_error("JackTimedDriver::Process XRun = %ld usec", (cur_time_usec - fBeginDateUst)); 00065 } 00066 00067 //jack_log("JackTimedDriver::Process wait_time = %d", wait_time_usec); 00068 JackSleep(wait_time_usec); 00069 } 00070 00071 int JackWaiterDriver::ProcessNull() 00072 { 00073 JackDriver::CycleTakeBeginTime(); 00074 00075 // Graph processing without Read/Write 00076 if (fEngineControl->fSyncMode) { 00077 ProcessGraphSync(); 00078 } else { 00079 ProcessGraphAsync(); 00080 } 00081 00082 // Keep end cycle time 00083 JackDriver::CycleTakeEndTime(); 00084 00085 ProcessWait(); 00086 return 0; 00087 } 00088 00089 } // end of namespace