HOWTO ALSA Complete (includes dmix)
From Gentoo Linux Wiki
It has been suggested that this article be Merged into one article with HOWTO ALSA (Discuss) |
Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
Introduction
This guide will explain how to set up both ALSA and one of its plugins, "dmix". Dmix is only required if your sound card seems unable to play more than one sound simultaneously, e.g. beeping to indicate a new email message whilst playing an mp3.
Dmix performs the audio channel mixing in software, adding a drain on the main CPU. It is generally better for hardware (the sound card) to perform the mixing, if it is capable.
Please note that as of alsa-lib-1.0.9 RC2, dmix should be automatically enabled for such cards that require it. Only follow the directions below if you find that the default configuration is not sufficient.
Setting up ALSA
The preparation differs depending on the kernel version.
Identify Your Card
The following section is from the official Gentoo ALSA documentation:
First find out what soundcard you have. An easy trick is to search for "audio" in the output of the lspci command. You can install it with emerge pciutils
.
# lspci | grep -i audio Multimedia audio controller: VIA Technologies, Inc. VT82C686 AC97 Audio Controller (rev 64).
Now go to the ALSA Soundcard Matrix and search for your soundcard. In the above example you should go to the "VIA" manufacturer. You will receive a table with the known chipsets of that vendor. The chipset in the above example is "via82c686"; the "Details" link then informs me that the driver is called via82xx. This is all the information you need, so you can safely discard the rest of that document.
Adjust Your USE Flags
Your use flags need to reflect that you want ALSA as your primary sound server. We'll add two flags, so that both new and old programs can use sound support:
File: /etc/make.conf |
... USE="alsa oss ..." ... |
The ALSA flag will allow new applications to use the ALSA sound server directly. OSS will build legacy support into new applications in case you need to use OSS emulation for some reason. It will also build this support into programs for which there is no ALSA option. Using the OSS flag is especially important for programs such as the Wine project, where ALSA drivers are not as mature.
Preparing Kernel 2.4
It's generally better to build ALSA with the kernel in 2.4 than to use the alsa-driver package.
Linux Kernel Configuration: Kernel Configuration |
Loadable module support ---> [*] Enable loadable module support Device Drivers ---> Sound ---> <M> Sound card Support Advanced Linux Sound Architecture ---> <M> Advanced Linux Sound Architecture Open Sound System ---> < > Open Sound System (Deprecated) |
Be sure to include modules for OSS Emulation support as well as for each sound card in your system.
When that is done, build the kernel and install.
Preparing Kernel 2.6
Building Support from Kernel Source
ALSA modules can be built from your kernel source. Select the following options in your kernel configuration:
Linux Kernel Configuration: Kernel Configuration (2.6.15 Example) |
Loadable module support ---> [*] Enable loadable module support Device Drivers ---> Character devices ---> <*> Enhanced Real Time Clock Support Sound ---> <M> Sound card Support Advanced Linux Sound Architecture ---> <M> Advanced Linux Sound Architecture <M> Sequencer Support <M> OSS Mixer API <M> OSS PCM (digital audio) API <M> RTC Timer support [ ] Verbose printk [ ] Debug Generic Devices ---> PCI Devices ---> USB Devices ---> Open Sound System ---> < > Open Sound System (DEPRECATED) |
Remember to select your sound card drivers from the PCI or USB Devices sections. Compile and install your kernel, then reboot to continue.
You can now simply
#emerge alsa-utils alsa-oss
and you're off to post-installation configuration, unless you need Jack or a rate sample converter (if so also emerge alsa-plugins). If you don't know what that it is, you probably won't need it (but remember jack and other plugins are in this separate package).
Building Support from alsa-driver Package
This option builds sound support into the kernel, but does not use a specific sound server. We'll use the alsa-driver package from portage to complete the building of actual card drivers. This allows better control of updating your ALSA and ALSA driver versions.
Linux Kernel Configuration: Kernel Configuration |
Loadable module support ---> [*] Enable loadable module support Device Drivers ---> Character devices ---> <*> Enhanced Real Time Clock Support Sound ---> <M> Sound card Support Advanced Linux Sound Architecture ---> < > Advanced Linux Sound Architecture Open Sound System ---> < > Open Sound System (DEPRECATED) |
Compile and install your kernel, then reboot to continue.
We will then setup your system to use the alsa-driver package.
Installing alsa-driver
Skip this section if you compiled ALSA modules directly from your kernel.
First, we'll need to tell alsa-driver which modules to build for your type of card. Edit /etc/make.conf and add a new option called ALSA_CARDS to it. Inside this variable you declare the soundcard driver you want to use (which you should have from the Identify Your Card section). These card driver names are NOT the same as the module names! Use the module name minus the prepending "snd-":
File: /etc/make.conf |
... ALSA_CARDS="via82xx emu10k1" |
Note that you can specify multiple cards on the ALSA_CARDS line separated by spaces. To get a list of other ALSA_CARDS see http://www.alsa-project.org/alsa-doc/index.php?vendor=All
Now we'll compile ALSA and the drivers you selected:
#emerge alsa-lib alsa-driver alsa-oss alsa-utils
Now update your configuration files:
#etc-update
Post-Installation Configuration
First, you'll have to edit /etc/modules.d/alsa and configure it specifically for your sound cards and OSS emulation.
Here is the gentoo default configuration file:
File: /etc/modules.d/alsa |
# Alsa 0.9.X kernel modules' configuration file. # $Header: /home/cvsroot/gentoo-x86/media-sound/alsa-utils/files/ # alsa-modules.conf-rc,v 1.1 2003/08/05 21:07:55 johnm Exp $ # ALSA portion alias char-major-116 snd # OSS/Free portion alias char-major-14 soundcore ## ## IMPORTANT: ## You need to customise this section for your specific sound card(s) ## and then run `update-modules' command. ## Read alsa-driver's INSTALL file in /usr/share/doc for more info. ## ## ALSA portion alias snd-card-0 snd-cmipci ## alias snd-card-1 snd-ens1371 ## OSS/Free portion alias sound-slot-0 snd-card-0 ## alias sound-slot-1 snd-card-1 ## # OSS/Free portion - card #1 alias sound-service-0-0 snd-mixer-oss alias sound-service-0-1 snd-seq-oss alias sound-service-0-3 snd-pcm-oss alias sound-service-0-8 snd-seq-oss alias sound-service-0-12 snd-pcm-oss ## OSS/Free portion - card #2 ## alias sound-service-1-0 snd-mixer-oss ## alias sound-service-1-3 snd-pcm-oss ## alias sound-service-1-12 snd-pcm-oss alias /dev/mixer snd-mixer-oss alias /dev/dsp snd-pcm-oss alias /dev/midi snd-seq-oss # Set this to the correct number of cards. options snd cards_limit=1 |
Single card example
Here is an acceptable single card configuration complete with OSS emulation:
File: /etc/modules.d/alsa (single card) |
alias char-major-116 snd alias char-major-14 soundcore alias snd-card-0 snd-emu10k1 alias sound-slot-0 snd-card-0 alias sound-service-0-0 snd-mixer-oss alias sound-service-0-1 snd-seq-oss alias sound-service-0-3 snd-pcm-oss alias sound-service-0-8 snd-seq-oss alias sound-service-0-12 snd-pcm-oss alias /dev/dsp snd-pcm-oss options snd cards_limit=1 |
Multiple cards
Here is an example of a two card configuration with OSS emulation for each (for cards that use different modules):
File: /etc/modules.d/alsa (multiple cards) |
alias char-major-116 snd alias char-major-14 soundcore #Card 1 alias snd-card-0 snd-emu10k1 alias sound-slot-0 snd-card-0 alias sound-service-0-0 snd-mixer-oss alias sound-service-0-1 snd-seq-oss alias sound-service-0-3 snd-pcm-oss alias sound-service-0-8 snd-seq-oss alias sound-service-0-12 snd-pcm-oss options snd-emu10k1 index=0 alias /dev/dsp snd-pcm-oss #Card 2 alias snd-card-1 snd-intel8x0 alias sound-slot-1 snd-card-1 alias sound-service-1-0 snd-mixer-oss alias sound-service-1-3 snd-pcm-oss alias sound-service-1-12 snd-pcm-oss options snd-intel8x0 index=1 alias /dev/dsp1 snd-pcm-oss options snd cards_limit=2 |
In the 2-card configuration above, the index=0
or index=1
decide the order in which the sound card modules are loaded and as such which card is the first sound card. You'd want to do that in order to have a specific sound card being default. Note that the module doesn't actually have to be loaded to 'reserve' the space. Therefore having index=0
and index=2
will leave space for a third soundcard in between should you choose to plug it in.
Now if that doesn't work for some reason, read the ALSA wiki entry for more info. But you can still tamper with the order of module loading. So now we'll tell the kernel which modules to load at boot. Replace the examples with your actual modules. The name of your modules will be prepended by "snd-"
File: /etc/modules.autoload.d/kernel-2.6 |
# /etc/modules.autoload.d/kernel-2.6: kernel modules to load when system boots. # # Note that this file is for 2.6 kernels. # # Add the names of modules that you'd like to load when the system # starts into this file, one per line. Comments begin with # and # are ignored. Read man modules.autoload for additional details. # For example: # 3c59x snd-emu10k1 snd-intel8x0 |
Note that the order with which you list your cards will be the order that ALSA uses to determine which card will be primary (default), and which will be secondary.
Now run modules-update to commit the changes to both /etc/modules.d/alsa and the previous entry:
#modules-update -f
The -f option forces changes to be committed. Some versions of Gentoo will require the full --force or force (modules-update force) option to be used instead. Adjust accordingly.
Multiple cards with the same module
(Please copy the example from the ALSA site)
In this case, you can still choose their index individually. The ALSA documentation has an excellent example on how to achieve that for the USB cards (check your card/module entry in ALSA to see if it has similar functions, if so it works just the same), but in the future udev should make it possible for all cards.
Start alsa automatically
We'll now add ALSA to your default runtime so it will start at boot:
#rc-update add alsasound boot
Now start ALSA manually:
#/etc/init.d/alsasound start
And run alsamixer to unmute your channels and set acceptable volume levels. You should run alsamixer with the -c flag to specify which card to adjust:
#alsamixer -c 0 or #alsamixer -c 1
After unmuting your channels and setting inital volume levels you can save your settings with:
#/etc/init.d/alsasound save or #alsactl store
This will save the settings to /etc/asound.state. /etc/init.d/alsasound will use that file to restore volume levels at boot-time.
User Configuration
Each user to utilize the sound system will need to be added to the "audio" group:
#gpasswd -a username audio
Replace "username" with the user you wish to grant access.
Notes
Your default ALSA configuration without dmix is now complete. Note that it is not at all necessary to continue with a dmix configuration unless you have a specific reason to do so, especially considering that both KDE and GNOME provide ways of doing software mixing. For the basic user, your ALSA is now complete.
Finding your ALSA card ID
If you have several soundcards, you may want to know the ID of your soundcards, so that you can easily switch between your soundcards when using, e.g., mplayer (see note on how to switch elsewhere in this HOWTO).
#cat /proc/asound/cards
The card ID is the identifier on the far right in the first line of each card listed. These card IDs should match the subdirectories in '/proc/asound', e.g., if you have a Sound Blaster Live! card, you should have a subdirectory named something like '/proc/asound/Live'
Known Issues
Kernel 2.6.16
There is currently a problem with the alsa-driver package and kernel 2.6.16, either vanilla, Gentoo, or -ck. Please note that upgrading to ALSA 1.0.11_rc3 or newer should solve the problem for some. Yet for others, this option might create modules that cannot load into your new kernel. Be aware that as of right now, you should only run 2.6.16 with Alsa built into the kernel. This issue is resolved in kernels 2.6.17 and above.
If you choose to compile sound card support directly into the kernel and have alsa-sound on video capture cards there may be problems starting with 2.6.16. (It worked for me in 2.6.15.) My system detects the TV card before the sound card as an alsa device. This makes the TV card the default sound card which results in no sound and causes many alsa utilites to fail. Compiling as modules [as in the 2.6.15 example above] solved this problem for me. This is also resolved in 2.6.17 and up.
UDEV 089-r2
As of UDEV 089 (which needs baselayout 1.12.0-pre18-r1 or greater to work properly), modules in /etc/modules.autoload.d/kernel-2.6 will load in REVERSE order. Adjust your settings for your primary sound card accordingly.
No Sound, Mixers Adjusted
When switching between built-in ALSA, kernel modules, and alsa-driver, you may need to delete /etc/asound.state in order to have your sound cards output sound. First, stop /etc/init.d/alsasound, then delete the file. When you next start the service, it will recreate and empty asound.state and you'll have to readjust your mixer settings as per these installation documents.
No Sound or very silent sound with noise
When you run "alsamixer" and see channels like "IEC958 Front", "IEC958 Rear" etc. instead of "Center" then change all channels to above 50% and mute "IEC958" channel (press M on it).
Some onboard sound cards have connectors to route sound to audio jacks on the front of the computer case rather than the back plugs. A bank of jumpers control where the sound is routed. (For example the onboard Sound Blaster 24bit LS (ca0106).) If these jumpers are set to route sound to the wrong jacks, there will be no errors but no sound either.
Other possible issue is with some old types of sound cards (for example Aureal Vortex). Their problem can be solved by enabling/disabling (with "M" button) "External amplifier" option in alsamixer.
Credits
Redeeman
Redeeman
Redeeman
sametoms - small adjustments
w0rm - some corrections
ep98 - small adjustments
chuck_theobald - some additions
jbdubbs - complete rewrite plus multiple cards support
high - small correction
Testing Your Installation
- Install mpg321:
$ emerge media-sound/mpg321
- Test basic dmix on alsa with:
$ mpg321 somesong1.mp3 & $ mpg321 somesong2.mp3 & $ mpg321 somesong3.mp3 &
With dmix enabled by default, this should work without flaw. If the second or third audio stream stutters, you may have a problem with the buffer size or sampling rate, depending on your card and it's specific issues. In this case, read on in order to customize your installation.
Intro to dmix
The dmix virtual sound mixing device is a plugin to ALSA which takes multiple sound streams and mixes them into one virtual stream which a lower-end card can handle. Any card which does not support multiple streams or hardware mixing of sounds must use this plugin to take full advantage of ALSA and its capabilities.
In most cases, dmix will be automatically configured for ALSA 1.0.9 RC2 and above. There is no need to adjust the default configuration for the basic user and it should work transparently with your system.
Test dmix
aplay -D plug:dmix some_sound.wav
If you hear something, your dmix is working (very likely in recent versions of ALSA). Try opening more shells and you will hear the sound of all at the same time. But, as explained above, you will need all apps to send sound to dmix like this one.
In case a particular application does not use dmix by default, or your application requires OSS emulation, some tweaking may be necessary. This HOWTO will cover most tweaks needed to get applications running properly with the plugin.
dmix Configuration for OSS Emulation
Now we are ready to create ~/.asoundrc, to enable the dmix plugin for OSS applications, and wrap our dsp devices and default pcm interfaces.
Test for OSS Emulation
First, we'll check that your OSS configuration is working properly:
Create ~/.asoundrc and enter this information:
File: ~/.asoundrc |
# ~/.asoundrc: pcm.dsp0 { type plug slave.pcm "hw:0,0" } # or: # pcm.dsp0 pcm.default # if "default" hasn't been redefined ctl.mixer0 { type hw card 0 } |
If you don't have it already:
# emerge mpg321
Next, test aoss with mpg321 in OSS mode:
# aoss mpg321 some.mp3
This should play the file, but not yet "dmix"ed.
Simple Configuration
File: ~/.asoundrc |
# ~/.asoundrc pcm.dsp0 { type plug slave.pcm "dmix" # <-- this line has been altered! } # mixer0 can stay unchanged, because it isn't used anyway, I guess ;) ctl.mixer0 { type hw card 0 } # I also had to add/alter the following, making ALSA use dmix by default pcm.!default { type plug slave.pcm "dmix" } |
Test this setup with mpg321 like example above. This should enable dmix'd OSS playback, but it will not work on cards like the M-Audio Audiophile or other Delta cards, that need a certain audio data format for playback on hw:0 (which dmix uses by default). A fix is below.
Advanced Configuration
This involves defining dmix parameters. If a card needs a certain format conversion we need to create a custom dmix device. Let's call it ossmix.
File: ~/.asoundrc |
pcm.ossmix { type dmix ipc_key 1024 # must be unique! ipc_perm 0660 # sound for everybody (at least in your group) slave { pcm "hw:0,0" # you cannot use a "plug" device here, darn. period_time 0 period_size 1024 # must be power of 2 buffer_size 8192 # dito. It #format "S32_LE" #periods 128 # dito. #rate 8000 # with rate 8000 you *will* hear, # if ossmix is used :) } } # bindings are cool. This says, that only the first # two channels are to be used by dmix, which is enough for # (most) oss apps and also lets multichannel chios work # much faster: bindings { 0 0 # from 0 => to 0 1 1 # from 1 => to 1 } pcm.dsp0 { type plug slave.pcm "ossmix" # use our new PCM here } # mixer0 like above ctl.mixer0 { type hw card 0 } |
It is important, that this "ossmix" PCM works with your card in ALSA mode. That is, the following should produce sound:
# alsaplayer -o alsa -d ossmix some.mp3
- Another complex example for nvidia nforce(2) boards (intel8x0) - while the above solution didn't work for me, the following does. (taken from forum.hardware.fr (thread in french language).
This probably works better on the nVidia chips because the codecs don't properly support 44k1 output; they work much more reliably at 48kHz.
File: ~/.asoundrc (nvidia nforce setup) |
pcm.nforce-hw { type hw card 0 } pcm.!default { type plug slave.pcm "nforce" } pcm.nforce { type dmix ipc_key 1234 ipc_perm 0660 slave { pcm "hw:0,0" period_time 0 period_size 1024 buffer_size 4096 #rate 44100 rate 48000 } } ctl.nforce-hw { type hw card 0 } |
Have a look at Hardware Related Configs below on this page for more configs. **
Credits
Software Related Configurations
Configuring aRts and KDE
aRts Approach
aRts is a framework for developing modular multimedia applications. The sound server, artsd, allows multiple applications to cooperatively process and output sound and music. aRts is designed to provide its filter and synthesis capabilities to other applications using the multimedia communication protocol (MCOP). aRts is also capable of modular realtime synthesis. It can create sounds & music (realtime midi synthesis) using small modules like oscillators for creating waveforms, various filters, mixers, faders, etc.
Redirect aRts to your dmix device for best performance. This can be done by overriding the device location to plug:dmix.
ALSA Approach
This is the preferred solution since there is no need for another layer below that.
Can be used with KDE 3.2.2 and above by redirecting aRts to your ALSA (dmix) device. Versions 3.2.1 and below require OSS emulation.
ESD (esound) Approach
The Enlightenment sound daemon, aka ESD, aka esound.
If you don't have such option in your control center, you have to recompile it with proper ./configure options. And of course you should have esd installed in your system (very often package is called esound).
Now sound in KDE is mixed with sound from alsa driven apps without need to use (almost always not working) artsdsp.
OSS Emulation Approach
This is only necessary for KDE versions 3.2.1 and below since those do not yet recognize ALSA. Using this in versions subsequent to that will cause degraded performance.
- Setup OSS Emulation as directed earlier in this article.
- In KDE Control Center, chose Open Sound System as your default sound server. If necessary, you can check Override Device Location and enter a /dev/dsp device corresponding to your configured sound card.
Credits
Zoltan (Note: Russian language post)
maHo
jbdubbs - Complete Rewrite
Configuring Gnome/eSound
Recent releases of esound support alsa plug in hw devices, so if your gnome apps, or some binary apps, could easily work with esound, and you don't care about latency, esound can play out to dmix, which works nicely.
Make sure that your esd uses alsa, and add -d default option to /etc/esd/esd.conf.
File: /etc/esd/esd.conf |
[esd] auto_spawn=1 spawn_options=-terminate -nobeeps -as 2 -d default spawn_wait_ms=100 |
If you notice that esd doesn't want to play through default device, or if you launch esd -d default, it segfaults, it means that you have esound<=0.2.32, which use obsolete alsa API. If it's true, install more recent, or compile latest esound with esound-alsa-pcm-newapi.patch
pulseaudio
Edit /etc/pulseaudio/defaults.pa, so that all lines containing module-alsa-sink also contain device=dmix (dmix, or whatever the mixing device in your .asoundrc is). Example config file:
File: /etc/pulseaudio/defaults.pa |
#!/usr/bin/pulseaudio -nF # # This file is part of pulseaudio. # # pulseaudio is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # pulseaudio is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with pulseaudio; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. # Load audio drivers statically #load-module module-alsa-sink sink device=dmix #load-module module-alsa-source device=plughw:1,0 #load-module module-oss device="/dev/dsp" sink_name=output source_name=input #load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input load-module module-null-sink #load-module module-pipe-sink # Load audio drivers automatically on access # ALSA add-autoload-sink output module-alsa-sink sink_name=output device=dmix add-autoload-source input module-alsa-source source_name=input # OSS add-autoload-sink output module-oss device="/dev/dsp" sink_name=output source_name=input add-autoload-source input module-oss device="/dev/dsp" source_name=input sink_name=output #add-autoload-sink output module-oss-mmap device="/dev/dsp" sink_name=output source_name=input #add-autoload-source input module-oss-mmap device="/dev/dsp" sink_name=output source_name=input # Load several protocols load-module module-esound-protocol-unix #load-module module-esound-protocol-tcp load-module module-native-protocol-unix #load-module module-simple-protocol-tcp #load-module module-cli-protocol-unix # Load the CLI module load-module module-cli # Make some devices default set-default-sink output set-default-source input .nofail # Load something to the sample cache load-sample x11-bell /usr/share/sounds/generic.wav #load-sample-dir-lazy /usr/share/sounds/*.wav # Load X11 bell module load-module module-x11-bell sample=x11-bell sink=output # Publish connection data in the X11 root window load-module module-x11-publish #load-module module-pipe-source #load-module module-pipe-sink |
jack
Alsa and oss applications can work with jack. The following will work with sound cards with hardware mixing capability (as exemple soundblaster live and audigy).
Alsa and jack
Edit ~/.asoundrc and add the following
File: ~/.asoundrc |
# convert alsa API over jack API # use it with # % aplay foo.wav # use this as default pcm.!default { type plug slave { pcm "jack" } } # pcm type jack pcm.jack { type jack playback_ports { 0 alsa_pcm:playback_1 1 alsa_pcm:playback_2 } capture_ports { 0 alsa_pcm:capture_1 1 alsa_pcm:capture_2 } } |
This will work with most alsa applications. Some applications will not work, as exemple beast with the alsa plugin. When starting an alsa application as usual, if jackd is started, the application will use by default the jack plugin and appear in the connection panel of qjackctl. Otherwise, it will generate an error message and start using alsa.
oss and jack
Edit ~/.asoundrc and add the text in the preceding text box (alsa and jack) as well as the following:
File: ~/.asoundrc |
# oss will use the alsa to jack API by default # test it with # % aoss mpg123 some.mp3 pcm.dsp pcm.!default |
It will work the same as the alsa to jack converter. Some applications will not work, as exemple beast.
Note
mplayer will crash with this setting when jackd is started. To avoid it, start mplayer with native jack driver:
# mplayer -ao jack movie.avi
MPlayer
If you enable alsa at compile time(done via USE variables) you can edit /etc/mplayer.conf in the line where you see ao=oss to:
File: /etc/mplayer.conf |
ao=alsa:device=dmix |
or simply start mplayer like this:
# mplayer -ao alsa:device=dmix movie.avi
you should run this command first
# mplayer -ao help
you will see all audio output parameter, this will more correct when you assign the -ao parameter.
The period_size and buffer_size in ~/.asoundrc should be set to
File: ~/.asoundrc |
... pcm.dmixer { type dmix ipc_key 1024 slave { pcm "hw:0,0" period_time 0 period_size 1024 <===== here buffer_size 8192 <===== and here periods 128 rate 44100 } bindings { 0 0 1 1 } } ... |
it's kinda magic numbers to allow mplayer work properly
Credits
Redeeman
00420
00420
Zoltan (Note: Russian language forum.)
XMMS
XMMS has been removed from Portage because it is unmaintained upstream - the closest replacement is probably audacious.
Options -> Preferences -> Audio
- Select Alsa Plugin
- Output Plugins Preferences
- Audio Device: "dmixer" (per example conf above) which is the same as "ossmix". If dmixer doesn't work with your version of the ALSA output plugin, try to specify plug:dmixer as the output device. If dmixer doesn't work, use dmix.
- Use software volume control
- Advanced Settings (these settings may be for a particular sound card)
- buffer time: 750ms
- period time: 75ms
- uncheck mmap mode, if present
GAIM
From the GAIM FAQ:
If you choose "Automatic", you can create a file, either /etc/libao.conf or ~/.libao, and put one of the following lines in it:default_driver=alsa default_driver=ossOther drivers, like alsa09, arts, esd, irix, macosx, nas, and sun might also be supported, depending on your platform and how libao was compiled. See also man 5 libao.conf.
Tools->Preferences->Sounds->Sound Command = aplay -D plug:dmix %s
If it doesn't work, try:
aplay %s
Alternatively, if you have `sox` installed, you may try
sox %s -t alsa -s default
as the "Sound Command".
Firefox, Mozilla, RealPlayer, Skype & Co
To make its plugins (especially libflashplayer.so) use dmix through aoss:
- Move the original firefox symlink
# rm /usr/bin/firefox # ln -s /usr/libexec/mozilla-launcher /usr/libexec/firefox
- Create a new executable script:
File: /usr/bin/firefox |
#!/bin/sh # This line needs to be maintained or Thunderbird (and # certain other apps) will not launch links when they # are clicked on export MOZILLA_LAUNCHER=firefox # not correct: #aoss /usr/libexec/firefox $* # # correct: aoss /usr/libexec/firefox "$@" |
- From my experience with Firefox 1.5.x (source, not bin), you don't need to do that stuff above, just edit last line of /usr/bin/firefox - insert aoss after exec
# exec aoss /usr/libexec/mozilla-launcher "$@"
- Alternatively to all above, you can simply edit /usr/libexec/mozilla-launcher to care take of mozilla, firefox, and seamonkey all at once. Around line 400
File: /usr/libexec/mozilla-launcher |
else #"$mozbin" "$@" & #old line aoss "$mozbin" "$@" & #new dmixed line fi |
In a similar fashion it is also possible to "dmix" other oss apps like:
- gflashplayer
- realplayer
- skype (note: it doesn't fully work though. See here)
- mozilla (suite)
NOTE: Skype 1.3 uses ALSA natively, you don't need dmix anymore unless you have some very specific requirements.
This way one can have, say, several tabs with flash all sounding together and receive an incoming call or system sounds.
For example:
# rm /usr/bin/skype # touch /usr/bin/skype # chmod +x /usr/bin/skype
and its contents:
File: /usr/bin/skype |
#!/bin/sh aoss /opt/skype/skype "$@" |
Even more - if You do this wisely, there is no need to edit any menus or preferences (like "default browser").
LICQ
Set to use aplay in preferences.
SDL
Set environment with:
File: /etc/env.d/99sdl |
SDL_AUDIODRIVER=alsa AUDIODEV=default |
ATTENTION: setting AUDIODEV can cause a non working Mozilla! :-/
GStreamer
Emerge gnome-media, then run gstreamer-properties and set your Audio-Sink. Output is Custom. Pipeline is alsasink -device=dmix (or device=ossmixer, if that's what you used in your asoundrc, or simply -device=dmix if you didn't edit it)
(Hint: rhythmbox uses gstreamer)
GStreamer in many ways handles ALSA badly. For example, with a dmix channel configured to output 48khz, GStreamer will natively play audio through this device at 48khz, but using (commonly) 44.1khz data. Without resampling, the audio will sound highly distorted.
The solution is to create a custom output pipeline incorporating explicit resampling to the desired format in gstreamer-properties:
audioconvert ! audioresample ! audio/x-raw-int, channels=2,depth=16,rate=48000 ! alsasink -device=channel0
Note that this solution is quite CPU intensive compared to functionaly similar software, such as the crossfade plugin.
MPD
Change mixer_device from default to dmix in /etc/mpd.conf.
mixer_type "alsa" mixer_device "dmix" mixer_control "PCM"
Then change ao_driver_options from dev=hw:0,0 to dev=dmixer in /etc/mpd.conf.
ao_driver_options "dev=dmixer" #or ao_driver_options "dev=plug:dmix"
Note: I had to use
ao_driver_options "dev=pcm.ossmix"
This is because I am using the "alternate method" (placed in /etc/asound.conf though).
If you still have problems getting it to work properly, try setting mpd to run under your user account by changing user in /etc/mpd.conf.
Xine Engine
Add this line to your xine config file:
File: ~/.xine/config |
audio.driver:alsa |
Be sure to remove or comment out all other "audio.driver:" lines in the file. Alternatively if you have xine-ui, run xine, right click the main windows and select Settings->Setup->audio
Set "audio driver to use" to alsa.
Amarok
aRts engine is deprecated and removed from newer versions of Amarok, as is GStreamer. Xine is the default output engine now.
Only necessary If arts is not working well with dmix. There are two possible solutions. Both require to change the engine used in amarok.
Settings->Configure amaroK...->Engine
1. solution: xine engine:
Set "Sound System" to "Xine Engine".
Configure xine to use alsa as shown above.
2. solution: gstreamer engine:
Set "Sound System" to "GStreamer Engine"
Set "Output Plugin" to "alsasink"
tick device and type in "dmix" if you have defined dmix before in your .asoundrc
Hardware Configurations - ~/.asoundrc Files
First look at http://www.alsa-project.org/alsa-doc and choose your sound card Card Specific Scripts can be found at The Alsa Project.
For local settings edit ~/.asoundrc, for global settings go to /etc/asound.conf
Simple asoundrc for intel8x0
File: ~/.asoundrc |
pcm.intel8x0 { type hw card 0 } ctl.intel8x0 { type hw card 0 } |
intel8x0 audio card integrated on nforce2 motherboards
File: ~/.asoundrc |
# Set default sound card # Useful so that all settings can be changed to a different card here. pcm.snd_card { type hw card 0 device 0 } # Allow mixing of multiple output streams to this device pcm.output { type dmix ipc_key 1024 ipc_perm 0660 # Sound for everybody in your group! slave.pcm "snd_card" slave { # This stuff provides some fixes for latency issues. # buffer_size should be set for your audio chipset. period_time 0 period_size 1024 buffer_size 8192 } bindings { 0 0 1 1 } } # Allow reading from the default device. # Also known as record or capture. pcm.input { type dsnoop ipc_key 2048 slave.pcm "snd_card" ## Possible artsd full duplex fix: # slave { # period_time 0 # period_size 1024 # buffer_size 8192 # } bindings { 0 0 1 1 } } # This is what we want as our default device # a fully duplex (read/write) audio device. pcm.duplex { type asym playback.pcm "output" capture.pcm "input" } ################### # CONVERSION PLUG # ################### # Setting the default pcm device allows the conversion # rate to be selected on the fly. # duplex mode allows any alsa enabled app to read/write # to the dmix plug (Fixes a problem with wine). pcm.!default { type plug slave.pcm "duplex" } # Apparently this is wrong (breaks mplayer for me opening the device) #ctl.!default { # type plug # slave.pcm "snd_card" #} ######## # AOSS # ######## # OSS dsp0 device (OSS needs only output support, duplex will break some stuff) pcm.dsp0 { type plug slave.pcm "output" } # OSS control for dsp0 (needed?...this might not be useful) ctl.dsp0 { type plug slave.pcm "snd_card" } #### #### As of November 2005 with the following packages: #### >=mozilla-firefox-1.0.7-r2, netscape-flash-7.0.25, #### alsa-oss-1.0.8-r1 and alsa-oss-1.0.10_rc3 #### #### I have been experiencing crashes related to firefox when rendering flash. #### I used "aoss firefox" to start the browser. #### Commenting out the below ctl.mixer0 and using the above ctl.dsp0 allows #### firefox to render flash without crashing (and yes the aoss mixing works) #### However aoss Skype does not work properly without mixer0 under some configurations. #### # OSS control for dsp0 (default old OSS is mixer0) #ctl.mixer0 { # type plug # slave.pcm "snd_card" #} |
Credits
via82cxxx onboard/ICE1712 chip
If config does not work (well) with an Audiophile card (ICE1712 chip) or a VIA VT82xx (snd-via82xx). The error is:
$ alsaplayer -d ossmix error on set_format SND_PCM_FORMAT_S16_LE Unavailable hw params: ACCESS: RW_INTERLEAVED FORMAT: S32_LE SUBFORMAT: ALL SAMPLE_BITS: ALL FRAME_BITS: ALL CHANNELS: 2 RATE: 48000 PERIOD_TIME: (21333 21334) PERIOD_SIZE: 1024 PERIOD_BYTES: ALL PERIODS: (6 7) BUFFER_TIME: (136520 136521) BUFFER_SIZE: 6553 <<<<====take a look here!! BUFFER_BYTES: ALL TICK_TIME: ALL
Jaroslav Kysela did know the reason: The max buffer size of the Delta card is "6553" as marked above. So we need to specify a buffer size in our dmix definition that is: a) a power of two and b) less than 6553. Here's the fixed OSS-dmix .asoundrc for a ICE1712 and VT82xx card:
File: ~/.asoundrc |
# ~/.asoundrc # our ICE1712 dmix: pcm.ossmix { type dmix ipc_key 1024 slave { pcm "hw:0,0" period_time 0 period_size 1024 buffer_size 4096 # buffer size < 6653, but pow(x, 2) rate 44100 # we want to play CDs only } bindings { 0 0 1 1 } } # Everything shall be dmixed, so redefine "default": pcm.!default { type plug slave.pcm "ossmix" } # OSS via aoss should d(mix)stroyed: pcm.dsp0 { type plug slave.pcm "ossmix" } ctl.mixer0 { type hw card 0 } |
Credits
http://alsa.opensrc.org/index.php?page=DmixPlugin
cmedia 8738 and Analog Devices AD1980
File: /etc/modules.d/alsa |
... |
File: ~/.asoundrc |
pcm.dmixer { type dmix ipc_key 1024 ipc_key_add_uid false ipc_perm 0666 # mixing for all users # for users only in your group use 0660 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 } |
Credits
VIA Envy24HT (ice1724) chip
Note: If you wish to use the S/PDIF output, change the hardware line to 0,1 (pcm "hw:0,1") and device to 1 (device 1). If you do not, you will be using the analog outputs.
File: ~/.asoundrc |
pcm.!default { type plug slave.pcm "dmixer" } pcm.dmixer { type dmix ipc_key 1024 slave { pcm "hw:0,0" format S32_LE period_time 0 period_size 1024 # increased buffer_size because in my system 1024 cause bad # audio performance (for totem media player and mplayer) buffer_size 8192 rate 44100 } bindings { 0 0 1 1 } } ctl.dmixer { type hw card 0 device 0 } |
Another Configuration.
This configuration has the following options:
- 1- upmixed stereo to 5.1 sound (stereo copy).
- 2- Optical output (Toslink).
- 3- normal analog speaker setup (fx used when multichannel sounds are played on analog outputs, you dont want the upmix to be used then ;) ) -note only analog multichannel!.
The difference in this one (look down) from the one above, in the way that you enable them, is that here, it is done by typing in manually the "profile name" in you audio/movie player (profiles; "default","spdif" & "analog").
File: ~/.asoundrc |
######################################################### #This is the standard setting (see: "!default") #This profile, the default loaded, upmixes stereo sound to 5.1. pcm.!default { type plug slave.pcm "surround51" slave.channels 6 route_policy duplicate } ######################################################## #This is the normal spdif output profile (optical, toslink). pcm.!spdif { type plug slave.pcm "hw:0,1" } ####################################################### #This is what one could call the "factory default setting", in other words, it only plays the actual channels. so if you fx want to watch a 5.1 movie, on the analog output, this is the option you want. pcm.analog { type plug slave analog_slave; } pcm_slave.analog_slave { pcm surround51; format S32_LE; } |
Credits
01mf02, Alrua, and ALSA-project.org Guide
individual customizations of ".asoundrc"
Troubleshooting
Creative X-Fi soundcards
These cards are supposed to have a closed driver made by Creative released by the second quarter of 2007.
Alsa record sound
Sorry if this is incomplete. I tried many many many ways of recording sound and using the microphone (I want to use skype!). After trying all possible configurations of my sound card, a night without sleep, I finally made it after reading the krec manual. They give the clue: start the sound system in full duplex mode. Hope it helps somebody.
Recording from the microphone: in alsamixer, you need to press F4 for the Capture view, then raise the microphone level appropriately. The default view in alsamixer does not show the microphone capture control.
Alsa + dmix + microphone
- Q: I can play a couple sounds at the same time but I can't record any sounds using arecord:
$ arecord -f cd -d 3 -t wav -N test.wav ALSA lib pcm_dmix.c:759:(snd_pcm_dmix_open) The dmix plugin supports only playback stream arecord: main:502: audio open error: Invalid argument
But when I remove my ~/.asoundrc I can record.
How can I fix this ?
- A: Use dsnoop, scan the page for a ~/.asoundrc with it
XMMS in KDE
- Q. KDE sounds and media players work, but XMMS says device is busy.
- A. This means that arts output isn't redirected to dmix, look at the arts section.
Errors inserting modules
If you have used alsa-driver in the past, switch to in-kernel drivers and get the following errors whilst running the alsasound initscript:
* Loading: snd-pcm-oss ... WARNING: Error inserting snd_mixer_oss (/lib/modules/2.6.12-gentoo-r6/kernel/sound/core/oss/snd-mixer-oss.ko): Unknown symbol in module, or unknown parameter (see dmesg) FATAL: Error inserting snd_pcm_oss (/lib/modules/2.6.12-gentoo-r6/kernel/sound/core/oss/snd-pcm-oss.ko): Unknown symbol in module, or unknown parameter (see dmesg) [ !! ] * Loading: snd-mixer-oss ... FATAL: Error inserting snd_mixer_oss (/lib/modules/2.6.12-gentoo-r6/kernel/sound/core/oss/snd-mixer-oss.ko): Unknown symbol in module, or unknown parameter (see dmesg)
Then you may well still have modules from alsa-driver left over. When you unmerge alsa-driver, the modules don't get deleted. When you then switch to in-kernel drivers (as modules), running "modprobe" will give you a hybrid of alsa-driver and in-kernel modules, which just doesn't work.
The solution is rm -rf /lib/modules/KERNELVER/alsa-driver after you unmerge alsa-driver. After that run depmod -a to generate new kernel module dependencies files.
Another good idea is to check if you remembered to install the new kernel, if so, is grub/lilo loading it? did you remember to mount /boot when installing the kernel?
Another Solution
You could also try muting the channels "Headphone Jack Sense" and "Line Jack Sense" as per this post
Problems with 32-bit dmix on AMD64
If you are trying to use dmix on an AMD64, ensure that 32 bits ALSA libs are new enough. It seems that there were changes to dmix in recent ALSA versions, which makes it impossible for 32-bit and 64-bit applications to play sounds together, if older 32-bit ALSA libraries are used.
Currently, the emul-linux-x86-soundlibs-2.5, which contains ALSA libs version 1.0.14_rc1, is masked, so you should unmask it in /etc/portage/package.keywords.
~app-emulation/emul-linux-x86-soundlibs-2.5 ~amd64 ~app-emulation/emul-linux-x86-baselibs-2.5.5 ~amd64
Feedback
Concerns or Compliments? please use our Discussion section.