Bug 105654 - Unable to properly switch between Speakers and Headphones (has "workaround")
Summary: Unable to properly switch between Speakers and Headphones (has "workaround")
Status: RESOLVED MOVED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: alsa (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-21 10:27 UTC by gbr
Modified: 2018-07-30 10:11 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
pactl list sinks (3.84 KB, text/plain)
2018-03-21 10:27 UTC, gbr
Details
amixer -c0 with "Line Out" set as default port and "Auto-Mute Mode" set to Enabled (3.75 KB, text/plain)
2018-03-21 11:25 UTC, gbr
Details
amixer -c0: "Headphones" set as default port / "Auto-Mute Mode" set to Disabled / [Element Front] switch=off,volume=off (3.75 KB, text/plain)
2018-03-22 14:59 UTC, gbr
Details

Description gbr 2018-03-21 10:27:22 UTC
Created attachment 138239 [details]
pactl list sinks

===
OS: Arch Linux x64
Kernel: 4.15.10
PulseAudio 11.1
Motherboard: B75M-DGS R2.0 (5.1 CH HD Audio (Realtek ALC662 Audio Codec)) [1]
===

Hi,

I was having trouble making PulseAudio switch the audio output between my headphones and speakers, and most importantly, play audio in them exclusively. My headphone is plugged into the front panel and my speakers are using the rear green connection, and both of them are 2 channel. I was able to find a workaround, which I will demonstrate later, but as of now I'll write like I didn't know of that workaround:

I'm using both ALSA and PulseAudio's default options (although I'm not sure if Arch Linux changes any configuration file).

I have two sinks (see attachment for the output of "pactl list sinks"), but the relevant one is the latter, which holds my headphones and speakers (they're split into two ports).

I'll do my best to reproduce the issue I'm having. I apologize in advance bacause English is not my first language. So, for now let's assume I have only my speakers plugged in (a port identified as "Line Out" in pavucontrol). When I decide to plug in my headphones, here's what happens in pavucontrol:

1. The "Line Out" port is set to unplugged and outputs no audio anymore
2. The "Headphones" port is set to plugged in and successfully outputs audio 

The only problem I see here is that the "Line Out" port was set to "unplugged" (this is about semantics, but it really wasn't phisically unplugged), but no big deal since I'm getting audio exclusively in my headphones, which is exactly what I wanted.

Okay, now that I have both speakers and headphones plugged in, let's say I want to switch back to my speakers. All I would have to do is change the "Port" to "Line Out (unplugged)", but here's what really happens:

1. The "Headphones" port gets muted (ok)
2. The "Line Out" port DOES NOT get unmuted
3. I get no audio output in both of them

Strangely, the "Headphones" port WAS NOT set to "unplugged" like it happened before with "Line Out".

---

WORKAROUND:

Here's the "workaround" (not sure if you can call it that) I found while messing with alsamixer:

Assuming we're still are in the previous scenario where I had no audio output, if I open "alsamixer -c0" and set the "Auto-Mute Mode" control to "Disabled", I get exclusive audio output in my speakers (which is perfect and exactly what I wanted). Now, let's say I'd switch back to my headphones. The audio does output to my headphones, but not exclusively. So I still hear audio coming from my speakers as well (I don't want that). That's it.

Speaking of that "Auto-Mute Mode" control, the documentation for Linux v4.5 states [2]:

>When both headphone and line-out jacks are present, it gives "Disabled", "Speaker Only" and "Line-Out+Speaker".

Well, I do have both of them present, but I the only options I get are: "Disabled" and "Enabled". So there's that as well...

---

I will be honest to you guys, I've been searching for a solution to this problem for a long time. At the same time, I'm not an expert (not even close to that) about Linux / PulseAudio / ALSA, so there's a high possibility that I might have missed some PulseAudio configuration (I'm really sorry if that's the case).

But based on a lot of Google searches [3][4][5][6], I'm definitely not the only person dealing with that issue, and while I found some possible solutions, none of them really worked for me... There's even a guy saying he has given up [5]. That "workaround" I found was by accident, while I was fiddling with alsamixer. I mean, it does work perfectly for me, but it's very inconvenient having to disable "Auto-Mute Mode" in alsamixer when I want to use my speakers, and then enable it again when I want to use my headphones. If there isn't a solution within PulseAudio or if this is not a bug at all, let me know. I'm sure this could be automated with scripts, but I'm not a programmer, so any help on would be appreciated as well.

Thank you very much.

TL;DR: I wanted to switch between speakers and headphones and output the audio in them EXCLUSIVELY, like you do on Windows [7], but I couldn't do it by default; But I've found a workaround (which is a tad inconvenient when you do it by hand); And I was not sure if this was a bug or not, so I decided to report here just in case.

===

REFERENCES:

[1] http://www.asrock.com/mb/Intel/B75M-DGS%20R2.0/
[2] https://github.com/torvalds/linux/blob/v4.15/Documentation/sound/hd-audio/controls.rst#realtek-codecs
[3] https://wiki.archlinux.org/index.php/PulseAudio/Examples#Having_both_speakers_and_headphones_plugged_in_and_switching_in_software_on-the-fly (this was the most promising one, unfortunately it didn't work)
[4] https://bbs.archlinux.org/viewtopic.php?id=187828
[5] https://bbs.archlinux.org/viewtopic.php?id=226651
[6] https://bbs.archlinux.org/viewtopic.php?id=161296
[7] https://i.imgur.com/gfKkQcS.png
Comment 1 gbr 2018-03-21 10:35:49 UTC
Sorry, I forgot to add the second part of the workaround. To exclusively output audio to your headphones back again, you'd have to simply set "Auto-Mute Mode" to "Enabled".
Comment 2 Tanu Kaskinen 2018-03-21 11:06:43 UTC
Thanks for the clear problem description!

My impression is that alsa usually sets "Auto-Mute Mode" to "Disabled" by default. If this doesn't happen on your machine, that issue could be reported to the alsa developers. That said, it would probably be a good idea to force it in PulseAudio, since as far as I can tell, enabling auto-mute in alsa is completely useless and can only cause confusion when using PulseAudio, since PulseAudio is perfectly capable of automatically muting unwanted outputs by itself (well, except that in your case there seems to be some problem with muting headphones when selecting the lineout port).

The issue that lineout is marked as unavailable ("unplugged" in pavucontrol) is something that should be fixed. That behaviour was deliberately changed to what it is now, but I think the reason behind that change was not very good: if alsa auto-mutes lineout when headphones are plugged in, we wanted to make clear that lineout isn't usable in that situation. But if the auto-muting in alsa is disabled, then it's wrong to mark the lineout port as unavailable. Maybe in the past it was more common to have auto-muting enabled in alsa (and it might not have been even configurable).

It sounds strange that muting headphones works when you have auto-mute enabled and doesn't work when you have auto-mute disabled. It should make no difference to how pulseaudio configures the mixer. I suspect this is a bug in the kernel driver, but I'd like to check the mixer settings anyway, so could you attach the output of "amixer -c0" when you have enabled auto-mute in alsa and selected the lineout port in pulseaudio?
Comment 3 gbr 2018-03-21 11:25:30 UTC
Created attachment 138240 [details]
amixer -c0 with "Line Out" set as default port and "Auto-Mute Mode" set to Enabled
Comment 4 gbr 2018-03-21 11:41:25 UTC
(In reply to Tanu Kaskinen from comment #2)
> Thanks for the clear problem description!
> 
> since PulseAudio is perfectly capable of automatically muting
> unwanted outputs by itself (well, except that in your case there seems to be
> some problem with muting headphones when selecting the lineout port).
Actually no, the main problem is that the Line Out port does NOT get muted unless Auto-Mute Mode is set to Enabled, so I get audio output in both ports. The Headphone behaves perfectly fine, despite of how Auto-Mute Mode is set, at least from my tests.
Comment 5 Tanu Kaskinen 2018-03-21 12:41:48 UTC
Sorry for the misundertanding.

This is not a kernel driver bug. Or it kind of is, but I don't think it will be fixed. There is a general design problem with snd_hda_intel, as it doesn't specify whether the "Front" mixer element applies to the headphone output or not. On some machines it does, on your machine it doesn't. PulseAudio doesn't mute the Front element when using the headphone port, because that would result in no audio on some machines.

As a workaround you can edit /usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf. Change this

    [Element Front]
    switch = mute
    volume = zero

to

    [Element Front]
    switch = off
    volume = off

We should add special configuration for you hardware so that it works out of the box.

Some details for my own reference:

Motherboard and audio codec:
ASRock B75M-DGS R2.0 (5.1 CH HD Audio (Realtek ALC662 Audio Codec))

udev identification:
ATTRS{subsystem_vendor}=="0x8086", ATTRS{subsystem_device}=="0x1e20"
Comment 6 gbr 2018-03-21 13:23:12 UTC
(In reply to Tanu Kaskinen from comment #5)
> Sorry for the misundertanding.
Please don't even worry about it!

> This is not a kernel driver bug. Or it kind of is, but I don't think it will
> be fixed. There is a general design problem with snd_hda_intel, as it
> doesn't specify whether the "Front" mixer element applies to the headphone
> output or not. On some machines it does, on your machine it doesn't.
> PulseAudio doesn't mute the Front element when using the headphone port,
> because that would result in no audio on some machines.
That's really interesting and it makes complete sense, but ironically now I don't get audio in my headphones no matter what options or port I choose. Also:

When the Line Out port is selected AND Auto-Mute is disabled, I do get audio in my speakers.
When the Line Out port is selected AND Auto-Mute is enabled, I do not get any audio in my speakers.

Isn't that weird?
Comment 7 Tanu Kaskinen 2018-03-22 07:14:27 UTC
It sounds like your headphones are muted - check if that's the case. If they don't seem to be muted, then attach the output of "amixer -c0" when you have selected the headphone port. Hmm, did you apply the workaround in analog-output-headphones.conf? Maybe the Front element actually does affect the headphone output, in which case it must not be set to off in analog-output-headphones.conf. I said previously that it doesn't affect the headphone output on your machine, but I actually don't have any evidence for that statement.

The lineout port is behaving as expected. If auto-mute is enabled in alsa, then lineout will be muted always when you have headphones plugged in. Auto-mute must be disabled if you wish to use lineout while having headphones plugged in.

It seems I blamed the kernel too soon. In my experience, usually "Front" is the only element that controls whether audio goes to lineout, which is why I jumped to the conclusion that the ambiguity of the Front element semantics is to blame, but it seems that you have a "Line" playback switch, which can probably be used to mute the speakers without muting the headphones. PulseAudio currently ignores that element, so try adding this to /usr/share/pulseaudio/alsa-mixer/paths/analog-output-lineout.conf:

    [Element Line]
    switch = mute
    volume = merge

...and this to /usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf:

    [Element Line]
    switch = off
    volume = off
Comment 8 gbr 2018-03-22 14:55:03 UTC
(In reply to Tanu Kaskinen from comment #7)
> It sounds like your headphones are muted - check if that's the case.
After I applied your first suggestion, here's how alsamixer looks like when:

* "Line Out (unplugged)" port is selected (in pavucontrol): https://i.imgur.com/19DS9bN.png
* "Headphones (plugged in)" port is selected (in pavucontrol): https://i.imgur.com/ZxqWNSJ.png

To summarize: When "Line Out" is selected, I hear audio coming from speakers and not from headphones -- perfect. But when "Headphones" is selected, I can't hear anything at all, in both headphones and speakers.

> If they don't seem to be muted, then attach the output of "amixer -c0"
> when you have selected the headphone port.
They don't seem to be muted (there's no "MM" under it), but in the other hand, the Headphone item set to "Off, Off" in alsamixer (see first screenshot), so I can't manipulate its volume. But I'm attaching the output of "amixer -c0" anyway.

> Hmm, did you apply the workaround in analog-output-headphones.conf?
Yes.

> Maybe the Front element actually does affect the headphone output,
I think it does as well.

> The lineout port is behaving as expected. If auto-mute is enabled in alsa,
> then lineout will be muted always when you have headphones plugged in.
That's correct and I can reproduce it. That's why the workaround I suggested  involves enabling Auto-Mute when I want to exclusively use my Headphones and mute my speakers. Obviously, I have no clue what Auto-Mute does, but it'd be great if there was a way for PulseAudio to automatically enable Auto-Mute for me when I want to exclusively use my headphones and not my speakers; And then PulseAudio would disable Auto-Mute when I switch back to speakers.

> Auto-mute must be disabled if you wish to use lineout while having
> headphones plugged in.
Okay, I guess I should only try new settings with Auto-Mute disabled from now on.

> PulseAudio currently ignores that element, so try adding this to
> /usr/share/pulseaudio/alsa-mixer/paths/analog-output-lineout.conf:
> 
>     [Element Line]
>     switch = mute
>     volume = merge
> 
> ...and this to
> /usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf:
> 
>     [Element Line]
>     switch = off
>     volume = off
I'm sad to say that this had no effect whatsoever; Well, at least none of the issues above were directly affected. I added those lines at end of both files because there wasn't any "[Element Line]" in there, did I do it right?

Anyway, I must say I'm really greateful for your help though, so thank you very much! I don't know if I can provide anything else to help you help me, but whatever you may need, just ask me and I'll do my best to fulfill it.
Comment 9 gbr 2018-03-22 14:59:30 UTC
Created attachment 138287 [details]
amixer -c0: "Headphones" set as default port / "Auto-Mute Mode" set to Disabled / [Element Front] switch=off,volume=off
Comment 10 Tanu Kaskinen 2018-03-23 06:51:14 UTC
Ok, undo the [Element Front] change, since it muted the headphones permanently.

It sounds like the Line element isn't doing anything. Can you verify that? Remove or comment out the [Element Line] section from both conf files, then restart pulseaudio and select the headphone port (you should get audio in the speakers as well), and then with alsamixer test if muting or changing volume of the Line element has any effect on the speaker output. If it doesn't have any effect, this should be reported to alsa. Instructions here: http://alsa-project.org/main/index.php/Bug_Tracking (remember to give them the alsa-info output, for some reasons when I point people to those instructions they still sometimes fail to follow them when filing bug reports to alsa).

Here's a new attempt at a workaround in pulseaudio: put this in analog-output-headphones.conf:

    [Element Auto-Mute Mode]
    enumeration = select

    [Option Auto-Mute Mode:Enabled]
    name = auto-mute-on

and this in analog-output-lineout.conf:

    [Element Auto-Mute Mode]
    enumeration = select

    [Option Auto-Mute Mode:Disabled]
    name = auto-mute-off

I don't want to add this workaround to pulseaudio, since it's so clearly a bug in alsa and the workaround is very ugly, but if it turns out that your alsa bug report doesn't lead to a fix (it happens), then I will have to consider doing this anyway in pulseaudio.
Comment 11 gbr 2018-03-23 08:22:13 UTC
(In reply to Tanu Kaskinen from comment #10)
> Ok, undo the [Element Front] change, since it muted the headphones
> permanently.
Done.

> It sounds like the Line element isn't doing anything. Can you verify that?
> Remove or comment out the [Element Line] section from both conf files, then
> restart pulseaudio and select the headphone port (you should get audio in
> the speakers as well), and then with alsamixer test if muting or changing
> volume of the Line element has any effect on the speaker output.
Yes, that's exactly what's happening! I did all that, then I opened alsamixer and the "Line" element was already muted by default, and unmuting it or changing its volume didn't affect anything; I could still hear the audio coming from both Headphones and Speakers no matter what.

> If it doesn't have any effect, this should be reported to alsa.
> Instructions here:
> http://alsa-project.org/main/index.php/Bug_Tracking (remember to give them
> the alsa-info output, for some reasons when I point people to those
> instructions they still sometimes fail to follow them when filing bug
> reports to alsa).
Thanks for pointing the directions, I'll definitely open a ticket there, but what title and description do you think I should choose? I'm not sure exactly what this bug is and I wouldn't want to "guess" a title/description for it, since I could be misleading...

> Here's a new attempt at a workaround in pulseaudio: put this in
> analog-output-headphones.conf:
> 
>     [Element Auto-Mute Mode]
>     enumeration = select
> 
>     [Option Auto-Mute Mode:Enabled]
>     name = auto-mute-on
> 
> and this in analog-output-lineout.conf:
> 
>     [Element Auto-Mute Mode]
>     enumeration = select
> 
>     [Option Auto-Mute Mode:Disabled]
>     name = auto-mute-off
> 
Oh my God, thank you soooo much! It worked perfectly!!! Pavucontrol still shows "Line Out" as "unplugged", but I can switch to it and it will still work as expected. Thanks again!
Comment 12 gbr 2018-03-23 08:39:52 UTC
On a side note, here's something curious: I also have Windows 10 installed on this machine, in dual boot with Arch Linux. But when I'm on Windows, I *have to* NOT install the official Realtek drivers, otherwise it will "unify" my Headphones and Speakers when they're both plugged-in, so I'm unable to freely choose between one of them. However, if I use the default Windows 10 audio drivers, I am able to do so... That is really weird to me.
Comment 13 Tanu Kaskinen 2018-03-23 09:00:35 UTC
(In reply to gbr from comment #11)
> Thanks for pointing the directions, I'll definitely open a ticket there, but
> what title and description do you think I should choose? I'm not sure
> exactly what this bug is and I wouldn't want to "guess" a title/description
> for it, since I could be misleading...

The title could be "ALC662: the Line playback volume and switch don't do anything". Here's some content for the full description (if you copy it as is, it's best to attribute the text to me, since there's some statements in first person):

    With speakers plugged in to the green connector on the back of ASRock
    B75M-DGS R2.0 motherboard[1] (with Realtek ALC662 audio codec), the speaker
    audio can't be muted without muting also front panel headphone output. The
    mixer has playback volume and switch elements named "Line", which I would
    expect to control the speaker audio, but those mixer elements don't seem
    to be doing anything.

    [1] http://www.asrock.com/mb/Intel/B75M-DGS%20R2.0/

You can also add a link to this bug. Let me know when you've filed the bug, I'll subscribe to it.

> Oh my God, thank you soooo much! It worked perfectly!!! Pavucontrol still
> shows "Line Out" as "unplugged", but I can switch to it and it will still
> work as expected. Thanks again!

You can fix the "unplugged" issue by removing this from analog-output-lineout.conf:

    [Jack Headphone]
    state.plugged = no
    state.unplugged = unknown

    [Jack Front Headphone]
    state.plugged = no
    state.unplugged = unknown
Comment 14 gbr 2018-03-23 09:55:12 UTC
(In reply to Tanu Kaskinen from comment #13)
> You can also add a link to this bug. Let me know when you've filed the bug,
> I'll subscribe to it.
Here's the ticket: https://bugzilla.kernel.org/show_bug.cgi?id=199187

> 
> You can fix the "unplugged" issue by removing this from
> analog-output-lineout.conf:
> 
>     [Jack Headphone]
>     state.plugged = no
>     state.unplugged = unknown
> 
>     [Jack Front Headphone]
>     state.plugged = no
>     state.unplugged = unknown

Perfect! Thank you so much for everything.
Comment 15 GitLab Migration User 2018-07-30 10:11:28 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/256.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.