[vlc-commits] waveout: correct scale

Rémi Denis-Courmont git at videolan.org
Mon May 21 22:49:57 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon May 21 23:49:06 2012 +0300| [669ce09e338a5a18a289d6b4aaca131fdd97f369] | committer: Rémi Denis-Courmont

waveout: correct scale

0xffff is full volume, which I understand to mean 0dB.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=669ce09e338a5a18a289d6b4aaca131fdd97f369
---

 modules/audio_output/waveout.c |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/modules/audio_output/waveout.c b/modules/audio_output/waveout.c
index 4bb6831..ef12c49 100644
--- a/modules/audio_output/waveout.c
+++ b/modules/audio_output/waveout.c
@@ -31,6 +31,7 @@
 #endif
 
 #include <stdio.h>
+#include <math.h>
 #include <wchar.h>
 
 #define UNICODE
@@ -995,22 +996,21 @@ static void* WaveOutThread( void *data )
 
 static int VolumeSet( audio_output_t * p_aout, float volume, bool mute )
 {
+#ifndef UNDER_CE
+    const HWAVEOUT hwo = p_aout->sys->h_waveout;
+#else
+    const HWAVEOUT hwo = 0;
+#endif
+    const float full = 0xffff.fp0;
+
     if( mute )
         volume = 0.;
+    volume *= full;
+    if( volume >= full )
+        volume = full;
 
-    unsigned long i_waveout_vol = volume
-        * (0xFFFF * AOUT_VOLUME_DEFAULT / AOUT_VOLUME_MAX);
-
-    if( i_waveout_vol <= 0xFFFF )
-        i_waveout_vol |= i_waveout_vol << 16;
-    else
-        i_waveout_vol = 0xFFFFFFFF;
-
-#ifdef UNDER_CE
-    waveOutSetVolume( 0, i_waveout_vol );
-#else
-    waveOutSetVolume( p_aout->sys->h_waveout, i_waveout_vol );
-#endif
+    uint16_t vol = lroundf(volume);
+    waveOutSetVolume( hwo, vol | (vol << 16) );
     return 0;
 }
 



More information about the vlc-commits mailing list