summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-11-14 21:42:18 +0100
committerwm4 <wm4@nowhere>2015-11-14 21:42:25 +0100
commit9f43778eb2305fed7b627a2b9947b7ac3bdca63a (patch)
tree1424347d035e48c51f8c9e8660a1de9c38c375b4 /player
parent0f3dedebb4c84deaa25abbd7dcfca3f3e10ea72c (diff)
downloadmpv-9f43778eb2305fed7b627a2b9947b7ac3bdca63a.tar.bz2
mpv-9f43778eb2305fed7b627a2b9947b7ac3bdca63a.tar.xz
player: fix audio drift computation at different playback speeds
This computed nonsense if the user set a playback speed other than 1 (in addition to the display-sync speed change).
Diffstat (limited to 'player')
-rw-r--r--player/video.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/player/video.c b/player/video.c
index f6ab3d44c9..043abeb3b1 100644
--- a/player/video.c
+++ b/player/video.c
@@ -854,11 +854,11 @@ static bool using_spdif_passthrough(struct MPContext *mpctx)
return false;
}
-// Compute the relative audio speed by taking A/V dsync into account.
-static double compute_audio_speed(struct MPContext *mpctx, double vsync)
+// Compute the relative audio speed difference by taking A/V dsync into account.
+static double compute_audio_drift(struct MPContext *mpctx, double vsync)
{
- // Least-squares linear regression, using relative file PTS values for x,
- // and audio time for y. Assume speed didn't change for the frames we're
+ // Least-squares linear regression, using relative real time for x, and
+ // audio desync for y. Assume speed didn't change for the frames we're
// looking at for simplicity. This also should actually use the realtime
// (minus paused time) for x, but use vsync scheduling points instead.
if (mpctx->num_past_frames <= 10)
@@ -870,7 +870,7 @@ static double compute_audio_speed(struct MPContext *mpctx, double vsync)
struct frame_info *frame = &mpctx->past_frames[n + 1];
if (frame->num_vsyncs < 0)
return NAN;
- double y = frame->av_diff + x;
+ double y = frame->av_diff;
sum_x += x;
sum_y += y;
sum_xy += x * y;
@@ -923,10 +923,11 @@ static void adjust_audio_resample_speed(struct MPContext *mpctx, double vsync)
if (new == 0) {
// If we're resetting, actually try to be clever and pick a speed
// which compensates the general drift we're getting.
- double drift = compute_audio_speed(mpctx, vsync);
+ double drift = compute_audio_drift(mpctx, vsync);
if (isnormal(drift)) {
- drift /= mpctx->audio_speed; // eliminate intended speed
- audio_factor = 1.0 / drift / mpctx->speed_factor_v;
+ // other = will be multiplied with audio_factor for final speed
+ double other = mpctx->opts->playback_speed * mpctx->speed_factor_v;
+ audio_factor = (mpctx->audio_speed - drift) / other;
MP_VERBOSE(mpctx, "Compensation factor: %f\n", audio_factor);
}
}