2 Copyright (C) 2014 Waves Audio Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __UMicroseconds_h__
21 #define __UMicroseconds_h__
24 #include "UMicroseconds.h"
29 #include "BasicTypes/WUDefines.h"
30 #include "BasicTypes/WUTypes.h"
33 // a wraper for Microseconds function from Timer.h
34 class DllExport UMicroseconds
38 #ifdef PLATFORM_WINDOWS
39 typedef int64_t TimeKeeper;
42 typedef uint64_t TimeKeeper;
45 typedef uint64_t TimeKeeper;
58 UMicroseconds(const TimeKeeper in_initVal) : theTime(in_initVal) {}
60 UMicroseconds(const UMicroseconds& inUM) : theTime(inUM.theTime) {}
61 UMicroseconds& operator=(const UMicroseconds& inUM) {theTime = inUM.theTime; return *this;}
62 UMicroseconds& operator+=(const TimeKeeper in_timeToAdd) {theTime += in_timeToAdd; return *this;}
64 UMicroseconds& ReadTime();
66 TimeKeeper GetNativeTime() const {return theTime;}
67 operator uint64_t () {return static_cast<uint64_t>(theTime);}
68 operator double () const {return static_cast<const double>(theTime);}
70 double Seconds() const {return static_cast<double>(theTime) / double(1000000);}
71 double MilliSeconds() const {return static_cast<double>(theTime) / double(1000);}
72 double MicroSeconds() const {return static_cast<double>(theTime);}
80 inline UMicroseconds operator-(const UMicroseconds& in_one, const UMicroseconds& in_two)
82 UMicroseconds retVal(in_one.GetNativeTime() - in_two.GetNativeTime());
86 class UMicrosecondsAccumulator
89 UMicrosecondsAccumulator() : m_start_time(0), m_accumulator(0) {}
95 UMicroseconds GetAccumulatedTime() const;
97 UMicrosecondsAccumulator& operator+=(const UMicrosecondsAccumulator&);
100 UMicroseconds m_start_time;
101 UMicroseconds m_accumulator;
104 inline UMicroseconds operator-(const UMicrosecondsAccumulator& in_one, const UMicrosecondsAccumulator& in_two)
106 UMicroseconds retVal(in_one.GetAccumulatedTime() - in_two.GetAccumulatedTime());
110 //=========================================================================================//
111 inline void MicrosecondDelay(double amt)
112 //=========================================================================================//
120 } while ((now.MicroSeconds() - than.MicroSeconds()) < amt);
123 } // namespace wvNS {
124 #endif //#ifndef __UMicroseconds_h__