]> git.sesse.net Git - vlc/commitdiff
aout: fix flawed resampling logic
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 13 Nov 2012 19:35:50 +0000 (21:35 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 13 Nov 2012 19:35:50 +0000 (21:35 +0200)
src/audio_output/dec.c
src/audio_output/filters.c

index 87310e615f35b91dc8eb9c4be7c88fbb8d3dea0c..8d72e27fff1dc5e9e57ca0cb3bf13083062c1cc8 100644 (file)
@@ -333,61 +333,50 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts,
     }
 
     /* 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",
-                      drift);
-            owner->sync.resamp_start_drift = +drift;
-        }
+        msg_Warn (aout, "playback too late (%"PRId64"): up-sampling",
+                  drift);
         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",
-                      drift);
-            owner->sync.resamp_start_drift = -drift;
-        }
+        msg_Warn (aout, "playback too early (%"PRId64"): down-sampling",
+                  drift);
         owner->sync.resamp_type = AOUT_RESAMPLING_DOWN;
+        owner->sync.resamp_start_drift = -drift;
     }
 
     if (owner->sync.resamp_type == AOUT_RESAMPLING_NONE)
         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
      * increased or decreased. Resampling rate changes must be kept slow for
      * 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))
-    {
+    {   /* Everything is back to normal: stop resampling. */
         owner->sync.resamp_type = AOUT_RESAMPLING_NONE;
         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);
-    }
 }
 
 /*****************************************************************************
index 056b9d06b9567b674983ef89f70e588207f37934..14f9e66e08a3b92494f2beae3e0c0107c2307902 100644 (file)
@@ -550,7 +550,7 @@ bool aout_FiltersAdjustResampling (audio_output_t *aout, int adjust)
         owner->resampling += adjust;
     else
         owner->resampling = 0;
-    return !owner->resampling;
+    return owner->resampling != 0;
 }
 
 block_t *aout_FiltersPlay (audio_output_t *aout, block_t *block, int rate)