Merge branch 'master' into develop
[jack2.git] / common / JackFrameTimer.h
bloba32e7423fe1405af2d0222ed8a5a2b11003e59bc
1 /*
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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #ifndef __JackFrameTimer__
22 #define __JackFrameTimer__
24 #include "JackAtomicState.h"
25 #include "JackCompilerDeps.h"
26 #include "types.h"
28 namespace Jack
31 /*!
32 \brief A structure used for time management.
35 PRE_PACKED_STRUCTURE
36 class SERVER_EXPORT JackTimer
39 friend class JackFrameTimer;
41 private:
43 jack_nframes_t fFrames;
44 jack_time_t fCurrentWakeup;
45 jack_time_t fCurrentCallback;
46 jack_time_t fNextWakeUp;
47 float fPeriodUsecs;
48 float fFilterOmega; /* set once, never altered */
49 bool fInitialized;
51 public:
53 JackTimer();
54 ~JackTimer()
57 jack_nframes_t Time2Frames(jack_time_t time, jack_nframes_t buffer_size);
58 jack_time_t Frames2Time(jack_nframes_t frames, jack_nframes_t buffer_size);
59 jack_nframes_t FramesSinceCycleStart(jack_time_t cur_time, jack_nframes_t frames_rate);
60 int GetCycleTimes(jack_nframes_t* current_frames, jack_time_t* current_usecs, jack_time_t* next_usecs, float* period_usecs);
62 jack_nframes_t CurFrame()
64 return fFrames;
67 jack_time_t CurTime()
69 return fCurrentWakeup;
72 } POST_PACKED_STRUCTURE;
74 /*!
75 \brief A class using the JackAtomicState to manage jack time.
78 PRE_PACKED_STRUCTURE
79 class SERVER_EXPORT JackFrameTimer : public JackAtomicState<JackTimer>
82 private:
84 bool fFirstWakeUp;
85 void IncFrameTimeAux(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
86 void InitFrameTimeAux(jack_time_t callback_usecs, jack_time_t period_usecs);
88 public:
90 JackFrameTimer(): fFirstWakeUp(true)
92 ~JackFrameTimer()
95 void InitFrameTime();
96 void ResetFrameTime(jack_time_t callback_usecs);
97 void IncFrameTime(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
98 void ReadFrameTime(JackTimer* timer);
100 } POST_PACKED_STRUCTURE;
103 } // end of namespace
105 #endif