vamp-sdk/RealTime.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef _VAMP_REAL_TIME_H_
00045 #define _VAMP_REAL_TIME_H_
00046
00047 #include <iostream>
00048 #include <string>
00049
00050 #ifndef _WIN32
00051 struct timeval;
00052 #endif
00053
00054 #include "plugguard.h"
00055 _VAMP_SDK_PLUGSPACE_BEGIN(RealTime.h)
00056
00057 namespace Vamp {
00058
00066 struct RealTime
00067 {
00068 int sec;
00069 int nsec;
00070
00071 int usec() const { return nsec / 1000; }
00072 int msec() const { return nsec / 1000000; }
00073
00074 RealTime(): sec(0), nsec(0) {}
00075 RealTime(int s, int n);
00076
00077 RealTime(const RealTime &r) :
00078 sec(r.sec), nsec(r.nsec) { }
00079
00080 static RealTime fromSeconds(double sec);
00081 static RealTime fromMilliseconds(int msec);
00082
00083 #ifndef _WIN32
00084 static RealTime fromTimeval(const struct timeval &);
00085 #endif
00086
00087 RealTime &operator=(const RealTime &r) {
00088 sec = r.sec; nsec = r.nsec; return *this;
00089 }
00090
00091 RealTime operator+(const RealTime &r) const {
00092 return RealTime(sec + r.sec, nsec + r.nsec);
00093 }
00094 RealTime operator-(const RealTime &r) const {
00095 return RealTime(sec - r.sec, nsec - r.nsec);
00096 }
00097 RealTime operator-() const {
00098 return RealTime(-sec, -nsec);
00099 }
00100
00101 bool operator <(const RealTime &r) const {
00102 if (sec == r.sec) return nsec < r.nsec;
00103 else return sec < r.sec;
00104 }
00105
00106 bool operator >(const RealTime &r) const {
00107 if (sec == r.sec) return nsec > r.nsec;
00108 else return sec > r.sec;
00109 }
00110
00111 bool operator==(const RealTime &r) const {
00112 return (sec == r.sec && nsec == r.nsec);
00113 }
00114
00115 bool operator!=(const RealTime &r) const {
00116 return !(r == *this);
00117 }
00118
00119 bool operator>=(const RealTime &r) const {
00120 if (sec == r.sec) return nsec >= r.nsec;
00121 else return sec >= r.sec;
00122 }
00123
00124 bool operator<=(const RealTime &r) const {
00125 if (sec == r.sec) return nsec <= r.nsec;
00126 else return sec <= r.sec;
00127 }
00128
00129 RealTime operator/(int d) const;
00130
00134 double operator/(const RealTime &r) const;
00135
00140 std::string toString() const;
00141
00146 std::string toText(bool fixedDp = false) const;
00147
00151 static long realTime2Frame(const RealTime &r, unsigned int sampleRate);
00152
00156 static RealTime frame2RealTime(long frame, unsigned int sampleRate);
00157
00158 static const RealTime zeroTime;
00159 };
00160
00161 std::ostream &operator<<(std::ostream &out, const RealTime &rt);
00162
00163 }
00164
00165 _VAMP_SDK_PLUGSPACE_END(RealTime.h)
00166
00167 #endif