Commit 9b2c48de authored by Pierre Ynard's avatar 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
parent 7b4e90a5
...@@ -356,8 +356,13 @@ static int VolumeSet( audio_output_t *p_aout, float volume ) ...@@ -356,8 +356,13 @@ static int VolumeSet( audio_output_t *p_aout, float volume )
aout_sys_t *sys = p_aout->sys; aout_sys_t *sys = p_aout->sys;
int ret = 0; int ret = 0;
/* millibels from linear amplification map 200% on DSBVOLUME_MAX */ /* Directsound doesn't support amplification, so we use software
LONG mb = lroundf( 6000.f * log10f( volume / 2.f )); 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 */ /* Clamp to allowed DirectSound range */
static_assert( DSBVOLUME_MIN < DSBVOLUME_MAX, "DSBVOLUME_* confused" ); static_assert( DSBVOLUME_MIN < DSBVOLUME_MAX, "DSBVOLUME_* confused" );
...@@ -527,7 +532,6 @@ static int CreateDSBuffer( audio_output_t *p_aout, int i_format, ...@@ -527,7 +532,6 @@ static int CreateDSBuffer( audio_output_t *p_aout, int i_format,
waveformat.Format.wBitsPerSample; waveformat.Format.wBitsPerSample;
waveformat.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; waveformat.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
waveformat.SubFormat = _KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; waveformat.SubFormat = _KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
aout_GainRequest(p_aout, 8.f);
break; break;
case VLC_CODEC_S16N: case VLC_CODEC_S16N:
...@@ -536,7 +540,6 @@ static int CreateDSBuffer( audio_output_t *p_aout, int i_format, ...@@ -536,7 +540,6 @@ static int CreateDSBuffer( audio_output_t *p_aout, int i_format,
waveformat.Format.wBitsPerSample; waveformat.Format.wBitsPerSample;
waveformat.Format.wFormatTag = WAVE_FORMAT_PCM; waveformat.Format.wFormatTag = WAVE_FORMAT_PCM;
waveformat.SubFormat = _KSDATAFORMAT_SUBTYPE_PCM; waveformat.SubFormat = _KSDATAFORMAT_SUBTYPE_PCM;
aout_GainRequest(p_aout, 8.f);
break; break;
} }
......
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