You are not logged in.

#1 2016-04-01 04:07:40

SaphirShroom
Member
Registered: 2016-03-20
Posts: 13

[SOLVED] Firefox ignores pulseaudio's + ALSA's sound card configs

Relevant/similar thread: https://bbs.archlinux.org/viewtopic.php?id=206629


I'm trying to switch the sound output to my headset as soon as I plug it in. That is, right now I've only set my headset as default card in ALSA and pulseaudio, I plan to make an udev rule later down the line.
Having my headset output the sound works fine for almost all things I tested - aplay, mplayer, chromium - except firefox. Instead, when I play sound on Firefox, e.g. Youtube, the sound card it uses is my laptop's onboard one.

In order to fix it, I tried following this wiki article to set the headset as default card for ALSA as such:
(The first line I had to add so that sound works at all - suggested by this article)

/etc/modprobe.d/alsa-base.conf
------------------------------------------
install snd_hda_intel /bin/false
options snd-usb-audio index=0
options snd-soc-sst-broadwell index=1

Using those indices, the snd_usb_audio module didn't appear in /proc/asound/modules anymore even though lsmod showed it as loaded, but unused, so I swapped the indices back and instead used the second method shown in the article (and also the solution suggested in the thread I linked at the beginning of this post):

/etc/modprobe.d/alsa-base.conf
------------------------------------------
install snd_hda_intel /bin/false
options snd-usb-audio index=1
options snd-soc-sst-broadwell index=0
/etc/asound.conf
--------------------------------------
defaults.ctl.card 1
defaults.pcm.card 1
defaults.pcm.device 0

which worked for aplay and mplayer, but not chromium nor firefox (sound from both of these would play on card 0, which is my onboard soundcard).

Finally, I tried setting the default soundcard in pulseaudio:

~/.config/pulse/default.pa
------------------------------------
.include /etc/pulse/default.pa
set-default-sink alsa_output.usb-Logitech_Logitech_G35_Headset-00.analog-stereo

This change made chromium's sound work on my headset, however firefox is still ignoring the configs. Emptying /etc/asound.conf and deleting ~/.asoundrc, as suggested in some posts I found online doesn't do anything more. When I do that, Chromium still outputs to the headset, aplay and mplayer (as expected) output to the ALSA default which is the onboard card. Firefox still outputs to the onboard card as well.


As a last note, I have read firefox always uses hw:0,0 (although the guy in the thread I linked seemed to have found a way to avoid this, so I don't know about the truth value of this fact) and the only way to change it is through the .conf files in /etc/modprobe.d - in which case, does anyone know how to adjust the ordering of caards in /etc/modprobe.d so snd_usb_audio is properly loaded?

Last edited by SaphirShroom (2016-04-01 15:21:47)

Offline

#2 2016-04-01 07:26:22

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

Re: [SOLVED] Firefox ignores pulseaudio's + ALSA's sound card configs

Use pulseaudio for everything. Remove whatever asound.conf or ~/.asoundrc you have (you can keep the modprobe loader stuff though), install pulseaudio-alsa (it sets up an asound.conf that redirects the default card to pulse). ALSA using applications (such as flash with firefox) will use the pulse-alsa compat layer and be handled by pulse. Add load-module module-switch-on-connect  BEFORE the if..udev-detect block in /etc/pulse/default.pa , no need to write your own udev rules, let pulse do what it is supposed to do.

Last edited by V1del (2016-04-01 09:12:39)

Offline

#3 2016-04-01 14:56:11

SaphirShroom
Member
Registered: 2016-03-20
Posts: 13

Re: [SOLVED] Firefox ignores pulseaudio's + ALSA's sound card configs

Thank you, I didn't know about the switch module. This is much easier than writing an udev rule indeed.

Unfortunately, setting pulse as the default in /etc/asound.conf doesn't seem to work. I changed back to the default /etc/asound.conf as you suggested:

/etc/asound.conf
-----------------------------------
 Use PulseAudio by default
pcm.!default {
  type pulse
  fallback "sysdefault"
  hint {
    show on
    description "Default ALSA Output (currently PulseAudio Sound Server)"
  }
}

ctl.!default {
  type pulse
  fallback "sysdefault"
}

# vim:set ft=alsaconf:

Then I deleted .asoundrc.
/etc/pulse/default.pa is still at default, except for the line I added, which causes pulse to correctly switch to the headset soundcard as soon as it is plugged in:

$ pacmd list-sinks                                                                                                                                                                            
2 sink(s) available.
    index: 1
	name: <alsa_output.platform-broadwell-audio.HiFi__hw_broadwellrt286__sink>
	driver: <module-alsa-card.c>
	flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: SUSPENDED
	suspend cause: IDLE 
	priority: 9000
	volume: front-left: 15736 /  24% / -37.18 dB,   front-right: 13769 /  21% / -40.65 dB
	        balance -0.12
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 0.00 ms
	max request: 0 KiB
	max rewind: 0 KiB
	monitor source: 2
	sample spec: s16le 2ch 48000Hz
	channel map: front-left,front-right
	             Stereo
	used by: 0
	linked by: 0
	configured latency: 0.00 ms; range is 0.50 .. 1365.33 ms
	card: 1 <alsa_card.platform-broadwell-audio>
	module: 8
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = ""
		alsa.id = "System Playback/Capture (*)"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "0"
		alsa.card_name = "broadwell-rt286"
		alsa.long_card_name = "broadwell-rt286"
		alsa.driver_name = "snd_soc_sst_broadwell"
		device.bus_path = "platform-broadwell-audio"
		sysfs.path = "/devices/pci0000:00/INT3438:00/broadwell-audio/sound/card0"
		device.vendor.name = "Interphase Corporation"
		device.string = "hw:broadwellrt286"
		device.buffering.buffer_size = "262144"
		device.buffering.fragment_size = "131072"
		device.access_mode = "mmap+timer"
		device.profile.name = "HiFi: hw:broadwellrt286: sink"
		device.profile.description = "Speaker playback + Headphones playback"
		device.description = "broadwell-rt286 Speaker playback + Headphones playback"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card"
	ports:
		[Out] Speaker: Speaker playback (priority 100, latency offset 0 usec, available: unknown)
			properties:
				
		[Out] Headphones: Headphones playback (priority 100, latency offset 0 usec, available: no)
			properties:
				
	active port: <[Out] Speaker>
  * index: 2
	name: <alsa_output.usb-Logitech_Logitech_G35_Headset-00.analog-stereo>
	driver: <module-alsa-card.c>
	flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
	state: SUSPENDED
	suspend cause: IDLE 
	priority: 9049
	volume: front-left: 40672 /  62% / -12.43 dB,   front-right: 40672 /  62% / -12.43 dB
	        balance 0.00
	base volume: 65536 / 100% / 0.00 dB
	volume steps: 65537
	muted: no
	current latency: 0.00 ms
	max request: 0 KiB
	max rewind: 0 KiB
	monitor source: 4
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	used by: 0
	linked by: 0
	configured latency: 0.00 ms; range is 0.50 .. 2000.00 ms
	card: 2 <alsa_card.usb-Logitech_Logitech_G35_Headset-00>
	module: 22
	properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "USB Audio"
		alsa.id = "USB Audio"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "1"
		alsa.card_name = "Logitech G35 Headset"
		alsa.long_card_name = "Logitech Logitech G35 Headset at usb-0000:00:14.0-1, full speed"
		alsa.driver_name = "snd_usb_audio"
		device.bus_path = "pci-0000:00:14.0-usb-0:1:1.0"
		sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/sound/card1"
		udev.id = "usb-Logitech_Logitech_G35_Headset-00"
		device.bus = "usb"
		device.vendor.id = "046d"
		device.vendor.name = "Logitech, Inc."
		device.product.id = "0a15"
		device.product.name = "Logitech G35 Headset"
		device.serial = "Logitech_Logitech_G35_Headset"
		device.form_factor = "headset"
		device.string = "front:1"
		device.buffering.buffer_size = "352800"
		device.buffering.fragment_size = "176400"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "Logitech G35 Headset Analog Stereo"
		alsa.mixer_name = "USB Mixer"
		alsa.components = "USB046d:0a15"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-headset-usb"
		device.intended_roles = "phone"
	ports:
		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: unknown)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-headphones>

Do the soundcard priorities matter at all?
There's also the config at ~/.config/pulse/default.pa which I left as such:

~/.config/pulse/default.pa
--------------------------------------------
.include /etc/pulse/default.pa
#set-default-sink alsa_output.usb-Logitech_Logitech_G35_Headset-00.analog-stereo

Uncommenting the second line doesn't make a difference.

With the above settings, firefox still outputs to the onboard card, and everything else, including chromium, outputs to the headset if it is plugged in.

Last edited by SaphirShroom (2016-04-01 15:04:11)

Offline

#4 2016-04-01 15:05:10

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

Re: [SOLVED] Firefox ignores pulseaudio's + ALSA's sound card configs

have you rebooted in between to reload ALSA configuration? Firefox (or any ALSA using stream) should show an [alsa-plugin] prefixed stream in pavucontrol or in

pacmd list-sink-inputs

If that didn't help, it might be that the firefox stream remembers that it was last played on the onboard soundcard, switching that over manually once should fix this.

Regarding the soundcard priorities, they only matter in case the default would be missing I'd assume. If you have a default set, as indicated by the asterix before the corresponding index line, it will always be the go to device. Should that be missing (because you unplugged your USB headset) all streams on the now missing sink will switch to the next sink per this priority. I haven't really tested this, but I'd say it's a safe assumption.

Last edited by V1del (2016-04-01 15:17:31)

Offline

#5 2016-04-01 15:20:19

SaphirShroom
Member
Registered: 2016-03-20
Posts: 13

Re: [SOLVED] Firefox ignores pulseaudio's + ALSA's sound card configs

You were right about reloading, it seems there was some issue with the configuration file not being loaded properly even though I rebooted multiple times in between my tests.

By chance, I found some sort of workaround reading through this stackexchange post.
That person wanted to redirect an audio stream to another sink during playback. Following the accepted answer, I ran:

$ pacmd list-sink-inputs
1 sink input(s) available.
    index: 7
	driver: <protocol-native.c>
	flags: START_CORKED 
	state: RUNNING
	sink: 2 <alsa_output.platform-broadwell-audio.HiFi__hw_broadwellrt286__sink>
[...]

while firefox was running and then redirected the stream with:

$ pacmd move-sink-input 7 1

where the second index is the pulseaudio sink belonging to my Headset obtained by

$ pacmd list-sinks

For some reason, this made firefox's sound output work permanently and caused it to be redirected to the Headset even after reboots.

Thank you for your help!

edit: I saw your edit just now, you were spot-on with redirecting the sound output! The fox probably remembered it's output sink.

Last edited by SaphirShroom (2016-04-01 15:25:15)

Offline

#6 2016-04-01 15:27:41

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

Re: [SOLVED] Firefox ignores pulseaudio's + ALSA's sound card configs

Pulse streams usually remember on which device they were last on  and will keep by that even if the "default" is a different card. If you would never ever want that behaviour you can extend load-module module-stream-restore in your /etc/pulse/default.pa with restore_device=0 so that all streams always default to whatever is the default sink or available.

No problem, glad to help tongue

Offline

Board footer

Powered by FluxBB