comparison base/RealTime.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 344c9ea90181
children a1cd5abcb38b
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
73 } 73 }
74 74
75 RealTime 75 RealTime
76 RealTime::fromTimeval(const struct timeval &tv) 76 RealTime::fromTimeval(const struct timeval &tv)
77 { 77 {
78 return RealTime(tv.tv_sec, tv.tv_usec * 1000); 78 return RealTime(int(tv.tv_sec), int(tv.tv_usec * 1000));
79 } 79 }
80 80
81 RealTime 81 RealTime
82 RealTime::fromXsdDuration(std::string xsdd) 82 RealTime::fromXsdDuration(std::string xsdd)
83 { 83 {
87 double second = 0.0; 87 double second = 0.0;
88 88
89 int i = 0; 89 int i = 0;
90 90
91 const char *s = xsdd.c_str(); 91 const char *s = xsdd.c_str();
92 int len = xsdd.length(); 92 int len = int(xsdd.length());
93 93
94 bool negative = false, afterT = false; 94 bool negative = false, afterT = false;
95 95
96 while (i < len) { 96 while (i < len) {
97 97
104 double value = 0.0; 104 double value = 0.0;
105 char *eptr = 0; 105 char *eptr = 0;
106 106
107 if (isdigit(s[i]) || s[i] == '.') { 107 if (isdigit(s[i]) || s[i] == '.') {
108 value = strtod(&s[i], &eptr); 108 value = strtod(&s[i], &eptr);
109 i = eptr - s; 109 i = int(eptr - s);
110 } 110 }
111 111
112 if (i == len) break; 112 if (i == len) break;
113 113
114 switch (s[i]) { 114 switch (s[i]) {
454 454
455 if (rTotal == 0) return 0.0; 455 if (rTotal == 0) return 0.0;
456 else return lTotal/rTotal; 456 else return lTotal/rTotal;
457 } 457 }
458 458
459 long 459 sv_frame_t
460 RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate) 460 RealTime::realTime2Frame(const RealTime &time, int sampleRate)
461 { 461 {
462 if (time < zeroTime) return -realTime2Frame(-time, sampleRate); 462 if (time < zeroTime) return -realTime2Frame(-time, sampleRate);
463 double s = time.sec + double(time.nsec + 1) / 1000000000.0; 463 double s = time.sec + double(time.nsec + 1) / 1000000000.0;
464 return long(s * double(sampleRate)); 464 return sv_frame_t(s * double(sampleRate));
465 } 465 }
466 466
467 RealTime 467 RealTime
468 RealTime::frame2RealTime(long frame, unsigned int sampleRate) 468 RealTime::frame2RealTime(sv_frame_t frame, int sampleRate)
469 { 469 {
470 if (frame < 0) return -frame2RealTime(-frame, sampleRate); 470 if (frame < 0) return -frame2RealTime(-frame, sampleRate);
471 471
472 RealTime rt; 472 RealTime rt;
473 rt.sec = frame / long(sampleRate); 473 rt.sec = int(frame / sv_frame_t(sampleRate));
474 frame -= rt.sec * long(sampleRate); 474 frame -= rt.sec * sv_frame_t(sampleRate);
475 rt.nsec = (int)(((double(frame) * 1000000.0) / long(sampleRate)) * 1000.0); 475 rt.nsec = (int)(((double(frame) * 1000000.0) / long(sampleRate)) * 1000.0);
476 return rt; 476 return rt;
477 } 477 }
478 478
479 const RealTime RealTime::zeroTime(0,0); 479 const RealTime RealTime::zeroTime(0,0);