Main Content

ALSA Audio Playback

Send audio to sound card for playback using ALSA

Since R2021a

Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

  • NVIDIA ALSA audio playback block

Libraries:
NVIDIA Jetson and NVIDIA DRIVE / Audio and Video

Description

The ALSA Audio Playback block sends audio data to the audio output devices, such as speakers or headphones, connected to the NVIDIA® hardware. The block uses an Advanced Linux Sound Architecture (ALSA) driver framework to send audio data.

The block accepts an N-by-C matrix, where N is the samples per channel, and C is the number of channels supported by the audio. The block determines these values from the input signal.

Note

To use the ALSA Audio Playback block with audio devices that support more than two channels, you must have an Audio Toolbox™ license.

Examples

Ports

Input

expand all

The block accepts an N-by-C matrix, where N is the samples per channel, and C is the number of channels supported by the audio. The block determines these values from the input signal.

Data Types: int8 | int16 | int32

Algorithm

Consider a Simulink® model that includes a ALSA Audio Capture block and a ALSA Audio Playback block. The ALSA Audio Capture reads stereo audio data from the microphone connected to the audio input connector of the hardware. The block outputs data as a 3-by-2 matrix. At each sample time, the ALSA Audio Playback block accepts the audio matrix and sends audio to the headphones connected to the audio output jack of the hardware.

Sample workflow diagram for the audio blocks

The ALSA Audio Playback block determines the sample time (Ts) from the samples per audio channel (N) and sampling frequency (Fs).

Ts = N / Fs

For example, if N is 4410 samples and Fs is 44,100 Hz, the block sample time is 4410/44,100 = 0.1 seconds.

N is the number of samples per audio channel. The block determines the value of N from the input data. Fs is the sampling frequency of the input data specified in the Audio sampling frequency (Hz) parameter.

Parameters

expand all

Specify the ALSA audio output device connected to the hardware to which the block sends data. The default value, 'hw:0,0', specifies that the block sends audio to the default audio jack of the hardware.

You can send audio to an ALSA audio output device connected to the hardware. To get the list of audio output devices connected to the hardware, use the listAudioDevices function as described in List Available ALSA Audio Output Devices.

Programmatic Use

Block Parameter: deviceStr
Type: character vector
Values: valid name|
Default: 'hw:0,0'

Specify the sample rate used by the audio device to play audio, in Hz. The range of Audio sampling frequency (Hz) depends on the connected ALSA audio output device. To find the range of sample rates supported by the audio output device, use the listAudioDevices function as described in List Available ALSA Audio Output Devices. However, if you specify a sampling frequency that is not supported by the device, set the ALSA audio output device as 'plughw:0,0' in Device name.

Programmatic Use

Block Parameter: sampleRateEnum
Type: character vector
Values: positive integer
Default: '44100'

Version History

Introduced in R2021a

Go to top of page