[vlc-commits] directsound: use software gain only when amplifying

Pierre Ynard git at videolan.org
Sun Sep 22 10:07:09 CEST 2013


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sun Sep 22 10:06:09 2013 +0200| [9b2c48deeb04fa8c3005900bd8f285b50e20539d] | committer: Pierre Ynard

directsound: use software gain only when amplifying

This way we get the features of both worlds: from 0% to 100% you
get quick volume change with no saturation, and you can still get
amplification over 100%.

Fixes #9371

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

 modules/audio_output/directsound.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/modules/audio_output/directsound.c b/modules/audio_output/directsound.c
index 6ff2382..0ca3b59 100644
--- a/modules/audio_output/directsound.c
+++ b/modules/audio_output/directsound.c
@@ -356,8 +356,13 @@ static int VolumeSet( audio_output_t *p_aout, float volume )
     aout_sys_t *sys = p_aout->sys;
     int ret = 0;
 
-    /* millibels from linear amplification map 200% on DSBVOLUME_MAX */
-    LONG mb = lroundf( 6000.f * log10f( volume / 2.f ));
+    /* Directsound doesn't support amplification, so we use software
+       gain if we need it and only for this */
+    float gain = volume > 1.f ? volume * volume * volume : 1.f;
+    aout_GainRequest( p_aout, gain );
+
+    /* millibels from linear amplification */
+    LONG mb = lroundf( 6000.f * log10f( __MIN( volume, 1.f ) ));
 
     /* Clamp to allowed DirectSound range */
     static_assert( DSBVOLUME_MIN < DSBVOLUME_MAX, "DSBVOLUME_* confused" );
@@ -527,7 +532,6 @@ 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:
@@ -536,7 +540,6 @@ 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, 8.f);
         break;
     }
 



More information about the vlc-commits mailing list