ALSA support for the Bt878a and Fedora Core 4

Versión en Castellano

Note: This article has a previous release using Fedora Core 2. Now is obsolete.

1.1 - Components
1.2 - Setup
1.3 - ALSA version update
1.4 - Check
2.1 - Mixer
3.1 - Capture test (1)
3.2 - Patch aplay.c
3.3 - Capture test (2)
4.1 - SoX under ALSA
4.2 - Capture test SoX ALSA Ensoniq
4.3 - Capture test SoX ALSA Bt878a
5.1 - Native GNUradio connection



1.1 - Components

Fedora Core 4
Linux Kernel 2.6.11
ALSA 1.0.9rc4
Ensoniq 1371 sound card
Modified Bt878a capture board


1.2 - Setup

Linux out of the box.

The installer has detected the Ensoniq 1371 sound card but the Bt878a don't.

/etc/modprobe.conf

alias eth0 3c59x
alias snd-card-0 snd-ens1371
options snd-card-0 index=0
options snd-ens1371 index=0
remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-ens1371
alias usb-controller uhci-hcd

Add the following lines at the /etc/modprobe.conf file to load automatically the ALSA support for the Bt87x. 

alias snd-card-1 snd-bt87x
alias sound-slot-1 snd-bt87x
options snd-bt87x index=1 load_all


Setting this way the Creative sound card with number 0 and the Bt878 audio stage with number 1. Is very important the "load_all" option to load the module successfully.

 

1.3 - ALSA version update

We should get the latest stable files from here: http://www.alsa-project.org/ . I downloaded: alsa-driver-1.0.9rc4a.tar.bz2, alsa-lib-1.0.9rc4.tar.bz2, alsa-utils-1.0.9rc4a.tar.bz2 y alsa-oss-1.0.9rc4.tar.bz2.

# cd alsa-lib-1.0.9rc4
# ./configure
# make
# make install

# cd alsa-driver-1.0.9rc4a
# ./configure --with-cards=ens1371,bt87x
# make
# make install

# cd alsa-utils-1.0.9rc4a
# ./configure
# make
# make install

# cd alsa-oss-1.0.9rc4
# ./configure
# make
# make install


Restart the PC.

 

1.4 - Check

After restart the modules in memory looks like this:

# lsmod
Module                  Size  Used by
lp                     13001  0 
autofs4                29253  2 
rfcomm                 42333  0 
l2cap                  30661  5 rfcomm
bluetooth              56133  4 rfcomm,l2cap
sunrpc                167813  1 
video                  15941  0 
button                  6609  0 
battery                 9413  0 
ac                      4805  0 
md5                     4033  1 
ipv6                  268097  8 
uhci_hcd               35152  0 
bt878                  10457  0 
bttv                  161393  1 bt878
video_buf              23749  1 bttv
i2c_algo_bit            9289  1 bttv
v4l2_common             5825  1 bttv
btcx_risc               4937  1 bttv
tveeprom               13017  1 bttv
videodev                9537  1 bttv
shpchp                 94405  0 
parport_pc             28933  0 
parport                40585  2 lp,parport_pc
i2c_viapro              8017  0 
i2c_core               21569  4 bttv,i2c_algo_bit,tveeprom,i2c_viapro
snd_bt87x              16712  3 
snd_ens1371            32224  3 
gameport               18633  1 snd_ens1371
snd_rawmidi            30880  1 snd_ens1371
snd_ac97_codec         79484  1 snd_ens1371
snd_seq_oss            39424  0 
snd_seq_midi_event      8704  1 snd_seq_oss
snd_seq                63504  4 snd_seq_oss,snd_seq_midi_event
snd_seq_device          9356  3 snd_rawmidi,snd_seq_oss,snd_seq
snd_pcm_oss            51872  0 
snd_mixer_oss          18560  4 snd_pcm_oss
snd_pcm               100104  5 snd_bt87x,snd_ens1371,snd_ac97_codec,snd_pcm_oss
snd_timer              34180  2 snd_seq,snd_pcm
snd                    56932  16 snd_bt87x,snd_ens1371,snd_rawmidi,snd_ac97_codec,snd_seq_oss,snd_seq,snd_seq_device,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer
soundcore              10913  4 snd
snd_page_alloc         10244  2 snd_bt87x,snd_pcm
3c59x                  45033  0 
mii                     5441  1 3c59x
floppy                 65269  0 
dm_snapshot            17413  0 
dm_zero                 2113  0 
dm_mirror              26029  0 
ext3                  132553  2 
jbd                    86233  1 ext3
dm_mod                 58101  6 dm_snapshot,dm_zero,dm_mirror


Check the ALSA sound devices:

# ll /dev/snd/
total 0
crw-------  1 root root 116,  0 Aug  7 20:17 controlC0
crw-------  1 root root 116, 32 Aug  7 20:17 controlC1
crw-------  1 root root 116,  8 Aug  7 20:17 midiC0D0
crw-------  1 root root 116, 24 Aug  7 20:17 pcmC0D0c
crw-------  1 root root 116, 16 Aug  7 20:17 pcmC0D0p
crw-------  1 root root 116, 17 Aug  7 20:17 pcmC0D1p
crw-------  1 root root 116, 56 Aug  7 20:17 pcmC1D0c
crw-------  1 root root 116, 57 Aug  7 20:17 pcmC1D1c
crw-------  1 root root 116,  1 Aug  7 20:17 seq
crw-------  1 root root 116, 33 Aug  7 20:17 timer

pcmC1D0c belongs to the Bt878 digital audio input and pcmC1D1c to the analog input.



2.1 - Mixer

Install gnome-alsamixer. Seems that the mixer included in Fedora Core 4 connects with the emulated OSS mixer and not with the native one from ALSA. (?)

Official gnome-alsamixer page http://www.paw.co.za/projects/gnome-alsamixer/ .
They have some problem in their FTP server. Finally I'd get the 0.9.6 version from here: http://rpm.pbone.net/index.php3/stat/4/idpl/1699907/com/gnome-alsamixer-0.9.6-3.1.fc3.rf.i386.rpm.html.

Install gnome-alsamixer-0.9.6-3.1.fc3.rf.i386.rpm

Gnome ALSA Mixer Ensoniq 1371

gnome-alsa-mixer-ensoniq

Gnome ALSA Mixer Bt878

gnome-alsa-mixer-bt87x-b7878a

Increase the volume at maximum and select TV Tuner input (see image).

 

3.1 - Capture test (1)

We do a capture test using the native arecord utility from ALSA:

# arecord -D hw:1,1 -r 448000 -f S16_LE -t wav test.wav
arecord: main:456:
bad speed value 448000

-D hw:1,1   
1 for the second physical device (0 is the first one, in my case the SoundBlaster) and 1 for the second logical device (0 is the first one, the digital audio interface from the Bt878a)
-r 448000      Samples per second
-f S16_LE    Format signed word little-endian

Fails. arecord is limited to 192000 Sps. Let's patch it.

 

3.2 - Patch aplay.c

We will modify aplay.c to obtain the maximum sampling speed. Go to the ALSA utilities folder we have previously compiled. The arecord utility is an alias from aplay.

# cd alsa-utils-1.0.9rc4a/aplay/
# gedit aplay.c

Place the cursor in line 456 and modify the value 192000 to 1792000:


if
(tmp < 2000 || tmp > 1792000) {
 

Save and compile.

# cd ..
# make
# make install
 


3.3 - Capture test (2)

Capture test again:

# arecord -D hw:1,1 -r 896000 -f S16_LE -t wav test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 896000 Hz, Mono

And works perfect. Now we have ALSA working at 896000 Sps. We get the following spectrum using the "cable around TV" technique (as previously explained).




baudline spectrogram


 

4.1 - SoX under ALSA

SoX supports ALSA but is necessary to compile it to be able use the native device. (?) Download the last stable version (sox-12.17.7.tar.gz) from here: http://sox.sourceforge.net/.

Compile:

# cd sox-12.17.7
# ./configure

I got this Warning but can be ignored:

...
configure: WARNING: sound/asound.h: present but cannot be compiled
configure: WARNING: sound/asound.h: check for missing prerequisite headers?
configure: WARNING: sound/asound.h: see the Autoconf documentation
configure: WARNING: sound/asound.h: section "Present But Cannot Be Compiled"
configure: WARNING: sound/asound.h: proceeding with the preprocessor's result
configure: WARNING: sound/asound.h: in the future, the compiler will take precedence
configure: WARNING: ## --------------------------------------------- ##
configure: WARNING: ## Report this to cbagwell@users.sourceforge.net ##
configure: WARNING: ## --------------------------------------------- ##
...


# make
# make install

The installer failed to place the SoX binary file. Let's copy it manually:

# cd src
# ll /usr/bin/sox
-rwxr-xr-x 1 root root 275584 May 12 16:09 /usr/bin/sox
# ll sox
-rwxr-xr-x 1 root root 756042 Aug 7 19:39 sox
# mv /usr/bin/sox /usr/bin/sox.old
# cp sox /usr/bin/

Check the Sox installation and we can see ALSA as one supported "file format":

# sox -Vh
sox: Version 12.17.7
Usage: [ gopts ] [ fopts ] ifile [ fopts ] ofile [ effect [ effopts ] ]
gopts: -e -h -p -v volume -V
fopts: -r rate -c channels -s/-u/-U/-A/-a/-i/-g/-f -b/-w/-l/-d -x
effect: avg band bandpass bandreject chorus compand copy dcshift deemph earwax 
echo echos fade filter flanger highp highpass lowp lowpass mask mcompand 
noiseprof noisered pan phaser pick pitch polyphase rate repeat resample reverb 
reverse silence speed stat stretch swap synth trim vibro vol
effopts: depends on effect
Supported file formats: aiff al alsa au auto avr cdr cvs dat vms gsm hcom 
la lu maud nul ossdsp prc raw sb sf sl smp sndt sph 8svx sw txw ub ul uw voc 
vorbis vox wav wve

 

4.2 - Capture test SoX ALSA Ensoniq

# sox -V -r 48000 -w -t alsa /dev/snd/pcmC0D0c -t .wav test.wav
sox: Input file /dev/snd/pcmC0D0c: using sample rate 48000
size shorts, encoding signed (2's complement), 1 channel
sox: Writing Wave file: Microsoft PCM format, 1 channel, 48000 samp/sec
sox: 96000 byte/sec, 2 block align, 16 bits/samp
sox: Output file test.wav: using sample rate 48000
size shorts, encoding signed (2's complement), 1 channel
sox: Output file: comment "Processed by SoX"

sox: Finished writing Wave file, 983040 data bytes 491520 samples


Works fine.

 

4.3 - Capture test SoX ALSA Bt878a

# sox -V -r 48000 -w -t alsa /dev/snd/pcmC1D1c -t .wav test.wav
sox: Failed reading /dev/snd/pcmC1D1c: ioctl operation failed 22


Fails.
 

Now the problem is that SoX gives the error "ioctl operation failed 22" with every parameters combination I've tried.

# sox -V -r 448000 -sw -t alsa /dev/snd/pcmC1D1c -t .wav test.wav
sox: Failed reading /dev/snd/pcmC1D1c: ioctl operation failed 22

-V   Verbose
-r   Sample rate
-w   Word
/dev/snd/pcmC0D0c
   Native device from ALSA for the Ensoniq 1371.
/dev/snd/pcmC1D1c
   Native device from ALSA for the Bt878a. D1 is the second logical device (D0 is the digital audio interface from the Bt878). The c letter in the device name stands for capture (and p for play).

I've successfully checked that SoX captures thru ALSA with the Ensoniq card (/dev/snd/pcmC0D0c) but not with our beloved chip.

To be continued...

 

5.1 - Native GNUradio connection

Once GNUradio successfully compiled is very easy to connect it to the Bt878 with the ALSA native device.

Example audio_fft_alsa.py

alsa-gnuradio-bt878-fft-spectrum-spectrogram-1
450Khz FFT from a 896000 Sps signal

 

 

 

- Credits

Clemens Ladisch
Chris Bagwell



- Author:

Juan Domenech Fernandez

http://www.domenech.org
 

Versión en Castellano

v1.1 26-august-2005
v0 11-october-2004