ECE497 Lab11 Using ALSA

Revision as of 21:14, 13 May 2011 by Yoder (Talk | contribs) (Setup: Added how to save settings.)

Jump to: navigation, search

Be sure you have done Lab 10 before this lab so all your software is set up.

Lab 11/6 - Using ALSA

This is a placeholder...

There are ALSA examples here that are built on DMAI.

Problems and Solutions

Installing alsa libraries for cross compiling

I tried using Dr. Yoder's 12-May-2011 version of his ALSA code to cross-compile it and then send it to my Beagle (just to run on the ARM, not the DSP). I ran into a number of problems with the cross-compiling not finding header files and libraries, and this is how I had to fix it...

From [1], download:


Then run:

$ ar -p alsa-dev_1.0.18-r0.1_armv7a.ipk data.tar.gz | tar -zx 
$ ar -p libasound2_1.0.18-r0.1_armv7a.ipk data.tar.gz | tar -zx 
$ ar -p alsa-lib-dev_1.0.18-r0.1_armv7a.ipk data.tar.gz | tar -zx 

This creates in the current directory a usr/include and usr/lib directory with the ALSA header files and libraries in them. I then copied these files into my armv7a cross-compiler toolchain. Specifically:

  • I copied the 'alsa' folder in usr/include to /home/carlsojs/toolchains/usr/local/angstrom/arm/lib/gcc/arm-angstrom-linux-gnueabi/4.3.3/include
  • and I copied usr/lib to /home/carlsojs/toolchains/usr/local/angstrom/arm/lib/gcc/arm-angstrom-linux-gnueabi/4.3.3/lib
  • Then in the Makefile, I changed the ARM_TOOLCHAIN_PREFIX and defined the ARM_TOOLCHAIN_PATH:
ARM_TOOLCHAIN_PREFIX  ?= arm-angstrom-linux-gnueabi- 
ARM_TOOLCHAIN_PATH    ?= /home/carlsojs/toolchains/usr/local/angstrom/arm 

I then added the following argument to ARM_CFLAGS, which gives the compiler an additional location to look for header files:


And I added the following argument immediately before -lasound in ARM_LDFLAGS, which gives the compiler an additional location to look for libraries:


My gpp_exec (ARM executable) then cross-compiled for me. When I copied it to my BeagleBoard, it ran (after I killed PulseAudio), but it did give me BufferUnderrun errors.

Installing alsa libraries for cross compiling (quick hack)

My solution to get the cross compile to work was a quick:

$ cd ~/BeagleBoard/c6run_0_95_02_02_beagleboard/toolchains/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/include 
$ ln -s /usr/include/alsa .

I didn't change anything in the Makefile. However this might introduce some problems since it is using the same headers on the ARM as on the host computer. Mine appeared to work without buffer underruns.


There are a couple of things you need to after booting up before running the ALSA stuff.

  • Run $ killall -9 pulseaudio to stop pulseaudio.
  • Run alsamixer and turn up DAC2 Analog and turn down Left Dig and Right Dig. Do this by using the right arrow key to move to the slider you want to adjust and use the up and down keys to adjust. It's a lot of right arrows before you see DAC2 Analog; I count 14. Don't stop at DAC Voice or DAC1 Analog. It's then another 20 to Left Dig.

The Left and Right Dig's control the audio pass through. By default, whatever comes in the Line In, goes out to the speakers. Turning down Left and Right Dig prevents this.

Keeping DAC2 Analog up allows the output of the ALSA program to be heard.

You can save your setting for after the next reboot with:

sudo alsactl store

Details are here.

Some notes on ALSA

I've gotten this example working. I'm also looking here.

On the Beagle you need to:

# opkg install alsa-dev

On the host:

$ sudo apt-get install libasound2-dev

Go to the class dfs site and get alsaWrite.c. Compile it with

# gcc -lasound alsaWrite.c
# ./a.out

It runs on the Beagle and desktop and produces a sound.

It's shouldn't be hard to convert alsaWrite.c to alsaRead.c. See the sites above for hints.