Skip to Main Content Skip to Search
Product Documentation

Linux Audio Capture - Capture ALSA audio from sound card and output data

Library

Embedded Coder/ Embedded Targets/ Operating Systems/ Embedded Linux

Simulink Coder/ Desktop Targets/ Operating Systems/ Linux

Description

This block uses the ALSA driver framework to capture an audio stream from a sound card. It outputs the left and right channels of the signal as an [Nx2] frame of int16 values. N is the number of samples per frame.

Dialog

Device

Use the default ALSA device, or enter the name of a specific audio output device.

Entering 'default' selects the ALSA device specified by an ALSA configuration file on your target Linux system.

One of the following ALSA configuration files defines the default device:

  • /etc/asound.conf, which defines system-wide options for all users

  • ~/.asoundrc, which overrides /etc/asound.conf for the current user

The entry that specifies the default device looks similar to this example:

pcm.!default {
    type hw
    card 0
    device 2
}

To enter the name of an alternate audio input device, review the /proc/asound/cards file on your target Linux system. For example, if /proc/asound/cards contained the following entries, you could set the value of Device to 'AudioPCI' :

$ cat /proc/asound/cards

0 [Dummy      ]: Dummy - Dummy
                 Dummy 1

1 [VirMIDI    ]: VirMIDI - VirMIDI
                 Virtual MIDI Card 1

2 [AudioPCI   ]: ENS1371 - Ensoniq AudioPCI
                 Ensoniq AudioPCI ENS1371 at 0xe400, irq 11

The default value for Device is 'default'.

Sample rate (Hz)

Enter a value that matches the sample rate of the ALSA audio output.

By default, the sample rate of the ALSA output equals the output of the audio capture device. In this case, enter the sample rate of the audio capture device.

The /etc/asound.conf and ~/.asoundrc files can configure ALSA to downsample the signal from the audio capture device. In this case, enter the downsample rate specified by the configuration files. For example, if one of the configuration files contained the following entry, you would set the value of Sample rate (Hz) to 16000 :

pcm_slave.sl3 {
    pcm ens1371
    format S16_LE
    channels 1
    rate 16000
}
pcm.complex_convert {
    type plug
    slave sl3
}

The default value for Sample rate (Hz) is 44100 Hz (44.1 kHz). The maximum rate equals the sampling rate of the audio capture device.

Queue duration (seconds)

Set the duration of the queue in seconds. This queue provides a software-based frame buffer between the ALSA output and the Linux Audio Capture block. The queue prevents dropped data caused by temporary mismatches in the rate of data arriving and leaving the queue. Higher values can handle more significant mismatches, but such values also increase signal latency and memory usage.

The default value for Queue duration (seconds) is 0.5 seconds.

Frame size (samples)

Set the number of samples per frame in the output this block sends to your model. The default value for this parameter is 4096 samples.

References

http://www.alsa-project.org

See Also

http://www.alsa-project.org

Linux Audio Playback

Linux Task

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS