Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Software mixing under Linux

created by Vimes

(idea) by Vimes (3.5 y) (print)   ?   (I like it!) 1 C! Wed Nov 17 2004 at 17:30:45

Linux (bless its little heart) wants to see mass adoption on the average computer user's desktop in the place of a certain product produced by a Redmond company of opposite alignment. However, despite its best intentions, people often avoid it because things hardly ever just work.

Now, sound in Linux has been improving steadily. The ALSA drivers and tools (part of the kernel source itself) support a lot of cards, and generally it isn't that hard to configure (your distro may even compile all supported sound cards as modules and load them appropriately). This is all well and good, until two applications try using the sound card at once...

Hardware & Software Mixing

If you are a very lucky soul, everything will just work, straight off, with no extra configuration needed. The reason for this is that you have a sound card with hardware mixing capabilities supported by ALSA. This means that when two different applications are trying to use the sound card, it will take everything they are throwing at it, and mix them together nicely before sending it to your speakers. If so, great - you can go read something else now. Go on, off with you.

Sadly, most cards don't provide this feature and need a little help. Under Windows this happens automatically, but ALSA does not support it natively. The most common solution is to use what's known as a sound server, such as the arts sound daemon provided by KDE. Unfortunately these programs tend to be bloated, slow, and unsupported by many common applications. Who needs stuff like network support in a mixer, when you just want to dump more than one stream at a sound card?

Dmix

Dmix is a plugin for ALSA which is included in the standard distribution. Through this you can mix multiple sound streams by sending them to a pseudo-device which performs the required mixing in software before sending the mixed data to the actual sound card device. By configuring it as your default sound device, all programs with ALSA support (practically every sound application under Linux) will use the device automatically. Older programs which use the deprecated OSS will still work, however you will need to launch them via the command aoss, e.g. "aoss realplayer". Your nasty, slow sound daemon can also be routed through a Dmix device.

To set up Dmix, simply create/add to an asound configuration file. You can do this in the system-wide location, "/etc/asound.conf", or in a per-user basis such as "~/.asroundrc". I suggest the latter method, as it makes it easier should you mess anything up. My personal configuration looks like this: (you can probably use this verbatim, and it will work straight off assuming that your sound card is configured as the first card in the system)

pcm.swmix {
        type dmix
        ipc_key 313
        slave {
                pcm "hw:0,0"
                period_time 0
                period_size 1024
                buffer_size 8192
                rate 44100
        }
}
pcm.dsp0 {
        type plug
        slave.pcm "swmix"
}
ctl.mixer0 {
        type hw
        card 0
}
pcm.!default {
        type plug
        slave.pcm "swmix"
}

Working? Happy? Good stuff. Play MP3s, watch videos, laugh at flash files... all at once, with little latency. Feel pleased. Wallow in your exuberance. You have triumphed against user-unfriendliness.

Useful source: http://alsa.opensrc.org/index.php?page=Hardware+mixing%2C+software+mixing


printable version
chaos

Chaotic Evil Dmix ALSA number one with a bullet
Linux KDE Thai Food Linux on the Sony Vaio C1XS Picturebook
Redmond, Washington Microsoft MP3 BSE
Perl
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Drink up!
The night I saw a man get his head blown off
bestiary
Jesus Christ Superstar
words with all the vowels
December 20, 2002
Treatise on Time (You Fucko)
The Lion, The Other Lion and the Kipper
A sandwich is not a sammich
All that innocence, shot to hell
Laughter and lying on grass
pumpkin
power structure
John Milton
New Writeups
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
Twin Eclipse
Conversations with God: An Uncommon Dialogue(idea)
SwimmingMonkey
Conversations with Fo Fo- the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
calgon
Buffalo Bill by the pool(poetry)
gate
Anarchy is Order(idea)
ushdfgakjasgh
Scribeling(thing)
XWiz
Trism(review)
This affordable entertainment brought to you by The Everything Development Company