To Audio Device - Write audio data to computer's audio device

Library

Signal Processing Sinks

dspsnks4

Description

The To Audio Device block sends audio data to your computer's audio device. This block has the following limitations:

Use the Device parameter to specify the device to which you want to send the audio data. This parameter is automatically populated based on the audio devices installed on your system. If you plug or unplug an audio device from your system, type clear mex at the MATLAB® command prompt to update the list.

Select the Inherit sample rate from input check box if you want the block to inherit the sample rate of the audio signal from the input to the block. If you clear this check box, the Sample rate (Hz) parameter appears on the block. Use this parameter to specify the number of samples per second in the signal.

Use the Device data type to specify the data type of the audio data that is sent to the device. You can choose:

If you choose Determine from input data type, the following table summarizes the block's behavior.

Input Data TypeDevice Data Type
Double-precision floating point or single-precision floating point32-bit floating point
32-bit integer24-bit integer
16-bit integer16-bit integer
8-bit integer8-bit integer

If you choose Determine from input data type and the device does not support the input data type, the block uses the next lowest-precision data type supported by the device.

Buffering

The To Audio Device block buffers the data from a Simulink signal using the process illustrated by the following figure.

  1. At the start of the simulation, the queue is filled with silence. Specify the size of this queue using the Queue duration (seconds) parameter. As Simulink runs, the block appends Simulink frames to the bottom of the queue.

  2. At each time step, the blocks sends a buffer of samples from the top of the queue to the audio device. Select the Automatically determine buffer size check box to allow the block to use a conservative buffer size. See the From Audio Device block reference page for the equation the block uses to calculate this buffer size. If you clear this check box, the Buffer size (samples) parameter appears on the block. Use this parameter to specify the size of the buffer in samples.

  3. The block writes the buffer of audio data to the device. If the queue did not contain enough data to completely fill the buffer, the block fills the remaining portion of the buffer with zeros. This data has a the data type specified by the Device data type parameter.

When the simulation throughput rate is lower than the hardware throughput rate, the queue, which is initially full, becomes empty. If the queue is empty, the block sends zeros (silence) to the audio device. When the simulation throughput rate is higher than the hardware throughput rate, the To Audio Device block waits to write data to the queue.

To minimize the chance of dropouts, the block checks to make sure the queue duration is at least as large as the maximum of the buffer size and the frame size. If it is not, the queue duration is automatically set to this maximum value.

Troubleshooting

When Simulink cannot keep up with an audio device that is operating in real time, the queue becomes empty and gaps occur in the audio data that the block sends to the device. Here are several ways to deal with this situation:

Other ways to improve throughput rates include simplifying the model and running the simulation on a faster PC processor. For other ideas on improving simulation performance, see Delay and Latency and Improving Simulation Performance and Accuracy in the Simulink documentation.

Channel-to-Speaker Mapping on Windows® Operating Systems

The To Audio Device and From Audio Device blocks can support multiple channels. On Windows® operating systems, the channel-to-speaker mapping is defined as listed below. This mapping only applies when your sound card is properly configured and capable of receiving the audio data you send. If the number of channels on the card does not match the number of channels on the block, or if you specify a data type for the Device data type parameter that is not supported by your device, the Windows mixer intervenes to translate from one format to another. If the Windows mixer does intervene, the channel-to-speaker mapping might differ from what is specified here.

Audio Hardware API

The To Audio Device and From Audio Device blocks use the open-source PortAudio library in order to communicate with the audio hardware on a given computer. The PortAudio library supports a range of API's designed to communicate with the audio hardware on a given platform. The following API choices were made when building the PortAudio library for the Signal Processing Blockset™ product:

If you are interested in using a different audio API, such as ASIO (Windows) or ALSA (Linux®) please search for PortAudio on the Matlab Central website.

Example

See the Positional Audio demo for an example of how to use this block. You can open this demo by typing dspAudioPos at the MATLAB command line.

Dialog Box

Device

Specify which device to send the audio data to.

Inherit sample rate from input

Select this check box if you want the block to inherit the sample rate of the audio signal from the input to the block.

Sample rate (Hz)

Specify the number of samples per second in the signal. This parameter is visible when the Inherit sample rate from input check box is cleared.

Device data type

Specify the data type of the audio data sent to the device.

Automatically determine buffer size

Select this check box to allow the block to calculate a conservative buffer size.

Buffer size (samples)

Specify the size of the buffer. This parameter is visible when the Automatically determine buffer size check box is cleared.

Queue duration (seconds)

Specify the size of the queue in seconds.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating point

  • Single-precision floating point

  • 32-bit signed integers

  • 16-bit signed integers

  • 8-bit unsigned integers

See Also

From Audio DeviceSignal Processing Blockset
To Wave FileSignal Processing Blockset
audioplayerMATLAB
soundMATLAB

  


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