Start of trail Audio Play navigation bar

Table of Contents

Audio Capture

Captures audio samples through the microphones on the target platform.

Library

QUARC Targets/Multimedia

Description

Audio Capture

The Audio Capture block captures audio samples through the microphones on the target platform. It produces PCM audio waveforms as output. It can output multiple channels of audio data. It can also read audio from a file on the target system.

There should only be one Audio Capture block per sound device.

The block supports two styles of output: a single matrix output containing the audio for all channels, or separate vector outputs for each channel. If the Use output for each channel parameter is not checked, then the block will have a single SxC matrix output, where S is the number of samples and C is the number of channels. If the Use output for each channel parameter is checked then the block will have one vector output for each channel, where the length of each output vector will be the number of samples. The number of samples will be the sample time multiplied by the sample rate.

Audio sample rates are generally faster than a Simulink model may run. For example, typical sample rates are 44100 Hz or 48000 Hz. Hence, the Audio Capture block is designed to process multiple audio samples every time the block executes. For instance, if the block's sample time is 0.1 seconds and the sample rate is 48000 Hz, then the block will produce 4800 audio samples each sampling instant.

To ensure uninterrupted audio, the block maintains a circular buffer, whose size in samples is specified in the Audio buffer size in samples parameter. The audio samples are read from the input device in the background and stored in the circular buffer. Then the audio samples are read from the circular buffer every sampling instant and output from the block. Hence, the buffer can be filling at the same time samples are being output from the block.

Limitations

Sampling rates

Warning On Windows, an audio resampler is used if the requested sample rate does not match the sample rate supported by the underlying audio hardware. However, the audio resampler only accepts floating-point PCM samples, so the single data type is recommended for audio samples. If the int16 data type is used then a sample rate of 48000 Hz will likely have to be selected. This restriction may be removed in future releases.

Helpful Hints

Sample times

Hint Sample times that are too fast are not recommended. Better quality sound is likely to be produced using slower sample times, such as 0.1 seconds, rather than faster sample times because of the nature of the underlying audio subsystems involved.

Configuration Requirements

Audio Toolbox

Configure To use the Audio Toolbox with QUARC for Windows, add MATLAB's bin\win64 folder (e.g. C:\Program Files\MATLAB\R2020a\bin\win64) to the system PATH environment variable and then reboot. This step only needs to be done once. Otherwise a runtime error will occur complaining of a missing hostlibaudio.dll. Note that the Audio Toolbox is not required to use the Audio Capture block.

Input Ports

trig

A trigger input that is only available when the Source of audio parameter is set to file and the Audio mode parameter is set to play on each trigger. A rising or falling edge at this input causes the sound to be repeated. Which edge(s) is used depends on the Trigger type parameter. It may be any of the built-in Simulink data types.

Output Ports

chs

When Use output for each channel is not checked then the block only has one output, the chs output. This output will be an SxC matrix where S is the number of samples and C is the number of channels.

0..(N-1)

When Use output for each channel is checked then the block will have N outputs, numbered 0 to N-1. Each output will be a vector containing the samples for one audio channel.

new

The new output is an integer scalar containing the number of samples that are valid in the output. If this output is zero then there is no new data. Any unused elements in the output are set to zero (silence).

Data Type Support

The output data type may be int16 or single. The single data type is recommended. The data type is set using the Output data type parameter.

Parameters and Dialog Box

Main Pane

The Main pane of the dialog appears as follows:

Audio Capture Main tab

Source of audio

This parameter determines whether the audio will come from a device or a file.

Device identifier

This parameter identifies the device from which to input the audio samples. On Windows, it is a positive integer scalar indicating the device to use. On Linux, it may also be an integer device number or it may be a PCM device name, such as "plughw:1,0" or "plughw:1,1". Valid device names can be determined by running the command arecord -L in a Terminal window or looking in the /etc/asound.conf file.

On the QCar, the "plughw:1,0" device corresponds to the rear microphones, and the "plughw:1,1" device corresponds to the front microphones.

This parameter is only visible when the Source of audio parameter is set to device.

Filename

The filename containing the audio samples. The file types supported depends on the platform, although WAV files are supported on all platforms. If a relative path is specified then it will be relative to the current directory of the model (see the MEX file arguments on the Interface tab of the Configuration Parameters).

This parameter is only visible when the Source of audio parameter is set to file.

Audio mode

Indicates how the file should be played. There are three options: play once at model start, repeat continuously from model start and play once on each trigger. The play once at model start option causes the file to be played only once, as soon as the model is started. The repeat continuously from model start option causes the file to be played repeatedly as soon as the model is started. Finally, when the play once on each trigger option is selected the block provides an additional trig input, which triggers playing of the file. The Trigger type parameter determines what constitutes a trigger event. The file is not played to a speaker, but rather the audio PCM data from the file is produced at the output(s) of the block.

This parameter is only visible when the Source of audio parameter is set to file.

Trigger type

This parameter determines what constitutes a trigger event at the trig input. If it is set to rising then a rising edge at the input causes the file to be played. If it is set to falling then a falling edge at the input causes the file to be played. Finally, if it is set to either then either a rising or falling edge at the input causes the file to be played. The file is not played to a speaker, but rather the audio PCM data from the file is produced at the output(s) of the block.

This parameter is only visible when the Source of audio parameter is set to file.

Sample rate (tunable offline)

The sample rate to use for capturing the audio samples, in Hertz.

Number of channels

The number of audio channels as a strictly positive integer scalar. The block will have one output for each channel if the Use output for each channel parameter is checked. If it is not checked, then the block will output a single matrix input with dimensions SxC, where S is the number of samples and C is the number of channels. The number of samples will be the sample time multiplied by the sample rate.

Audio buffer size in samples (tunable offline)

The size of the circular buffer used to store audio samples. The block will maintain a buffer of this size for each channel, so it is not necessary to scale this value with the number of channels. The size should be at least as large as the output from the block. If continuous sound is being produced then it is recommended to make the buffer size at least twice the size of the output.

Sample time

The sample time of the block. A sample time of 0 indicates that the block will be treated as a continuous time block. A positive sample time indicates that the block is a discrete time block with the given sample time.

Since the Audio Capture block is a source block it does not support an inherited sample time.

To set the sample time to the fundamental sampling time of the model, use the qc_get_step_size function, which is a QUARC function that returns the fundamental sampling time of the model. The fundamental sampling time of the model is the sampling time entered in the Fixed step size field of the Solver pane of the Configuration parameters dialog.

Output Pane

The Output pane of the dialog appears as follows:

Audio Capture Output tab

Output data type

Sets the data type of the output. The single data type is recommended.

Use output for each channel

If this option is checked then the block will have a separate output for each audio channel. Otherwise it will have a single SxC matrix output where S is the number of samples and C is the number of channels.

Targets

Target Name

Compatible*

Model Referencing

Comments

QUARC Win32 Target

Yes

Yes

QUARC Win64 Target

Yes

Yes

QUARC Linux Nvidia Target

Yes

Yes

QUARC Linux QBot Platform Target

No

No

Not currently supported

QUARC Linux QCar 2 Target

No

No

Not currently supported

QUARC Linux QDrone 2 Target

No

No

Not currently supported

QUARC Linux Raspberry Pi 3 Target

No

No

Not currently supported

QUARC Linux Raspberry Pi 4 Target

No

No

Not currently supported

QUARC Linux RT ARMv7 Target

No

No

Not currently supported

QUARC Linux x64 Target

No

No

Not currently supported

QUARC Linux DuoVero Target

No

No

Not currently supported

QUARC Linux DuoVero 2016 Target

No

No

Not currently supported

QUARC Linux Verdex Target

No

No

Not currently supported

QUARC QNX x86 Target

No

No

Last fully supported in QUARC 2018.

Rapid Simulation (RSIM) Target

No

No

Not currently supported

S-Function Target

No

N/A

Old technology. Use model referencing instead.

Normal simulation

No

No

Not currently supported

* Compatible means that the block can be compiled for the target.

See Also

 

navigation bar