I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later
Dependencies: BufferedSerial FatFileSystemCpp mbed
Diff: frameRates.cpp
- Revision:
- 0:97661408d0f9
- Child:
- 9:7214e3c3e5f8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frameRates.cpp Fri Jan 15 11:49:01 2021 +0000 @@ -0,0 +1,93 @@ +#include "LTCApp.h" + +frameRates::frameRates() { + setRate(1); +} + +void frameRates::setRate(int index) { + _currentRate = frameRateInfo::FrameRates[index]; +_currentPeriod = frameRateInfo::FramePeriods[index]; +_currentIndex = index; +TimeSinceLastFrameWrap = frameRateInfo::FramePeriods[index]; +} + +bool frameRates::isSyncable() { + if (_currentIndex < 2) // 0 or 1 + return false; + if (((_currentIndex == 4) || (_currentIndex == 9)) && !_currentDrop) + return false; + return true; +} + + +const char *frameRates::frameRateString() { + switch (_currentIndex) { + case 0: + default: + return "Unknown"; + case 1: + return "23.976"; + case 2: + return "24"; + case 3: + return "25"; + case 4: + return _currentDrop ? "29.97 Drop" : "29.97"; + case 5: + return "30"; + case 6: + return "47.95"; + case 7: + return "48"; + case 8: + return "50"; + case 9: + return _currentDrop ? "59.94 Drop" : "59.94"; + case 10: + return "60"; + } +} + + +long frameRates::getOffsetFromSecondStart(int minutes, int seconds, int frame, + int rateIndex, bool frameDrop){ + if (!frameDrop) { + return frameRateInfo::FramePeriods[rateIndex] * + frame; // for non frame drops all second starts are perfect + // not true for non-integer rates but for non-drop versions we + // don't try to sync to those. + } else { + int MinutesSinceLastSync = minutes % 10; + const int framesPerMinute = 30 * 59 + 28; + + double indicatedTimeSinceLastSync = + (MinutesSinceLastSync * framesPerMinute + seconds * 30 + frame) * + frameRateInfo::FramePeriods[rateIndex]; + double framesMismatch = + (MinutesSinceLastSync * framesPerMinute + seconds * 30) - + (frameRateInfo::FrameRates[rateIndex] * (MinutesSinceLastSync * 60 + seconds)); + double timeErrorAtSecondStart = framesMismatch * frameRateInfo::FramePeriods[rateIndex]; + double timeThisSecond = frame * frameRateInfo::FramePeriods[rateIndex]; + return (long)(timeThisSecond + timeErrorAtSecondStart + 0.5); + } +} + +long frameRates::getOffsetFromSecondStart(int minutes, int seconds, int frame){ + if (!_currentDrop) { + return _currentPeriod * frame; // for non frame drops all second starts are perfect + // not true for non-integer rates but for non-drop versions we + // don't try to sync to those. + } else { + int MinutesSinceLastSync = minutes % 10; + const int framesPerMinute = 30 * 59 + 28; + + double indicatedTimeSinceLastSync = + (MinutesSinceLastSync * framesPerMinute + seconds * 30 + frame) * _currentPeriod; + double framesMismatch = + (MinutesSinceLastSync * framesPerMinute + seconds * 30) - (_currentRate * (MinutesSinceLastSync * 60 + seconds)); + double timeErrorAtSecondStart = framesMismatch * _currentPeriod; + double timeThisSecond = frame * _currentPeriod; + return (long)(timeThisSecond + timeErrorAtSecondStart + 0.5); + } +} +