Play to sound card
Audio Toolbox / Sinks
DSP System Toolbox / Sinks
The Audio Device Writer block writes audio samples to an audio output device.
Parameters of the Audio Device Writer block specify the driver, the device, and device attributes such as sample rate and bit depth.
Data Flow of Audio Device Writer Block
An audio signal frame is input to the Audio Device Writer block.
The Audio Device Writer block uses the specified driver to pass the frame (device input) to your specified audio device buffer.
The audio device performs digital-to-analog conversion at the specified sample rate and bit depth.
The audio device outputs an analog chunk to your speaker.
Port_1— Input signal
If input to the Audio Device Writer block is
of data type
the block clips values outside the range [–1, 1]. For other
data types, the allowed input range is [min, max] of the specified
Port_1— Number of samples underrun
This port outputs the number of samples underrun while writing a frame of data (one input matrix).
To enable this port, select the Output number of samples underrun parameter.
Driver— Driver used to access your audio device
ASIO drivers do not come pre-installed on Windows machines. To use
ASIO driver option, install an ASIO
driver outside of MATLAB®.
If Driver is set to
ASIO, open the ASIO UI
outside of MATLAB to set the sound card buffer size to the frame
size (number of rows) input to the Audio Device
Writer block. See the documentation of your ASIO
driver for more information.
WASAPI drivers are supported for exclusive-mode only.
ASIO and WASAPI drivers do not provide sample rate conversion. For ASIO and WASAPI drivers, supply an audio stream with a sample rate supported by your audio device.
This parameter applies only on Windows machines. Linux machines always use the ALSA driver. Mac machines always use the CoreAudio driver.
To specify nondefault Driver values, you must install Audio Toolbox™. If the toolbox is not installed, specifying nondefault Driver values returns an error.
Device— Device used to play audio samples
The device list is populated with devices available on your computer.
Info— View information about your audio output configuration
This button opens a dialog box that lists your selected audio driver, the full name of your audio device, and the maximum output channels for your configuration. For example:
Inherit sample rate from input— Specify source of input sample rate
When you select this parameter, the block inherits its sample rate from the input signal. When you clear this parameter, you specify the sample rate in Sample rate (Hz).
Sample rate (Hz)— Sample rate used by device to play audio data
44100(default) | positive scalar
The possible range of Sample rate (Hz) depends on your audio hardware.
To enable this parameter, clear the Inherit sample rate from input parameter.
Device bit depth— Data type used by device to perform digital-to-analog conversion
16-bit integer(default) |
Before performing digital-to-analog conversion, the input data is cast to a data type specified by this parameter.
To specify a nondefault Device bit depth, you must install Audio Toolbox. If the toolbox is not installed, specifying a nondefault Device bit depth returns an error.
Use default channel mapping— Toggle channel mapping source
When you select this parameter, the block uses the default mapping between columns of the matrix input to this block and the channels of your device. When you clear this parameter, you specify the mapping in Device output channels.
Device output channels— Specify nondefault channel mapping
[1:MaximumOutputChannels](default) | scalar | vector
Nondefault mapping between columns of matrix input to the Audio Device Writer block and channels of output device, specified as a scalar or vector. For example:
If Device output channels is specified as
The first column of the input matrix maps to channel 1.
The second column of the input matrix maps to channel 2.
The third column of the input matrix maps to channel 3.
If Device output channels is specified as
The first column of the input matrix maps to channel 3.
The second column of the input matrix maps to channel 1.
The third column of the input matrix maps to channel 2.
To selectively map between columns of the input matrix and your sound card's output channels, you must install Audio Toolbox. If the toolbox is not installed, specifying nondefault values for Device output channels returns an error.
To enable this parameter, clear the Use default mapping between columns of input of this block and sound card’s output channels parameter.
Output number of samples underrun— Specify output port for number of samples underrun
When you select this parameter, an output port is added to the block. The port outputs the number of samples underrun while writing a frame of data (one input matrix).
The following code generation limitations apply:
Host computer only. Excludes Simulink® Desktop Real-Time™ code generation.
The executable generated from this block relies on prebuilt dynamic
library files (
.dll files) included with MATLAB. Use the
packNGo function to package the
code generated from this block and all the relevant files in a compressed
zip file. Using this zip file, you can relocate, unpack, and rebuild your
project in another development environment where MATLAB is not installed. For more details, see How To Run a Generated Executable Outside MATLAB.