annotate base/test/TestOurRealTime.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 71207822a7e0
children
rev   line source
Chris@1262 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1262 2
Chris@1262 3 /*
Chris@1262 4 Sonic Visualiser
Chris@1262 5 An audio file viewer and annotation editor.
Chris@1262 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1262 7
Chris@1262 8 This program is free software; you can redistribute it and/or
Chris@1262 9 modify it under the terms of the GNU General Public License as
Chris@1262 10 published by the Free Software Foundation; either version 2 of the
Chris@1262 11 License, or (at your option) any later version. See the file
Chris@1262 12 COPYING included with this distribution for more information.
Chris@1262 13 */
Chris@1262 14
Chris@1262 15 #ifndef TEST_OUR_REALTIME_H
Chris@1262 16 #define TEST_OUR_REALTIME_H
Chris@1262 17
Chris@1262 18 #include <QObject>
Chris@1262 19 #include <QtTest>
Chris@1262 20 #include <QDir>
Chris@1262 21
Chris@1262 22 #include <iostream>
Chris@1262 23
Chris@1262 24 #include "../RealTime.h"
Chris@1262 25
Chris@1262 26 using namespace std;
Chris@1262 27
Chris@1262 28 #define ONE_MILLION 1000000
Chris@1262 29 #define ONE_BILLION 1000000000
Chris@1262 30
Chris@1262 31 class TestOurRealTime : public QObject
Chris@1262 32 {
Chris@1262 33 Q_OBJECT
Chris@1262 34
Chris@1262 35 void compareTexts(string s, const char *e) {
Chris@1262 36 QCOMPARE(QString(s.c_str()), QString(e));
Chris@1262 37 }
Chris@1262 38
Chris@1262 39 typedef sv_frame_t frame_type;
Chris@1262 40
Chris@1262 41 private slots:
Chris@1262 42
Chris@1262 43 void zero()
Chris@1262 44 {
Chris@1344 45 QCOMPARE(RealTime(0, 0), RealTime::zeroTime);
Chris@1344 46 QCOMPARE(RealTime(0, 0).sec, 0);
Chris@1344 47 QCOMPARE(RealTime(0, 0).nsec, 0);
Chris@1344 48 QCOMPARE(RealTime(0, 0).msec(), 0);
Chris@1344 49 QCOMPARE(RealTime(0, 0).usec(), 0);
Chris@1262 50 }
Chris@1262 51
Chris@1262 52 void ctor()
Chris@1262 53 {
Chris@1344 54 QCOMPARE(RealTime(0, 0), RealTime(0, 0));
Chris@1262 55
Chris@1344 56 // wraparounds
Chris@1344 57 QCOMPARE(RealTime(0, ONE_BILLION/2), RealTime(1, -ONE_BILLION/2));
Chris@1344 58 QCOMPARE(RealTime(0, -ONE_BILLION/2), RealTime(-1, ONE_BILLION/2));
Chris@1262 59
Chris@1344 60 QCOMPARE(RealTime(1, ONE_BILLION), RealTime(2, 0));
Chris@1344 61 QCOMPARE(RealTime(1, -ONE_BILLION), RealTime(0, 0));
Chris@1344 62 QCOMPARE(RealTime(-1, ONE_BILLION), RealTime(0, 0));
Chris@1344 63 QCOMPARE(RealTime(-1, -ONE_BILLION), RealTime(-2, 0));
Chris@1262 64
Chris@1268 65 QCOMPARE(RealTime(1, -ONE_BILLION-ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
Chris@1268 66 QCOMPARE(RealTime(-1, ONE_BILLION+ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
Chris@1268 67
Chris@1344 68 QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0));
Chris@1344 69 QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
Chris@1262 70
Chris@1344 71 QCOMPARE(RealTime(-2, ONE_BILLION*2), RealTime(0, 0));
Chris@1344 72 QCOMPARE(RealTime(-2, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
Chris@1427 73
Chris@1427 74 QCOMPARE(RealTime(1, -ONE_BILLION/2).sec, 0);
Chris@1427 75 QCOMPARE(RealTime(1, -ONE_BILLION/2).nsec, ONE_BILLION/2);
Chris@1427 76 QCOMPARE(RealTime(-1, ONE_BILLION/2).sec, 0);
Chris@1427 77 QCOMPARE(RealTime(-1, ONE_BILLION/2).nsec, -ONE_BILLION/2);
Chris@1344 78
Chris@1344 79 QCOMPARE(RealTime(0, 1).sec, 0);
Chris@1344 80 QCOMPARE(RealTime(0, 1).nsec, 1);
Chris@1344 81 QCOMPARE(RealTime(0, -1).sec, 0);
Chris@1344 82 QCOMPARE(RealTime(0, -1).nsec, -1);
Chris@1344 83 QCOMPARE(RealTime(1, -1).sec, 0);
Chris@1344 84 QCOMPARE(RealTime(1, -1).nsec, ONE_BILLION-1);
Chris@1344 85 QCOMPARE(RealTime(-1, 1).sec, 0);
Chris@1344 86 QCOMPARE(RealTime(-1, 1).nsec, -ONE_BILLION+1);
Chris@1344 87 QCOMPARE(RealTime(-1, -1).sec, -1);
Chris@1344 88 QCOMPARE(RealTime(-1, -1).nsec, -1);
Chris@1344 89
Chris@1344 90 QCOMPARE(RealTime(2, -ONE_BILLION*2).sec, 0);
Chris@1344 91 QCOMPARE(RealTime(2, -ONE_BILLION*2).nsec, 0);
Chris@1344 92 QCOMPARE(RealTime(2, -ONE_BILLION/2).sec, 1);
Chris@1344 93 QCOMPARE(RealTime(2, -ONE_BILLION/2).nsec, ONE_BILLION/2);
Chris@1262 94
Chris@1344 95 QCOMPARE(RealTime(-2, ONE_BILLION*2).sec, 0);
Chris@1344 96 QCOMPARE(RealTime(-2, ONE_BILLION*2).nsec, 0);
Chris@1344 97 QCOMPARE(RealTime(-2, ONE_BILLION/2).sec, -1);
Chris@1344 98 QCOMPARE(RealTime(-2, ONE_BILLION/2).nsec, -ONE_BILLION/2);
Chris@1262 99 }
Chris@1262 100
Chris@1262 101 void fromSeconds()
Chris@1262 102 {
Chris@1344 103 QCOMPARE(RealTime::fromSeconds(0), RealTime(0, 0));
Chris@1262 104
Chris@1344 105 QCOMPARE(RealTime::fromSeconds(0.5).sec, 0);
Chris@1344 106 QCOMPARE(RealTime::fromSeconds(0.5).nsec, ONE_BILLION/2);
Chris@1344 107 QCOMPARE(RealTime::fromSeconds(0.5).usec(), ONE_MILLION/2);
Chris@1344 108 QCOMPARE(RealTime::fromSeconds(0.5).msec(), 500);
Chris@1344 109
Chris@1344 110 QCOMPARE(RealTime::fromSeconds(0.5), RealTime(0, ONE_BILLION/2));
Chris@1344 111 QCOMPARE(RealTime::fromSeconds(1), RealTime(1, 0));
Chris@1344 112 QCOMPARE(RealTime::fromSeconds(1.5), RealTime(1, ONE_BILLION/2));
Chris@1262 113
Chris@1344 114 QCOMPARE(RealTime::fromSeconds(-0.5).sec, 0);
Chris@1344 115 QCOMPARE(RealTime::fromSeconds(-0.5).nsec, -ONE_BILLION/2);
Chris@1344 116 QCOMPARE(RealTime::fromSeconds(-0.5).usec(), -ONE_MILLION/2);
Chris@1344 117 QCOMPARE(RealTime::fromSeconds(-0.5).msec(), -500);
Chris@1344 118
Chris@1344 119 QCOMPARE(RealTime::fromSeconds(-1.5).sec, -1);
Chris@1344 120 QCOMPARE(RealTime::fromSeconds(-1.5).nsec, -ONE_BILLION/2);
Chris@1344 121 QCOMPARE(RealTime::fromSeconds(-1.5).usec(), -ONE_MILLION/2);
Chris@1344 122 QCOMPARE(RealTime::fromSeconds(-1.5).msec(), -500);
Chris@1344 123
Chris@1344 124 QCOMPARE(RealTime::fromSeconds(-0.5), RealTime(0, -ONE_BILLION/2));
Chris@1344 125 QCOMPARE(RealTime::fromSeconds(-1), RealTime(-1, 0));
Chris@1344 126 QCOMPARE(RealTime::fromSeconds(-1.5), RealTime(-1, -ONE_BILLION/2));
Chris@1262 127 }
Chris@1262 128
Chris@1262 129 void fromMilliseconds()
Chris@1262 130 {
Chris@1344 131 QCOMPARE(RealTime::fromMilliseconds(0), RealTime(0, 0));
Chris@1344 132 QCOMPARE(RealTime::fromMilliseconds(500), RealTime(0, ONE_BILLION/2));
Chris@1344 133 QCOMPARE(RealTime::fromMilliseconds(1000), RealTime(1, 0));
Chris@1344 134 QCOMPARE(RealTime::fromMilliseconds(1500), RealTime(1, ONE_BILLION/2));
Chris@1262 135
Chris@1344 136 QCOMPARE(RealTime::fromMilliseconds(-0), RealTime(0, 0));
Chris@1344 137 QCOMPARE(RealTime::fromMilliseconds(-500), RealTime(0, -ONE_BILLION/2));
Chris@1344 138 QCOMPARE(RealTime::fromMilliseconds(-1000), RealTime(-1, 0));
Chris@1344 139 QCOMPARE(RealTime::fromMilliseconds(-1500), RealTime(-1, -ONE_BILLION/2));
Chris@1262 140 }
Chris@1541 141
Chris@1541 142 void fromMicroseconds()
Chris@1541 143 {
Chris@1541 144 QCOMPARE(RealTime::fromMicroseconds(0), RealTime(0, 0));
Chris@1541 145 QCOMPARE(RealTime::fromMicroseconds(500000), RealTime(0, ONE_BILLION/2));
Chris@1541 146 QCOMPARE(RealTime::fromMicroseconds(1000000), RealTime(1, 0));
Chris@1541 147 QCOMPARE(RealTime::fromMicroseconds(1500000), RealTime(1, ONE_BILLION/2));
Chris@1541 148
Chris@1541 149 QCOMPARE(RealTime::fromMicroseconds(-0), RealTime(0, 0));
Chris@1541 150 QCOMPARE(RealTime::fromMicroseconds(-500000), RealTime(0, -ONE_BILLION/2));
Chris@1541 151 QCOMPARE(RealTime::fromMicroseconds(-1000000), RealTime(-1, 0));
Chris@1541 152 QCOMPARE(RealTime::fromMicroseconds(-1500000), RealTime(-1, -ONE_BILLION/2));
Chris@1541 153 QCOMPARE(RealTime::fromMicroseconds(13500000), RealTime(13, ONE_BILLION/2));
Chris@1541 154 }
Chris@1262 155
Chris@1262 156 void fromTimeval()
Chris@1262 157 {
Chris@1344 158 struct timeval tv;
Chris@1262 159
Chris@1344 160 tv.tv_sec = 0; tv.tv_usec = 0;
Chris@1344 161 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, 0));
Chris@1344 162 tv.tv_sec = 0; tv.tv_usec = ONE_MILLION/2;
Chris@1344 163 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, ONE_BILLION/2));
Chris@1344 164 tv.tv_sec = 1; tv.tv_usec = 0;
Chris@1344 165 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, 0));
Chris@1344 166 tv.tv_sec = 1; tv.tv_usec = ONE_MILLION/2;
Chris@1344 167 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, ONE_BILLION/2));
Chris@1262 168
Chris@1344 169 tv.tv_sec = 0; tv.tv_usec = -ONE_MILLION/2;
Chris@1344 170 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, -ONE_BILLION/2));
Chris@1344 171 tv.tv_sec = -1; tv.tv_usec = 0;
Chris@1344 172 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, 0));
Chris@1344 173 tv.tv_sec = -1; tv.tv_usec = -ONE_MILLION/2;
Chris@1344 174 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, -ONE_BILLION/2));
Chris@1262 175 }
Chris@1262 176
Chris@1262 177 void fromXsdDuration()
Chris@1262 178 {
Chris@1344 179 QCOMPARE(RealTime::fromXsdDuration("PT0"), RealTime::zeroTime);
Chris@1344 180 QCOMPARE(RealTime::fromXsdDuration("PT0S"), RealTime::zeroTime);
Chris@1344 181 QCOMPARE(RealTime::fromXsdDuration("PT10S"), RealTime(10, 0));
Chris@1344 182 QCOMPARE(RealTime::fromXsdDuration("PT10.5S"), RealTime(10, ONE_BILLION/2));
Chris@1344 183 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").sec, 1);
Chris@1344 184 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").msec(), 500);
Chris@1344 185 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").sec, -1);
Chris@1344 186 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").msec(), -500);
Chris@1344 187 QCOMPARE(RealTime::fromXsdDuration("PT1M30.5S"), RealTime(90, ONE_BILLION/2));
Chris@1344 188 QCOMPARE(RealTime::fromXsdDuration("PT1H2M30.5S"), RealTime(3750, ONE_BILLION/2));
Chris@1262 189 }
Chris@1262 190
Chris@1262 191 void toDouble()
Chris@1262 192 {
Chris@1344 193 QCOMPARE(RealTime(0, 0).toDouble(), 0.0);
Chris@1344 194 QCOMPARE(RealTime(0, ONE_BILLION/2).toDouble(), 0.5);
Chris@1344 195 QCOMPARE(RealTime(1, 0).toDouble(), 1.0);
Chris@1344 196 QCOMPARE(RealTime(1, ONE_BILLION/2).toDouble(), 1.5);
Chris@1262 197
Chris@1344 198 QCOMPARE(RealTime(0, -ONE_BILLION/2).toDouble(), -0.5);
Chris@1344 199 QCOMPARE(RealTime(-1, 0).toDouble(), -1.0);
Chris@1344 200 QCOMPARE(RealTime(-1, -ONE_BILLION/2).toDouble(), -1.5);
Chris@1262 201 }
Chris@1262 202
Chris@1262 203 void assign()
Chris@1262 204 {
Chris@1344 205 RealTime r;
Chris@1344 206 r = RealTime(0, 0);
Chris@1344 207 QCOMPARE(r, RealTime::zeroTime);
Chris@1344 208 r = RealTime(0, ONE_BILLION/2);
Chris@1262 209 QCOMPARE(r.sec, 0);
Chris@1262 210 QCOMPARE(r.nsec, ONE_BILLION/2);
Chris@1344 211 r = RealTime(-1, -ONE_BILLION/2);
Chris@1262 212 QCOMPARE(r.sec, -1);
Chris@1262 213 QCOMPARE(r.nsec, -ONE_BILLION/2);
Chris@1262 214 }
Chris@1262 215
Chris@1262 216 void plus()
Chris@1262 217 {
Chris@1344 218 QCOMPARE(RealTime(0, 0) + RealTime(0, 0), RealTime(0, 0));
Chris@1262 219
Chris@1344 220 QCOMPARE(RealTime(0, 0) + RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
Chris@1344 221 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(0, ONE_BILLION/2), RealTime(1, 0));
Chris@1344 222 QCOMPARE(RealTime(1, 0) + RealTime(0, ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
Chris@1262 223
Chris@1344 224 QCOMPARE(RealTime(0, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
Chris@1344 225 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(-1, 0));
Chris@1344 226 QCOMPARE(RealTime(-1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
Chris@1262 227
Chris@1344 228 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
Chris@1344 229 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, 0));
Chris@1344 230 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
Chris@1262 231
Chris@1344 232 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(-1, 0), RealTime(0, -ONE_BILLION/2));
Chris@1344 233 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(1, 0), RealTime(0, ONE_BILLION/2));
Chris@1262 234 }
Chris@1262 235
Chris@1262 236 void minus()
Chris@1262 237 {
Chris@1344 238 QCOMPARE(RealTime(0, 0) - RealTime(0, 0), RealTime(0, 0));
Chris@1262 239
Chris@1344 240 QCOMPARE(RealTime(0, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
Chris@1344 241 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(0, ONE_BILLION/2), RealTime(0, 0));
Chris@1344 242 QCOMPARE(RealTime(1, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
Chris@1262 243
Chris@1344 244 QCOMPARE(RealTime(0, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
Chris@1344 245 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(0, 0));
Chris@1344 246 QCOMPARE(RealTime(-1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
Chris@1262 247
Chris@1344 248 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
Chris@1344 249 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, 0));
Chris@1344 250 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, ONE_BILLION/2));
Chris@1262 251
Chris@1344 252 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(-1, 0), RealTime(1, ONE_BILLION/2));
Chris@1344 253 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(1, 0), RealTime(-1, -ONE_BILLION/2));
Chris@1262 254 }
Chris@1262 255
Chris@1262 256 void negate()
Chris@1262 257 {
Chris@1344 258 QCOMPARE(-RealTime(0, 0), RealTime(0, 0));
Chris@1344 259 QCOMPARE(-RealTime(1, 0), RealTime(-1, 0));
Chris@1344 260 QCOMPARE(-RealTime(1, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
Chris@1344 261 QCOMPARE(-RealTime(-1, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
Chris@1262 262 }
Chris@1262 263
Chris@1262 264 void compare()
Chris@1262 265 {
Chris@1344 266 int sec, nsec;
Chris@1344 267 for (sec = -2; sec <= 2; sec += 2) {
Chris@1344 268 for (nsec = -1; nsec <= 1; nsec += 1) {
Chris@1344 269 QCOMPARE(RealTime(sec, nsec) < RealTime(sec, nsec), false);
Chris@1344 270 QCOMPARE(RealTime(sec, nsec) > RealTime(sec, nsec), false);
Chris@1344 271 QCOMPARE(RealTime(sec, nsec) == RealTime(sec, nsec), true);
Chris@1344 272 QCOMPARE(RealTime(sec, nsec) != RealTime(sec, nsec), false);
Chris@1344 273 QCOMPARE(RealTime(sec, nsec) <= RealTime(sec, nsec), true);
Chris@1344 274 QCOMPARE(RealTime(sec, nsec) >= RealTime(sec, nsec), true);
Chris@1344 275 }
Chris@1344 276 }
Chris@1344 277 RealTime prev(-3, 0);
Chris@1344 278 for (sec = -2; sec <= 2; sec += 2) {
Chris@1344 279 for (nsec = -1; nsec <= 1; nsec += 1) {
Chris@1262 280
Chris@1344 281 RealTime curr(sec, nsec);
Chris@1262 282
Chris@1344 283 QCOMPARE(prev < curr, true);
Chris@1344 284 QCOMPARE(prev > curr, false);
Chris@1344 285 QCOMPARE(prev == curr, false);
Chris@1344 286 QCOMPARE(prev != curr, true);
Chris@1344 287 QCOMPARE(prev <= curr, true);
Chris@1344 288 QCOMPARE(prev >= curr, false);
Chris@1262 289
Chris@1344 290 QCOMPARE(curr < prev, false);
Chris@1344 291 QCOMPARE(curr > prev, true);
Chris@1344 292 QCOMPARE(curr == prev, false);
Chris@1344 293 QCOMPARE(curr != prev, true);
Chris@1344 294 QCOMPARE(curr <= prev, false);
Chris@1344 295 QCOMPARE(curr >= prev, true);
Chris@1262 296
Chris@1344 297 prev = curr;
Chris@1344 298 }
Chris@1344 299 }
Chris@1262 300 }
Chris@1262 301
Chris@1262 302 void frame()
Chris@1262 303 {
Chris@1262 304 int frames[] = {
Chris@1262 305 0, 1, 2047, 2048, 6656,
Chris@1262 306 32767, 32768, 44100, 44101,
Chris@1262 307 999999999, 2000000000
Chris@1262 308 };
Chris@1262 309 int n = sizeof(frames)/sizeof(frames[0]);
Chris@1262 310
Chris@1262 311 int rates[] = {
Chris@1262 312 1, 2, 8000, 22050,
Chris@1262 313 44100, 44101, 192000, 2000000001
Chris@1262 314 };
Chris@1262 315 int m = sizeof(rates)/sizeof(rates[0]);
Chris@1262 316
Chris@1262 317 vector<vector<RealTime>> realTimes = {
Chris@1262 318 { { 0, 0 }, { 1, 0 }, { 2047, 0 }, { 2048, 0 },
Chris@1262 319 { 6656, 0 }, { 32767, 0 }, { 32768, 0 }, { 44100, 0 },
Chris@1262 320 { 44101, 0 }, { 999999999, 0 }, { 2000000000, 0 } },
Chris@1262 321 { { 0, 0 }, { 0, 500000000 }, { 1023, 500000000 }, { 1024, 0 },
Chris@1262 322 { 3328, 0 }, { 16383, 500000000 }, { 16384, 0 }, { 22050, 0 },
Chris@1262 323 { 22050, 500000000 }, { 499999999, 500000000 }, { 1000000000, 0 } },
Chris@1262 324 { { 0, 0 }, { 0, 125000 }, { 0, 255875000 }, { 0, 256000000 },
Chris@1262 325 { 0, 832000000 }, { 4, 95875000 }, { 4, 96000000 }, { 5, 512500000 },
Chris@1262 326 { 5, 512625000 }, { 124999, 999875000 }, { 250000, 0 } },
Chris@1262 327 { { 0, 0 }, { 0, 45351 }, { 0, 92834467 }, { 0, 92879819 },
Chris@1262 328 { 0, 301859410 }, { 1, 486031746 }, { 1, 486077098 }, { 2, 0 },
Chris@1262 329 { 2, 45351 }, { 45351, 473877551 }, { 90702, 947845805 } },
Chris@1262 330 { { 0, 0 }, { 0, 22676 }, { 0, 46417234 }, { 0, 46439909 },
Chris@1262 331 { 0, 150929705 }, { 0, 743015873 }, { 0, 743038549 }, { 1, 0 },
Chris@1262 332 { 1, 22676 }, { 22675, 736938776 }, { 45351, 473922902 } },
Chris@1262 333 { { 0, 0 }, { 0, 22675 }, { 0, 46416181 }, { 0, 46438856 },
Chris@1262 334 { 0, 150926283 }, { 0, 742999025 }, { 0, 743021700 }, { 0, 999977325 },
Chris@1262 335 { 1, 0 }, { 22675, 222761389 }, { 45350, 445568128 } },
Chris@1262 336 { { 0, 0 }, { 0, 5208 }, { 0, 10661458 }, { 0, 10666667 },
Chris@1262 337 { 0, 34666667 }, { 0, 170661458 }, { 0, 170666667 }, { 0, 229687500 },
Chris@1262 338 { 0, 229692708 }, { 5208, 333328125 }, { 10416, 666666667 } },
Chris@1262 339 { { 0, 0 }, { 0, 0 }, { 0, 1023 }, { 0, 1024 },
Chris@1262 340 { 0, 3328 }, { 0, 16383 }, { 0, 16384 }, { 0, 22050 },
Chris@1262 341 { 0, 22050 }, { 0, 499999999 }, { 1, 0 } }
Chris@1262 342 };
Chris@1262 343
Chris@1262 344 for (int i = 0; i < n; ++i) {
Chris@1262 345 frame_type frame = frames[i];
Chris@1262 346 for (int j = 0; j < m; ++j) {
Chris@1262 347 int rate = rates[j];
Chris@1262 348
Chris@1262 349 RealTime rt = RealTime::frame2RealTime(frame, rate);
Chris@1262 350 QCOMPARE(rt.sec, realTimes[j][i].sec);
Chris@1262 351 QCOMPARE(rt.nsec, realTimes[j][i].nsec);
Chris@1262 352
Chris@1262 353 frame_type conv = RealTime::realTime2Frame(rt, rate);
Chris@1262 354
Chris@1262 355 rt = RealTime::frame2RealTime(-frame, rate);
Chris@1262 356 frame_type negconv = RealTime::realTime2Frame(rt, rate);
Chris@1262 357
Chris@1262 358 if (rate > ONE_BILLION) {
Chris@1263 359 // We don't have enough precision in RealTime
Chris@1262 360 // for this absurd sample rate, so a round trip
Chris@1262 361 // conversion may round
Chris@1262 362 QVERIFY(abs(frame - conv) < 2);
Chris@1262 363 QVERIFY(abs(-frame - negconv) < 2);
Chris@1262 364 } else {
Chris@1262 365 QCOMPARE(conv, frame);
Chris@1262 366 QCOMPARE(negconv, -frame);
Chris@1262 367 }
Chris@1262 368 }
Chris@1262 369 }
Chris@1262 370 }
Chris@1262 371
Chris@1262 372 // Our own RealTime has toMSText, toFrameText, toSecText
Chris@1262 373
Chris@1262 374 void toText()
Chris@1262 375 {
Chris@1262 376 // we want to use QStrings, because then the Qt test library
Chris@1262 377 // will print out any conflicts. The compareTexts function
Chris@1262 378 // does this for us
Chris@1262 379
Chris@1262 380 int halfSec = ONE_BILLION/2; // nsec
Chris@1262 381
Chris@1262 382 RealTime rt = RealTime(0, 0);
Chris@1262 383 compareTexts(rt.toMSText(false, false), "0");
Chris@1262 384 compareTexts(rt.toMSText(true, false), "0.000");
Chris@1262 385 compareTexts(rt.toMSText(false, true), "0");
Chris@1262 386 compareTexts(rt.toMSText(true, true), "0.000");
Chris@1262 387 compareTexts(rt.toFrameText(24, false), "0:00");
Chris@1262 388 compareTexts(rt.toFrameText(24, true), "0:00");
Chris@1262 389 compareTexts(rt.toSecText(), "0s");
Chris@1262 390
Chris@1262 391 rt = RealTime(1, halfSec);
Chris@1262 392 compareTexts(rt.toMSText(false, false), "1.5");
Chris@1262 393 compareTexts(rt.toMSText(true, false), "1.500");
Chris@1262 394 compareTexts(rt.toMSText(false, true), "1.5");
Chris@1262 395 compareTexts(rt.toMSText(true, true), "1.500");
Chris@1262 396 compareTexts(rt.toFrameText(24, false), "1:12");
Chris@1262 397 compareTexts(rt.toFrameText(24, true), "1:12");
Chris@1262 398 compareTexts(rt.toFrameText(25, false), "1:12");
Chris@1262 399 compareTexts(rt.toFrameText(25, true), "1:12");
Chris@1262 400 compareTexts(rt.toSecText(), "1s");
Chris@1262 401
Chris@1262 402 rt = RealTime::fromSeconds(-1.5);
Chris@1262 403 compareTexts(rt.toMSText(false, false), "-1.5");
Chris@1262 404 compareTexts(rt.toMSText(true, false), "-1.500");
Chris@1262 405 compareTexts(rt.toMSText(false, true), "-1.5");
Chris@1262 406 compareTexts(rt.toMSText(true, true), "-1.500");
Chris@1262 407 compareTexts(rt.toFrameText(24, false), "-1:12");
Chris@1262 408 compareTexts(rt.toFrameText(24, true), "-1:12");
Chris@1262 409 compareTexts(rt.toSecText(), "-1s");
Chris@1262 410
Chris@1262 411 rt = RealTime(1, 1000);
Chris@1262 412 compareTexts(rt.toMSText(false, false), "1");
Chris@1262 413 compareTexts(rt.toFrameText(24, false), "1:00");
Chris@1262 414 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000001");
Chris@1262 415 compareTexts(rt.toSecText(), "1s");
Chris@1262 416
Chris@1262 417 rt = RealTime(1, 100000);
Chris@1262 418 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000100");
Chris@1262 419 compareTexts(rt.toSecText(), "1s");
Chris@1262 420
Chris@1262 421 rt = RealTime::fromSeconds(60);
Chris@1262 422 compareTexts(rt.toMSText(false, false), "60");
Chris@1262 423 compareTexts(rt.toMSText(true, false), "60.000");
Chris@1262 424 compareTexts(rt.toMSText(false, true), "1:00");
Chris@1262 425 compareTexts(rt.toMSText(true, true), "1:00.000");
Chris@1262 426 compareTexts(rt.toFrameText(24, false), "60:00");
Chris@1262 427 compareTexts(rt.toFrameText(24, true), "1:00:00");
Chris@1262 428 compareTexts(rt.toSecText(), "1:00");
Chris@1262 429
Chris@1262 430 rt = RealTime::fromSeconds(61.05);
Chris@1262 431 compareTexts(rt.toMSText(false, false), "61.05");
Chris@1262 432 compareTexts(rt.toMSText(true, false), "61.050");
Chris@1262 433 compareTexts(rt.toMSText(false, true), "1:01.05");
Chris@1262 434 compareTexts(rt.toMSText(true, true), "1:01.050");
Chris@1262 435 compareTexts(rt.toFrameText(24, false), "61:01");
Chris@1262 436 compareTexts(rt.toFrameText(24, true), "1:01:01");
Chris@1262 437 compareTexts(rt.toSecText(), "1:01");
Chris@1262 438
Chris@1262 439 rt = RealTime::fromSeconds(601.05);
Chris@1262 440 compareTexts(rt.toMSText(false, false), "601.05");
Chris@1262 441 compareTexts(rt.toMSText(true, false), "601.050");
Chris@1262 442 compareTexts(rt.toMSText(false, true), "10:01.05");
Chris@1262 443 compareTexts(rt.toMSText(true, true), "10:01.050");
Chris@1262 444 compareTexts(rt.toFrameText(24, false), "601:01");
Chris@1262 445 compareTexts(rt.toFrameText(24, true), "10:01:01");
Chris@1262 446 compareTexts(rt.toSecText(), "10:01");
Chris@1262 447
Chris@1262 448 rt = RealTime::fromSeconds(3600);
Chris@1262 449 compareTexts(rt.toMSText(false, false), "3600");
Chris@1262 450 compareTexts(rt.toMSText(true, false), "3600.000");
Chris@1262 451 compareTexts(rt.toMSText(false, true), "1:00:00");
Chris@1262 452 compareTexts(rt.toMSText(true, true), "1:00:00.000");
Chris@1262 453 compareTexts(rt.toFrameText(24, false), "3600:00");
Chris@1262 454 compareTexts(rt.toFrameText(24, true), "1:00:00:00");
Chris@1262 455 compareTexts(rt.toSecText(), "1:00:00");
Chris@1262 456
Chris@1262 457 // For practical reasons our time display always rounds down
Chris@1262 458 rt = RealTime(3599, ONE_BILLION-1);
Chris@1262 459 compareTexts(rt.toMSText(false, false), "3599.999");
Chris@1262 460 compareTexts(rt.toMSText(true, false), "3599.999");
Chris@1262 461 compareTexts(rt.toMSText(false, true), "59:59.999");
Chris@1262 462 compareTexts(rt.toMSText(true, true), "59:59.999");
Chris@1262 463 compareTexts(rt.toFrameText(24, false), "3599:23");
Chris@1262 464 compareTexts(rt.toFrameText(24, true), "59:59:23");
Chris@1262 465 compareTexts(rt.toSecText(), "59:59");
Chris@1262 466
Chris@1262 467 rt = RealTime::fromSeconds(3600 * 4 + 60 * 5 + 3 + 0.01);
Chris@1262 468 compareTexts(rt.toMSText(false, false), "14703.01");
Chris@1262 469 compareTexts(rt.toMSText(true, false), "14703.010");
Chris@1262 470 compareTexts(rt.toMSText(false, true), "4:05:03.01");
Chris@1262 471 compareTexts(rt.toMSText(true, true), "4:05:03.010");
Chris@1262 472 compareTexts(rt.toFrameText(24, false), "14703:00");
Chris@1262 473 compareTexts(rt.toFrameText(24, true), "4:05:03:00");
Chris@1262 474 compareTexts(rt.toSecText(), "4:05:03");
Chris@1262 475
Chris@1262 476 rt = RealTime::fromSeconds(-(3600 * 4 + 60 * 5 + 3 + 0.01));
Chris@1262 477 compareTexts(rt.toMSText(false, false), "-14703.01");
Chris@1262 478 compareTexts(rt.toMSText(true, false), "-14703.010");
Chris@1262 479 compareTexts(rt.toMSText(false, true), "-4:05:03.01");
Chris@1262 480 compareTexts(rt.toMSText(true, true), "-4:05:03.010");
Chris@1262 481 compareTexts(rt.toFrameText(24, false), "-14703:00");
Chris@1262 482 compareTexts(rt.toFrameText(24, true), "-4:05:03:00");
Chris@1262 483 compareTexts(rt.toSecText(), "-4:05:03");
Chris@1262 484 }
Chris@1262 485 };
Chris@1262 486
Chris@1262 487 #endif
Chris@1262 488