Jack2  1.9.9
JackFrameTimer.h
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 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.
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 Lesser General Public License for more details.
14 
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.
18 
19 */
20 
21 #ifndef __JackFrameTimer__
22 #define __JackFrameTimer__
23 
24 #include "JackAtomicState.h"
25 #include "JackCompilerDeps.h"
26 #include "types.h"
27 
28 namespace Jack
29 {
30 
35 PRE_PACKED_STRUCTURE
36 class SERVER_EXPORT JackTimer
37 {
38 
39  friend class JackFrameTimer;
40 
41  private:
42 
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;
50 
51  public:
52 
53  JackTimer();
54  ~JackTimer()
55  {}
56 
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);
61 
62  jack_nframes_t CurFrame()
63  {
64  return fFrames;
65  }
66 
67  jack_time_t CurTime()
68  {
69  return fCurrentWakeup;
70  }
71 
72 } POST_PACKED_STRUCTURE;
73 
78 PRE_PACKED_STRUCTURE
79 class SERVER_EXPORT JackFrameTimer : public JackAtomicState<JackTimer>
80 {
81 
82  private:
83 
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);
87 
88  public:
89 
90  JackFrameTimer(): fFirstWakeUp(true)
91  {}
93  {}
94 
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);
99 
100 } POST_PACKED_STRUCTURE;
101 
102 
103 } // end of namespace
104 
105 #endif
A structure used for time management.
A class to handle two states (switching from one to the other) in a lock-free manner.
A class using the JackAtomicState to manage jack time.