Repaired a defect in the calculation of delay before starting audio streams

This commit is contained in:
Bill Somerville 2019-05-10 20:31:16 +01:00
parent 62f9b32758
commit 8d6c7649e0

View File

@ -18,6 +18,7 @@
#include <QAudioOutput> #include <QAudioOutput>
#include <QTimer> #include <QTimer>
#include <QDateTime> #include <QDateTime>
#include <QDebug>
#include "revision_utils.hpp" #include "revision_utils.hpp"
#include "Audio/BWFFile.hpp" #include "Audio/BWFFile.hpp"
@ -52,7 +53,12 @@ public:
} }
else else
{ {
QTimer::singleShot (int ((((start - (QDateTime::currentMSecsSinceEpoch () / 1000) % 60) + 60) % 60) * 1000), Qt::PreciseTimer, this, &Record::start_recording); auto now = QDateTime::currentDateTimeUtc ();
auto time = now.time ();
auto then = now;
then.setTime (QTime {time.hour (), time.minute (), start});
auto delta_ms = (now.msecsTo (then) + (60 * 1000)) % (60 * 1000);
QTimer::singleShot (int (delta_ms), Qt::PreciseTimer, this, &Record::start_recording);
} }
} }
@ -113,7 +119,12 @@ public:
} }
else else
{ {
QTimer::singleShot (int ((((start - (QDateTime::currentMSecsSinceEpoch () / 1000) % 60) + 60) % 60) * 1000), Qt::PreciseTimer, this, &Playback::start_playback); auto now = QDateTime::currentDateTimeUtc ();
auto time = now.time ();
auto then = now;
then.setTime (QTime {time.hour (), time.minute (), start});
auto delta_ms = (now.msecsTo (then) + (60 * 1000)) % (60 * 1000);
QTimer::singleShot (int (delta_ms), Qt::PreciseTimer, this, &Playback::start_playback);
} }
} }