[vlc-devel] [PATCH] aout: add rounding to playlist_VolumeUp

Alex Peak bobcatawareness at gmail.com
Wed Mar 5 08:54:20 CET 2014


Additional rounding step ensures that new volume is a multiple of the
"volume-step" as defined in libvlc-module.c.
---
 src/playlist/aout.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/playlist/aout.c b/src/playlist/aout.c
index 05ed231..c70e45d 100644
--- a/src/playlist/aout.c
+++ b/src/playlist/aout.c
@@ -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 = (round (vol / stepSize)) * stepSize;
             if (volp != NULL)
                 *volp = vol;
             ret = aout_VolumeSet (aout, vol);
-- 
1.8.5.5




More information about the vlc-devel mailing list