Audio Capture GenICam Capture navigation bar

Table of Contents

Audio Play

Plays audio samples through the speakers on the target platform.

Library

QUARC Targets/Multimedia

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

qc_open_library('quarc_library/Multimedia')

Description

Audio Play

The Audio Play block plays audio samples through the speakers on the target platform. It takes PCM audio waveforms as input. It can accept multiple channels of audio data.

If multiple Audio Play blocks are in the diagram then the sound from each instance will be mixed if a device capable of mixing is selected. For example, on Windows all devices should support mixing. On Linux, the "demixer" device needs to be selected. The demixer device is defined in the /etc/asound.conf file as using the ALSA dmix plugin to mix audio streams.

The block supports two styles of input: a single matrix input containing the audio for all channels, or separate vector inputs for each channel. If the Number of channels parameter is an empty matrix, then the block will have a single SxC matrix input, where S is the number of samples and C is the number of channels. If the Number of channels parameter is an integer then the block will have one vector input for each channel, where each input must be the same length. The vector length is the number of samples.

The input(s) may be variable-size signals, in which case a different number of samples may be written each sampling instant. This can be useful when the Audio Play block is in a

Triggered Subsystem

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

doc('Triggered Subsystem')
and different sounds are being triggered.

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 Play 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, then providing 4800 audio samples as input would produce 48000 Hz sound at the output.

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 inputs are written to the circular buffer every sampling instant and the data is written to the output device in the background. Hence, the buffer can be filling while sound is being produced.

The use of a buffer also means that entire sound clips can be written to the buffer and then played over time. This capability is particularly useful when the Audio Play block is placed in a Triggered Subsystem. When the trigger occurs, a complete sound clip can be written to the circular buffer and the sound will continue to play until the clip is over, even though the clip may last multiple sampling instants. For instance, this paradigm can be used to honk the horn on the QCar in response to a trigger event.

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 Play block.

Input Ports

chs

When Number of channels is an empty matrix then the block only has one input, the chs input. This input must be an SxC matrix where S is the number of samples and C is the number of channels. If the input is variable-size then the number of samples dimension may vary. The number of channels cannot vary.

0..(N-1)

When Number of channels is a scalar, N, then the block will have N inputs, numbered 0 to N-1. Each input must be a vector containing the samples for one audio channel. All inputs must be the same length. If the input is variable-size then all inputs must have the same length at the same time.

Output Ports

This block has no output ports.

Data Type Support

The input data type may be int16 or single. The single data type is recommended.

Parameters and Dialog Box

Audio Play

Device identifier

This parameter identifies the device to which to output 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 "demixer" or "plughw:1,0". Valid device names can be determined by running the command aplay -L in a Terminal window or looking in the /etc/asound.conf file.

On the QCar, the "demixer" device is recommended because it allows multiple Audio Play blocks to be placed in a model, all sharing the same audio device. Note that the destination of the "demixer" will depend on whether an HDMI cable is plugged into the car or not. If no HDMI cable is plugged in then the output will go to the car speaker. Otherwise, it will go to the monitor.

Sample rate (tunable offline)

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

Number of channels

The number of audio channels as a strictly positive integer scalar. The block will have one input for each channel. Alternatively, if this parameter is set to the empty matrix, [], then the block will accept a single matrix input with dimensions SxC, where S is the number of samples and C is the number of channels.

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 input to the block. If continuous sound is being produced then it is recommended to make the buffer size at least twice the size of the input.

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.

A sample time of -1 indicates that the block inherits its sample time from the input. The block inherits the sample time by default.

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.

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