You are not logged in.

#1 2016-07-25 19:38:58

Job
Member
Registered: 2011-07-06
Posts: 4

[SOLVED] PulseAudio combo jack - setting default source port

Hello,

I've been struggling with this for a while now, looking all over the internet for a solution, including thoroughly inspecting the wiki. What I want to do seems like a simple enough task, yet it is clearly beyond me and I would really appreciate some assistance from someone more skilled.

My situation is as follows:

I have a combo audio jack on my laptop, which does not automatically detect whether what I plug in are simple headphones, or a headset that includes a microphone. When I plug in my headset, PulseAudio assumes I plugged in headphones and changes the sink port appropriately, so that I can hear sound coming out of my headset instead of the built-in speakers. PulseAudio does not however change the source port appropriately, leaving it set to the internal microphone. As a result, I have to manually change the source port to the headset microphone, at which point the microphone finally works.

The issue is that even if I manually configure the appropriate port for the microphone, if I later disconnect the headset, the port defaults back to the internal microphone. What I would like to do is ensure that whenever the headset is plugged in, PulseAudio will default to the headset microphone, not the internal microphone. I don't mind if this means the internal microphone has to be completely disabled, I don't use it and don't plan to.

I will happily provide any of my current configuration files and further information upon request. I wasn't sure what would be needed.

Bonus question:

Upon booting into Arch, if the headset is already plugged in, it is not detected as such - the sound plays through the built-in speakers. I have to disconnect the headset and plug it back in, before the system detects them. Any way to deal with that?

Thank you very much, any assistance I can get will help tremendously.

Last edited by Job (2016-08-08 13:42:15)

Offline

#2 2016-08-05 22:08:17

onslow77
Member
Registered: 2014-09-21
Posts: 278

Re: [SOLVED] PulseAudio combo jack - setting default source port

Hello!

Have a look at "switch on connect" section of Arch wiki page for PulseAudio.

Regards
Martin


It is advised to follow the How to post guide when posting on the Arch forum. If one consciously jumps over these elementary steps like reading the wiki and providing necessary information about the problem, one can be regarded as a Help Vampire.

Offline

#3 2016-08-06 12:45:02

Job
Member
Registered: 2011-07-06
Posts: 4

Re: [SOLVED] PulseAudio combo jack - setting default source port

onslow77 wrote:

Have a look at "switch on connect" section of Arch wiki page for PulseAudio.

Thank you for your help, but unfortunately this is not the solution for me. module-switch-on-connect will switch to a newly connected source, which is not what I am trying to achieve. I only have a single source, but it has multiple ports. I need to ensure that when I plug my headset in, the source port will switch from the internal microphone to the headset microphone.

This is how the source ports are listed when my headset is not plugged in:

        ports:
                analog-input-internal-mic: Internal Microphone (priority 8700, latency offset 0 usec, available: unknown)
                        properties:
                                device.icon_name = "audio-input-microphone"
                analog-input-headphone-mic: Microphone (priority 8700, latency offset 0 usec, available: no)
                        properties:
                                device.icon_name = "audio-input-microphone"
                analog-input-headset-mic: Headset Microphone (priority 8700, latency offset 0 usec, available: no)
                        properties:
                                device.icon_name = "audio-input-microphone"
        active port: <analog-input-internal-mic>

And this is how they look when I plug in my headset:

        ports:
                analog-input-internal-mic: Internal Microphone (priority 8700, latency offset 0 usec, available: unknown)
                        properties:
                                device.icon_name = "audio-input-microphone"
                analog-input-headphone-mic: Microphone (priority 8700, latency offset 0 usec, available: unknown)
                        properties:
                                device.icon_name = "audio-input-microphone"
                analog-input-headset-mic: Headset Microphone (priority 8700, latency offset 0 usec, available: unknown)
                        properties:
                                device.icon_name = "audio-input-microphone"
        active port: <analog-input-internal-mic>

As you can see, their availability changes to unknown, while the active port remains the same. I assume this is because the system does not know for sure whether the device I plugged in includes a microphone or whether it's just a speaker (because of the combo jack).

What I would like to do is make sure that when I plug the headset in, the port will get changed to "Headset Microphone" (audio-input-headset-mic), even if its status is unknown.

Offline

#4 2016-08-07 22:11:02

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 7,771

Re: [SOLVED] PulseAudio combo jack - setting default source port

Does it help if you set the appropriate

set-source-port $SOURCENAME analog-input-headset-mic

at the end of your etc/pulse/default.pa ? if it still switches around on plug/unplug you might want to disable the module-switch-on-port-available in the same file. If you can't do that either because then the headphone/speaker switch doesn't work, you might want to look into ACPI events, where your jack event will hopefully register and one could execute a script in response

Last edited by V1del (2016-08-07 22:23:57)

Offline

#5 2016-08-08 12:09:52

Job
Member
Registered: 2011-07-06
Posts: 4

Re: [SOLVED] PulseAudio combo jack - setting default source port

V1del wrote:

Does it help if you set the appropriate

set-source-port $SOURCENAME analog-input-headset-mic

at the end of your etc/pulse/default.pa ?

No. If I do that, the sink port is going to be set to the internal speaker as it should be initially, and the source port to the headset microphone. When I plug in the headset, the sink will correctly switch to the headset, however the source will actually switch from the headset microphone to the internal microphone and remain there no matter how many time I unplug and plug back the headset, unless I manually go and correct it after plugging my headset in.

if it still switches around on plug/unplug you might want to disable the module-switch-on-port-available in the same file.

If I do that, the source port will remain set to the headset microphone, however the sink port won't switch back to the internal speakers either, when the headset is unplugged.

If you can't do that either because then the headphone/speaker switch doesn't work

Exactly.

you might want to look into ACPI events, where your jack event will hopefully register and one could execute a script in response

Looks like I'm going to have to try that. Thank you for pointing me in the right direction.

EDIT:

My bash is rusty, but I have managed to set up acpid and write a script which solves this somewhat neatly for me. I am posting it here for further reference, in case anyone stumbles upon a similar problem.

/etc/acpi/events/headphone-jack:

event=jack/headphone
action=/etc/acpi/actions/headphone-jack.sh %e

/etc/acpi/actions/headphone-jack.sh (requires run permission):

#!/bin/sh

SINK="alsa_output.pci-0000_00_1f.3.analog-stereo"
SINK_PLUG="analog-output-headphones"
SINK_UNPLUG="analog-output-speaker"

SOURCE="alsa_input.pci-0000_00_1f.3.analog-stereo"
SOURCE_PLUG="analog-input-headset-mic"
SOURCE_UNPLUG="analog-input-internal-mic"

USERS="$(ps axc -o command,user | grep pulseaudio | tr -s ' ' | cut -f2 -d ' ' | sort | uniq)"

case "$1" in jack/headphone)
    case "$2" in HEADPHONE)
        case "$3" in
            unplug)
                logger "Headphones unplugged"
                for user in $USERS;
                do
                    PULSE_RUNTIME_PATH=/run/user/$(id -u $user)/pulse su $user -c "pacmd set-sink-port $SINK $SINK_UNPLUG"
                    PULSE_RUNTIME_PATH=/run/user/$(id -u $user)/pulse su $user -c "pacmd set-source-port $SOURCE $SOURCE_UNPLUG"
                done
                ;;
            plug) 
                logger "Headphones plugged"
                for user in $USERS;
                do
                    PULSE_RUNTIME_PATH=/run/user/$(id -u $user)/pulse su $user -c "pacmd set-sink-port $SINK $SINK_PLUG"
                    PULSE_RUNTIME_PATH=/run/user/$(id -u $user)/pulse su $user -c "pacmd set-source-port $SOURCE $SOURCE_PLUG"
                done
                ;;
        esac
    esac
esac

Additionally, I have commented out the contents of /etc/acpi/events/anything, because I didn't want acpid to handle any other events. I also commented out module-switch-on-port-available in /etc/pulse/default.pa, so that Pulse doesn't attempt to switch the ports itself. This should work for multi-user systems, but I haven't tested it, so no guarantees.

EDIT 2:
I have modified the script so that pacmd is run as the user, not root. This avoids file permission issues if the PulseAudio daemon was not running while the script was activated. Additionally, I have realised that it is actually better to leave module-switch-on-port-available enabled. The script will still function as necessary, with the added benefit that when the system boots up, the sink and source will be set correctly if the headset is not plugged in.

Last edited by Job (2016-08-09 09:27:59)

Offline

#6 2018-10-26 16:41:00

vae77
Member
Registered: 2010-07-02
Posts: 75
Website

Re: [SOLVED] PulseAudio combo jack - setting default source port

This sounds like another solution using configuration instead:
https://bugs.freedesktop.org/show_bug.cgi?id=101798#c5

Offline

#7 2018-10-26 16:50:33

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 7,771

Re: [SOLVED] PulseAudio combo jack - setting default source port

Thanks for the relevant and potentially useful contribution, however as this thread is 2 years old and considered [SOLVED] I'll close this now.

Closing.

Offline

Board footer

Powered by FluxBB