a644b61c92cd6339414ab06909cdc3d80687b41d
[ardour.git] / libs / backends / wavesaudio / wavesapi / miscutils / UMicroseconds.cpp
1 #ifdef _WINDOWS
2     #include "IncludeWindows.h"
3 #endif
4 #if defined(__linux__) || defined(__MACOS__)
5         #include <sys/time.h>
6 #endif
7
8 #include "UMicroseconds.h"
9
10 namespace wvNS { 
11 UMicroseconds& UMicroseconds::ReadTime()
12 {
13 #ifdef _WINDOWS
14         LARGE_INTEGER Frequency, Count ;
15
16         QueryPerformanceFrequency(&Frequency) ;
17         QueryPerformanceCounter(&Count);
18         theTime = uint64_t((Count.QuadPart * 1000000.0 / Frequency.QuadPart));
19 #endif
20
21 #if defined(__linux__) || defined(__MACOS__)
22 //      Mac code replaced by posix calls, to reduce Carbon dependency. 
23         timeval buf;
24
25         gettimeofday(&buf,NULL);
26
27         // micro sec
28         theTime = uint64_t(buf.tv_sec) * 1000*1000 + buf.tv_usec;
29 #endif
30
31         return *this;
32 }
33 /*
34  Removed in favor of the posix implementation. 
35 #ifdef __MACOS__
36         uint32_t UMicroseconds::hi() {return reinterpret_cast<UnsignedWide*>(&theTime)->hi;}
37         uint32_t UMicroseconds::lo() {return reinterpret_cast<UnsignedWide*>(&theTime)->lo;}
38 #endif
39 */
40 void UMicrosecondsAccumulator::Start()
41 {
42         m_start_time.ReadTime();
43 }
44
45 void UMicrosecondsAccumulator::Stop()
46 {
47         UMicroseconds stop_time;
48         
49         m_accumulator += stop_time.GetNativeTime() - m_start_time.GetNativeTime();
50 }
51
52 void UMicrosecondsAccumulator::Clear()
53 {
54         m_start_time = 0;
55         m_accumulator = 0;
56 }
57
58 UMicroseconds UMicrosecondsAccumulator::GetAccumulatedTime() const
59 {
60         return m_accumulator;
61 }
62
63 UMicrosecondsAccumulator& UMicrosecondsAccumulator::operator+=(const UMicrosecondsAccumulator& inaccum_to_add)
64 {
65         m_accumulator += inaccum_to_add.GetAccumulatedTime();
66         return *this;
67 }
68         
69 } // namespace wvNS {