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

Rémi Denis-Courmont remi at remlab.net
Thu Aug 8 21:44:54 CEST 2013


Le jeudi 8 août 2013 10:13:21 Denis Charmet a écrit :
> Since directsound doesn't support amplification, we use a default *2 soft
> gain and map DSBVOLUME_MAX to 200%.

Note that I care as a Linux user, but that will confuse the volume control in 
the Windows mixer.

> This change is restricted to float32 to limit possible saturation

That subtlety will be very hard for users to grasp. Some don't even understand 
that S/PDIF cannot be attenuated.

> ---
>  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 ));

This seems wrong for the S16N case.

> 
>      /* Clamp to allowed DirectSound range */
>      static_assert( DSBVOLUME_MIN < DSBVOLUME_MAX, "DSBVOLUME_* confused" );
> if( mb > DSBVOLUME_MAX )
> -    {
>          mb = DSBVOLUME_MAX;
> -        ret = -1;
> -    }

That's a separate and debatable change of its own.

>      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;
>      }
-- 
Rémi Denis-Courmont
http://www.remlab.net/




More information about the vlc-devel mailing list