Simultaneous sound streams with ALSA
March 7th, 2005Today is a momentous day for my ears. After years of mucking about with ALSA and .asoundrc files, I can finally say I have been able to achieve simultaneous sound streams on my linux box. Admittedly, by years I mean maybe a couple of times a year, for only a few hours at a time, but at least I have finally done it. I am not talking about some cheaters way of doing it either, like piping it through aRts, ESD or any other sound server. I have actually got ALSA itself to mix sound streams on the fly using Dmix.
Previously, if I was listening to music while chatting away in Gaim, all of the Gaim sounds would queue behind the current stream. So when I stopped the media player, I would get a rush of repeating “message received” sounds as alsa emptied the queue. Sometimes this could go on for a few minutes or more - very annoying to say the least. Well, such annoyances are now a thing of the past, and my ears are rejoicing in the audio-goodness that ALSA is now pushing out.
Here is how I did it.
I simply added the following to my .asoundrc file in my $HOME directory:
pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:0,0"
period_time 0
period_size 1024
buffer_size 8192
rate 44100
}
bindings {
0 0
1 1
}
}
pcm.dsp0 {
type plug
slave.pcm "dmixer"
}
pcm.!default {
type plug
slave.pcm "dmixer"
}
pcm.default {
type plug
slave.pcm "dmixer"
}
ctl.mixer0 {
type hw
card 0
}
So simple, and only 36 lines of code.
This entry was posted on Monday, March 7th, 2005 at 6:42 pm and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
June 2nd, 2005 at 3:15 am
Hey, you’re GREAT.
GREAT THANX !!
June 3rd, 2005 at 11:36 am
I am glad I could help. It is amazing how a few lines of code can make such a big difference.
If only I had figured this out about 2 years and 50 cups of coffee ago.
February 17th, 2007 at 1:58 am
Found this page in my search for a solution for the same problem. The .asoundrc above didn’t help though, but the complete ALSA HOWTO on the Gentoo wiki did. Some of the contents are indeed Gentoo specific, but the important stuff isn’t.
Just thought I’d mention this here since this came up at the top of my Google search.
Cheers!