3.2.2.2. Audio
3.2.2.2.1. Introduction
The audio subsystem present on various TI SoCs consists of two major components:
Multi-channel Audio Serial Port (McASP) - Provides a full-duplex serial interface between the host processor and external audio peripherals like codecs over industry-standard protocols like Inter-IC sound (I2S).
System DMA engine - Provides McASP with direct access to system memory to read audio samples from (for playback) or store audio samples to (for capture).
Along with the above, most TI EVMs and SKs have line input/output jack(s) wired to an on-board codec that can convert between the analog signals and the digital protocol supported by McASP.
3.2.2.2.2. Software Architecture
All the hardware components are exposed to userspace applications using the Linux ALSA (Advance Linux Sound Architecture) framework, which allows control and configuration of the hardware through common APIs. For more details check the links below.
Within the kernel there are separate drivers for each component. For each
board a sound-card instance is created, usually using the sound {}
device tree node, that links together various components like different McASP
instances to a codec or an HDMI bridge.
![../../../../_images/audio-asoc-arch.png](../../../../_images/audio-asoc-arch.png)
3.2.2.2.3. Generic commands and instructions
Most of the boards have simple audio setup which means we have one sound card with one playback and one capture PCM. To list the available sound cards and PCMs for playback:
aplay -l
To list the available sound cards and PCMs for capture:
arecord -l
In most cases -Dplughw:0,0
is the device we want to use for audio
but in case we have several audio devices (onboard + USB for example)
one need to specify which device to use for audio:
-Dplughw:j784s4cpb,0
will use the onboard audio on J721E-EVM
board.
To play audio on card0’s PCM0 and let ALSA to decide if resampling is needed:
aplay -Dplughw:0,0 <path to wav file>
To record audio to a file:
arecord -Dplughw:0,0 -t wav <path to wav file>
To test full duplex audio (play back the recorded audio w/o intermediate file):
arecord -Dplughw:0,0 | aplay -Dplughw:0,0
To request specific audio format to be used for playback/capture take a look
at the help of aplay/arecord. For example, one can specify the format with -f
,
the sampling rate with -r
, or the number of channels with -c
.
In this case, one should open the hw device (not the plughw) via -Dhw:0,0
.
For example, record 48KHz, stereo 16bit audio:
arecord -Dhw:0,0 -fdat -t wav record_48K_stereo_16bit.wav
Or to record record 96KHz, stereo 24bit audio:
arecord -Dhw:0,0 -fS24_LE -c2 -r96000 -t wav record_96K_stereo_24bit.wav
It is a good practice to save the mixer settings found to be good and reload them after every boot (if your distribution is not doing this already)
Set the mixers for the board with amixer, alsamixer
alsactl -f board.aconf store
After booting up the board it can be restored with a single command:
alsactl -f board.aconf restore
3.2.2.2.4. Board-specific instructions
J784S4 Evaluation Board
|o|c1
| |
|o|p1
--------------------------
c1 - capture jack
p1 - playback jack
Kernel config
Device Drivers --->
Sound card support --->
Advanced Linux Sound Architecture --->
ALSA for SoC audio support --->
Audio support for Texas Instruments SoCs --->
<*> SoC Audio support for j721e EVM
~/.asoundrc file needed for audio playback
pcm_slave.j784s4-evm {
pcm "hw:0,0"
format S16_LE
channels 2
rate 48000
}
pcm.j784s4-playback {
type plug
slave j784s4-evm
}
User space
NOTE: Playback volume is HIGH after boot. Do not use headset without lowering it!!!
Master volume control is disabled by default. It can be enabled by:
amixer -c j784s4cpb sset 'codec1 DAC Volume Control Type' 'Master + Individual'
Then, a master gain control can be applied to all outputs:
amixer -c j784s4cpb sset 'codec1 Master' 141 # Master Playback volume for p1 jack
3.2.2.2.5. Potential issues
In case of XRUN (under or overrun)
Increase the buffer size (ALSA buffer and period size)
Try to cache the file to be played in memory
Try to use application which uses threads for interacting with ALSA and with the filesystem
In case of CPU stalls (when recording)
arecord -Dplughw:0,0 -r 48000 -t wav --period-size=64 <path to wav file>
ALSA period size must be aligned with the FIFO depth (tx/rx numevt)
3.2.2.2.6. Additional Information
ALSA links
Using ALSA Audio API Author: Paul Davis
Software Help
Audio hardware codecs