xref: /haiku/src/add-ons/media/media-add-ons/multi_audio/TimeComputer.h (revision a085e81e62d7a860f809b4fb7c7bf5654c396985)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef TIME_COMPUTER_H
6 #define TIME_COMPUTER_H
7 
8 
9 #include <SupportDefs.h>
10 
11 
12 struct TimeComputer {
13 								TimeComputer();
14 
15 			void				Init(float frameRate, bigtime_t realBaseTime);
16 			void				SetFrameRate(float frameRate);
17 
18 			void				AddTimeStamp(bigtime_t realTime, uint64 frames);
19 
20 			bigtime_t			RealTime() const	{ return fRealTime; }
21 			bigtime_t			PerformanceTime() const
22 									{ return fPerformanceTime; }
23 			double				Drift() const		{ return fDrift; }
24 
25 private:
26 	static	const int32			kEntryCount = 32;
27 
28 			struct Entry {
29 				bigtime_t	realTime;
30 				bigtime_t	performanceTime;
31 			};
32 
33 private:
34 			void				_AddEntry(bigtime_t realTime,
35 									bigtime_t performanceTime);
36 
37 private:
38 			bigtime_t			fRealTime;
39 			bigtime_t			fPerformanceTime;
40 			double				fDrift;
41 			float				fFrameRate;
42 			double				fUsecsPerFrame;
43 			bigtime_t			fPerformanceTimeBase;
44 			uint64				fFrameBase;
45 			bool				fResetTimeBase;
46 			Entry				fEntries[kEntryCount];
47 			int32				fFirstEntry;
48 			int32				fLastEntry;
49 };
50 
51 
52 #endif	// TIME_COMPUTER_H
53