JackFrameTimer.h 2.66 KB
Newer Older
sletz's avatar
sletz committed
1
/*
sletz's avatar
sletz committed
2
Copyright (C) 2001 Paul Davis
sletz's avatar
sletz committed
3
Copyright (C) 2004-2008 Grame
sletz's avatar
sletz committed
4
5

This program is free software; you can redistribute it and/or modify
sletz's avatar
sletz committed
6
7
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
sletz's avatar
sletz committed
8
9
10
11
12
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
sletz's avatar
sletz committed
13
GNU Lesser General Public License for more details.
sletz's avatar
sletz committed
14

sletz's avatar
sletz committed
15
16
17
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
sletz's avatar
sletz committed
18
19
20
21
22
23
24

*/

#ifndef __JackFrameTimer__
#define __JackFrameTimer__

#include "JackAtomicState.h"
25
#include "JackCompilerDeps.h"
sletz's avatar
sletz committed
26
27
28
29
30
31
32
33
34
#include "types.h"

namespace Jack
{

/*!
\brief A structure used for time management.
*/

35
class SERVER_EXPORT JackTimer
sletz's avatar
sletz committed
36
37
{

sletz's avatar
sletz committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    friend class JackFrameTimer;
    
    private: 
    
        jack_nframes_t fFrames;
        jack_time_t	fCurrentWakeup;
        jack_time_t	fCurrentCallback;
        jack_time_t	fNextWakeUp;
        float fSecondOrderIntegrator;
        bool fInitialized;
        float fFilterCoefficient;	/* set once, never altered */

    public: 
    
        JackTimer();
        ~JackTimer()
        {}
        
        jack_nframes_t Time2Frames(jack_time_t time, jack_nframes_t buffer_size);
        jack_time_t Frames2Time(jack_nframes_t frames, jack_nframes_t buffer_size);
        jack_nframes_t FramesSinceCycleStart(jack_time_t cur_time, jack_nframes_t frames_rate);
        
        jack_nframes_t CurFrame()
        {
            return fFrames;
        }
        
        jack_time_t CurTime()
        {
            return fCurrentWakeup;
        }
sletz's avatar
sletz committed
69

sletz's avatar
sletz committed
70
71
72
};

/*!
sletz's avatar
sletz committed
73
\brief A class using the JackAtomicState to manage jack time.
sletz's avatar
sletz committed
74
75
*/

sletz's avatar
sletz committed
76
class SERVER_EXPORT JackFrameTimer : public JackAtomicState<JackTimer>
sletz's avatar
sletz committed
77
{
sletz's avatar
sletz committed
78
    
sletz's avatar
sletz committed
79
80
81
    private:

        bool fFirstWakeUp;
sletz's avatar
sletz committed
82
        void IncFrameTimeAux(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
sletz's avatar
sletz committed
83
        void InitFrameTimeAux(jack_time_t callback_usecs, jack_time_t period_usecs);
sletz's avatar
sletz committed
84
85
86
87
88
89
90
91

    public:

        JackFrameTimer(): fFirstWakeUp(true)
        {}
        ~JackFrameTimer()
        {}

sletz's avatar
sletz committed
92
        void InitFrameTime();
sletz's avatar
sletz committed
93
        void ResetFrameTime(jack_nframes_t frames_rate, jack_time_t callback_usecs, jack_time_t period_usecs);
sletz's avatar
sletz committed
94
        void IncFrameTime(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
sletz's avatar
sletz committed
95
        void ReadFrameTime(JackTimer* timer);
sletz's avatar
sletz committed
96
97
        
} POST_PACKED_STRUCTURE;
sletz's avatar
sletz committed
98
99
100
101
102


} // end of namespace

#endif