Mercurial > hg > svcore
comparison base/RealTimeSV.cpp @ 1262:c4f873749ab5 3.0-integration
RealTime fixes to comply with new, more demanding tests; also run same (failing) tests on Vamp SDK version
author | Chris Cannam |
---|---|
date | Tue, 15 Nov 2016 16:12:48 +0000 |
parents | a2091d148d7f |
children | b7b84ae5f0a7 |
comparison
equal
deleted
inserted
replaced
1261:968d54d893d2 | 1262:c4f873749ab5 |
---|---|
447 static RealTime | 447 static RealTime |
448 frame2RealTime_i(sv_frame_t frame, sv_frame_t iSampleRate) | 448 frame2RealTime_i(sv_frame_t frame, sv_frame_t iSampleRate) |
449 { | 449 { |
450 if (frame < 0) return -frame2RealTime_i(-frame, iSampleRate); | 450 if (frame < 0) return -frame2RealTime_i(-frame, iSampleRate); |
451 | 451 |
452 RealTime rt; | 452 int sec = int(frame / iSampleRate); |
453 sv_frame_t sec = frame / iSampleRate; | |
454 rt.sec = int(sec); | |
455 frame -= sec * iSampleRate; | 453 frame -= sec * iSampleRate; |
456 rt.nsec = (int)(((double(frame) * 1000000.0) / double(iSampleRate)) * 1000.0); | 454 int nsec = int((double(frame) / double(iSampleRate)) * ONE_BILLION + 0.5); |
457 return rt; | 455 // Use ctor here instead of setting data members directly to |
456 // ensure nsec > ONE_BILLION is handled properly. It's extremely | |
457 // unlikely, but not impossible. | |
458 return RealTime(sec, nsec); | |
458 } | 459 } |
459 | 460 |
460 sv_frame_t | 461 sv_frame_t |
461 RealTime::realTime2Frame(const RealTime &time, sv_samplerate_t sampleRate) | 462 RealTime::realTime2Frame(const RealTime &time, sv_samplerate_t sampleRate) |
462 { | 463 { |
463 if (time < zeroTime) return -realTime2Frame(-time, sampleRate); | 464 if (time < zeroTime) return -realTime2Frame(-time, sampleRate); |
464 double s = time.sec + double(time.nsec + 1) / 1000000000.0; | 465 double s = time.sec + double(time.nsec) / 1000000000.0; |
465 return sv_frame_t(s * sampleRate); | 466 return sv_frame_t(s * sampleRate + 0.5); |
466 } | 467 } |
467 | 468 |
468 RealTime | 469 RealTime |
469 RealTime::frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate) | 470 RealTime::frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate) |
470 { | 471 { |