[PATCH 1/2] mixer: do not unmute to volume 0, instead unmute to max.
It's not very useful for unmute to still result in volume 0. Plus it makes it easier to enable sound for devices that were on mute at startup. --- mixer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mixer.c b/mixer.c index 8b290d5..d2d6e18 100644 --- a/mixer.c +++ b/mixer.c @@ -129,7 +129,12 @@ void mixer_getbothvolume(mixer_t *mixer, float *b) void mixer_mute(mixer_t *mixer) { - if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + if (mixer->muted) { + // unmuting to volume 0 makes no sense + if (mixer->last_l == 0) mixer->last_l = 100; + if (mixer->last_r == 0) mixer->last_r = 100; + mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + } else { mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r); -- 1.9.1
If no mixer channel was specified and PCM does not exist, just pick the first. If no volume control is available, at least support mute and full volume switching if a playback switch exists. This is also useful for being able to unmute S/PDIF devices. Especially useful since there seem to be several driver/ALSA bugs that mean these devices often start as muted after every boot. --- libao2/ao_alsa.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c index 091bd00..2ec96f4 100644 --- a/libao2/ao_alsa.c +++ b/libao2/ao_alsa.c @@ -169,13 +169,50 @@ static int control(int cmd, void *arg) } elem = snd_mixer_find_selem(handle, sid); + if (!elem && !mixer_channel) { + // if nothing specified just try picking the first + elem = snd_mixer_first_elem(handle); + if (elem) + mp_msg(MSGT_AO, MSGL_V, "[AO_ALSA] Auto-selected element %s\n", snd_mixer_selem_get_name(elem)); + } if (!elem) { mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_UnableToFindSimpleControl, snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid)); + mp_msg(MSGT_AO, MSGL_INFO, "[AO_ALSA] Available elements for device:\n"); + for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) + mp_msg(MSGT_AO, MSGL_INFO, "[AO_ALSA] %s\n", snd_mixer_selem_get_name(elem)); + mp_msg(MSGT_AO, MSGL_INFO, "\n"); snd_mixer_close(handle); return CONTROL_ERROR; } + if (!snd_mixer_selem_has_playback_volume(elem) && + !snd_mixer_selem_has_playback_volume_joined(elem)) + { + if (!snd_mixer_selem_has_playback_switch(elem)) + return CONTROL_FALSE; + if (cmd == AOCONTROL_GET_VOLUME) { + int v; + snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT, &v); + vol->left = v ? 100 : 0; + snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_RIGHT, &v); + vol->right = v ? 100 : 0; + return CONTROL_TRUE; + } + // special case: only mute supported + if (vol->left != 0 && vol->left != 100 || + vol->right != 0 && vol->right != 100) + return CONTROL_FALSE; + if (snd_mixer_selem_has_playback_switch_joined(elem)) { + if (vol->left != vol->right) + return CONTROL_FALSE; + } else { + snd_mixer_selem_set_playback_switch(elem, SND_MIXER_SCHN_FRONT_RIGHT, vol->right != 0); + } + snd_mixer_selem_set_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT, vol->left != 0); + return CONTROL_TRUE; + } + snd_mixer_selem_get_playback_volume_range(elem,&pmin,&pmax); f_multi = (100 / (float)(pmax - pmin)); -- 1.9.1
Reimar Döffinger wrote on Sat, 5 Apr 2014 14:53:03 +0200:
If no mixer channel was specified and PCM does not exist, just pick the first. If no volume control is available, at least support mute and full volume switching if a playback switch exists. This is also useful for being able to unmute S/PDIF devices.
I can't detect any different behaviour here, but maybe I don't fulfil the conditions. Ingo
On Sun, Apr 06, 2014 at 03:36:28PM +0200, Ingo Brückl wrote:
Reimar Döffinger wrote on Sat, 5 Apr 2014 14:53:03 +0200:
If no mixer channel was specified and PCM does not exist, just pick the first. If no volume control is available, at least support mute and full volume switching if a playback switch exists. This is also useful for being able to unmute S/PDIF devices.
I can't detect any different behaviour here, but maybe I don't fulfil the conditions.
Well, if your device is unmuted from the start, the difference will be that a simple mute/unmute will not insert the volume filter. (Though if you were to use a full soundcard with both spdif and normal output, you could have had any effect, e.g. it might have had working volume control or you might have gotten no volume control at all) But if you (e.g. using alsamixer) mute the spdif device you should notice that there was no way to make it produce sound using MPlayer before. Now just pressing 'm' twice will make it work. Unfortunately I can't test it, but I also suspect that by moving the AC3 special-case for volume control this patch should also allow muting AC3 streams.
Reimar Döffinger wrote on Sun, 6 Apr 2014 17:52:12 +0200:
On Sun, Apr 06, 2014 at 03:36:28PM +0200, Ingo Brückl wrote:
Reimar Döffinger wrote on Sat, 5 Apr 2014 14:53:03 +0200:
If no mixer channel was specified and PCM does not exist, just pick the first. If no volume control is available, at least support mute and full volume switching if a playback switch exists. This is also useful for being able to unmute S/PDIF devices.
I can't detect any different behaviour here, but maybe I don't fulfil the conditions.
Well, if your device is unmuted from the start, the difference will be that a simple mute/unmute will not insert the volume filter.
I did not check this.
(Though if you were to use a full soundcard with both spdif and normal output, you could have had any effect, e.g. it might have had working volume control or you might have gotten no volume control at all)
There is no spdif volume control for me with or without the patch (although the volume bar is displayed when pressing 9 or 0 - but it's always a 0% bar).
But if you (e.g. using alsamixer) mute the spdif device you should notice that there was no way to make it produce sound using MPlayer before.
I can't mute spdif with or without the patch. Although I'm getting the information that the device is muted, it isn't. Unmuting updates the information, but there is sound all the time - without any issues.
Unfortunately I can't test it, but I also suspect that by moving the AC3 special-case for volume control this patch should also allow muting AC3 streams.
Not for me. I just did some quick testing, if I can assist in doing more specific things, please just tell. Ingo
On Sun, Apr 06, 2014 at 06:27:06PM +0200, Ingo Brückl wrote:
Reimar Döffinger wrote on Sun, 6 Apr 2014 17:52:12 +0200:
(Though if you were to use a full soundcard with both spdif and normal output, you could have had any effect, e.g. it might have had working volume control or you might have gotten no volume control at all)
There is no spdif volume control for me with or without the patch (although the volume bar is displayed when pressing 9 or 0 - but it's always a 0% bar).
I assume you tried PCM, not passthrough? There will be no volume control with passthrough no matter what.
But if you (e.g. using alsamixer) mute the spdif device you should notice that there was no way to make it produce sound using MPlayer before.
I can't mute spdif with or without the patch. Although I'm getting the information that the device is muted, it isn't. Unmuting updates the information, but there is sound all the time - without any issues.
I was talking about unmuting after muting in an external application. If you can't mute/unmute in an external application it won't work in MPlayer either, but normally you should have a mute/unmute switch for the SPDIF outputs. If you have multiple, chance are MPlayer picked one that you don't have connected, so it won't do anything. You'd need to use -mixer-channel. And this is all assuming you are using -mixer if the default mixer device doesn't control your SPDIF output.
Reimar Döffinger wrote:
It's not very useful for unmute to still result in volume 0. Plus it makes it easier to enable sound for devices that were on mute at startup. --- mixer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/mixer.c b/mixer.c index 8b290d5..d2d6e18 100644 --- a/mixer.c +++ b/mixer.c @@ -129,7 +129,12 @@ void mixer_getbothvolume(mixer_t *mixer, float *b)
void mixer_mute(mixer_t *mixer) { - if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + if (mixer->muted) { + // unmuting to volume 0 makes no sense + if (mixer->last_l == 0) mixer->last_l = 100; + if (mixer->last_r == 0) mixer->last_r = 100; + mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + } else { mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r);
Unmute to only 10 or 50 or so, in order to not unexpectedly load the speakers (and the audience's ears) with full power? Hans-Dieter
On 08.04.2014, at 02:31, Hans-Dieter Kosch <hdkosch@kabelbw.de> wrote:
Reimar Döffinger wrote:
It's not very useful for unmute to still result in volume 0. Plus it makes it easier to enable sound for devices that were on mute at startup. --- mixer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mixer.c b/mixer.c index 8b290d5..d2d6e18 100644 --- a/mixer.c +++ b/mixer.c @@ -129,7 +129,12 @@ void mixer_getbothvolume(mixer_t *mixer, float *b) void mixer_mute(mixer_t *mixer) { - if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + if (mixer->muted) { + // unmuting to volume 0 makes no sense + if (mixer->last_l == 0) mixer->last_l = 100; + if (mixer->last_r == 0) mixer->last_r = 100; + mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + } else { mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r);
Unmute to only 10 or 50 or so, in order to not unexpectedly load the speakers (and the audience's ears) with full power?
That completely breaks the intended purpose of working with devices that only have a mute toggle...
Reimar Döffinger wrote:
On 08.04.2014, at 02:31, Hans-Dieter Kosch <hdkosch@kabelbw.de> wrote:
Reimar Döffinger wrote:
It's not very useful for unmute to still result in volume 0. Plus it makes it easier to enable sound for devices that were on mute at startup. --- mixer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mixer.c b/mixer.c index 8b290d5..d2d6e18 100644 --- a/mixer.c +++ b/mixer.c @@ -129,7 +129,12 @@ void mixer_getbothvolume(mixer_t *mixer, float *b) void mixer_mute(mixer_t *mixer) { - if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + if (mixer->muted) { + // unmuting to volume 0 makes no sense + if (mixer->last_l == 0) mixer->last_l = 100; + if (mixer->last_r == 0) mixer->last_r = 100; + mixer_setvolume(mixer, mixer->last_l, mixer->last_r); + } else { mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r);
Unmute to only 10 or 50 or so, in order to not unexpectedly load the speakers (and the audience's ears) with full power?
That completely breaks the intended purpose of working with devices that only have a mute toggle...
That's a shame, not that I use mute amy-way, but my card has a proper headphone amp and goes really loud as do my headphones. Using line out to my old stereo system, where the amp is too big for the speakers, which themselves are quite big/loud would certainly be an issue. were I say to mute with mixer on 50% and have it unmute to 100.
Andy Furniss wrote:
Reimar Döffinger wrote:
On 08.04.2014, at 02:31, Hans-Dieter Kosch <hdkosch@kabelbw.de> wrote:
Unmute to only 10 or 50 or so, in order to not unexpectedly load the speakers (and the audience's ears) with full power?
That completely breaks the intended purpose of working with devices that only have a mute toggle...
That's a shame, not that I use mute amy-way, but my card has a proper headphone amp and goes really loud as do my headphones.
Using line out to my old stereo system, where the amp is too big for the speakers, which themselves are quite big/loud would certainly be an issue. were I say to mute with mixer on 50% and have it unmute to 100.
Having just tested "m" my setup doesn't unmute to 0 anyway, it comes back at what it was. I am not using softvol, just alsa -mixer-channel Master.
On 08.04.2014, at 11:52, Andy Furniss <adf.lists@gmail.com> wrote:
Andy Furniss wrote:
Reimar Döffinger wrote:
On 08.04.2014, at 02:31, Hans-Dieter Kosch <hdkosch@kabelbw.de> wrote:
Unmute to only 10 or 50 or so, in order to not unexpectedly load the speakers (and the audience's ears) with full power?
That completely breaks the intended purpose of working with devices that only have a mute toggle...
That's a shame, not that I use mute amy-way, but my card has a proper headphone amp and goes really loud as do my headphones.
Using line out to my old stereo system, where the amp is too big for the speakers, which themselves are quite big/loud would certainly be an issue. were I say to mute with mixer on 50% and have it unmute to 100.
Having just tested "m" my setup doesn't unmute to 0 anyway, it comes back at what it was.
I am not using softvol, just alsa -mixer-channel Master.
The issue you are thinking of would happen if you first reduce the volume to 0, then mute and then unmute. The same if the mixer volume is 0 at startup, and you then mute and unmute. I do not feel completely comfortable with it due to the reasons you mention, on the other hand it's not something that should happen frequently.
participants (4)
-
Andy Furniss -
Hans-Dieter Kosch -
Ingo Brückl -
Reimar Döffinger