[vlc-commits] PulseAudio: limit resampling to 1% variation at a time

Rémi Denis-Courmont git at videolan.org
Sun Jul 31 21:31:42 CEST 2011


vlc/vlc-1.1 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jul 27 21:19:41 2011 +0300| [429558a97d89a16f316bc2817e8ce38d0dd7b6a0] | committer: Rémi Denis-Courmont

PulseAudio: limit resampling to 1% variation at a time

1kHz is way too much for human perception.
(cherry picked from commit a97f3aa7dab9f58b55dbf489677c9a1ab22875f1)

Conflicts:

	modules/audio_output/pulse.c

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=429558a97d89a16f316bc2817e8ce38d0dd7b6a0
---

 modules/audio_output/pulse.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 711307d..71bdee0 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -207,27 +207,27 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
 
     /* Compute playback sample rate */
     const unsigned inrate = aout->output.output.i_rate;
+    int limit = inrate / 100; /* max varation per iteration */
 
 #define ADJUST_FACTOR 4
-#define ADJUST_MAX    1000 /* Hz (max rate variation per call) */
     /* This is empirical. Feel free to define something smarter. */
     int adj = sys->rate * (delta + change) / (CLOCK_FREQ * ADJUST_FACTOR);
 
     /* This avoids too fast rate variation. They sound ugly as hell and they
      * make the algorithm unstable (e.g. oscillation around inrate). */
-    if (adj > +ADJUST_MAX)
-        adj = +ADJUST_MAX;
-    if (adj < -ADJUST_MAX)
-        adj = -ADJUST_MAX;
+    if (adj > +limit)
+        adj = +limit;
+    if (adj < -limit)
+        adj = -limit;
 
     unsigned outrate = sys->rate - adj;
     /* Favor native rate to avoid resampling (FIXME: really a good idea?) */
-    if (abs(outrate - inrate) < (inrate >> 10))
+    if (abs(outrate - inrate) < limit)
         outrate = inrate;
 
     /* This keeps the effective rate within specified range
      * (+/-AOUT_MAX_RESAMPLING% - see <vlc_aout.h>) of the nominal rate. */
-    const int limit = inrate * AOUT_MAX_RESAMPLING / 100;
+    limit *= AOUT_MAX_RESAMPLING;
     if (outrate > inrate + limit)
         outrate = inrate + limit;
     if (outrate < inrate - limit)



More information about the vlc-commits mailing list