From Audio Device - Read audio data from computer's audio device

Library

Signal Processing Sources

dspsrcs4

Description

The From Audio Device block reads audio data from an audio device in real time. This block has the following limitations:

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:

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:

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

Output 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 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.

Buffering

The From Audio Device block buffers the data from the audio device using the process illustrated by the following figure.

  1. 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.

  2. 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.

  3. 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.

Troubleshooting

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:

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.

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.

Dialog Box

Device

Specify the device from which to acquire audio data.

Number of channels

Specify the number of audio channels.

Sample rate (Hz)

Specify the number of samples per second in the signal.

Device data type

Specify the data type used by the device to acquire audio data.

Automatically determine buffer size

Select this check box to enable the block to use a conservative buffer size.

Buffer size (samples)

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.

Queue duration (seconds)

Specify the size of the queue in seconds.

Frame size (samples)

Specify the number of samples in the block's output signal.

Output data type

Select the data type of the block's output.

Supported Data Types

PortSupported Data Types

Output

  • Double-precision floating point

  • Single-precision floating point

  • 32-bit signed integers

  • 16-bit signed integers

  • 8-bit unsigned integers

See Also

From Wave FileSignal Processing Blockset
To Audio DeviceSignal Processing Blockset
audiorecorderMATLAB

  


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