[vlc-commits] [Git][videolan/vlc][master] aout: respect AOUT_VOLUME_MAX in aout_volumeUpdate()
    Steve Lhomme (@robUx4) 
    gitlab at videolan.org
       
    Tue Apr  9 04:24:16 UTC 2024
    
    
  
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
4134f7f3 by Fatih Uzunoglu at 2024-04-09T03:57:08+00:00
aout: respect AOUT_VOLUME_MAX in aout_volumeUpdate()
- - - - -
2 changed files:
- include/vlc_aout.h
- src/audio_output/output.c
Changes:
=====================================
include/vlc_aout.h
=====================================
@@ -514,7 +514,7 @@ VLC_API float aout_VolumeGet (audio_output_t *);
 VLC_API int aout_VolumeSet (audio_output_t *, float);
 
 /**
- * Raises the volume.
+ * Adjusts the volume.
  * \param aout the audio output to update the volume for
  * \param value how much to increase (> 0) or decrease (< 0) the volume
  * \param volp if non-NULL, will contain contain the resulting volume
=====================================
src/audio_output/output.c
=====================================
@@ -46,6 +46,16 @@ typedef struct aout_dev
 
 /* Local functions */
 
+static inline float clampf(const float value, const float min, const float max)
+{
+    if (value < min)
+        return min;
+    else if (value > max)
+        return max;
+    else
+        return value;
+}
+
 static int var_Copy (vlc_object_t *src, const char *name, vlc_value_t prev,
                      vlc_value_t value, void *data)
 {
@@ -830,18 +840,15 @@ int aout_VolumeSet (audio_output_t *aout, float vol)
 int aout_VolumeUpdate (audio_output_t *aout, int value, float *volp)
 {
     int ret = -1;
-    float stepSize = var_InheritFloat (aout, "volume-step") / (float)AOUT_VOLUME_DEFAULT;
-    float delta = value * stepSize;
+    const float defaultVolume = (float)AOUT_VOLUME_DEFAULT;
+    const float stepSize = var_InheritFloat (aout, "volume-step") / defaultVolume;
     float vol = aout_VolumeGet (aout);
 
     if (vol >= 0.f)
     {
-        vol += delta;
-        if (vol < 0.f)
-            vol = 0.f;
-        if (vol > 2.f)
-            vol = 2.f;
+        vol += (value * stepSize);
         vol = (roundf (vol / stepSize)) * stepSize;
+        vol = clampf(vol, 0.f, AOUT_VOLUME_MAX / defaultVolume);
         if (volp != NULL)
             *volp = vol;
         ret = aout_VolumeSet (aout, vol);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/4134f7f3ef05de28ab882fd4c30cd69ad2e8cea4
-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/4134f7f3ef05de28ab882fd4c30cd69ad2e8cea4
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
    
    
More information about the vlc-commits
mailing list