[vlc-devel] [PATCH] Use soft gain by default to achieve 200% with directsound

Denis Charmet typx at dinauz.org
Thu Aug 8 10:13:21 CEST 2013


Since directsound doesn't support amplification, we use a default *2 soft gain and map DSBVOLUME_MAX to 200%.

This change is restricted to float32 to limit possible saturation
---
 modules/audio_output/directx.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/modules/audio_output/directx.c b/modules/audio_output/directx.c
index 2f47c47..c86c49d 100644
--- a/modules/audio_output/directx.c
+++ b/modules/audio_output/directx.c
@@ -331,19 +331,13 @@ static int VolumeSet( audio_output_t *p_aout, float volume )
     aout_sys_t *sys = p_aout->sys;
     int ret = 0;
 
-    /* Convert UI volume to linear factor (cube) */
-    float vol = volume * volume * volume;
-
-    /* millibels from linear amplification */
-    LONG mb = lroundf(2000.f * log10f(vol));
+    /* millibels from linear amplification map 200% on DSBVOLUME_MAX */
+    LONG mb = lroundf( 5000.f * log10f( volume / 2.f ));
 
     /* Clamp to allowed DirectSound range */
     static_assert( DSBVOLUME_MIN < DSBVOLUME_MAX, "DSBVOLUME_* confused" );
     if( mb > DSBVOLUME_MAX )
-    {
         mb = DSBVOLUME_MAX;
-        ret = -1;
-    }
     if( mb <= DSBVOLUME_MIN )
         mb = DSBVOLUME_MIN;
 
@@ -504,6 +498,7 @@ static int CreateDSBuffer( audio_output_t *p_aout, int i_format,
             waveformat.Format.wBitsPerSample;
         waveformat.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
         waveformat.SubFormat = _KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
+        aout_GainRequest(p_aout, 8.f);
         break;
 
     case VLC_CODEC_S16N:
@@ -512,6 +507,7 @@ static int CreateDSBuffer( audio_output_t *p_aout, int i_format,
             waveformat.Format.wBitsPerSample;
         waveformat.Format.wFormatTag = WAVE_FORMAT_PCM;
         waveformat.SubFormat = _KSDATAFORMAT_SUBTYPE_PCM;
+        aout_GainRequest(p_aout, 1.f);
         break;
     }
 
-- 
1.7.10.4




More information about the vlc-devel mailing list