btaudio is an OSS legacy kernel module that allows you to get the audio from your bttv device directly over the PCI bus without using a patch cable to your sound card. This is useful if you would like to reserve your sound card for other functions, if you want to have multiple tuner cards in one computer, or if your sound card does not handle full-duplex.
- Gerd Knorr's instructions (copied from the 2.6.12-rc2 kernel and lightly updated)
- MythTV wiki: setting up btaudio on an ATI TV Wonder card
- Failed attempt at getting the sound directly off a AVerMedia TVCapture 98
- Note that saa713x cards unproblematically let you get the audio directly
Although all cards with BT87x chips are capable of supporting btaudio, not all cards do. In some cases, the manufacturer elected not to connect the TV tuner analogue audio out to one of the two ADC analogue inputs, which means you'll get no sound from btaudio. In other cases, (see Initialization failures below or AVerMedia TVCapture_98), the card is wired correctly, but not adequately initialized, so that the btaudio driver fails.
According to the MythTV HowTo, you need a bttv tuner device with an MSP34xx chip. This is incorrect. While a digital signal processor such as the MSP34xx is required for btaudio's digital mode, any bt87x card has the required hardware to work with btaudio's analog mode.
These cards are known to work with btaudio; the real set of working cards is much larger:
ATI TV Wonder Hauppauge WinTV-radio with dbx-TV stereo, model 401 Hauppauge WinTV-Theater, model 495, 498 (Europe) Hauppauge WinTV Express, models 751, 753 (but see note)
Note: Hauppauge model labels are often uninformative. For example, the box labeled model 753 may contain one of these:
board #44804 rev #D183, auto card=10; tuner TCL2002MB-3 (hidden sticker), but has to be forced to tuner=41 (Phillips PAL-MK(FI1216MK) board #44804 rev #D108, auto card=10; tuner FI1216MK15 (hidden sticker), autodetected as tuner=5.
The following cards are said not to work, but it's not known if they are wired the wrong way, not properly initialized, or just mistakenly thought not to work:
Pinnacle Studio PCTV Pro ATI TV Wonder VE Leadtek Winfast 2000 XP (PAL, UK and NTSC) I/O Magic PC-PVR Gateway/3Dfx STB OEM 6000704 Capture may appear under another sound card capture channel.
Some cards are reported to work, but the quality is poor; there may be individual differences within a model series.
If your tv audio works more or less on boot, please add a page about it and any kernel options required to get it going to the wiki.
The analog mode of the btaudio driver should just work on any BT87x card. The functions it supports are all integrated into the BT87x; all that is required is that the analog audio from the tuner is connected to the analog audio in on the chip, which in most cases it will be. The digital mode requires an additional digital audio source, such as the MSP34xx, which not all cards have. The following information is assembled largely from David Martin's informative posts to the v4l mailing list in April 2005.
The bt878 and bt879 (the latter no longer in production) include a high-frequency Analog to Digital Converter, supporting both 8 and 16 bits audio at 448000 samples per second.
Juan Domenech Fernandez has written up his experiments with the "low frequency ADC that comes with the Bt878A chip" in two parts; these articles provide valuable technical detail about the hardware driven by btaudio:
- Analog to Digital Converter with 16 bits and 448000 Samples per second based in the Bt878A
- btaudio.c module modification to get 896000 Samples per second with the Bt878A ADC
The 878 audio ADC has two inputs - STV (Sound TV) and SML (Sound Mic/Line). The 878A also has an FM input, SFM (Sound FM), used only if the card has a radio tuner. The BT879 has a pair of FM/FM stereo inputs. The cards all have a digital audio packetizer and FIFO buffer for DMA audio transport across the PCI bus to the host PC. All of this is on the BT87x silicon - identical on every card - and accessible via the btaudio driver. As a result the btaudio driver is almost entirely card agnostic. It only does a few things, roughly something like:
- Control the ADC switching mux to determine which of the two analogue input lines will be sampled.
- Control the ADC input gain (ie. the volume)
- Control the digital low pass filter to set the decimation factor and, hence, the digital output frequency.
- Control the digital audio packetizer input selection (the ADC or the external digital line in).
- Set the digital audio packetizer output mode and characteristics for the PCI bus data transfer.
On the 878 datasheet, the relevant pins are 94, 98, and 100. You need to inspect your card to see how the card manufacturer has used these pins:
These ADC pins serve the following functions:
|100||STV I||TV sound input from TV tuner.|
|98||SFM I||FM sound input from FM tuner.|
|94||SML I||MIC/line input.|
Analogue mono audio comes via the tuner or an external input source onto one or both of the BT87x analogue audio input pins. The btaudio driver controls the BT87x audio A/D and digital audio packetizer and provides a pseudo OSS device for applications to get access to the sound stream.
There are cases where the TV card designer elected NOT to connect the TV tuner analogue audio out to one of the two ADC analogue inputs (usually pin 100 on the BT87x). In this case, and in this case only, you will not get the broadcast audio. You will get static or silence. Nothing short of a soldering iron will help you.
However, the majority of cards have the required connections. Most designs seem to hook up the tuner mono TV audio to the BT87x STV pin. In some cases cards have multiple signal sources (a tuner and an external composite video and audio input pair, for example). In these designs there will be an analogue switching IC between the two input sources and the BT87x. Usually the the audio inputs bypass the switcher IC and the tuner is on the STV pin and the auxiliary audio is on the LINE pin. I have seen at least one card where the switcher IC routes both audio and video, and with the audio output from the switch only going to the external audio out, so you can use btaudio for the TV tuner, but not for the external audio input.
When you do get sound, the quality of the output can vary wildly from card to card (from good to unusably awful). Sometimes you can play around with sample frequencies and input gain settings and improve things.
The analog mixer
The analog device created by the btaudio driver has three mixer channels, called Line1, Line2, and Line3. The wiring varies; the sound can come through on different lines (cf. Instructions section above). One of the line inputs that show up in the mixer is an internal mux switch between STV and SML. According to the datasheet, sections 2.15.1 and 6.3, the mux is controlled by bits 24-25, A_SEL; legal values are 0 (STV, default), 1 (SFM), 2 (SML), or 3 (no mux), cf. pp. 165-6.
The other is a switch for a single stage 6dB preamp boost for the audio signal. The input gain control in the audio A/D (Line2 in the mixer) has 15 gain settings, from 0.5 times (-6db) to 3 times (10db) - this is in addition to the 6dB switchable audio preamp boost. What gain setting you need depends on the magnitude of the input signal from the tuner. The audio A/D is designed with a nominal input signal of 0.5V RMS, but the tuner input could be wildly different.
The ADC audio stage runs a 1.792MHz clock with valid hardware decimation values between 4 and 15 (controlled by bits 8-11, DA_SDR, of local register 0x10C, Audio Control Register (GPIO_DMA_CTL).
Juan uses these commands to test the device:
sox -w -r 448000 -t ossdsp /dev/dsp1 -t .wav test.wav
The dmesg results indicates which decimation values are used to downsample, yielding this table of twelve valid hardware rates:
4: 448 kHz 5: 358.4 kHz 6: 298.67 kHz 7: 256 kHz 8: 224 kHz 9: 199.1 kHz 10: 179.2 kHz 11: 162.9 kHz 12: 149.3 kHz 13: 137.8 kHz 14: 128 kHz 15: 119.47 kHz
He notes that by editing the btaudio driver, it's possible to make the ADC accept a decimation value lower than 4 for even higher sampling rates.
In the case of analog broadcast capture, digital audio inputs will always come via an external source - normally a NICAM or FM-FM stereo decoder IC which provides an i2s output signal to the BT87x digital audio input line. Those are generally controlled (control meaning mode and input selection) via i2c using the tvaudio driver.
However, most analogue capture cards have nothing connected to the inputs and they don't work - if you try and use the btaudio digital input, your application will freeze and nothing will happen.
The long and short of this is that analog mono audio via btaudio should either "just work" or it won't work at all and there is essentially nothing you can do about it if it doesn't, although I would expect the latter case to be in the minority. Digital audio won't work in the majority of cases because there is no external digital audio source to drive it.
Petr Vandrovec describes a case where a bt878 card fails to work with the btaudio driver unless it is first initialized by a Win98 driver:
- "On my hardware (AVerMedia TVCapture98) digital channel is not connected anywhere, and analog grabbing works only if Win98 with btpcivid.vxd from Feb 25 1999 (105492 bytes) are booted after poweron, but before Linux. Without performing initialization by this .vxd only samples with value 0x7FFF are captured, as some voltage reference is not programmed or something. And only this .vxd seems to do needed intialization - newer .vxds and WDM *.sys drivers do not seem to perform this initialization."
It is the tvaudio driver that handles the initialisation and controls external i2c-connected audio processors. The bttv driver itself contains GPIO controls for connected tuners, muxes/switches, and the like. There are already Aver card-specific audio initialisation functions in the bttv driver to handle this case -- Petr himself wrote them. If there are initialization problems, they occur outside of the btaudio driver.
See the captured graph after power-on and compare with the graph captured after booting Win98. The signal in the latter comes from a square wave generator with digital low-pass filter at ~24.85kHz. Vertical lines denote 49.7kHz samples from tone generator, and whole thing was grabbed at 448kHz.
Update: Ytlin reports that he initialized his cards successfully with another driver for MS Windows, the LGPL'd btwdmdrv. Since this driver is open source, it may be possible to use it to determine what needs to be done by the Linux driver.