11 sound programming with alsa, Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual
Page 92

KTD-S0057-I
Page 88 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
10.11 Sound Programming with ALSA
The following examples assume that the compilation runs on an x86 Desktop PC using a cross compiler. One
possible Makefile might look like this (Ubuntu
TM
environment):
CC := arm-linux-gnueabihf-gcc -march=armv7
LDFLAGS := -l
asound
-l c -l m
all: pcm
pcm.o: pcm.c
pcm: pcm.o
$(CC) -o $@ pcm.o $(LDFLAGS)
clean:
rm pcm pcm.o
You can see the special shared library
libasound.so
(
libc
and
libm
are standard libraries and referenced by
libasound) which is typically not available. The library package also contains some necessary Include-files.
One possible way to install the binary library consists in the download of
libasound2-dev
on the target
hardware with
sudo
apt-get install libasound2-dev
and copy it from the Archive-directory to a storage medium
sudo cp /var/cache/apt/archives/libasound2-dev_..._armhf.deb <storage medium>
On the x86 Desktop PC extract the files to a temporary directory with
sudo dpkg -x libasound2-dev_..._armhf.deb
Now you can find out the library search paths by adding the
-v
option into the Makefile:
LDFLAGS := -l asound -l c -l m
-v
and then copy libasound.so into a search path.
The easiest way to install the Include-files is to install
libasound2-dev
also on the x86 Desktop PC (no dif-
ferences between x86 and ARM
®
Include-files, likely the compiler uses the x86 search paths). The cross
compiler ignores the x86 library file.
There are some interesting sourcecode examples on the webpage
http://www.alsa-project.org/alsa-doc/alsa-lib/examples.html
The PCM demo provides a comprehensive playback program (sinus frequency range 50 - 22000 Hz).
/***************************************************************
* This small demo sends a simple sinusoidal wave to your audio output
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
****************************************************************/