[MPlayer-dev-eng] [PATCH] use playback_switch with alsa for muting
Matthias Lederhofer
matled at gmx.net
Fri Nov 18 14:09:17 CET 2005
Hi,
I wrote a patch to libao2/ao_alsa.c which uses
snd_mixer_selem_set_playback_switch when the volume is set to 0.0.
This is the function intended for muting by alsa and I can still hear
a bit of the sound without it when I set master and my speakers to
full volume.
-------------- next part --------------
Index: libao2/ao_alsa.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_alsa.c,v
retrieving revision 1.20
diff -u -r1.20 ao_alsa.c
--- libao2/ao_alsa.c 25 Aug 2005 21:46:32 -0000 1.20
+++ libao2/ao_alsa.c 14 Nov 2005 23:08:24 -0000
@@ -197,6 +197,34 @@
}
mp_msg(MSGT_AO,MSGL_DBG2,"right=%li, pmin=%li, pmax=%li, mult=%f\n",
set_vol, pmin, pmax, f_multi);
+
+ //muting
+ if (snd_mixer_selem_has_playback_switch(elem)) {
+ int status;
+ if (snd_mixer_selem_has_playback_switch_joined(elem)) {
+ snd_mixer_selem_get_playback_switch(elem,SND_MIXER_SCHN_FRONT_LEFT,&status);
+ if (status && vol->left == 0.0 && vol->right == 0.0) {
+ // mute
+ snd_mixer_selem_set_playback_switch(elem,SND_MIXER_SCHN_FRONT_LEFT,0);
+ } else if (!status && (vol->left != 0.0 || vol->right != 0.0)) {
+ // unmute
+ snd_mixer_selem_set_playback_switch(elem,SND_MIXER_SCHN_FRONT_LEFT,1);
+ }
+ } else {
+ snd_mixer_selem_get_playback_switch(elem,SND_MIXER_SCHN_FRONT_LEFT,&status);
+ if (status && vol->left == 0.0) {
+ snd_mixer_selem_set_playback_switch(elem,SND_MIXER_SCHN_FRONT_LEFT,0);
+ } else if (!status && vol->left != 0.0) {
+ snd_mixer_selem_set_playback_switch(elem,SND_MIXER_SCHN_FRONT_LEFT,1);
+ }
+ snd_mixer_selem_get_playback_switch(elem,SND_MIXER_SCHN_FRONT_RIGHT,&status);
+ if (status && vol->right == 0.0) {
+ snd_mixer_selem_set_playback_switch(elem,SND_MIXER_SCHN_FRONT_RIGHT,0);
+ } else if (!status && vol->right != 0.0) {
+ snd_mixer_selem_set_playback_switch(elem,SND_MIXER_SCHN_FRONT_RIGHT,1);
+ }
+ }
+ }
}
else {
snd_mixer_selem_get_playback_volume(elem, 0, &get_vol);
More information about the MPlayer-dev-eng
mailing list