no intersection more awesome
Header

Selecting Alsa’s Default Sound Card

April 26th, 2014 | Posted by Jason "moofang" in Howto's | Linux

So yeah I’m still alive. Just on hiatus thanks to loads of irl stuff, as usual. I suppose the saving grace of this blog’s livelihood is that I’ll always have practical motivations to come here and drop a fixit I discover – since it works as my own personal documentation as well. I still want to write anime of course, I just need to find the time.

Anyway, shoutout to Idyllictux for his help with this one.

So OpenSUSE comes built with Pulseaudio nowadays, and for the most part it’s well set up and “just works”. There are obscure cases where it doesn’t quite perform though, for me anyway, cases like recording sound via the mic input, and playing games on PCSX2. Wonderfully enough, it’s fairly trivial on OpenSUSE to kill Pulse and fall back on Alsa. Having done that though, I found myself in a peculiar pickle where Alsa appeared to have found 2 sound cards and picked the non-working one for default. This, too, is not normally a big problem, since for KDE stuff you could just configure phonon in one place, and for stuff like smplayer you could just direct it manually to use the right sound card. Sometimes though, like in PCSX2′s case, things appear to be hardcoded to use the default soundcard, leaving you with non-working sound.

I tried Googling briefly for how I could tell Alsa to disable/forget a sound card, or to switch its default sound card, and found that there, apparently, used to be a tool called ‘asoundconf’ that lets you deal with such things. However, I wasn’t able to find nor install this on my system. Fortunately, Mr Idyllictux demonstrated there was another way:

First, list your sound cards with:

aplay -l

You should get an output that looks like:

**** List of PLAYBACK Hardware Devices ****
card 0: MID [HDA Intel MID], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: MID [HDA Intel MID], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: MID [HDA Intel MID], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: CX20756 Analog [CX20756 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0

Look for the number of the sound card you want to make default. Then, create (or edit) the file ~/.asoundrc with the following:

pcm.!default {
type hw
card 1
}

Replacing the ’1′ in ‘card 1′ with the number of the sound card you want to be default. Save it and restart your session, and Alsa should now use the card as default.

Edit: The above will work, but will also create the iffy (and sickeningly familiar) problem of every sound application hogging the sound card (so you can’t have two applications playing sound at the same time). Copying and trial-and-error-ing blobs of config from Idyllictux‘s setup, I was able to discover an optimal .asoundrc as follows:

pcm.!default {
type hw
card 1
}

pcm.!default {
type plug
slave.pcm "dmixer"
}

pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:1,0"
period_time 0
buffer_time 0
period_size 2048
buffer_size 32768
rate 44100
}
bindings {
0 0
1 1
}
}

Replace ‘Card 1′ with your card as per above. This config (which also works with pulse enabled) actually lets everything I have co-exist sound-wise (including PCSX2 on PortAudio, and smplayer using ‘alsa’ for audio). The only minor downside is that if you run this with pulse, you’ll lose the per-app volume control feature, presumably because we’re bypassing pulse’s software mixer.

This was the last link I needed to get PCSX2 fully working on my 64-bit Linux system. I’ll try and find time to document that one too, hopefully in the near future.

  • Facebook
  • Twitter
  • Identi.ca
  • Delicious
  • Digg
  • Google Buzz
  • StumbleUpon
  • Add to favorites
  • RSS
1326
Rate this post
Thanks!
An error occurred!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

2 Responses



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>