Send audio data to standard Windows audio device in real time
The To Wave Device block is still supported but is likely to be obsoleted in a future release. We strongly recommend replacing this block with the To Audio Device block.
The To Wave Device block sends audio data to a standard Windows® audio device in real time. It is compatible with most popular Windows hardware, including Sound Blaster cards. The data is sent to the hardware in uncompressed pulse code modulation (PCM) format, and should typically be sampled at one of the standard Windows audio device rates: 8000, 11025, 22050, or 44100 Hz. Some hardware might support other rates in addition to these.
Models that contain both the To Wave Device block and the From Wave Device block require a duplex-capable sound card.
The Use default audio device check box allows the To Wave Device block to detect and use the system's default audio hardware. You should select this option for systems that have a single sound device installed, or when the default sound device on a multiple-device system is your desired target. When the default sound device is not your desired output device, clear Use default audio device, and set the desired hardware in the Audio device parameter. This parameter lists the names of the installed audio devices.
The block input can contain audio data from a mono or stereo signal. A mono signal is represented as either a sample-based scalar or a frame-based length-M vector, where M is frame size. A stereo signal is represented as a sample-based length-2 vector or a frame-based M-by-2 matrix.
When the input data type is
uint8, the block conveys the signal
samples to the audio device using 8 bits. When the input data type is
fixed point with a word length of 16 and a fraction length of 15, the block conveys the
signal samples to the audio device using 16 bits by default. For inputs of data type
single, you can also set the block
to convey the signal samples using 24 bits by selecting the Enable 24-bit
output for double- and single-precision input signals check box. The
24-bit sample width requires more memory but in general yields better fidelity.
The amplitude of the input must be in a valid range that depends on the input data type, as shown in the following table. Amplitudes outside the valid range are clipped to the nearest allowable value.
|Input Data Type||Valid Input Amplitude Range|
Fixed point with a word length of 16 and a fraction length of 15
Because audio devices generate real-time audio output, the Simulink® environment must maintain a continuous flow of data to a device throughout simulation. Delays in passing data to the audio hardware can result in hardware errors or distortion of the output. This means that the To Wave Device block must in principle supply data to the audio hardware as quickly as the hardware reads the data. However, the To Wave Device block often cannot match the throughput rate of the audio hardware, especially when the simulation is running within Simulink rather than as generated code. Simulink execution speed can vary during the simulation as the host operating system services other processes. The block must therefore rely on a buffering strategy to ensure that signal data is available to the hardware on demand.
This block requires real-time execution of the parent model for best performance.
The following block parameters control the memory management for this block:
Automatically determine internal buffer size or User-defined internal buffer size
Initial output delay
The Queue duration parameter defines the overall size of the block's buffer. The block reads in chunks of data in the size of the input dimensions and stores them in the buffer. The internal buffer size defines the dimensions of the block output to the hardware. You can define the internal buffer size yourself in the User-defined internal buffer size parameter. If you select Automatically determine internal buffer size instead, the internal buffer size is calculated for you according to the following rules:
If the input to the block has a frame size of 32 samples or larger, the internal buffer size be the same as the input frame size.
If the input to the block has a frame size smaller than 32 samples, the internal buffer size is based on the input sample rate according to the following table, where
Internal Buffer Size (samples)
To minimize the chance of dropouts, the block checks to make sure that the queue duration is at least as big as twice the internal buffer size. If it is not, the queue duration is automatically set to twice the internal buffer size.
The Initial output delay parameter enables you to preload the buffer before the block starts to output data to the audio device, which can be helpful for models that do not run in real time. However, for real-time applications, it is best to set the initial output delay to zero (one frame of delay), or as close to zero as possible.
If you are getting undesirable audio output using the To Wave Device block, first determine whether your model can run in real time. Replace the To Wave Device block with a To Wave File block, run the model, and compare the model's simulation stop time to the elapsed time on your watch. If the model simulation stop time is less than the elapsed time on your watch, your model can probably run in real time. Then,
If your model can run in real time,
Select Automatically determine internal buffer size. This alone might solve the problem. If not,
Try increasing the Queue duration parameter to a relatively large value, such as 0.5 s.
If one or both of these options restores desirable audio output, you can try reducing the internal buffer size and/or queue duration until the quality of the audio output again degrades.
If your model is not running in real time, try to make it run in real time by
Optimizing the model (using a more efficient implementation), or
Using a Simulink Acceleration (Simulink) mode, or
Generating stand-alone code
If none of these are possible, but the model only runs for a short period of time, set the Queue duration parameter to a size equal to a significant fraction of the model stop time and use a similarly large initial delay. This is not an optimal solution, but might work in some cases.
Specify the overall buffer size. To minimize the chance of dropouts, the block checks to make sure that the queue duration is as least as large as twice the internal buffer size. If it is not, the queue duration is automatically set to twice the internal buffer size.
Select to have the block automatically select the internal buffer size for you. For details, see Buffering.
Define the internal buffer size, or the size of the chunks of data sent by the block to the audio hardware device.
This parameter is only visible when Automatically determine internal buffer size is not selected.
Specify the amount of time by which to delay the initial output to the audio device. During this time data accumulates in the block's buffer. Any value less than or equal to the queue duration specifies the smallest possible initial delay, which is a single frame.
Select to direct audio output to the system's default audio device.
This parameter lists the names of the installed audio devices. Specify the name of the audio device to receive the audio output. Select Use default audio device when the system has only a single audio card installed.
This parameter is only enabled when the Use default audio device check box is not selected.
Select to output 24-bit data when inputs are double- or single-precision. Otherwise, the block outputs 16-bit data for double- and single-precision inputs.
|Port||Supported Data Types|