From c48c0f453bde933170ec2fa32c8abca1bd650fc6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 12 Mar 2012 01:46:25 +0100 Subject: ao_dsound: fix volume controls The recent changes in mixer.c require the AO to return a volume of exactly 0 when audio has been muted. Rather than adding just another special case to mixer.c, fix ao_dsound.c to return previously set volumes exactly. Because DirectSound volume control is not connected with the system mixer, which could change the volume without mplayer knowing, reading the volume back from DirectSound is pointless. Also, the code tried to calculate log10(0). Clip the volume to 1, which results in -10000, DirectSound's definition of silence. --- libao2/ao_dsound.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libao2/ao_dsound.c b/libao2/ao_dsound.c index d21e39df9e..f1fc0dd00a 100644 --- a/libao2/ao_dsound.c +++ b/libao2/ao_dsound.c @@ -124,6 +124,7 @@ static int min_free_space = 0; ///if the free space is below this val static int underrun_check = 0; ///0 or last reported free space (underrun detection) static int device_num = 0; ///wanted device number static GUID device; ///guid of the device +static int audio_volume; /***************************************************************************************/ @@ -394,16 +395,16 @@ static int control(int cmd, void *arg) switch (cmd) { case AOCONTROL_GET_VOLUME: { ao_control_vol_t* vol = (ao_control_vol_t*)arg; - IDirectSoundBuffer_GetVolume(hdsbuf, &volume); - vol->left = vol->right = pow(10.0, (float)(volume+10000) / 5000.0); - //printf("ao_dsound: volume: %f\n",vol->left); + vol->left = vol->right = audio_volume; return CONTROL_OK; } case AOCONTROL_SET_VOLUME: { ao_control_vol_t* vol = (ao_control_vol_t*)arg; - volume = (DWORD)(log10(vol->right) * 5000.0) - 10000; + volume = audio_volume = vol->right; + if (volume < 1) + volume = 1; + volume = (DWORD)(log10(volume) * 5000.0) - 10000; IDirectSoundBuffer_SetVolume(hdsbuf, volume); - //printf("ao_dsound: volume: %f\n",vol->left); return CONTROL_OK; } } @@ -424,6 +425,7 @@ static int init(int rate, int channels, int format, int flags) if (!InitDirectSound()) return 0; global_ao->no_persistent_volume = true; + audio_volume = 100; // ok, now create the buffers WAVEFORMATEXTENSIBLE wformat; -- cgit v1.2.3