| DSP Blockset | ![]() |
Read audio data from a Microsoft Wave (.wav) file (32-bit Windows operating systems only)
Library
Platform-specific I/O / Windows (WIN32)
Description
The From Wave File block reads audio data from a Microsoft Wave (.wav) file and generates a signal with one of the data types and amplitude ranges in the following table.
| Output Data Type |
Output Amplitude Range |
double |
±1 |
single |
±1 |
int16 |
-32768 to 32767 (-215 to 215 - 1) |
uint8 |
0 to 255 |
The audio data must be in uncompressed pulse code modulation (PCM) format.
The block supports 8-, 16-, 24-, and 32-bit Microsoft Wave (.wav) files.
The File name parameter can specify an absolute or relative path to the file. If the file is on the MATLAB path or in the current directory (the directory returned by typing pwd at the MATLAB command line), you need only specify the file's name. You do not need to specify the.wav extension.
If the audio file contains two channels (stereo), the block's output is an M-by-2 matrix containing one frame (M consecutive samples) of audio data from each of the two channels. If the audio file contains a single channel (mono), the block's output is an M-by-1 matrix containing one frame (M consecutive samples) of mono audio data. The frame size, M, is specified by the Samples per output frame parameter. For M=1, the output is sample based; otherwise, the output is frame based.
The output frame period, Tfo, is
,
where Fs is the data sample rate in Hz.
To reduce the required number of file accesses, the block acquires L consecutive samples from the file during each access, where L is specified by the Minimum number of samples for each read from file parameter (L
M). For L <M, the block instead acquires M consecutive samples during each access. Larger values of L result in fewer file accesses, which reduces run-time overhead.
Select the Loop check box if you want to play the file more than once. Then, enter the number of times to play the file. The number you enter must be a positive integer or inf.
The Samples restart parameter determines whether the samples from the audio file repeat immediately or repeat at the beginning of the next frame output from the output port. If you select immediately after last sample, the samples repeat immediately. If you select at beginning of next frame, the frame containing the last sample value from the audio file is zero padded until the frame is filled. The block then places the first sample of the audio file in the first position of the next output frame.
Use the Output first sample read parameter to determine when the first sample of the audio file is contained within an output frame. If you select this check box, a Boolean output port labeled First appears on the From Wave File block. The output from the First port is 1 when the frame output from the output port contains the first sample of the audio file. Otherwise, the output from the First port is 0.
Use the Output last sample read parameter to determine when the last sample of the audio file is contained within an output frame. If you select this check box, a Boolean output port labeled Last appears on the From Wave File block. The output from the Last port is 1 when the frame output from the output port contains the last sample of the audio file. Otherwise, the output from the Last port is 0.
The block icon shows the name, sample rate (in Hz), number of channels (1 or 2), and sample width (in bits) of the data in the specified audio file. All sample rates are supported; the sample width must be either 8, 16, 24, or 32 bits.
Dialog Box
Double, Single, Uint8, or Int16. The data type setting determines the output's amplitude range, as shown in the table above.
immediately after last sample to repeat the audio file immediately. Select at beginning of next frame to place the first sample of the audio file in the first position of the next output frame.
Supported Data Types
To learn how to convert your data types to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.
See Also
| From Wave Device |
DSP Blockset |
| Signal From Workspace |
DSP Blockset |
| To Wave File |
DSP Blockset |
wavread |
MATLAB |
See Importing WAV Files for related information.
| From Wave Device | Histogram | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |