You are not logged in.

#1 2014-05-02 02:46:06

hotze
Member
Registered: 2014-03-04
Posts: 9

Automatic switching HDMI/front audio

Hey,

I have an htpc box with arch. It mainly runs xbmc and steam.
It is connected via hdmi to a TV.
I have installed pulse audio and I would like the sound to switch to headphones
when they are plugged into the front headphone jack.
When no headphones are plugged in, the sound should be output to hdmi.

Both devices work and I can play a sound on the TV with

aplay -D plughw:0,8 /usr/share/sounds/alsa/Front_Right.wav

and on the headphones with

aplay -D plughw:1,0 /usr/share/sounds/alsa/Front_Right.wav

Detection of plugged in headphones seems to work as well.
Here is a diff of pacmd list-sinks with headphones plugged in and plugged out:

$ diff sinks_plugged_in sinks_plugged_out
128c128
< 		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes)
---
> 		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: no)

Here are the outputs of some other commands i thought might be useful:
pacmd list-cards
pacmd list-sinks
aplay -lL

My pulseaudio config can be found here:
/etc/pulse/default.pa

I don't know how I can achieve this. All I found was guides on how to turn this feature off,
giving me the impression that it is supposed to be turned on by default ?!

I am very greatful for any help and am happy to supply additional info if required.

Offline

#2 2014-05-08 18:44:49

hotze
Member
Registered: 2014-03-04
Posts: 9

Re: Automatic switching HDMI/front audio

Sorry to bump my own thread, but I still haven't found a solution for this.
On my Linux Mint laptop, auto switching from the built in speakers to the headphones worked out-of-the-box,
so I guess this should be, in general, possible.

Offline

#3 2014-05-08 19:13:59

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: Automatic switching HDMI/front audio

hotze wrote:

Sorry to bump my own thread, but I still haven't found a solution for this.
On my Linux Mint laptop, auto switching from the built in speakers to the headphones worked out-of-the-box,
so I guess this should be, in general, possible.

That is probably an internal feature of pulseaudio or even a hardware feature of your laptop. Do you look for something like this?
I would check if udev recognizes that headphones are plugged in/out (udevadm monitor), create a rule and a script setting the default output via pacmd. Or create a systemd service, or your own script periodically checking the status.

I am not using PulseAudio any more since a long time ago, so things might have changed and there might be modules for this.

Last edited by emeres (2014-05-08 19:55:04)

Offline

#4 2014-05-08 20:22:05

hotze
Member
Registered: 2014-03-04
Posts: 9

Re: Automatic switching HDMI/front audio

emeres wrote:

Do you look for something like this?

I am not sure. I had a look at the code (I dont know Perl, though), and it seems that, in the end, all it does is issuing

pacmd set-default-sink x

However, when I do this manually, it doesnt switch the sound to the other sink.

emeres wrote:

I would check if udev recognizes that headphones are plugged in/out (udevadm monitor), create a rule and a script setting the default output via pacmd. Or create a systemd service, or your own script periodically checking the status.

Unfortunately, udev does not seem to detect plugging in or out
(udev monitor doesnt output anything when I plug headphones in or out).
However, I can see the change in pacmd list-sinks as described above.
When I set pulse log level to debug, I also get some output from there, indicating that it gets recognized:

D: [pulseaudio] module-alsa-card.c: Jack 'Front Headphone Jack' is now unplugged
D: [pulseaudio] device-port.c: Setting port analog-output-headphones to status no
D: [pulseaudio] module-switch-on-port-available.c: finding port analog-output-headphones
D: [pulseaudio] module-alsa-card.c: Jack 'Front Headphone Jack' is now plugged in
D: [pulseaudio] device-port.c: Setting port analog-output-headphones to status yes
D: [pulseaudio] module-switch-on-port-available.c: finding port analog-output-headphones

Offline

#5 2014-05-08 20:48:15

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: Automatic switching HDMI/front audio

So you want to switch already running audio to another sink on the fly?

Offline

#6 2014-05-08 21:09:27

hotze
Member
Registered: 2014-03-04
Posts: 9

Re: Automatic switching HDMI/front audio

emeres wrote:

So you want to switch already running audio to another sink on the fly?

Yes, exactly.

Offline

#7 2014-05-08 21:34:26

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: Automatic switching HDMI/front audio

I do not know if that is easily possible. I would create a device for both TV/Box and headphones, and then mute the appropriate channels, when sink status  changes on un-/plugging. Since you have that feature with your laptop, look it up. See what modules pulseaudio loads and what changes are made. (If it is not a hardware feature)

Offline

Board footer

Powered by FluxBB