| Signal Processing Blockset™ | ![]() |
Signal Processing Sinks
dspsnks4
The To Audio Device block sends audio data to your computer's audio device. This block has the following limitations:
Not supported for use with the Simulink® Model block.
Not currently supported on Solaris™ platforms.
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:
8-bit integer
16-bit integer
24-bit integer
32-bit float
Determine from input data type
If you choose Determine from input data type, the following table summarizes the block's behavior.
| Input Data Type | Device Data Type |
|---|---|
| Double-precision floating point or single-precision floating point | 32-bit floating point |
| 32-bit integer | 24-bit integer |
| 16-bit integer | 16-bit integer |
| 8-bit integer | 8-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.
The To Audio Device block buffers the data from a Simulink signal using the process illustrated by the following figure.

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.
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.
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.
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:
Increase the queue duration.
The Queue duration (seconds) parameter specifies the duration of the signal, in seconds, that can be buffered during the simulation. This is the maximum length of time that the block's data supply can lag the hardware's data demand.
Increase the buffer size.
The size of the buffer processed in each interrupt from the audio device affects the performance of your model. If the buffer is too small, a large portion of hardware resources are used to write data to the device. If the buffer is too big, Simulink must wait for the device to empty the buffer before it can write the data to the queue, which introduces latency.
Increase the simulation throughput rate.
Two useful methods for improving simulation throughput rates are increasing the signal frame size and compiling the simulation into native code:
Increase frame sizes and convert sample-based signals to frame-based signals throughout the model to reduce the amount of block-to-block communication overhead. This can increase throughput rates in many cases. However, larger frame sizes generally result in greater model latency due to initial buffering operations.
Generate executable code with Real-Time Workshop® code generation software. Native code runs much faster than Simulink and should provide rates adequate for real-time audio processing.
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.
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.
Single channel input — Front center speaker
On systems with two speakers, the front center channel is split between the right and left speakers.
Multichannel input — Channels are assigned to speakers as follows:
One channel — Front center
Two channels — Front left, front right
Four channels — Front left, front right, rear left, rear right
Six channels — Front left, front right, front center, low frequency, rear left, rear right
Eight channels — Front left, front right, front center, low frequency, rear left, rear right, front left center, front right center
For all other channel combinations, the channel assignment is dictated by the audio card.
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:
Windows: DirectSound
Linux: OSS
Mac: CoreAudio
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.
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.

Specify which device to send the audio data to.
Select this check box if you want the block to inherit the sample rate of the audio signal from the input to the block.
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.
Specify the data type of the audio data sent to the device.
Select this check box to allow the block to calculate a conservative buffer size.
Specify the size of the buffer. This parameter is visible when the Automatically determine buffer size check box is cleared.
Specify the size of the queue in seconds.
| Port | Supported Data Types |
|---|---|
Input |
|
| From Audio Device | Signal Processing Blockset |
| To Wave File | Signal Processing Blockset |
| audioplayer | MATLAB |
| sound | MATLAB |
![]() | Toeplitz | To Multimedia File | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |