Thursday 5 August 2010

LAP - Audio

The next thing to install is the linux audio software, also known as alsa or [a]dvanced [l]inux [s]ound [a]rchitecture.

Again, we need to download from the LiveCD:
umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources
mkdir audio
chmod -v a+wt audio
cd audio
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.21.tar.bz2
wget ftp://ftp.alsa-project.org/pub/plugins/alsa-plugins-1.0.21.tar.bz2
wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.21.tar.bz2
wget http://www.linuxfromscratch.org/patches/blfs/svn/alsa-utils-1.0.21-no_xmlto-1.patch
wget http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20090302.tar.bz2

I'm downloading the BLFS bootscripts again, just incase we didn't grab them when doing the network install. We'll adopt the same approach as for the network and documentation software:
cd /sources/audio
tar -jxvf /sources/audio/alsa-lib-1.0.21.tar.bz2

The [alsa-lib-1.0.21.tar.bz2] contains Alsa's libraries, and is absolutely essential to what follows. These are the core pieces of software that let programs, inlcuding alsa programs that we are about to install, access the ALSA drivers that we activated in the Kernel configuration earlier.

cd alsa-lib-1.0.21
./configure --enable-static

The [enable-static] option presumably makes static instead of dynamic libraries. Someone is going to have to take the time to explain that to me in the future.

make $CORES_TO_USE
make install
install -v -m644 -D doc/asoundrc.txt /usr/share/doc/alsa-lib-1.0.21/asoundrc.txt
make doc
install -v -d -m755 /usr/share/doc/alsa-1.0.21/html
install -v -m644 doc/doxygen/html/* /usr/share/doc/alsa-1.0.21/html
cd ..
rm -rvf alsa-lib-1.0.21
tar -jxvf /sources/audio/alsa-plugins-1.0.21.tar.bz2

In [alsa-plugins-1.0.21.tar.bz2] there are several add on libraries that seem to mostly assist in making alsa interact with other sound software in Linux. We are only going to be using alsa, and not pulseaudio or jack, so these may not be necessary. There is a huge gulf between 'may not be necessary' and 'actually not necessary' filled with nightmarish problem solving, so I am just going to install these anyway.

cd alsa-plugins-1.0.21
./configure
make $CORES_TO_USE
make install
install -v -m755 -d /usr/share/doc/alsa-plugins-1.0.21
install -v -m644 doc/{README*,*.txt} /usr/share/doc/alsa-plugins-1.0.21
cd ..
rm -rvf alsa-plugins-1.0.21
tar -jxvf /sources/audio/alsa-utils-1.0.21.tar.bz2

We now need to actually have some programs to configure the sound card settings, and more importantly at this stage, test to see if it is working. The [alsa-utils-1.0.21.tar.bz2] package achieves this.

cd alsa-utils-1.0.21
patch -Np1 -i /sources/audio/alsa-utils-1.0.21-no_xmlto-1.patch

BLFS contains precisely no information about why we want to apply this patch, but given the name it is probably something to do with stopping some xml documentation being produced.

./configure
make $CORES_TO_USE
make install
cd ..
rm -rvf alsa-utils-1.0.21

We now need to do some setup work so that alsa will work when we restart. The first thing to do is to install a script from BLFS which starts up alsa on boot.

tar -xjvf /sources/audio/blfs-bootscripts-20090302.tar.bz2
cd blfs-bootscripts-20090302
make install-alsa
cd ..
rm -rvf blfs-bootscripts-20090302

We also need to create the file which stores the settings (volume and stuff):

touch /etc/asound.state

And we need to fill it with the current settings:

alsactl store

Finally, udev needs a rule to tell it to reload the settings file we just made when it detects a soundcard at boot time. Not exactly sure what the difference is between this and the BLFS bootscript we just installed.

cat > /etc/udev/rules.d/40-alsa.rules << "EOF"
# /etc/udev/rules.d/40-alsa.rules

# When a sound device is detected, restore the volume settings
KERNEL=="controlC[0-9]*", ACTION=="add", RUN+="/usr/sbin/alsactl restore %n"
EOF
chmod -v 644 /etc/udev/rules.d/40-alsa.rules

What you then have to do is run the control program to activate your speakers. It is fairly self explanatory to use.

alsamixer

You can test the installation has worked by running:
speaker-test

If that does not work (and it did for me) then I can only suggest going back to the kernel configuration and making double sure that your hardware is supported in the kernel you have built. If in doubt, activate everything and try it then.

And, now for the wonder command that makes all of that into an executable script (apart from the last two commands):

sudo cat > install_alsa.sh << "ARSE" 
cd /sources/audio
tar -jxvf /sources/audio/alsa-lib-1.0.21.tar.bz2
cd alsa-lib-1.0.21
./configure --enable-static &&
make $CORES_TO_USE
make install &&
install -v -m644 -D doc/asoundrc.txt /usr/share/doc/alsa-lib-1.0.21/asoundrc.txt
make doc
install -v -d -m755 /usr/share/doc/alsa-1.0.21/html
install -v -m644 doc/doxygen/html/* /usr/share/doc/alsa-1.0.21/html
cd ..
rm -rvf alsa-lib-1.0.21
tar -jxvf /sources/audio/alsa-plugins-1.0.21.tar.bz2
cd alsa-plugins-1.0.21
./configure
make $CORES_TO_USE
make install
install -v -m755 -d /usr/share/doc/alsa-plugins-1.0.21
install -v -m644 doc/{README*,*.txt} /usr/share/doc/alsa-plugins-1.0.21
cd ..
rm -rvf alsa-plugins-1.0.21
tar -jxvf /sources/audio/alsa-utils-1.0.21.tar.bz2
cd alsa-utils-1.0.21
patch -Np1 -i /sources/audio/alsa-utils-1.0.21-no_xmlto-1.patch
./configure
make $CORES_TO_USE
make install
cd ..
rm -rvf alsa-utils-1.0.21
tar -xjvf /sources/audio/blfs-bootscripts-20090302.tar.bz2
cd blfs-bootscripts-20090302
make install-alsa
cd ..
rm -rvf blfs-bootscripts-20090302
touch /etc/asound.state
alsactl store
cat > /etc/udev/rules.d/40-alsa.rules << "EOF"
# /etc/udev/rules.d/40-alsa.rules

# When a sound device is detected, restore the volume settings
KERNEL=="controlC[0-9]*", ACTION=="add", RUN+="/usr/sbin/alsactl restore %n"
EOF
chmod -v 644 /etc/udev/rules.d/40-alsa.rules
ARSE
chmod +x ./install_alsa.sh
sudo mv ./install_alsa.sh /media/lfs/root 

No comments:

Post a Comment