Saa7134-alsa

From LinuxTVWiki
Revision as of 19:15, 26 March 2006 by Liontooth (talk | contribs)
Jump to navigation Jump to search

How to use alsa with saa7134

Starting with kernel 2.6.15, the module saa7134-alsa lets you use ALSA to get sound directly from your capture card. From 2.6.16 you can use this module with more than one capture card. In kernel 2.6.16, the saa7134-oss module is separated out, and the two modules are treated in much the same way; you can build both and switch between them.

Insmod parameters

When inserting the modules, add the parameter "alsa=1". I found it was not safe to use the parameter "disable_ir=1" to turn off the infrared system (I don't use the remote) -- that caused an oops on my 2.6.16 kernel.

In the case of more than one card, you can use something like this:

saa7134 card=2,2,2,2 tuner=43,43,43,43 video_nr=1,2,3,4 vbi_nr=1,2,3,4 radio_nr=1,2,3,4 alsa=1,1,1,1

In dmesg, you should see this type of content murmuring:

input: saa7134 IR (LifeView FlyVIDEO30 as /class/input/input5
tuner 5-0061: chip found @ 0xc2 (saa7133[3])
tuner 5-0061: type set to 43 (Philips NTSC MK3 (FM1236MK3 or FM1236/F))
tuner 5-0063: chip found @ 0xc6 (saa7133[3])
saa7133[3]: i2c eeprom 00: 69 51 38 01 10 28 ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: i2c eeprom 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
saa7133[3]: registered device video4 [v4l2]
saa7133[3]: registered device vbi4
saa7133[3]: registered device radio4

Then load the new driver that lets you get sound off the PCI bus via ALSA, you would normally just issue "sudo modprobe saa7134-alsa". For four cards, do this:

sudo modprobe saa7134-alsa index=1,2,3,4

Again, dmesg approves:

saa7134 ALSA driver for DMA sound loaded
saa7133[0]/alsa: saa7133[0] at 0xf5006000 irq 19 registered as card 1
saa7133[1]/alsa: saa7133[1] at 0xf5007000 irq 20 registered as card 2
saa7133[2]/alsa: saa7133[2] at 0xf5004000 irq 21 registered as card 3
saa7133[3]/alsa: saa7133[3] at 0xf5005000 irq 22 registered as card 4 

Insert modules on boot

To insert the modules with these parameters on boot, you can create a file called /etc/modprobe.d/saa7134 with the following lines (adjust card and tuner numbers as required):

options saa7134 card=2,2,2,2 tuner=43,43,43,43 video_nr=1,2,3,4 vbi_nr=1,2,3,4 radio_nr=1,2,3,4 alsa=1,1,1,1
install saa7134 /sbin/modprobe --ignore-install saa7134; /sbin/modprobe saa7134-alsa
options saa7134-alsa index=1,2,3,4

Your distribution may require you to put these lines into /etc/modprobe.conf; this is not a good idea in Debian, since the files in /etc/modprobe.d will then be ignored.

If instead you use OSS, these lines will load the modules for four cards:

options saa7134 card=2,2,2,2 tuner=43,43,43,43 video_nr=1,2,3,4 vbi_nr=1,2,3,4 radio_nr=1,2,3,4 oss=1,1,1,1
install saa7134 /sbin/modprobe --ignore-install saa7134; /sbin/modprobe saa7134-oss
options saa7134-oss index=1,2,3,4

These instructions are of course specific to kernels 2.6.16 and later, as earlier kernels do not have separate DMA modules.

For kernels before 2.6.16, DMA sound via OSS is activated simply by the insmod parameter "oss=1".

Set permissions

Make sure your users are added to the group "audio" to get access to them -- in Debian, if your user name is "tv", you would use

adduser tv audio

List your capture devices

To get a list of your alsa capture devices, issue

arecord -l

You should see your regular sound card and the capture card(s):

**** List of CAPTURE Hardware Devices ****
card 0: CK8S [NVidia CK8S], device 0: Intel ICH [NVidia CK8S]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: CK8S [NVidia CK8S], device 1: Intel ICH - MIC ADC [NVidia CK8S - MIC ADC]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: SAA7134 [SAA7134], device 0: SAA7134 PCM [SAA7134 PCM]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: SAA7134_1 [SAA7134], device 0: SAA7134 PCM [SAA7134 PCM]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: SAA7134_2 [SAA7134], device 0: SAA7134 PCM [SAA7134 PCM]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 4: SAA7134_3 [SAA7134], device 0: SAA7134 PCM [SAA7134 PCM]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Configure the cards to record

Set the cards to record on channel 1 and max volume, using for instance

alsamixergui -c 1

for each of the cards.

Watch with mplayer

You should now be ready to watch live tv with mplayer, using something like this:

mplayer tv:// -tv driver=v4l2:device=/dev/video0:chanlist=us-bcast:alsa:\
adevice=hw.1,0:amode=1:audiorate=32000:forceaudio:volume=100:\
immediatemode=0:norm=NTSC

If "adevice=hw.1,0" doesn't work, try simply "adevice=hw.1".

I don't know how to use ALSA with xawtv, motv, kdtv, tvtime, or zapping; if you do, please add it in here!

Record with mencoder

It may be simpler to get sound during recording than during playback. I get good sound using this, where $DEV is the number of the device node:

mencoder -tv driver=v4l2:device=/dev/video$DEV:fps=30000/1001:chanlist=us-bcast:\
audiorate=32000:alsa:adevice=hw.$DEV:input=0:amode=1:normid=4:width=576:height=432 \
-ovc x264 -x264encopts threads=2:bitrate=500:bframes=2:subq=1:me=1:frameref=4:8x8dct \
-oac mp3lame -lameopts cbr:br=64 -endpos $TIM -o $DIR/$FIL.avi tv:// > /dev/null

So the alsa device is simply called hw.1 -- not hw.1,0. The line is taken from the channel script.

I haven't been able to find a way to tell ffmpeg to use this ALSA device; if you know, please add it here!

Because so many applications still appear to have difficulties accessing ALSA's odd device enumeration, the OSS module for DMA sound continues to be very useful.