ALSA

From Gentoo Wiki
Revision as of 13:20, 21 July 2014 by Fturco (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
External resources

This article describes the setup of a sound card with ALSA (Advanced Linux Sound Architecture).

Installation

Hardware detection

To choose the right driver, first detect the used audio controller. You can use lspci for this task:

root # lspci | grep -i audio

With the controller name you can find the needed driver in the ALSA SoundCard Matrix.

Kernel

You need to activate the following kernel options:

Kernel configuration

Device Drivers --->
    Sound --->
        <*> Sound card Support
            <*> Advanced Linux Sound Architecture --->
                [*]   PCI sound devices  --->

                      Select the driver for your audio controller, e.g.:
                      <*>   Intel HD Audio  ---> (snd-hda-intel)
                            Select a codec or enable all and let the generic parse choose the right one:
                            [*] Build Realtek HD-audio codec support
                            [*] ...
                            [*] Build Silicon Labs 3054 HD-modem codec support
                            [*] Enable generic HD-audio codec parser

The lsmod command can sometimes be helpful.

Software

Portage knows the global USE flag alsa for enabling support for ALSA in other packages. Enabling this USE flag will pull in media-libs/alsa-lib automatically (default in x86 and amd64 desktop profiles):

root # euse -E alsa

The euse command is part of app-portage/gentoolkit.

The USE flags of media-libs/alsa-lib are:

→ Information about USE flags
USE flag Default Recommended Description
alisp No Enable support for ALISP (ALSA LISP) interpreter for advanced features.
debug No Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see http://www.gentoo.org/proj/en/qa/backtraces.xml
doc No Adds extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
python Yes Adds optional support/bindings for the Python language

After setting this you want to update your system so the changes take effect:

root # emerge --ask --changed-use --deep @world

You also want to install media-sound/alsa-utils, if it isn't already pulled in:

root # emerge --ask alsa-utils

Configuration

Permissions

If you have the USE flag acl enabled globally and are using ConsoleKit (i.e you're using a desktop profile) permissions to sound cards will be handled automatically. You can check the permissions using getfacl:

user $ getfacl /dev/snd/controlC0 | grep larry
user:larry:rw-

A broader solution is to add the user you want to be able to access the sound card to the audio group:

root # gpasswd -a larry audio
Warning
You should logout and login again to make alsamixer work, otherwise running the alsamixer command will give you the error "cannot open mixer: No such file or directory"

Service

You can now start ALSA:

root # /etc/init.d/alsasound start

To start ALSA at boot time, add it your boot runlevel:

root # rc-update add alsasound boot

Mixer

If you can't hear anything, the output channels may be muted. Unmute the channels with your desktop environment's mixer or with alsamixer by selecting the appropriate channels and hitting the m key to mute or unmute:

user $ alsamixer

Test setup

If everything above is perfect, you should now be able to test your sound card and your speakers. We will use the speaker-test command line tool from package media-sound/alsa-utils (this should already be installed as per our previous recommendation).

user $ speaker-test -t wav -c 2

If you have a 5.1 system:

user $ speaker-test -t wav -c 6 -D surround51

Press Ctrl+C to interrupt the test.

Advanced Configuration

~/.asoundrc

This file can be optionally used so that on a per-user basis, ALSA defaults can be overridden. You might have special hardware, or card 0 and device 0 (the defaults) are not going to work for you.

One of the simplest changes is card and device. This is the case for me with an HDMI coming from an Nvidia card connected to an onboard Realtek ALC88* audio device.

File~/.asoundrc

defaults.pcm.!card 1
defaults.pcm.!device 7

You can find out what devices and cards you have with:

user $ aplay -L

Note: If you can't seem to find the card number assigned to the device that is the sound card you intend to use, don't panic - the card number is internally a name, so if your card is listed like this...

user $ aplay -L
front:CARD=Generic,DEV=0
HD-Audio Generic, ALC282 Analog
Front speakers

... then it means your .asoundrc should be like this!

File~/.asoundrc

defaults.pcm.!card Generic
defaults.pcm.!device 0

S/PDIF or HDMI .asoundrc

Background

Most sound cards allow passing through audio to an external consumer receiver or DAC using S/PDIF digital coaxial or optical cables. Doing so, preserves sound quality and compressed Dolby/DTS encoded material. Uncompressed Dolby/DTS or Bluray material, require HDMI connections. The more common mono or analog stereo cables cannot carry Dolby/DTS signals.

You may find your S/PDIF or HDMI connection with default installed ALSA works with no .asoundrc file alterations. While only some applications, such as the Web browser Flash plugin will fail playing sound. As such, the below .asoundrc is usually required for most S/PDIF and HDMI connections. Also, any media applications open will need to be restarted for the .asoundrc files to take affect. (i.e. Web browser with Flash plugin)

Preference for Connections Versus Media Types

Basic Analog

Basic Analog (ie. RCA) Connections - Basic user. Quality depends on sound card DAC. Look for a sound card with a high SNR db level.

S/PDIF

S/PDIF provides good quality audio for music, videos and DVD quality movies containing Dobly/DTS compressed signals. Most sound cards and motherboards, these days, provide some sort of S/PDIF port. Nowadays, it's more common to see S/PDIF Toslink ports on motherboards. Many computer games provide compressed Dolby/DTS signals.

S/PDIF Digital Coaxial

S/PDIF Digital Coaxial may have problems with voltage cross talk, but is more common as it only requires a simple mini jack or RCA coaxial cable.

S/PDIF Optical (Toslink)

S/PDIF Optical (Toslink) Cable completely avoids possible electrical cross talk or interference amongst cables as it's fiber optic, but is susceptible to signal degradation if the cable is bent too much. You'll find audiophiles tend to favor Optical/Toslink.

HDMI

HDMI can carry compressed Dolby/DTS and uncompressed (i.e. Blu-ray) Dolby/DTS signals. The audio market has favored this connection, but still preserves S/PDIF connections. One concern being, HDMI cables are copper wire, still susceptible to electrical cross talk or interference, similar to S/PDIF Digital Coaxial connections. There are HDMI Optical cables, but too expensive for the consumer market. If audiophiles have S/PDIF Optical ports, they will use the S/PDIF connections for other media such as music and DVD movies, while only using HDMI when needed for processing uncompressed Dolby/DTS encoded material such as Blu-ray media. Again, the basic user will likely just use HDMI, avoiding the fuss of changing configuration files around.


Configuration

Find your digital output device.

root # aplay --list-devices

Adjust the below file to use your card/device number.

File{$HOME}/.asoundrc

pcm.!spdif {
     type hw
     card 0
     device 1
}

pcm.!default {
     type plug
     slave {
           pcm "spdif"
     }
}

# Share a single card with multiple applications 
#pcm.!default {
#    type plug
#    slave.pcm "dmix:CARD=0,DEVICE=1,RATE=48000"
#}
Note
The above will not allow sound to be played from more than one sound application, or more than two sounds played at once through one sound card. In order to perform this task, the sounds are remixed with a slight degradation with sound quality. Most people listening to music, prefer not to allow this due to interrruptions and decreased sound quality. However, for those that desire this, the above commented section of code will achieve this.
Note
When playing sound files using aplay, the beginning of the playback will be clipped because the digital S/PDIF or HDMI connection is not held open and needs to be started each time a sound file is played. Notice Microsoft Windows both, holds open the receiver or DAC and remixes media on playback.

A/52, AC3, Dolby, DTS

Soundcards providing S/PDIF output can pass through lossy compressed multichannel audio. To my hears, the high bitrate compressed media has little loss in comparison to two channel CD or DVD audio. I surmise this is because we now have multichannels feeding multiple speakers. Hence, the more hardware, the equivelant or better sounding?

If a soundcard states it has S/PDIF, it will likely pass through Dolby or DTS even though it does not specifically show a Dolby or DTS icon or listed within it's features. This is because, when they do list Dolby or DTS, it's because they're providing software for upmixing, or providing the decoded signal through analog output.

HDMI will pass through uncompressed multichannel audio, but a video feed is interleaved as required by the HDMI specification. In comparison to DVD video and audio, I see and hear very little quality difference, if any! About the only thing I noticed between S/PDIF Toslink and HDMI, HDMI seems to amplify the signal by a few watts or 5db. (I conclude this is because of the higher bitrate?)

As such, S/PDIF is still quite popular, even today.

Note
A S/PDIF or HDMI connection is required for passing through advanced encodings. Analog connections (ie RCA and minijacks) do not support any advanced encodings.

Decoding or encoding to Dolby or DTS requires a license. If you have already purchased a sound card with this multichannel support, then you likely already have a license. See this article for more informations.

ALSA media-plugins/alsa-plugins package requires recompilation to include the ffmpeg USE Flag with the A/52 (pcm.a52encode) plugin.

root # USE="ffmpeg" emerge -q media-plugins/alsa-plugins

Decode or Playback

Recompile mplayer or your other favorite software player to include the ALSA libraries.

root # USE="a52 dts" emerge -q media-video/mplayer

Add the multichannel codecs to mplayer.conf, so media attempting to be played has first been provided the option of hardware passthrough rather then down mixing.

File/etc/mplayer/mplayer.conf

ac=hwac3,hwdts,hwmpa,spdifac3,spdifeac3,spdifaac,spdifdts,spdifmpa,spdifthd,dts,ffaac,

You should now be able to pass through (and enjoy) almost any Dolby or DTS signal through S/PDIF to your receiver.

Encode to A/52

Upmix Two Channel Audio to a A/52 Multi-channel Audio Stream

To similate A/52 encoded audio from normal one or two channel audio streams or files, ALSA can upmix using its A/52 plugin. (A/52 is also known as AC-3 or Dolby Digital encoding.)

A/52 upmixing preferred when playing computer games or watching video without Dolby/DTS encoded material, such as older Movies. Many sound card manufacturers provide their applications with a feature for software upmixing to Dolby Digital, and recommend enabling this upmixing when listening to such media, except for Music.

Upmixing to A/52 is frowned upon by audiophiles. As such, it's user preference if you want to upmix all your sounds to A/52 before sending the stream to your consumer stereo receiver or DAC. Matter of fact, audiophiles prefer simple stereo, and further state stereo is still better quality than Dolby/DTS material or other audio encoded with gimmicks. Also, your consumer stereo or DAC likely possibly includes a feature for upmixing audio into five channel audio.

File{$HOME/.asoundrc}

pcm.!default {
    type plug:surroundaudio
}

ctl.!default {
    type plug:surroundaudio
}

pcm.a52encode {
    type a52
    format S16_LE
    channels 6
    rate 48000
    bitrate 448
}

pcm.surroundaudio a52encode

ctl.surroundaudio {
    type hw
    card 0
    device 1
}
user $ speaker-test -Dsurroundaudio -c 6
Encode PCM 5.1 24 Bit Audio into a A/52 16 Bit Audio Stream (For Streaming via S/PDIF)

Also known as, encoding PCM 5.1 audio stream into a compressed Dolby Digital stream for playing over S/PDIF. No real need to use this if you're using HDMI, as HDMI can handle the bandwith of a PCM 5.1 audio stream. S/PDIF Toslink has also supposedly been upgrade to do so also, but most hardware has yet to be upgraded to the new specifications, and some doubt it will ever happen. (Personally, I think HDMI is evil and only gives me problems, with little benefit.)

For some reason, the previous .asoundrc section previously mentioned doesn't work with PCM 5.1 streams. Another issue I run into with 24 bit PCM 5.1 audio streams, they require downmixing from S24_LE to S16_LE bit format. Reason being, 24 bit is a common format for most media, however receivers can sometimes only decode 16 or 32 bit audio. Also, the S/PDIF can only handle 16 bit audio when encoding to multi-channel formats such as A/52, for the time being until S/PDIF TosLink hardware specifications are upgraded.

The following .asoundrc excerpt will encode a PCM 5.1 24 bit stream into a 16 bit A/52 stream, for streaming over S/PDIF.

File{$HOME/.asoundrc}

#####
# Description: This will make it possible to use a52 with PulseAudio out of 
#          the box. It may be useful for other use cases. Just include 
#          this in your ~/.asoundrc .

pcm.a52 {
    @args [ CARD ]
    @args.CARD {
               type string
               default 0
    }
    type plug
    slave {
           pcm {
               type a52
               card $CARD
               bitrate 640 # default 448
           }
    # Convert to S16 bit format, per SPDIF spec
    format S16_LE # Required for current S/PDIF spec
    }
}
user $ aplay -D pcm.a52 /home/me/Music/Led_Zeppelin/Celegration_Day/PCM51-24bit/*.wav

JACK Audio Connection Kit

Jack provides an additional layer, to the already low latency ALSA drivers and applications, and further it guarantees a constant sound latency and synchronous operation of all its clients. Jack can only use one sound card at a time, and will provide separated outputs and inputs for each audio channel of the sound card. Jack further provides the ability to view, manipulate or pipe audio streams, both hardware and software streams, in a similar manner we use cables to interface different audio equipments. As example, JAMin can intercept an audio stream before exporting the stream to another audio application and/or through analog or S/PDIF outputs. The Jack user owned daemon, is usually started using qjackctl. The qjackctl utility provides many other functions including audio stream connections.

What Jack does not do, is handle A/52 encoded (ie. AC-3 or Dolby/DTS) material on input; it is just a sound server that deal with separated channels of audio streams. And it has the capability to connect simultaneously and synchronously any output stream on any input, and any input to any output stream, that on any hardware and software audio component, and with a constant latency. This make JACK an outstanding tool for audio producion and creation. The ac3jack tool can be used for encoding multiple separated audio channels to AC-3 streams.

When playing an A/52 encoded media, the player will request as many outputs from JACK than audio channels in the media. This will fail if your sound card doesn't have the requested amount of audio outputs, but will be fine otherwise. As example, you can use smplayer as usual, and configure it to output a 5.1 stream on a 7.1 output configuration, or a 7.1 stream on a 2 channels stereo output.

What I suggest, configure your kernel and ALSA according to Jack installation instructions for providing low latency audio. Since ALSA is said to be already very efficient and low latency, providing very good quality playback with no additional mixing when stated within its .asoundrc file, unlike MS Windows, Jack probably isn't needed for most. The main audience of JACK is audio producers and musicians (in studio, live performances, dj, ...). (The ac3jack package is currently hosted by the pro-audio overlay available with layman.)

It is possible to interconnect JACK and ALSA. At that time of writing, the best solution is via the snd-loopback module and zita-*2* bridge. For that, see Using an ALSA Loopback device and zita-ajbridge on the ProAudio gentoo overlay wiki.

Using zita-ajbridge, it is also possible to add additional real sound cards into JACK. (Example needed)

If you want to try JACK, you must know one thing: if you are happy with pulseaudio, you don't need to setup a realtime kernel for JACK. You will need rt operations only if you want to make a Digital Audio Workstation (DAW) with your computer, which necessitate something pulseaudio is not able to archive: constant sound latencies as low or lower than 20 msec (pulseaudio is not able to provide constant sound latency at all), and synchronous operations. But if you want to make a DAW, JACK is definitely the way to go, and you will never look back.

Hopefully this small brief section about Jack will give some quick insight about Jack's features, while reserving the details of Jack to a Wiki page specifically focused on Jack.

In the maintaime, you can take a look at the Pro-Audio Gentoo Overlay Wiki.

Tips

Try one of the many configuration options in PaulBredbury's asoundrc file.

Test Mic Recording

If needed, select your audio device if no default one is provided and add the "--device=hw:0,0" to your incantation of arecord, substituting your CardNumber,DeviceNumber.

The following will list possible devices.

user $ arecord --list-devices
Note
You may also need to unmute the Line or Microphone channel. Go into alsamixer and first select your soundcard (i.e. F6), then press F4 to show the Capture Channels, "left/right cursor keys" to select the "Mic" channel and press Space to toggle CAPTURE the channel.

The following will record indefinitely until CTRL + C is depressed and provide a default 8000 Hz mono quality recording.

user $ arecord /tmp/test.wav

The following will provide will record for two seconds (--duration=2) using DAT 48000 Hz quality (--format=dat) and display the curses vumeter in stereo (--vumeter=stereo) and save to /tmp/test.wav.

user $ arecord --channels=1 --duration=2 --format=dat --vumeter=stereo /tmp/test.wav

Or optionally,

File~/.bashrc

alias arecord-mic-3s="arecord --channels=1 --device=plughw:0,0 --duration=3 --format=S32_LE --rate 48000 --vumeter=mono /tmp/test.wav && aplay /tmp/test.wav"

Notice, arecord cannot record in S24_LE, and is only capable of recording using S16_LE or S32_LE formats. For the human ear, any audio resolutions greater than 24 bit (S24_LE) or 48000Hz are said to be indistinguishable to differentiate using the human ear. Reference Sampling (signal processing) Wikipedia, Audio sampling. Users should also specify channels=1, as all recordings are performed in mono/monaural when typically using the Microphone Input unless recordings are using the stereo Line Input. In order to further encourage arecord to record monaural or only one channel, using the device=plughw:0,0 is further specified. (Alleviates a common problem, microphone/mic playback only occurs on the right or left channels.)

Use mplayer or aplay to playback the saved file. I usually record in "dat" or atleast "cd" quality formats. DAT is best when benchmarking..

Troubleshooting

Soundcard only available for one application

Sometimes one app essentially takes over all sound devices. This might even be for performance reasons.

Force the use of dmix instead of direct audio output (which is what most things use by default, such as Flash, which really means your browser, and Wine).

If your device is card 1 and device 7 (which is the case for Nvidia HDMI for me):

File~/.asoundrc

pcm.dmixed {
        type asym
        playback.pcm {
                type dmix
                ipc_key 5678293
                ipc_perm 0660
                ipc_gid audio

                slave {
                        channels 2 # make 6 or 5.1 channel
                        pcm {
                                format S16_LE # S32_LE
                                rate 48000 # can also be 44100
                                type hw
                                card 1 # your card
                                device 7 # your device
                                subdevice 0 #important?
                        }

                        period_size 1024
                        buffer_size 8192
                }

                bindings {
                        0 0
                        1 1
# Uncomment below if using 6 channel
#                       2 2
#                       3 3
#                       4 4
#                       5 5
                }
        }
        capture.pcm "hw:0"
}

pcm.!default {
        type plug
        slave.pcm "dmixed"
}

Use of ~/.asoundrc is immediate and as long as you are not forcing the use of specific devices in any applications, they either will require a restart or will begin working immediately. One of the best tests is to run Chrome, go to YouTube, open a terminal, run mplayer with an audio or video file and see that you do not get an error about audio (such an error might be 'Device or resource busy').

Missing dialogue (sounds) with 4.0 speakers

If you're using a 4.0 sound card (like an old SB Live!) or 4.0 speakers in general, you may notice that in some games or movies the dialogues are very quiet or even missing. This is because most of those applications/movies support only either 2.0 (stereo) or 5.1 output. In order to achieve surround sound, the 5.1 audio track is used but the two excessive channels are discarded — the center channel (which usually carries dialogues) and subwoofer channel.

The above issue can be circumvented through creating a virtual device which will downmix 5.1 to 4.0, mixing the center and subwoofer channels with other audio channels.

File~/.asoundrc

pcm.downmix {
    type route

    slave {
        # the sound card output to be used
        pcm         surround40
        # real number of output channels
        channels    4
    }

    # ttable.A.B G
    # where A - input channel
    #       B - output channel
    #       G - volume gain (1.0 = original)

    # copy channels 0-3
    ttable.0.0 1
    ttable.1.1 1
    ttable.2.2 1
    ttable.3.3 1

    # mix channel 4 (center) into front speakers, and a bit (0.3) into rear ones
    ttable.4.0 1.0
    ttable.4.1 1.0
    ttable.4.2 0.3
    ttable.4.3 0.3

    # mix channel 5 (subwoofer) mostly (0.6) into rear speakers, and a bit (0.3) into front ones
    ttable.5.0 0.3
    ttable.5.1 0.3
    ttable.5.2 0.6
    ttable.5.3 0.6
}

ctl.downmix {
    type hw
    card 0
}

HDMI/SPDIF 5.1 and 7.1 Speaker Testing

It's stated ALSA's speaker-test utility will not test more then two channel audio over HDMI or SPDIF. For this, you need to use mplayer, as quoted from ALSA's documentation.

Get the Microsoft's 8 Channel Speaker Test and unzip the file. (The file creates a sub directory named "8 Channel/", with files named "8_Channel_ID.wav" and "8_Channel_ID.wma".)

user $ unzip 8Channel.exe

Play the provided sound file; specifying your HDMI or SPDIF device, PCM file, and number of channels which will likely be either 6 or 8.

user $ mplayer -ao alsa:device=hw=0.7 -channels 6 ${HOME}/tmp/8\ Channel/8_Channel_ID.wav -channels 6

APlay SPDIF/HDMI Output has Incorrect Speaker Channels!

Now that you know how to use MPlayer to play a speaker test PCM WAV file per "HDMI/SPDIF 5.1 and 7.1 Speaker Testing" above, you now find APlay doesn't output to the speaker channels properly when using SPDIF/HDMI. With HDMI, this is likely caused by the snd_hda_intel HDMI audio module/driver which is used by other manufacturers such as NVidia HDMI aside from just Intel's HDMI hardware. As to why MPlayer does use the correct channels, MPlayer is usually under constant development and manually corrects this issue?

Another problem this solution pertains to, trying to play a 24 bit PCM 2.0 or PCM5.1 WAV files and finding APlay constantly refuses to play the stream, due to incorrect bit rate, etc.

To correct this for ALSA (APlay) with minimal alterations to the PCM streams, we'll need to remap the speaker channels within a ${HOME}/.asoundrc file. Add the following to the bottom of your ${HOME}/.asoundrc file. Also note, the below configuration is for both 5.1 and 7.1 audio, or you could further map/copy the two extra channels to your 5.1 channels incase you do not want to omit the audio from a 7.1 stream.

File.asoundrc

pcm.myHDMI {
        type plug slave {
            pcm "hw:1,7"
            format S32_LE
            channels 6 }
        ttable {
            0.0= 1
            1.1= 1
            2.4= 1
            3.5= 1
            4.2= 1
            5.3= 1
            6.6= 1
            7.7= 1
        }
}

It seems that most HDMI to Stereo Receiver connections only stream 16 and 32 bit formats, skipping 24 bit. The above configuration up-mixes any PCM stream to 32 bit when using the pcm.myHDMI profile, as it's quite common to see PCM 2.0 and 5.1 24 bit audio files. It just doesn't seem right to down-mix everything to 16 bit, or use Float as the latter uses more processing power. (Users can also set an alias within their bashrc file for 16 bit or 24 bit incantations as well.)

Test the speaker routing using a surround test PCM file. (See the above previously mentioned "8 Channel Speaker Test".)

user $ aplay -D my.HDMI 8Channel.wav

Add the incantation to your .bashrc file as an alias.

File.bashrc

  alias mplayer-hdmi="printf '\nENABLE 2nd Screen in xorg.conf and Unmute ALSA HDMI for HDMI Audio!\n\n'; mplayer -ao alsa:device=hw=1.3 $1"
  alias mplayer2-hdmi="mplayer2 --ao=alsa:device=hw=1.3 $1"
  alias mplayer-spdif="mplayer -ao alsa:device=hw=0.1 $1"
  alias mplayer2-spdif="mplayer2 --ao=alsa:device=hw=0.1 $1"
  alias mplayer-hdmi-movie="mplayer -ao alsa:device=hw=1.3 br:// -bluray-device /mnt/dvd-udf"
  alias mplayer2-hdmi-movie="mplayer --ao=alsa:device=hw=1.3 br:// -bluray-device /mnt/dvd-udf"
  alias mplayer-hdmi-music51-intel="mplayer -ao alsa:device=hw=1.7 -channels 6 -format s32le $1"
  
  alias aplay-hdmi="aplay -D pcm.myHDMI $1"
Note
MPlayer2 is seeing little to no development recently, and development seems to have migrated to media-video/mpv. The entries above are shown to display the versatility and ease of playing different media types via the command line, without having to resort to a graphical user interface.

Weak Center Channel on PCM 5.1 Live Music?

If you have a multi-channel sound track or music with an apparently weak center channel, and the sound track is a live recording; it is possible to map the center channel to the rear channels. Note, the rear channels on live recordings usually contain only the audiance screaming with very little music.

The following incanatation of mplayer specifies; your HDMI device of hw:1.7, your PCM 5.1 file, number of channels, the format (not needed if your receiver can natively handle 24 bit and in my case I need to upmix as my Yamaha HDMI receiver can only natively handle 16 or 32 bit audio), and then the mapping. Mapping as follows; specify this is a 6 channel audio stream, with 6 mappings immediately following, copy left front channel to left speaker, copy right channel to right speaker, copy center channel to left rear speaker, copy center channel to right rear speaker, copy center channel to center speaker, and finally copy the subwoofer channel to the subwoofer speaker.

user $ mplayer -ao alsa:device=hw=1.7 Music/MyAlbum/PCM51-24bit/01.MyMusic.wav -channels 6 -format s32le -af channels=6:6:0:0:1:1:4:2:4:3:4:4:5:5

See MPlayer's Channel manipulation.

Need to view more detailed information per ALSA stream?

If you need to look at an in-depth illustration of how your program is connecting to ALSA, use the /proc interface. You will need to substitute your relevant card/device details into the command below.

user $ cat /proc/asound/card2/pcm0p/sub0/*

You should see a dump of information regarding the program and useful things like its sample rate(rate) and PID(owner_pid).

access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 5513
buffer_size: 22050
card: 2
device: 0
subdevice: 0
stream: PLAYBACK
id: USB Audio
name: USB Audio
subname: subdevice #0
class: 0
subclass: 0
subdevices_count: 1
subdevices_avail: 0
state: RUNNING
owner_pid   : 934
trigger_time: 86393.193574796
tstamp      : 86540.250594985
delay       : 17714
avail       : 4602
avail_max   : 7379
-----
hw_ptr      : 6485052
appl_ptr    : 6502500
tstamp_mode: NONE
period_step: 1
avail_min: 5513
start_threshold: 2147483647
stop_threshold: 22050
silence_threshold: 0
silence_size: 0
boundary: 6206523236469964800

HTML5 does not play in firefox browser

Some system motherboards (i.e. Asus Z87-EXPERT) cause Card 0 to be a MID device instead of a PCM device. The same driver module snd_hda_intel is used for both the MID and PCM cards on this motherboard. For some reason Firefox HTML 5 requires Card 0 of the snd_hda_intel no matter how you change it with asoundrc. You can make flash work using the asoundrc file, but HTML 5 audio is silent.

You must remap the PCM device in Linux as card 0 and remove the changes to asoundrc that were added to make flash work. This wiki page indicates that you should compile the snd_hda_intel driver into the kernel. Using this configuration you must remap the card 0 and card 1 devices using boot parameters instead of a /etc/modprobe.d/alsa.conf file. For example the following kernel command line option will swap the MID and PCM card indicies so that the default card 0 is the PCM card:

snd-hda-intel.index=1,0

Note
The module is named snd_hda_intel, but the boot parameter name is snd-hda-intel.
Note
index is an array of int.