Commit 62a75145 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: fix flawed resampling logic

parent 17b69f2d
...@@ -333,61 +333,50 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts, ...@@ -333,61 +333,50 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts,
} }
/* Resampling */ /* Resampling */
if (drift > +AOUT_MAX_PTS_DELAY
if (drift > +AOUT_MAX_PTS_DELAY) && owner->sync.resamp_type != AOUT_RESAMPLING_UP)
{
if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
{ {
msg_Warn (aout, "playback too late (%"PRId64"): up-sampling", msg_Warn (aout, "playback too late (%"PRId64"): up-sampling",
drift); drift);
owner->sync.resamp_start_drift = +drift;
}
owner->sync.resamp_type = AOUT_RESAMPLING_UP; owner->sync.resamp_type = AOUT_RESAMPLING_UP;
owner->sync.resamp_start_drift = +drift;
} }
if (drift < -AOUT_MAX_PTS_ADVANCE
if (drift < -AOUT_MAX_PTS_ADVANCE) && owner->sync.resamp_type != AOUT_RESAMPLING_DOWN)
{
if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
{ {
msg_Warn (aout, "playback too early (%"PRId64"): down-sampling", msg_Warn (aout, "playback too early (%"PRId64"): down-sampling",
drift); drift);
owner->sync.resamp_start_drift = -drift;
}
owner->sync.resamp_type = AOUT_RESAMPLING_DOWN; owner->sync.resamp_type = AOUT_RESAMPLING_DOWN;
owner->sync.resamp_start_drift = -drift;
} }
if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE) if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
return; /* Everything is fine. Nothing to do. */ return; /* Everything is fine. Nothing to do. */
if (llabs (drift) > 2 * owner->sync.resamp_start_drift)
{ /* If the drift is ever increasing, then something is seriously wrong.
* Cease resampling and hope for the best. */
msg_Warn (aout, "timing screwed (drift: %"PRId64" us): "
"stopping resampling", drift);
aout_StopResampling (aout);
return;
}
/* Resampling has been triggered earlier. This checks if it needs to be /* Resampling has been triggered earlier. This checks if it needs to be
* increased or decreased. Resampling rate changes must be kept slow for * increased or decreased. Resampling rate changes must be kept slow for
* the comfort of listeners. */ * the comfort of listeners. */
const int adj = (owner->sync.resamp_type == AOUT_RESAMPLING_UP) ? +2 : -2; int adj = (owner->sync.resamp_type == AOUT_RESAMPLING_UP) ? +2 : -2;
if (2 * llabs (drift) <= owner->sync.resamp_start_drift)
/* If the drift has been reduced from more than half its initial
* value, then it is time to switch back the resampling direction. */
adj *= -1;
/* Check if everything is back to normal, then stop resampling. */
if (!aout_FiltersAdjustResampling (aout, adj)) if (!aout_FiltersAdjustResampling (aout, adj))
{ { /* Everything is back to normal: stop resampling. */
owner->sync.resamp_type = AOUT_RESAMPLING_NONE; owner->sync.resamp_type = AOUT_RESAMPLING_NONE;
msg_Dbg (aout, "resampling stopped (drift: %"PRId64" us)", drift); msg_Dbg (aout, "resampling stopped (drift: %"PRId64" us)", drift);
} }
else
if (2 * llabs (drift) <= owner->sync.resamp_start_drift)
{ /* If the drift has been reduced from more than half its initial
* value, then it is time to switch back the resampling direction. */
if (owner->sync.resamp_type == AOUT_RESAMPLING_UP)
owner->sync.resamp_type = AOUT_RESAMPLING_DOWN;
else
owner->sync.resamp_type = AOUT_RESAMPLING_UP;
owner->sync.resamp_start_drift = 0;
}
else
if (llabs (drift) > 2 * owner->sync.resamp_start_drift)
{ /* If the drift is ever increasing, then something is seriously wrong.
* Cease resampling and hope for the best. */
msg_Warn (aout, "timing screwed (drift: %"PRId64" us): "
"stopping resampling", drift);
aout_StopResampling (aout);
}
} }
/***************************************************************************** /*****************************************************************************
......
...@@ -550,7 +550,7 @@ bool aout_FiltersAdjustResampling (audio_output_t *aout, int adjust) ...@@ -550,7 +550,7 @@ bool aout_FiltersAdjustResampling (audio_output_t *aout, int adjust)
owner->resampling += adjust; owner->resampling += adjust;
else else
owner->resampling = 0; owner->resampling = 0;
return !owner->resampling; return owner->resampling != 0;
} }
block_t *aout_FiltersPlay (audio_output_t *aout, block_t *block, int rate) block_t *aout_FiltersPlay (audio_output_t *aout, block_t *block, int rate)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment