Commit a4e7d801 authored by Rémi Denis-Courmont's avatar 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...
parent b10e5817
...@@ -580,25 +580,24 @@ static void Play( audio_output_t *p_aout, block_t *p_buffer ) ...@@ -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 ) static int VolumeSet( audio_output_t *p_aout, float vol, bool mute )
{ {
aout_sys_t *sys = p_aout->sys; 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 */ /* Convert UI volume to linear factor (cube) */
if( f > 1. ) vol = vol * vol * vol;
f = 1.;
/* millibels from linear amplification */ /* millibels from linear amplification */
if( f <= powf(10., DSBVOLUME_MIN / -2000.) ) LONG mb = lroundf(2000.f * log10f(vol));
volume = DSBVOLUME_MIN;
else /* Clamp to allowed DirectSound range */
volume = lroundf(-2000. * log10f(f)); 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 ); aout_VolumeHardSet( p_aout, vol, mute );
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment