fix audio desync for realsies, stderr to log.txt
This commit is contained in:
@@ -159,6 +159,31 @@ namespace anm2ed
|
||||
{
|
||||
auto currentTick = SDL_GetTicks();
|
||||
auto currentUpdate = SDL_GetTicks();
|
||||
auto isRecording = manager.isRecording;
|
||||
auto tickIntervalMs = (double)TICK_INTERVAL;
|
||||
|
||||
if (isRecording)
|
||||
{
|
||||
if (auto document = manager.get())
|
||||
{
|
||||
auto fps = std::max(document->anm2.info.fps, 1);
|
||||
tickIntervalMs = std::max(1.0, 1000.0 / (double)fps);
|
||||
}
|
||||
}
|
||||
|
||||
if (isRecording != wasRecording)
|
||||
{
|
||||
// Drop any accumulated backlog when entering/leaving recording mode.
|
||||
tickAccumulatorMs = 0.0;
|
||||
previousTick = currentTick;
|
||||
wasRecording = isRecording;
|
||||
}
|
||||
|
||||
if (previousTick == 0) previousTick = currentTick;
|
||||
auto tickDeltaMs = currentTick - previousTick;
|
||||
tickDeltaMs = std::min<Uint64>(tickDeltaMs, 250);
|
||||
tickAccumulatorMs += (double)tickDeltaMs;
|
||||
previousTick = currentTick;
|
||||
|
||||
if (currentUpdate - previousUpdate >= UPDATE_INTERVAL)
|
||||
{
|
||||
@@ -167,10 +192,10 @@ namespace anm2ed
|
||||
previousUpdate = currentUpdate;
|
||||
}
|
||||
|
||||
if (currentTick - previousTick >= TICK_INTERVAL)
|
||||
if (tickAccumulatorMs >= tickIntervalMs)
|
||||
{
|
||||
tick(settings);
|
||||
previousTick = currentTick;
|
||||
tickAccumulatorMs -= tickIntervalMs;
|
||||
}
|
||||
|
||||
SDL_Delay(1);
|
||||
|
||||
Reference in New Issue
Block a user