]> git.sesse.net Git - vlc/commitdiff
aout: add rounding to playlist_VolumeUp
authorAlex Peak <bobcatawareness@gmail.com>
Thu, 6 Mar 2014 00:49:44 +0000 (16:49 -0800)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 6 Mar 2014 20:13:01 +0000 (22:13 +0200)
Additional rounding step ensures that new volume is a multiple of the
"volume-step" as defined in libvlc-module.c.

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
src/playlist/aout.c

index 05ed231ad14c30d6e07fc2967e415a79d24f8b05..f00eaa247d6d191af72e9bdbfe87f419f3a5febb 100644 (file)
@@ -24,6 +24,8 @@
 # include "config.h"
 #endif
 
+#include <math.h>
+
 #include <vlc_common.h>
 #include <vlc_aout.h>
 #include <vlc_playlist.h>
@@ -76,7 +78,9 @@ int playlist_VolumeUp (playlist_t *pl, int value, float *volp)
 {
     int ret = -1;
 
-    float delta = value * var_InheritFloat (pl, "volume-step");
+    float stepSize = var_InheritFloat (pl, "volume-step") / (float)AOUT_VOLUME_DEFAULT;
+
+    float delta = value * stepSize;
 
     audio_output_t *aout = playlist_GetAout (pl);
     if (aout != NULL)
@@ -84,11 +88,12 @@ int playlist_VolumeUp (playlist_t *pl, int value, float *volp)
         float vol = aout_VolumeGet (aout);
         if (vol >= 0.)
         {
-            vol += delta / (float)AOUT_VOLUME_DEFAULT;
+            vol += delta;
             if (vol < 0.)
                 vol = 0.;
             if (vol > 2.)
                 vol = 2.;
+            vol = (roundf (vol / stepSize)) * stepSize;
             if (volp != NULL)
                 *volp = vol;
             ret = aout_VolumeSet (aout, vol);