NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Sitara SDK Linux Audio ALSA User Space

From Texas Instruments Wiki
Jump to: navigation, search


Sitara Linux Software Developer's Guide Sitara Linux SDK Audio: ALSA User Space


Introduction[edit]

ALSA provides a number of useful command line utilities that can be used to gather information about sound cards, playback and record audio, and configure sound cards. It is the foundation upon which audio frameworks, such as GStreamer and PulseAudio, are built. In other words, GStreamer and PulseAudio are actually using the ALSA API to communicate with audio hardware.

Furthermore, ALSA exposes the functionality of the kernel drivers to userspace via an API, which can be utilized to develop custom audio applications.

Asoundrc[edit]

Asoundrc (or asound.conf) is a configuration file that is not technically needed for audio to work in linux, but it is a powerful tool to tailor to the audio needs of a specific system. Routing and sample-rate conversion are examples of properties that can be configured through Asoundrc.

For more information, please visit the official page:


Command Line Utilities[edit]

This section lists a number of useful command line utilities for ALSA. A further demonstration of their uses can be found on this wiki page.

aplay[edit]

aplay can be used to playback audio. Furthermore, it can provide the user with some basic information about playback devices detected by the system.

Please consult the aplay manual to learn more about this tool: aplay man page

Example usage (play back of a wave file):

aplay audio.wav 

arecord[edit]

arecord can be used to record audio. Furthermore, it can provide the user with some basic information about recording devices detected by the system.

Please consult the arecord manual to learn more about this tool: arecord man page

Example usage (recording a CD quality wave file for 10 seconds):

arecord -d 10 -f cd -t wav audio.wav 

Device Interface[edit]

The operational interface in /dev/ contains three main types of devices: 

  • PCM devices for recording or playing digitized sound samples,
  • CTL devices that allow manipulating the internal mixer and routing of the card, and,
  • MIDI devices to control the MIDI port of the card, if any.
Device Interface
Name Description
/dev/snd/controlC0 Control devices (i.e. mixer, etc)
/dev/snd/pcmC0D0c PCM Card 0 Device 0 Capture device
/dev/snd/pcmC0D0p PCM Card 0 Device 0 Playback device


Proc Interface[edit]

The /proc/asound kernel interface is a status and configuration interface. A lot of useful information about the sound system can be found in the /proc/asound subdirectory.

See the table below for different proc entries in /proc/asound:

Proc Interface
Name Description
cards List of registered cards
version Version and date the driver was built on
devices List of registered ALSA devices
pcm The list of allocated PCM streams
cardX/ (X = 0-7) The card specific directory
cardX/pcm0p The directory of the given PCM playback stream
cardX/pcm0c The directory of the given PCM capture stream


ALSA API[edit]

Any application that requires audio in linux will call the ALSA API in order to interact with the sound drivers. The ALSA API is standardized and can be used in any linux system, including Sitara devices.

For a complete overview of the ALSA API, refer to the official documentation: ALSA C Library Reference

Commonly Used APIs[edit]

Some of the commonly used APIs to write an ALSA based application are:

Commonly Used APIs
Name Description
snd_pcm_open Opens a PCM stream
snd_pcm_close Closes a previously opened PCM stream
snd_pcm_hw_params_any Fill params with a full configuration space for a PCM
snd_pcm_hw_params_test_ <<parameter>> Test the availability of important parameters like number of channels, sample rate etc. For e.g. snd_pcm_hw_params_test_format, snd_pcm_hw_params_test_rate etc.
snd_pcm_hw_params_set_ <<parameter>> Set the different configuration parameters. For e.g. snd_pcm_hw_params_set_format, snd_pcm_hw_params_set_rate etc.
snd_pcm_hw_params Install one PCM hardware configuration chosen from a configuration space
snd_pcm_writei Write interleaved frames to a PCM
snd_pcm_readi Read interleaved frames from a PCM
snd_pcm_prepare Prepare PCM for use
snd_pcm_drop Stop a PCM dropping pending frames
snd_pcm_drain Stop a PCM preserving pending frames


User Space Interactions[edit]

This section depicts the sequence of operations for a simple playback and capture application.

Playback:
ASoC Driver: Half Duplex Playback
Record:
ASoC Driver: Half Duplex Record


Archived[edit]

Sitara Linux SDK 08.00.00.00

E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Sitara SDK Linux Audio ALSA User Space here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Sitara SDK Linux Audio ALSA User Space here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article Sitara SDK Linux Audio ALSA User Space here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity