comparison base/RealTime.h @ 1040:a1cd5abcb38b cxx11

Introduce and use a samplerate type
author Chris Cannam
date Wed, 04 Mar 2015 12:01:04 +0000
parents cc27f35aa75c
children b8a788c9a6f1
comparison
equal deleted inserted replaced
1039:b14064bd1f97 1040:a1cd5abcb38b
24 #include "BaseTypes.h" 24 #include "BaseTypes.h"
25 25
26 #include <iostream> 26 #include <iostream>
27 #include <string> 27 #include <string>
28 28
29 #include <vamp-hostsdk/RealTime.h>
30
29 struct timeval; 31 struct timeval;
30 32
31 /** 33 /**
32 * RealTime represents time values to nanosecond precision 34 * RealTime represents time values to nanosecond precision
33 * with accurate arithmetic and frame-rate conversion functions. 35 * with accurate arithmetic and frame-rate conversion functions.
45 RealTime(int s, int n); 47 RealTime(int s, int n);
46 48
47 RealTime(const RealTime &r) : 49 RealTime(const RealTime &r) :
48 sec(r.sec), nsec(r.nsec) { } 50 sec(r.sec), nsec(r.nsec) { }
49 51
52 RealTime(const Vamp::RealTime &r) :
53 sec(r.sec), nsec(r.nsec) { }
54
50 static RealTime fromSeconds(double sec); 55 static RealTime fromSeconds(double sec);
51 static RealTime fromMilliseconds(int msec); 56 static RealTime fromMilliseconds(int msec);
52 static RealTime fromTimeval(const struct timeval &); 57 static RealTime fromTimeval(const struct timeval &);
53 static RealTime fromXsdDuration(std::string xsdd); 58 static RealTime fromXsdDuration(std::string xsdd);
54 59
55 double toDouble() const; 60 double toDouble() const;
61 Vamp::RealTime toVampRealTime() const { return Vamp::RealTime(sec, nsec); }
56 62
57 RealTime &operator=(const RealTime &r) { 63 RealTime &operator=(const RealTime &r) {
58 sec = r.sec; nsec = r.nsec; return *this; 64 sec = r.sec; nsec = r.nsec; return *this;
59 } 65 }
60 66
148 std::string toXsdDuration() const; 154 std::string toXsdDuration() const;
149 155
150 /** 156 /**
151 * Convert a RealTime into a sample frame at the given sample rate. 157 * Convert a RealTime into a sample frame at the given sample rate.
152 */ 158 */
153 static sv_frame_t realTime2Frame(const RealTime &r, int sampleRate); 159 static sv_frame_t realTime2Frame(const RealTime &r, sv_samplerate_t sampleRate);
154 160
155 /** 161 /**
156 * Convert a sample frame at the given sample rate into a RealTime. 162 * Convert a sample frame at the given sample rate into a RealTime.
157 */ 163 */
158 static RealTime frame2RealTime(sv_frame_t frame, int sampleRate); 164 static RealTime frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate);
159 165
160 static const RealTime zeroTime; 166 static const RealTime zeroTime;
161 }; 167 };
162 168
163 std::ostream &operator<<(std::ostream &out, const RealTime &rt); 169 std::ostream &operator<<(std::ostream &out, const RealTime &rt);