Allow multiple programs to play sound at once

From ArchWiki

Jump to: navigation, search


i18n
English
Slovensky
Español

In Linux, only one program can play a sound at a time unless you have a soundcard that supports hardware mixing (all/most onboard soundchips don't.) or one of the methods outlined below are being used. All the methods are using some form of software mixing.

Contents

[edit] dmix - Alsa's software mixing system.

Note: For ALSA 1.0.9rc2 and higher you don't need to setup dmix. Dmix is enabled as default for soundcards which don't support hardware mixing (from the alsa wiki).

Note: dmix reduces the sound quality during mixing more or less noticeably. You should try another solution if this concerns you or you need TeamSpeak (because this is the only important app not supporting alsa yet right?).

One should not need to even have an asound.conf as dmix kicks in automatically but in 1% of cases it might be needed, so appearing here for brevity:

#/etc/asound.conf start:
pcm.!default {
    type plug
    slave.pcm "dmixer"
}


pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
}
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 8192
        rate 44100   #many new cards are 48000 only
    }
    bindings {
        0 0
        1 1
    }
}

ctl.dmixer {
    type hw
    card 0
}

#end.

And magically, next time a program tries to use sound, dmix will kick in.

You might find that only one user can use the dmixer at a time. This is probably ok for most but for those like myself who run mpd as a separate user this poses a problem. When mpd is playing my normal user can't play though the dmixer. While its quite possible to just run mpd under my login account I found another solution. Adding the line ipc_key_add_uid 0 to the pcm.dmixer block disables this locking. The following is a snippet of my asound.conf, the rest is the same as above.

...
pcm.dmixer {
 type dmix
 ipc_key 1024
 ipc_key_add_uid 0 
slave {
...

To make most programs use Alsa, make sure /etc/libao.conf only contains the following.

default_driver=alsa10

For other programs who insist on their own audio setup, eg, XMMS or Mplayer, you would need to set their specific options.

For mplayer, open up ~/.mplayer/config (or /etc/mplayer/mplayer.conf for global setting) and put the following line in:

ao=alsa

For XMMS/Beep Media Player, go into their options and make sure the sound driver is set to Alsa, not oss.

To do this in XMMS:

  • Open XMMS
    • Options -> preferences.
    • Choose the Alsa output plugin.


For applications which do not provide a ALSA output, you can use aoss from the alsa-oss package. To use aoss, when you run the program, prefix it with aoss, eg:

aoss realplay

pcm.!default{ ... } doesnt work for me anymore. but this does:

 pcm.default pcm.dmixer  


PS: WINE will sound glitchy with some games unless you select oss 'as-of-now' (08-12-06) but with alsas oss kernel emulation modules this should work fine. You might want to set winecfg -> Sound -> HW acceleration to 'emulation' though for music/sound to work in some games. Or you could use this patch:

http://kcat.strangesoft.net/wine_thread_prio.diff mirror: http://pastebin.archlinux.org/341

which enables alsa to not glitch. You may or may not(maybe the entry already there for audio is sufficient) need to set

username  -  rtprio  1

in /etc/security/limits.conf (or you could also substitute group for username). Then logout/login :)

[edit] vmix - OSS' software mixing system.

OSS v4.0 is an open-source (or commercial: it is available under 3 licenses) sound driver (alternative to ALSA) that contains a software mixer in kernel-space. See OSS for more information.

[edit] PulseAudio

PulseAudio (formerly Polypaudio) is a networked sound server, similar in theory to the Enlightened Sound Daemon (EsounD). PulseAudio is however much more advanced and has numerous features. The PulseAudio daemon and utilities are still under heavy development. Although they are generally considered stable, they haven't seen enough testing to warrant a first completely stable release.

More: PulseAudio

[edit] Hardware mixing

Use soundcard that supports hardware mixing: old SoundBlaster Live series (emu10k1 chip) and new Audigy series (emu10k2 chip) cards are known to work.

The SoundBlaster Live 5.1 is fairly easy to find and is cheap to buy.

Note: new cheap Audigy SE, Audigy 2 NX, SoundBlaster Live 24bit and SoundBlaster Live 7.1 does not support hardware mixing (they use other chips).

99% of motherboards with integrated sound do not support hardware mixing.

The onboard VIA8237 chip supports 4-stream hardware mixing. However it does only 3 for some motherboards (the 4th makes no sound), or just broken. Even if it works, the quality is not good compared to other solutions.

[edit] Old, discouraged or less popular methods

[edit] aRTS - KDE Project's software mixing system

pacman -S arts

Then if you use KDE, aRTS will be started for you automatically. If you don't use KDE and want arts to start whenever you start your computer, add this line to a system startup file such as /etc/rc.local:

/opt/kde/bin/artsd -a oss &

To hear the music, set your program's audio outputs to arts.

For apps that do not provide an aRTS output, you may prefix them with artsdsp, eg:

/opt/kde/bin/artsdsp -m xmms

or

/opt/kde/bin/artsdsp -m EnemyTerritory <-- although the sound will lagg behind.

If you find you have problems, try different arguments, which can be found by running the commands below.

artsd --help
artsdsp --help

[edit] EsounD (ESD) - also GNOME Project's software mixing system

EsounD is a dated solution that hasn't been updated for many years, however it has excellent application support and works well for basic desktop usage.

adding 'esd' to the daemons section in rc.conf did the trick for me.

also see ESD for info on how to disable it, if it is hogging your sound devices.,etc

Info: http://www.tux.org/~ricdude/EsounD.html

[edit] ALSA + oss2jack

(UPDATE: Flash now uses alsa thus rendering an oss solution even less desirable. Even so there are alsa -> oss "converters" but i haven't tested it)

"oss2jack - A Linux kernel based approach to using OSS applications with the Jack Audio Connection Kit"

You might want to remove esd, artsd, polypaudio, etc. too as you won't really be needing them unless an app only has artsd output for example.

To use oss2jack, you will need two packages, oss2jack and fusd-kor.

You will need to download the tarballs for each package and run makepkg to create the package. 1.

After having installed the packages, put the oss2jack after jack-audio-connection-kit in the DAEMONS array in /etc/rc.conf if you want oss2jack to start automagically on boot.

Edit /etc/conf.d/jack-audio-connection-kit and change the SERVER_PARAMS and DRIVER_PARAMS to suit your needs. I make the entries look like this:

SERVER_PARAMS="-R -s -d alsa"
DRIVER_PARAMS="hw:0 -p 64 -r 44100"
  1. the reason you write "hw:0" is because the "-d" is already specified in /etc/rc.d/jack-audio-connection-kit thus making jackd run like "jackd -R -s -d alsa -d hw:0 -p 64 -r 44100" :) geddit? good.

If you have a slower computer, you may want to increase the period from 64 to 128 or 256.1 (Note by AqD: 512 or 1024 is just fine, don't waste your CPU)

This can be used as solution to the "TEAMSPEAK and mic + ingame sound/music while using XMMS" or whatever problem one see all around the net. If you need more info see the oss2jack site (linked below).

[edit] Notes
  • Wine requires the audio to be 'Emulated' (change in winecfg's audio tab)
  • If you have MOD_AUTOLOAD="yes" in your rc.conf you might need to have !snd_pcm_oss !snd_seq_oss in your MODULES array to disable autoloading of these modules by udev.
  • If you need to start oss2jack as a user(with realtime capabilities), you need to compile and install the realtime-lsm module.
  • Some apps/games require the snd-mixer-oss kernel-module loaded(UT2004 for example), this might be(but probably isn't) unstable for the oss2jack daemon. Note that alsamixer will still let you set PCM, MASTER, etc volume regardless of if you have snd-mixer-oss loaded.
  • If you have issues setting the OSS volumes, try using audacity to set the volumes. Audacity is available in the Extra repository and is a sound editor that uses OSS. It has controls for input (mic) and output volumes. The volumes set with Audacity are OSS volumes, not ALSA volumes. You should only use this solution if using an ALSA mixer doesn't work for some reason, as setting the OSS volumes may unintentionally change the ALSA volumes due to oss2jack's emulation.
  • If you are running other OSS drivers in your kernel, you will have to bind oss2jack to a different device. To bind oss2jack to /dev/dsp2, edit /etc/rc.d/os2jack and change the line:
/usr/bin/oss2jack &

to this:

/usr/bin/oss2jack -n 2 &
[edit] More Information

oss2jack
oss2jack Installation Instructions
JACK Audio Connection Kit
Errors I encountered - Read this if you have other problems not mentioned here

[edit] joss(up until now it has been called q3jack..)

recently a similar solution as the above has come up which doesn't require a kernel module but has other limitations. Note that it has no capture support as-of-yet (04-12-2006) and development have been stalled for some quite some time :/.

To install use the package in aur: joss

Just start your app with

joss <appname>

You could manage some settings with command line options.

 -n, --name=NAME           use name to identify application to jack" (default: joss-PID)
 -o, --outputs=out_1,out_2 connect to specific outputs (default: first 2 physical outputs)
 -b, --blocks=N            set DMA block count (affects latency) (min: 4, max/default: 16)

Here are some examples from the README.

This just starts quake3 app with joss, getting an default name to jack and connects to the first 2 physical outputs.

joss quake3 

This start et with the specific name "enemy-territory" to jack. And links the output to alsa pcm playback device 3 and 4.

joss -n enemy-territory -o alsa_pcm:playback_3,alsa_pcm:playback_4 et 

With "-b" this example reduce DMA block count to 4 to reduce latency.

joss -b 4 lugaru

So you could tweak latency with "-b", change the jack name with "-n" to relieve identification in an jack control client. When you like to record output from an app started with joss you can link output with "-o" to an jack amplified recorder app.

site: http://www.konstruktiv.org/q3jack mirror: http://www.craknet.net/joss

[edit] NAS http://radscan.com/nas.html

Unique features. Check the readme. Has builtin mixing. You may get it to work with libaudioss, therefore nearly audio apps that have an OSS output will work with this, and it will be "lag-free". It does not have mmap support however, and this causes it to not work with many games.

[edit] USound - http://mattcamp.paunix.org/usound/

USound is somewhat similar to the Enlightened Sound Daemon (EsounD), but as the name suggests, USound aims to be more useful, particularly for consumer desktop and multimedia applications. At the time of writing (0.2) it has support for libao, mplayer, madplay and Speak Freely.

[edit] Troubleshooting

[edit] Permanently change the daemons priority

Take a look at "schedtoold" [1]

[edit] Skype

Click here for a Skype dmix how-to.

[edit] Other information

Personal tools