Search:  
Gentoo Wiki

ALSA/Omitted_Items

Contents

Installation

Notes

Notes (AMD64) (magik)

You may find that you need to define your default device, otherwise you will always be redirecting your audio to dmix manually. To do so create a file /etc/asound.conf (this will make changes system wide, you may also use ~/.asoundrc for user level settings, ~/.asoundrc does take precedence over /etc/asound.conf) and include the following.


 pcm.!default {
        type hw
        card 0
        }

        ctl.!default {
        type hw
        card 0
        }

This will assign card 0 to "default", most of your alsa applications should now be able to pick up your alsa card without extra configuration.
If you have an ~/.asoundrc in your home direcotry be sure it doesnt attempt to redefine your default card

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.

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.

Fixme: newer versions use /var/lib/alsa/asound.state


This will show you what PID's are using your soundcard in case you need to kill a PID that is interfering:

# fuser -v /dev/snd/*

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.

Try also muting "Jack" outputs (in alsamixer) as it might, in some configurations, mute the main sound output.

Testing Your Installation

$ emerge media-sound/mpg321
$ 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.

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.

Warning: (I see this error all the time): it does not mean you can use multiple apps at the same time straight away! Even if some app uses ALSA, first you need to make sure it sends its sound to dmix and that does not happen by default. Instead your apps will gain exclusive access to the default card. To change that, we will need to create a .asoundrc in your home folder that will send all the sound to the mixer and then back to the card.

May 2008: The warning is not true for alsa device. If I play sound with alsaplayer and look at a movie with mplayer, then both sounds are mixed. Without configuration, without sound daemon. This does not work with oss apps: mplayer -ao oss does not play any sound, if an other app is using sound. So I use the USE-Flag "alsa -oss" and enjoy mixing without a sound daemon.

Testing 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.

OSS Emulation & dmix

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

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

Frank Barknecht

spdif

File: ~/.asoundrc
pcm.!default {
type plug
slave {
rate 48000
pcm "spdif"
}
}

asym

If you want your microphone to be split à la dmix, you'll need an asym setup utilizing dmix and dsnoop:

File: /etc/asound.conf
pcm.dmixed {
    ipc_key 1025
    type dmix
    slave.pcm "hw:0,0"
}

#one called "dsnooped" for capturing 
pcm.dsnooped {
    ipc_key 1027
    type dsnoop
    slave.pcm "hw:0,0"
}

#and this is the real magic
pcm.asymed {
    type asym
    playback.pcm "dmixed"
    capture.pcm "dsnooped"
}

#a quick plug plugin for above device to do the converting magic
pcm.!default {
    type plug
    slave.pcm "asymed"
}

#a ctl device to keep xmms happy
ctl.asymed {
    type hw
    card 0
}

#for aoss:
pcm.dsp0 {
    type plug
    slave.pcm "asymed"
}

ctl.mixer0 {
    type hw
    card 0
}
Retrieved from "http://www.gentoo-wiki.info/ALSA/Omitted_Items"

Last modified: Tue, 26 Aug 2008 20:57:00 +0000 Hits: 4,424