You are not logged in.

#1 2018-11-11 03:05:26

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

[SOLVED] How do you change the default output with PulseAudio

So, I have two "sound cards" (I guess they're called "sinks"?), the analog stereo output on my motherboard and the HDMI output on my Radeon card.

$ pacmd list-sinks|egrep -i 'index:|name:'
    index: 0
	name: <alsa_output.pci-0000_20_00.1.hdmi-stereo-extra3>
  * index: 1
	name: <alsa_output.pci-0000_22_00.3.analog-stereo>

Both work great, and I can easily toggle between the two using the "pavucontrol" PulseAudio GUI tool.

...my problem is, how do I set the default output when I toggle my TV on or off?

My desired effect is to have it so when I push a button on my keyboard, the TV will turn on (using "xrandr" which works great) and ALL AUDIO will now go to the TV. Likewise, when I push another button on my keyboard, the TV will turn on (leaving only my desktop monitor enabled) and all audio will now go to my desktop speakers.

Things I've tried:

  • In "/etc/pulse/default.pa" set "load-module module-stream-restore restore_device=false".

  • Using "pactl set-default-sink 0".

  • Setting up defaults in "pavucontrol".

These commands seem to have either no effect or random effect. ("You were JUST playing on the TV, why are you now playing out my speakers when I restart you???")

Are there are PulseAudio gurus who can please help me change the default PulseAudio sink for all newly started applications? smile

Last edited by drcouzelis (2018-11-12 21:25:50)

Offline

#2 2018-11-11 12:32:32

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,740

Re: [SOLVED] How do you change the default output with PulseAudio

Does your HDMI sink disappear when the TV is off? If that is the case, and it gets properly recreated and disappears on TV shutdown, the easiest way would be enabling

load-module module-switch-on-connect

somewhere before the if...udev-detect code block. On newly appearing and relevantly disappearing sinks that should do the correct thing.

Other than that having restore_device=false should do the right thing on application restarts, given you've changed the default sink properly (FWIW if using pactl set-default-sink to change the sink don't rely on the index, that has a chance to change use the fully qualified name, e.g.

pactl set-default-sink alsa_output.pci-0000_20_00.1.hdmi-stereo-extra3

will be more reliable in a scripting context.

FWIW there's this script which you could just plug into yours that will move everything between outputs.

Also something to consider for the applications that seem to behave "randomly": Are you on KDE? Respectively are the applications that appear to have random behaviour KDE applications? They do have their own distinct default device logic within phonon that not seldom bites itself with what your intentions from pulse's side are. Afaik they do intend to get rid of that and simply follow pulse's setup.

Offline

#3 2018-11-12 21:29:27

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] How do you change the default output with PulseAudio

Thanks, V1del. smile I think that did the trick.

I made two changes. In "/etc/pulse/default.pa" I commented out "module-switch-on-port-available" and added "module-switch-on-connect" (I assume if I do one I don't need the other?).

### Should be after module-*-restore but before module-*-detect
#load-module module-switch-on-port-available
load-module module-switch-on-connect

Lastly, I changed my toggle script to use the full name of the sinks.

pactl set-default-sink alsa_output.pci-0000_20_00.1.hdmi-stereo-extra3
# and
pactl set-default-sink alsa_output.pci-0000_22_00.3.analog-stereo

And it appears to be working as expected!

That is a great script you posted. I'll check it out if I ever decide I want all audio to be immediately moved to the other sink at my command, but for now this gets the job done. smile

Last edited by drcouzelis (2018-11-12 21:29:49)

Offline

#4 2018-11-29 03:12:42

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] How do you change the default output with PulseAudio

...a little update.

My video card audio out wasn't being enabled on reboots. So I added this to the bottom of my "/etc/pulse/default.pa" file. (I included both of my audio out devices, just because.) This forces the video card HDMI to turn on at boot, instead of me having to enable it in pavucontrol.

### Enable all of my audio output devices
# HDMI
set-card-profile alsa_card.pci-0000_20_00.1 output:hdmi-stereo-extra3
# Line out
set-card-profile alsa_card.pci-0000_22_00.3 output:analog-stereo+input:analog-stereo

Offline

Board footer

Powered by FluxBB