Init engine fields, cleanup.
[jack2.git] / common / JackFrameTimer.h
blobaca70add380635b4c9682edb79d2a01f66fa909e
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 class SERVER_EXPORT JackTimer
38 friend class JackFrameTimer;
40 private:
42 jack_nframes_t fFrames;
43 jack_time_t fCurrentWakeup;
44 jack_time_t fCurrentCallback;
45 jack_time_t fNextWakeUp;
46 float fSecondOrderIntegrator;
47 float fFilterCoefficient; /* set once, never altered */
48 bool fInitialized;
50 public:
52 JackTimer();
53 ~JackTimer()
56 jack_nframes_t Time2Frames(jack_time_t time, jack_nframes_t buffer_size);
57 jack_time_t Frames2Time(jack_nframes_t frames, jack_nframes_t buffer_size);
58 jack_nframes_t FramesSinceCycleStart(jack_time_t cur_time, jack_nframes_t frames_rate);
60 jack_nframes_t CurFrame()
62 return fFrames;
65 jack_time_t CurTime()
67 return fCurrentWakeup;
70 } POST_PACKED_STRUCTURE;
72 /*!
73 \brief A class using the JackAtomicState to manage jack time.
76 class SERVER_EXPORT JackFrameTimer : public JackAtomicState<JackTimer>
79 private:
81 bool fFirstWakeUp;
82 void IncFrameTimeAux(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
83 void InitFrameTimeAux(jack_time_t callback_usecs, jack_time_t period_usecs);
85 public:
87 JackFrameTimer(): fFirstWakeUp(true)
89 ~JackFrameTimer()
92 void InitFrameTime();
93 void ResetFrameTime(jack_nframes_t frames_rate, jack_time_t callback_usecs, jack_time_t period_usecs);
94 void IncFrameTime(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
95 void ReadFrameTime(JackTimer* timer);
97 } POST_PACKED_STRUCTURE;
100 } // end of namespace
102 #endif