toofishes.net

Using your PC as a high-quality audio source

I’ve written here before about writing a program to control my A/V receiver. Although I recently did a computer shuffle, I still have a machine that serves its purpose as my media “server”- that is, it holds a lot of media files as well as outputs them to my home theater setup and control the A/V receiver.

The most important part for me is not the video connection, but the audio one. I listen to my music collection a lot more than watching TV or movies or anything else, so getting good sound quality out of my setup is something I really wanted. Because my computer is a bit older, I spent some money on an add-on sound card that has digital out as the original motherboard didn’t sport one of these connections. I got the Razer Barracuda AC-1 card on woot! as it fit my requirements- digital out, good Linux support, and relatively cheap.

If you can’t tell the difference between a 128kbps MP3 and a good VBR MP3 or FLAC, you can stop reading here. However, if you are someone like me who trades larger file sizes for a better aural experience, keep reading.

Having a digital out is enough, right? The output is optical in my case, but coaxial is not any different. It actually isn’t enough if you dive down into the details of sound processing. ALSA by default uses the dmix plugin to allow software mixing on just about every sound card out there. An unwanted side effect of this is resampling all your audio to one standard rate. In every case I have seen, this rate is 48 kHz, which is a rate supported by nearly all sound cards (and on cheap sound cards, the only rate they support). The problem? 99% of the audio files I have are sampled at 44.1 kHz, the standard rate used on CDs. My A/V receiver has a nice display which shows details about the incoming PCM stream, and this made it really easy to determine my audio was getting resampled.

The solution is easy if you are willing to give up the ability to play multiple audio sources at once. This isn’t a problem for me, as I am either playing music through mpd or media through mplayer, but never both at once. What is the solution? Take dmix and all software mixing out of the output chain.

For me, this involved making a ~/.asoundrc file that changed the default ALSA device used by applications. The ALSA wiki has an informative article describing this file in further detail. For me, the following file works just fine:

pcm.directout {
  type hw
  card 0
  device 0
}
pcm.!default directout

This tells ALSA by default to send any audio streams it receives straight to the hardware. The output of aplay -l should make it easy to determine the correct card and device numbers for your sound card.

44.1 kHz audio now freely flows to my receiver and it sounds great! Unless of course it is one of my vintage MP3s from the Napster era in 1999, but the novelty value of those is more important than the quality.

Tags

See Also