You are not logged in.

#1 2013-12-26 16:41:49

oilgame
Member
Registered: 2010-01-19
Posts: 41

Changing sound card

I have laptop with external sound card  and I would like to use the external one when its connected and the internal one when its not.

What have I done
I made simple udev rule which switches the default sound card like this:

su - $USER -c 'asoundconf set-default-card DAC'

Asoundconf is a simple python script which makes changes to local asoundconf

Problem with my solution
It works without issues when I'm not playing anything while connecting or disconnecting the card, but for example if I'm playing something on Spotify with the internal card and then connect the external one Spotify keeps on playing on my laptop speakers, but forgets the volume configurations. And if I'm playing something on the external card and then unplug it Spotify crashes.

What I want

  1. Running programs to detect the sound card change automaticly

  2. Alsa to remember volume configurations

  3. Spotify to stop crashing when it loses the sound card

Last edited by oilgame (2013-12-29 03:40:15)

Offline

#2 2013-12-26 23:07:49

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Changing sound card

oilgame wrote:

Running programs to detect the sound card change automatically

I think you'll need pulseaudio.

Offline

#3 2013-12-26 23:29:18

oilgame
Member
Registered: 2010-01-19
Posts: 41

Re: Changing sound card

brebs wrote:
oilgame wrote:

Running programs to detect the sound card change automatically

I think you'll need pulseaudio.

Thank you. I was hoping I could manage without a sound server.

Offline

#4 2013-12-28 14:15:25

oilgame
Member
Registered: 2010-01-19
Posts: 41

Re: Changing sound card

I decided to install pulseaudio and now my problem is that I can't control pulseaudio without X.

paswitch alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00-DAC.analog-stereo

Works beautifully in X, but when I run it via SSH from example I get:

pa_context_connect() failed: Connection refused
can't get pulseaudio context.

EDIT: Managed to bypass the problem by running pulseaudio as system-wide instance.

Last edited by oilgame (2013-12-28 14:41:43)

Offline

#5 2013-12-29 03:41:07

oilgame
Member
Registered: 2010-01-19
Posts: 41

Re: Changing sound card

Noticed that it isn't too smart to run pulseaudio as system-wide instance, what other options do I have?

Offline

#6 2013-12-29 06:03:01

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Changing sound card

to make it work over network, allow tcp connections... or copy over your pulse cookie file.


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#7 2013-12-29 13:13:47

oilgame
Member
Registered: 2010-01-19
Posts: 41

Re: Changing sound card

Rasi wrote:

to make it work over network, allow tcp connections... or copy over your pulse cookie file.

So this should work out of the box, because I obviously have the pulse cookie file myself?

laasonen@t430s ~ % pactl stat | grep "alsa_output" | cut -d " " -f 3
alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00-DAC.analog-stereo
alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
laasonen@t430s ~ % sudo su - laasonen                                    
laasonen@t430s ~ % pactl stat | grep "alsa_output" | cut -d " " -f 3
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
laasonen@t430s ~ % ls -la .pulse-cookie 
-rw------- 1 laasonen laasonen 256 Dec 18 03:32 .pulse-cookie
laasonen@t430s ~ %

I managed to archive the behavior I was looking for by loading "module-switch-on-connect"-module in default.pa, but I really would like to know how to manage pulseaudio in automatized scripts.

Last edited by oilgame (2013-12-29 13:18:15)

Offline

Board footer

Powered by FluxBB