| Signal Processing Blockset™ | ![]() |
Signal Processing Sources
dspsrcs4
The From Audio Device block reads audio data from an audio device in real time. 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 from which to acquire audio. 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 this list.
Use the Number of channels parameter to specify the number of audio channels in the signal. For example:
Enter 2 if the audio source is two channels (stereo).
Enter 1 if the audio source is single channel (mono).
Enter 6 if you are working with a 5.1 speaker system.
The block's output is an M-by-N matrix, where M is the number of consecutive samples and N is the number of audio channels.
Use the Sample rate (Hz) parameter to specify the number of samples per second in the signal. If the audio data is processed in uncompressed pulse code modulation (PCM) format, it should typically be sampled at one of the standard audio device rates: 8000, 11025, 22050, 44100, or 48000 Hz.
Use the Device data type parameter to specify the data type of the audio data that the device is placing in the buffer. You can choose:
8-bit integer
16-bit integer
24-bit integer
32-bit float
Determine from output data type
If you choose Determine from output data type, the following table summarizes the block's behavior.
| Output 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 output data type and the device does not support a data type, the block uses the next lowest precision data type supported by the device.
Use the Frame size (samples) parameter to specify the number of samples in the block's output. Use the Output data type parameter to specify the data type of audio data output by the block.
The From Audio Device block buffers the data from the audio device using the process illustrated by the following figure.

At the start of the simulation, the audio device begins writing the input data to a buffer. This data has the data type specified by the Device data type parameter.
When the buffer is full, the From Audio Device block writes the contents of the buffer to the queue. Specify the size of this queue using the Queue duration (seconds) parameter.
As the audio device appends audio data to the bottom of the queue, the From Audio Device block pulls data from the top of the queue to fill the Simulink frame. This data has the data type specified by the Output data type parameter.
Select the Automatically determine buffer size check box to allow the block to calculate a conservative buffer size using the following equation:
![]()
In this equation, size is the buffer size, and sr is the sample rate. If you clear this check box, the Buffer size (samples) parameter appears on the block. Use this parameter to specify the buffer size in samples.
When the simulation throughput rate is lower than the hardware throughput rate, the queue, which is initially empty, fills up. If the queue is full, the block drops the incoming data from the audio device. When the simulation throughput rate is higher than the hardware throughput rate, the From Audio Device block waits for new samples to become available.
When Simulink cannot keep up with an audio device that is operating in real time, the queue fills up and the block begins to lose audio data. 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 demand can lag behind the hardware's data supply.
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 queue. If the buffer is too big, Simulink must wait for the device to fill the buffer before it moves 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 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.

Specify the device from which to acquire audio data.
Specify the number of audio channels.
Specify the number of samples per second in the signal.
Specify the data type used by the device to acquire audio data.
Select this check box to enable the block to use a conservative buffer size.
Specify the size of the buffer that the block uses to communicate with the audio device. This parameter is visible when the Automatically determine buffer size check box is cleared.
Specify the size of the queue in seconds.
Specify the number of samples in the block's output signal.
Select the data type of the block's output.
| Port | Supported Data Types |
|---|---|
Output |
|
| From Wave File | Signal Processing Blockset |
| To Audio Device | Signal Processing Blockset |
| audiorecorder | MATLAB |
![]() | Frame Status Conversion | From Multimedia File | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |