ALSA Audio Capture

Capture audio from sound card using ALSA

  • Library:
  • Simulink Support Package for Raspberry Pi Hardware

Description

The ALSA Audio Capture block reads audio data from the audio input device connected to the hardware. The block uses the Advanced Linux Sound Architecture (ALSA) driver framework to read audio data.

The block outputs the audio data as an N-by-C matrix, where N is the samples per audio channel, and C is the number of channels supported by the audio device. Specify the values for N and C in the Samples per frame (N) and Number of channels (C) parameters, respectively.

Note

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

Algorithm

Consider a Simulink® model that includes an ALSA Audio Capture block and an ALSA Audio Playback block. At each sample time, 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. The ALSA Audio Playback block accepts the audio matrix and sends audio to the headphones connected to the audio output jack of the hardware.

The ALSA Audio Capture 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 specified in the Number of channels (C) parameter. Fs is the sampling frequency of audio data specified in the Audio sampling frequency (Hz) parameter.

Ports

Output

expand all

The block outputs the audio data as an N-by-C matrix, where N is the samples per channel, and C is the number of channels supported by the audio. Specify the values of N and C in the Samples per frame (N) and Number of channels (C) parameters, respectively.

For example, for a stereo audio source file with three samples per channel, the block organizes the audio data into a 3-by-2 matrix.

The data type of the output matrix is of the type specified in the Device Bit depth parameter.

Data Types: int8 | int16 | int32

Parameters

expand all

Specify the ALSA audio input device connected to the hardware from which the block reads audio data.

You can receive audio from any ALSA audio input device connected to the hardware. To get the list of audio input devices connected to the hardware, use the listAudioDevices function as described in List Available ALSA Audio Input Devices.

Before performing analog-to-digital conversion, the audio data is cast to the data type specified in this parameter.

To find the number of channels supported by the audio input device, use the listAudioDevices function as described in List Available ALSA Audio Input Devices.

Specify the sample rate used by the audio input device to read audio data, in Hz. The sample rates listed in the Audio sampling frequency (Hz) parameter depends on the audio input device. To find the sample rates supported by the audio input device, use the listAudioDevices function as described in List Available ALSA Audio Input Devices.

This parameter specifies the number of rows of the output matrix that the block outputs. The output matrix has dimensions N-by-C, where N is the number of samples per channel, and C is the number of channels.

Introduced in R2013a