From 9c9ce227f50302379f9cb0d0af517e1a9f1e2b64 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 23 Mar 2004 21:18:19 +0000 Subject: [PATCH] alsa volume fixes git-svn-id: https://svn.musicpd.org/mpd/trunk@421 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/volume.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/volume.c b/src/volume.c index 7906acbba..d38a2c2c8 100644 --- a/src/volume.c +++ b/src/volume.c @@ -248,6 +248,8 @@ int getAlsaVolumeLevel() { long min = volume_alsaMin; int err; + snd_mixer_handle_events(volume_alsaMixerHandle); + if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem, SND_MIXER_SCHN_FRONT_LEFT,&level))<0) { ERROR("problems getting alsa volume: %s\n",snd_strerror(err)); @@ -255,8 +257,12 @@ int getAlsaVolumeLevel() { } snd_mixer_selem_get_playback_volume(volume_alsaElem, - SND_MIXER_SCHN_FRONT_LEFT,&level); - ret = (int)(100*(((float)(level-min))/(max-min))+0.5); + SND_MIXER_SCHN_FRONT_LEFT,&level); + ret = ((volume_alsaSet/100.0)*(max-min)+min)+0.5; + if(volume_alsaSet>0 && ret==level) { + ret = volume_alsaSet; + } + else ret = (int)(100*(((float)(level-min))/(max-min))+0.5); return ret; } @@ -269,6 +275,8 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) { long min = volume_alsaMin; int err; + snd_mixer_handle_events(volume_alsaMixerHandle); + if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem, SND_MIXER_SCHN_FRONT_LEFT,&level))<0) { myfprintf(fp,"%s problems getting volume\n", @@ -282,9 +290,7 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) { if(volume_alsaSet >= 0 && level==test) { vol = volume_alsaSet; } - else { - vol = 100.0*(((float)(level-min))/(max-min)); - } + else vol = 100.0*(((float)(level-min))/(max-min)); vol+=change; } else