comparison src/vamp-sdk/RealTime.cpp @ 419:55de53d7c777

Merge
author Chris Cannam
date Tue, 01 Mar 2016 12:21:23 +0000
parents 6f88563ea26f
children 35fa4733bc5d
comparison
equal deleted inserted replaced
418:a13635e9c440 419:55de53d7c777
90 } 90 }
91 91
92 RealTime 92 RealTime
93 RealTime::fromSeconds(double sec) 93 RealTime::fromSeconds(double sec)
94 { 94 {
95 return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5)); 95 if (sec != sec) { // NaN
96 cerr << "ERROR: NaN/Inf passed to Vamp::RealTime::fromSeconds" << endl;
97 return RealTime::zeroTime;
98 } else if (sec >= 0) {
99 return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5));
100 } else {
101 return -fromSeconds(-sec);
102 }
96 } 103 }
97 104
98 RealTime 105 RealTime
99 RealTime::fromMilliseconds(int msec) 106 RealTime::fromMilliseconds(int msec)
100 { 107 {
137 RealTime::toString() const 144 RealTime::toString() const
138 { 145 {
139 std::stringstream out; 146 std::stringstream out;
140 out << *this; 147 out << *this;
141 148
142 #if (__GNUC__ < 3)
143 out << std::ends;
144 #endif
145
146 std::string s = out.str(); 149 std::string s = out.str();
147 150
148 // remove trailing R 151 // remove trailing R
149 return s.substr(0, s.length() - 1); 152 return s.substr(0, s.length() - 1);
150 } 153 }
155 if (*this < RealTime::zeroTime) return "-" + (-*this).toText(); 158 if (*this < RealTime::zeroTime) return "-" + (-*this).toText();
156 159
157 std::stringstream out; 160 std::stringstream out;
158 161
159 if (sec >= 3600) { 162 if (sec >= 3600) {
160 out << (sec / 3600) << ":"; 163 out << (sec / 3600) << ":";
161 } 164 }
162 165
163 if (sec >= 60) { 166 if (sec >= 60) {
164 out << (sec % 3600) / 60 << ":"; 167 int minutes = (sec % 3600) / 60;
165 } 168 if (sec >= 3600 && minutes < 10) out << "0";
166 169 out << minutes << ":";
170 }
171
167 if (sec >= 10) { 172 if (sec >= 10) {
168 out << ((sec % 60) / 10); 173 out << ((sec % 60) / 10);
169 } 174 }
170 175
171 out << (sec % 10); 176 out << (sec % 10);
172 177
173 int ms = msec(); 178 int ms = msec();
174 179
175 if (ms != 0) { 180 if (ms != 0) {
189 } 194 }
190 } else if (fixedDp) { 195 } else if (fixedDp) {
191 out << ".000"; 196 out << ".000";
192 } 197 }
193 198
194 #if (__GNUC__ < 3)
195 out << std::ends;
196 #endif
197
198 std::string s = out.str(); 199 std::string s = out.str();
199 200
200 return s; 201 return s;
201 } 202 }
202
203 203
204 RealTime 204 RealTime
205 RealTime::operator/(int d) const 205 RealTime::operator/(int d) const
206 { 206 {
207 int secdiv = sec / d; 207 int secdiv = sec / d;