ALSA

Advanced Linux Sound Architecture (ALSA).

USB microphone for raspberry pi

pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 3: UACDemoV10 [UACDemoV1.0], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

alsa-utils

See https://github.com/alsa-project/alsa-utils

sudo apt-get install alsa-utils

It contains source code for arecord, areplay, etc.

aplay

List playback devices:

aplay -l

**** List of PLAYBACK Hardware Devices ****
card 1: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

To play foo.wav on card 1, device 0, use:

aplay -D hw:1,0 foo.wav

arecord

cat /proc/asound/pcm
00-00: bcm2835 Headphones : bcm2835 Headphones : playback 8
01-00: MAI PCM i2s-hifi-0 : MAI PCM i2s-hifi-0 : playback 1
02-00: MAI PCM i2s-hifi-0 : MAI PCM i2s-hifi-0 : playback 1
03-00: USB Audio : USB Audio : capture 1
arecord -l
**** List of CAPTURE Hardware Devices ****
card 3: UACDemoV10 [UACDemoV1.0], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
cat  /proc/asound/card3/stream0

Jieli Technology UACDemoV1.0 at usb-0000:01:00.0-1.4, full speed : USB Audio

Capture:
  Status: Stop
  Interface 1
    Altset 1
    Format: S16_LE
    Channels: 1
    Endpoint: 0x83 (3 IN) (ASYNC)
    Rates: 48000
    Bits: 16
    Channel map: MONO

Cross compiling alsa-lib

See https://github.com/alsa-project/alsa-lib/blob/master/INSTALL

git clone --depth 1 https://github.com/alsa-project/alsa-lib
cd alsa-lib
CC=aarch64-linux-gnu-gcc ./gitcompile --host=aarch64-linux-gnu

/bin/bash: plantuml: command not found: sudo apt-get install plantuml

alsa-lib$ find . -name "*.so"

./src/.libs/libasound.so
./src/topology/.libs/libatopology.so
alsa-lib$ find . -name asoundlib.h
./include/asoundlib.h

Then copy the include directory to raspberry pi and rename include to alsa. Also, copy libasound.so to raspberry pi.

We can pass -I/path/to/alsa/parent and -lasound to g++ on raspberry pi.

Introduction to Sound Programming with ALSA

sudo apt-get install libasound2-dev libasound2
See