I’m beginning to appreciate how much Ubuntu does out of the box more and more as I find more little things in Crunchbang that require a non-trivial amount of internet scouring and trial/error to figure out. Ubuntu by default uses pulseaudio as the Linux soundserver, and Ubuntu provides a pretty GUI for switching between output audio devices. Crunchbang uses ALSA by default, and switching audio devices is slightly more difficult.
The default output device is set through the ~/.asoundrc file. You list the devices typing “aplay -L” in terminal. The output looks something like this:
front:CARD=PCH,DEV=0 HDA Intel PCH, CONEXANT Analog Front speakers front:CARD=Audio,DEV=0 Display Audio, USB Audio Front speakers
The first entry is my laptop’s internal speakers. The second is the Apple Cinema Display connected to my laptop via the DisplayPort. My .asoundrc looks like this:
pcm.!default front:Audio # apple cinema display # pcm.!default front:PCH # laptop
I switch devices by commenting and uncommenting out the relevant lines for selecting what device I want. Switching a default device by configuration file requires restarting the process that uses sound. For playing Youtube videos in your browser, this means restarting the browser whenever you switch an audio device. (There might be a better way to do this, I haven’t figured it out yet.)
The above method works for all processes that require sound that are started by me. However, I also use mpd/mpc as my music player, which is a background service that doesn’t consult ~/.asoundrc for sound settings. Output devices are specified in /etc/mpd.conf. The syntax for setting an output device in mpd.conf is “device “hw:x,y”, where x is the sound card and y is the output device. This is slightly different from the information you provide for ~/.asoundrc; you get this information from “aplay -l” (note the lower case L). The output of “aplay -l” looks like this:
**** List of PLAYBACK Hardware Devices **** card 0: PCH [HDA Intel PCH], device 0: CONEXANT Analog [CONEXANT Analog] Subdevices: 1/1 Subdevice #0: subdevice #0 card 2: Audio [Display Audio], device 0: USB Audio [USB Audio] Subdevices: 0/1 Subdevice #0: subdevice #0
The chunk of my mpd.conf that is relevant to output devices looks like this:
audio_output { type "alsa" name "My ALSA Device" #device "hw:0,0" # internal speakers device "hw:2,0" # apple display format "44100:16:2" # optional mixer_device "default" # optional mixer_control "PCM" # optional mixer_index "0" # optional }
Again, I comment and uncomment the device lines to switch audio devices. Switching audio devices for mpd requires a service restart, just like for the processes that consult ~/.asoundrc, which I do with “sudo service mpd restart”.
These links were useful in helping me figure out what settings to use:
Thanks, this got me closer to getting HDMI audio working with XBMCbuntu 11 – still not quite there yet though.
Thanks. Found this through google; been trying to get my USB DAC to work through my browser in Peppermint Linux for ages!
as for mpd config file you better do this:
audio_output {
type “alsa”
name “My ALSA Device”
device “hw:0,0” # internal speakers
format “44100:16:2” # optional
mixer_device “default” # optional
mixer_control “PCM” # optional
mixer_index “0” # optional
}
audio_output {
type “alsa”
name “My ALSA Device”
device “hw:2,0” # apple display
format “44100:16:2” # optional
mixer_device “default” # optional
mixer_control “PCM” # optional
mixer_index “0” # optional
}
then you will select your output directly from you mpd player without restart of the daemon!
have done copy/cut and forgot to change the name for the second device, take a different one than the first of course!