How to use the snd-hda-intel module with the Sigmatel codec

Accesses to this page since 25/09/2007: Page Visit Counter

Index


Basic Functioning

The Sigmatel chip is capable of recording 16 and 24-bit samples. However, due to restrictions of the HDA spec (only 8, 16, and 32 bit sample formats), the codec zero-pads 24 bit samples to 32 bits. As a consequence, it is not possible to use -f S24, but -f S32. Therefore, this will record 24 bit sound (zero padded to 32 bits).

Typically, there are three ADCs (Analog to Digital Converters), and each ADC has three controls:

In general, all three ADCs have the same mixer control names, which means that you will see three 'Input source' controls, three 'Capture volume' controls, and so on. In amixer, they can be distinguished by a control index, such as:

#set capture source of second ADC to line-in
amixer -c 0 sset 'Input Source',1 'Line'

In alsamixer, on the other hand, there are controls like "Input source, Input source 1, Input source 2", meaning that
ADC0's controls have no suffix, ADC1's controls have suffix "1", and ADC2's controls have suffix "2". The "PF3" and "PF4" keys switch between the Playback and Capture views, and the "space" key makes a selection. The "m" key toggles between mute/unmute.

kmix and gnome-alsamixer do not use indices at all. Therefore, one should rely on the fact that the first control is for ADC0, and so on.

There has been implemented support for using all of the three ADCs at the same time, and recording from different sources. Besides, there is an Analog Loopback, which works as follow:

1) First, sound enters through input of ADC0.
2) Second, it can be muted and/or amplified by the analog part of ADC0 (on that codec, ADC can amplify the sound, but can not decrease it)
3) Then, it is mixed with output of ADC0, after its volume is applied. Therefore, the only way to control the volume is to increase it with the capture volume / capture boost.

Furthermore, since ADC0 is connected to the headphone/line out, the loopback will not be heard on the other output channels, and this is the reason for the loud volume: headphone outputs are amplified more than the other outputs.

Finally, there are three input source mixer controls for each ADC, and a Master Volume, which will affect the output of all DACs at the same time.

If you have 5.1/7.1 speakers, and the connector for the Center/Sub-woofer is non-standard, it is possible to swap the Center/Sub-woofer channels.

What is good, is the fact that recording from different input sources is not supported by the Windows driver! Note that the Windows driver has an analog loopback (they call it a Monitor Input), and its volume can be decreased to zero, but it seems that this loopback is fake (records first and then plays the sound back).


Recording

The format of ALSA (Advanced Linux Sound Architecture) hw devices is shown below, and the capture device is a stream with three substreams:

hw:card:stream:substream

To record from an specific ADC, one should specify hw:0,0,0 ; hw:0,0,1 ; hw:0,0,2 as a record device (and use an audio rate up to 192000 Hz):

# to record from 2nd ADC and play on the first sound card
arecord -D hw:0,0,1 -f S16_LE -c2 -r48000 | aplay -D hw:0 &

# to record from 1st ADC and play via pulseaudio
arecord -D hw:0,0,0 -f S16_LE -c2 -r48000 | aplay -D pulse &

# to record from 3rd ADC and play on the third sound card
arecord -D hw:0,0,2 -f S16_LE -c2 -r48000 | aplay -D hw:3 &

Note that this can be used to avoid the high volume from the Analog Loopback (a "software" loopback).

For controlling the channel levels, it is possible to use a graphical tool, such as gnome-alsamixer. However, amixer can also be used for that purpose.


gnome-alsamixer

For instance:

# set input source for ADC0:
amixer -c 0 sset 'Input Source',0 'Mic'

# set Mux volume for ADC0:
amixer -c 0 cset iface=MIXER,name='Mux Capture Volume',index=0 4

# set Capture volume for ADC0:
amixer -c 0 cset iface=MIXER,name='Capture Volume',index=0 12

# mute ADC1
amixer -c 0 sset 'Capture',1 nocap 0%

# mute ADC2
amixer -c 0 sset 'Capture',2 nocap 0%

# set input source for ADC0 to Line-in
amixer -c 0 sset 'Input Source',0 'Line'

# set input source for ADC1 to Mic
amixer -c 0 sset 'Input Source',1 'Mic'

# set input source for ADC2 to Front Mic
amixer -c 0 sset 'Input Source',2 'Front Mic'

# set low volume (no gain) on ADC0 + enable it
amixer -c 0 sset 'Capture',0 cap 0%

# disable Mux gain on ADC0
amixer -c 0 sset 'Mux',0 0%

#disable Mux gain on ADC1
amixer -c 0 sset 'Mux',1 0%

#disable Mux gain on ADC2
amixer -c 0 sset 'Mux',2 0%

Therefore, bash scripts can be associated to buttons (application launchers) on the Desktop, thus providing a fast way of setting recording levels for a Microphone, Line in, or activating the software loopback.


Using OSS (Open Sound System)

OSS was used back to the 2.4 kernel series. However, ALSA can emulate its API, because several applications still use it.

Basically, there are two methods to emulate OSS:

1) In-kernel emulation: It is not possible to tell the programs which sub-stream to use, but they will pick the first available. Just launch, say, skype, then xvidcap, and skype will use ADC0, and xvidcap the ADC1.

For example, you can open /dev/dsp three times, and each time a free ADC will be used. This can be tested by doing:

# will record from 1st ADC
cat /dev/dsp > /dev/null &

# will record from 2nd ADC
cat /dev/dsp > /dev/null &

# will record from 3rd ADC
cat /dev/dsp > /dev/null &

# will fail, since all ADCs are already in use
cat /dev/dsp > /dev/null &

Note: remember to configure the ADCs for your needs, that is, set input sources, increase/decrease gain if necessary, etc.

2) Using aoss (alsa-oss-1.0.14):
(configurable through ~/.asoundrc)

#
# for using with aoss
# e.g., aoss xvidcap
#
pcm.dsp0 {
        type plug
        slave.pcm "hw:0,0,1"
}


Jack

Jack is a low-latency audio server based on ALSA, and allows performing low-latency professional-grade audio editing and mixing. To avoid xruns when using jack (callback messages and statistics reports, which occur when the delayed_usecs reported by the driver is "too large"), the following option can be added to /etc/modprobe.conf:

options snd-hda-intel position_fix=1 model=ref

There are several models available to choose from (/usr/share/doc/alsa-driver-1.0.15/Documentation/ALSA-Configuration.txt):


Jack Setup
Model Layout
ref Reference board
3stack D965 3stack
5stack D965 5stack + SPDIF
dell-3stack Dell Dimension E520
List of Models for STAC9227/8/9/927x

Skype

Skype is supporting ALSA natively. Just add the appropriate configuration to ~/.asoundrc:

#
# for using with skype-1.4.0.74
# set card0 as the input device
# ADC1 (subdevice 1)
#
pcm.card0 {
        type hw
        card 0
        device 0
        subdevice 1
}


Skype Setup

MythTV

This module (snd-hda-intel) is working just fine with MythTV (a PVR - Personal Video Recorder). Just set the Audio Device to /dev/dsp in the Capture Card Setup, turn off the Analog Loopback and set the recording level of ADC0. For being able to use pulseaudio, the Audio output device must be set to ALSA:default in the frontend. In my case, I have to turn on the sound of my capture card first, by using v4lctl from xawtv:

v4lctl -c /dev/tvtuner volume mute off


Capture Card and Audio Setup

Final Remarks

This howto is applicable only to the STAC922x and STAC927x codec family, because some STACs have two ADCs, some have just one, some may not have an analog loopback, and some may have significantly different mixer controls.

This is the list of supported codecs by the patch_sigmatel.c driver:

List of Supported Codecs
Name #DACs #ADCs Analog loopback Maximum sampling rate Notes
9200 1 1 yes(?) 96000 (1)
9202/9202D 1 1 yes(?) 192000 (1)
9250(D)/1(D) 1 1 yes(?) 192000 (1)
9204(D)/5(D) 2 2 yes 192000
9254(D)/5(D) 2 2 yes(?) 192000(?) (2)
9220(D)/1(D)/3D 4 2 no 192000
9227/8/9 4 3 yes 192000
9271(D)/2(D)/3(D)/4(D) 5 3 yes 192000
9872 ? ? ? 192000 (3)
Notes:
(1) - these chips are very different from what is described here.
(2) - no data-sheet available. Master volume + analog loopback may not be available.
(3) - no data-sheet available. Driver currently partially supports codecs found on Sony Vaio laptops.

Miscellaneous:

Written by: Maxim Levitsky and Paulo Roma Cavalcanti.
#alsa on freenode: MaximLevitsky (nick)