[vlc-commits] DirectSound: possibly fix volume computation
Rémi Denis-Courmont
git at videolan.org
Wed May 30 21:05:15 CEST 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed May 30 22:03:59 2012 +0300| [a4e7d80196972f8f236219d51e2777c86fcb6aeb] | committer: Rémi Denis-Courmont
DirectSound: possibly fix volume computation
It seems the volume is expected to be negative. At least, WinCE MSDN
and MingW and the Internets say so. Windows MSDN says the opposite...
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a4e7d80196972f8f236219d51e2777c86fcb6aeb
---
modules/audio_output/directx.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/modules/audio_output/directx.c b/modules/audio_output/directx.c
index 6069c24..97df5ff 100644
--- a/modules/audio_output/directx.c
+++ b/modules/audio_output/directx.c
@@ -580,25 +580,24 @@ static void Play( audio_output_t *p_aout, block_t *p_buffer )
static int VolumeSet( audio_output_t *p_aout, float vol, bool mute )
{
aout_sys_t *sys = p_aout->sys;
- LONG volume;
- float f = vol;
- if( mute )
- f = 0.;
- /* Convert UI volume percentage to linear factor (cube) */
- f = f * f * f;
-
- /* "DirectSound does not support amplification." -- MSDN */
- if( f > 1. )
- f = 1.;
+ /* Convert UI volume to linear factor (cube) */
+ vol = vol * vol * vol;
/* millibels from linear amplification */
- if( f <= powf(10., DSBVOLUME_MIN / -2000.) )
- volume = DSBVOLUME_MIN;
- else
- volume = lroundf(-2000. * log10f(f));
+ LONG mb = lroundf(2000.f * log10f(vol));
+
+ /* Clamp to allowed DirectSound range */
+ static_assert( DSBVOLUME_MIN < DSBVOLUME_MAX, "DSBVOLUME_* confused" );
+ if( mb >= DSBVOLUME_MAX )
+ mb = DSBVOLUME_MAX;
+ if( mb <= DSBVOLUME_MIN )
+ mb = DSBVOLUME_MIN;
+
+ InterlockedExchange(&sys->volume, mute ? DSBVOLUME_MIN : mb);
- InterlockedExchange(&sys->volume, volume);
+ /* Convert back to UI volume */
+ vol = cbrtf(powf(10.f, ((float)mb) / -2000.f));
aout_VolumeHardSet( p_aout, vol, mute );
return 0;
}
More information about the vlc-commits
mailing list