Chinaunix首页 | 论坛 | 博客
  • 博客访问: 544623
  • 博文数量: 84
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 2109
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-25 14:02
文章分类

全部博文(84)

文章存档

2011年(10)

2010年(22)

2009年(16)

2008年(36)

我的朋友

分类: LINUX

2009-11-12 12:00:03

DigitalOut

From the ALSA wiki

Jump to: ,

These instructions apply to digital connections using either electrical coax or optical connections.

Contents

[]

[] Special terms

Terms used when dealing with digital outputs are:

  • IEC958 - The name of the IEC standards document and often seen in the alsamixer controls
  • S/PDIF or SPDIF - Stands for Sony/Philips Digital Interface Format, a specification for digital audio communication

[] Check Your Mixer

Mixer settings will affect your testing later on, so check them now. Run . Check that Playback or All is selected for View (top of screen). Look for the following channels and take action as noted.

  • IEC958 Output: Press M to unmute.
    Error creating thumbnail: Unable to run external programs in safe mode.
    alsamixer with IEC958 channels set to PCM out.
  • IEC958, IEC958 1 or similarly named channels: Set to "PCM Out". <-- HOW do you do this?? Added sample image, but thumbnail creation doesn't work... For now: [1]

When referring to a digital output, setting it to "PCM Out" instructs the card to pass through the audio bytestream exactly as it is received from an application without applying any mixer settings. This is important, since a main point of having a digital audio output is to extract raw data from the PC to a device that may be more capable. Many people, apparently including hardware designers, my regard digital outputs purely as a noise-free version of analog outputs. However, the interface is really a separate (if unidirectional) interface. This is important to keep in mind when passing AC3 surround data streams through the card to an external decoder. In that case, modifications of the stream would make it completely invalid.

TODO: Tell people how to set "PCM out" mode. Add more common mixer settings, try to keep it simple and as general as possible.

[] Find Your Device

There are different ways by which the digital output may be exposed to the system by ALSA: as an independent device of a soundcard, or as an alias. The ways to find either one are described below.

[] Separate Playback Device

On most cards the digital out is a specific audio playback device. To see which ALSA playback devices you have, you can use this command:

aplay -l

Sample output:

[jranders@chickadee ~]$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: T71Space [Terratec Aureon 7.1-Space], device 0: ICE1724 [ICE1724]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: T71Space [Terratec Aureon 7.1-Space], device 1: IEC1724 IEC958 [IEC1724 IEC958]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: T71Space [Terratec Aureon 7.1-Space], device 2: ICE1724 Surrounds [ICE1724 Surround PCM]
Subdevices: 3/3
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2

The device is specified as hw:(card),(device). The sample above shows device 1 is labeled "IEC1724 IEC958". That is the digital output device on this card, so it would be called hw:0,1. If your card does not show an IEC958 device, look for S/PDIF or digital.

If you get errors about "invalid arguments", etc, then try substituting "plughw" for "hw" in the above examples.

[] Device Aliases

On some cards digital out is already -- or even exclusively -- defined as an alias. See aplay -L for available playback devices. On a system with nForce 4 chipset onboard audio and an M-Audio Delta Audiophile 2496, this results in:

$ aplay -L
default:CARD=CK804
NVidia CK804, NVidia CK804
Default Audio Device
front:CARD=CK804,DEV=0
NVidia CK804, NVidia CK804
Front speakers
surround40:CARD=CK804,DEV=0
NVidia CK804, NVidia CK804
4.0 Surround output to Front and Rear speakers
surround41:CARD=CK804,DEV=0
NVidia CK804, NVidia CK804
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=CK804,DEV=0
NVidia CK804, NVidia CK804
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=CK804,DEV=0
NVidia CK804, NVidia CK804
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=M2496
M Audio Audiophile 24/96, ICE1712 multi
Default Audio Device
front:CARD=M2496,DEV=0
M Audio Audiophile 24/96, ICE1712 multi
Front speakers
surround40:CARD=M2496,DEV=0
M Audio Audiophile 24/96, ICE1712 multi
4.0 Surround output to Front and Rear speakers
surround41:CARD=M2496,DEV=0
M Audio Audiophile 24/96, ICE1712 multi
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=M2496,DEV=0
M Audio Audiophile 24/96, ICE1712 multi
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=M2496,DEV=0
M Audio Audiophile 24/96, ICE1712 multi
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
iec958:CARD=M2496,DEV=0
M Audio Audiophile 24/96, ICE1712 multi
IEC958 (S/PDIF) Digital Audio Output

If you see iec958 or S/PDIF in that list you can use the complete identification including the CARD and DEV parameters as a playback device instead of ```hw:x,y```.

Important Note: The uses devices ```hw:0,0``` and ```hw:0,1``` for /dev/dsp and /dev/adsp. See the page .

[] Alternate Method to Find Device

If you did not find your digital device with the above command, keep reading. Otherwise, skip to the Use Your Device section.

This is another command to show ALSA devices on your sound card:

cat /proc/asound/devices

Here is an example:

tapas@mango:~$ cat /proc/asound/devices 
1:  : sequencer
0: [0- 0]: ctl
8: [0- 0]: raw midi
18: [0- 2]: digital audio playback
17: [0- 1]: digital audio playback
16: [0- 0]: digital audio playback
24: [0- 0]: digital audio capture
33:  : timer

There are three audio playback devices:

 18: [0- 2]: digital audio playback
17: [0- 1]: digital audio playback
16: [0- 0]: digital audio playback

One of these is the digital out. We can test all outputs using the command, or alternatively or mplayer. If you want to use for this test, you need to have a .wav file. The numbers inside the square brackets ("[x- y]") are indexes for the soundcard (x) and the device (y) on that soundcard. So to play using the first playback device on the first card ("[0- 0]") you could use

aplay -D hw:0,0 file.wav

For the second and third you could use

aplay -D hw:0,1 file.wav
aplay -D hw:0,2 file.wav

Or with mplayer on [0- 0]:

mplayer file.wav -ao alsa:device=hw=0,0

If you hear sound when running one of these commands, you have found your digital device. If not, check your connection, receiver volume, and mixer settings described in the section above.

[] Use Your Device

To utilize the digital output, connect your sound card to something with a digital cable (possibly a stereo or surround receiver). Tell your program to send sound to 'hw:x,y' or 'plughw:x,y', where x is the card number and y is the device number shown by 'aplay -l'. For my card, this is hw:0,1.

Examples

  • Mplayer can be set with '-ao alsa:device=plughw=0.1' (beware it's a dot, not a comma)
  • XMMS can be set in Preferences->Audio I/O Plugins->Output Plugin by choosing ALSA, then Configure and set Audio device to 'plughw:0,1'
  • MythTV can be set in Utilities/Setup->Setup->General, on the third page, by typing 'ALSA:plughw:0,1' into Audio output device
  • xine can be set on the audio tab in setup by setting any output you like to 'pcm.plughw:0,1' and the audio driver to alsa

If you hear screeching or modem-like sounds using 'hw', try 'plughw'. (TODO: Explain why.)

If neither of these work for you, it may be due to the driver and card's support of sample rates and formats. This might be the case if you see errors about "invalid arguments". This is one reason to use the dmix mixer plugin. Look for user notes on your card at , and . Read about and (asound.conf).

[] Set your default

You can set the default playback device by using or /etc/asound.conf, you need to add this to set the defaults:

pcm.!default {
type hw
card
device
}

[] Digital Surround Passthrough

While the setup thus far allows you to use the digital connection, it doesn't enable Dolby Digital or dts passthrough, where the complete signal is sent to your receiver for decoding. Without that, you don't get surround. Please note, not all sources have digital surround in them. DVDs and digital TV signals commonly do.

[] mplayer

In Mplayer, use -ac hwac3 or -ac hwdts. Do not specify channels, because history dictates channels be set to 2, the default. Make sure channels is not in your config file. To find the desired audio track, run with -v and look for 'aid'. English Dolby 5.1 is sometimes 128. Then run mplayer with '-aid 128'. If the audio track is dts, use hwdts.

[] MythTV

MythTV can pass through digital surround from digital TV. Go to Utilities/Setup->Setup->General, on the third page, and select "Enable AC3 to S/PDIF passthrough".

[] xine

In xine, go to the audio tab in setup and set speaker arrangement to Pass Through and 5.1 output (alsa passthrough) to your digital ALSA pcm, like 'pcm.plughw:0,1'.

Setting 5.1 output (alsa passthrough) to 'plug:iec958' worked for me. Now my AV Receiver reports the Dolby/DTS modes correctly, not just PCM sound

The settings below work for me with an M-Audio Delta Audiophile (ICE1712 chip) to get passthrough to work in xine. Note the syntax for card specification, which is taken straight from aplay -L. The card only offers the IEC958 link as an alias, while only exposing a single device to the system. Those lines are supposed to go in the ~/.xine/config file:

audio.device.alsa_passthrough_device:iec958:CARD=M2496,DEV=0
audio.device.alsa_surround40_device:surround40:CARD=M2496,DEV=0
audio.device.alsa_surround51_device:surround51:CARD=M2496,DEV=0
audio.output.speaker_arrangement:Pass Through

When you start watching the actual movie (not previews or menu), your receiver should show that it's receiving digital surround.

[] Testing Your Setup

[] Raw Digital Output

A good test for "bit-perfect" digital passthrough (or S/PDIF passthrough) is to play these to your receiver decoder through a single TOSlink or analog digital connection. The DD of DTS light should come on and it should sound amazing. You can use aplay for playback, since that is rather easy to use if you just want to dump data into the card. The command may look like that:

aplay -D iec958:CARD=M2496,DEV=0 Norrlanda.wav

The parameters:

  • -D iec958:CARD=M2496,DEV=0: Set the output device. You use the device names from aplay -L.
  • The files provided at the site have proper headers that set up the data stream. If you get garbled results with other source material, you may try -f dat to use 48kHz sample rate, 16 bit little endian sample format, which is often used on DVDs.

[] Analog Surround Output

An alternative method would be to let ffmpeg decode the ac3 or dts and send it through 5.1(6) or 6.1(7) separate analog channels to an amplifier of amplified computer speakers using 3 RCA cables. At least with the files from the site above, mplayer seems to properly recognize DTS encoded autio and chooses a decoder library (libdca in my case), so playback is trivial:

Untested command (no 5.1-capable hardware, tested with -ao null)

$ mplayer -channels 6 Norrlanda.wav


Playing Norrlanda.wav.
Audio file file format detected.
==========================================================================
Opening audio decoder: [libdca] DTS decoding with libdca
AUDIO: 44100 Hz, 6 ch, s16le, 1411.2 kbit/33.33% (ratio: 176400->529200)
Selected audio codec: [dts] afm: libdca (DTS-libdca)
==========================================================================
AO: [null] 44100Hz 6ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 26.7 (26.7) of 265.0 (04:25.0) 12.8%
阅读(1621) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~