mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 05:43:36 +02:00
fix underflow for agent audio timer
This commit is contained in:
parent
745f6546dd
commit
68f05bee87
1 changed files with 11 additions and 7 deletions
|
@ -15,19 +15,23 @@
|
||||||
// this should send a signal every 10ms, with pretty good precision. Hardcoding
|
// this should send a signal every 10ms, with pretty good precision. Hardcoding
|
||||||
// to 10ms since that's what you'd want for audio.
|
// to 10ms since that's what you'd want for audio.
|
||||||
void AvatarAudioTimer::start() {
|
void AvatarAudioTimer::start() {
|
||||||
qDebug() << "AvatarAudioTimer::start called";
|
qDebug() << __FUNCTION__;
|
||||||
auto startTime = usecTimestampNow();
|
auto startTime = usecTimestampNow();
|
||||||
quint64 frameCounter = 0;
|
quint64 frameCounter = 0;
|
||||||
const int TARGET_INTERVAL_USEC = 10000; // 10ms
|
const int TARGET_INTERVAL_USEC = 10000; // 10ms
|
||||||
while (!_quit) {
|
while (!_quit) {
|
||||||
frameCounter++;
|
++frameCounter;
|
||||||
// simplest possible timer
|
|
||||||
|
// tick every 10ms from startTime
|
||||||
quint64 targetTime = startTime + frameCounter * TARGET_INTERVAL_USEC;
|
quint64 targetTime = startTime + frameCounter * TARGET_INTERVAL_USEC;
|
||||||
quint64 interval = std::max((quint64)0, targetTime - usecTimestampNow());
|
quint64 now = usecTimestampNow();
|
||||||
usleep(interval);
|
|
||||||
|
// avoid quint64 underflow
|
||||||
|
if (now < targetTime) {
|
||||||
|
usleep(targetTime - now);
|
||||||
|
}
|
||||||
|
|
||||||
emit avatarTick();
|
emit avatarTick();
|
||||||
}
|
}
|
||||||
qDebug() << "AvatarAudioTimer is finished";
|
qDebug() << "AvatarAudioTimer is finished";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue