From Wave File (Obsolete)

Read audio data from Microsoft Wave (.wav) file

Library

dspwin32

Description

    Note:   The From Wave File block is still supported but is likely to be obsoleted in a future release. We strongly recommend replacing this block with the From Multimedia File block.

The From Wave File block streams 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.

    Note:   AVI files are the only supported file type for non-Windows platforms.

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

y = wavread('filename')							% Equivalent MATLAB code

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. When the file is on the MATLAB® path or in the current folder (the folder returned by typing pwd at the MATLAB command line), you need only specify the file name. You do not need to specify the.wav extension.

    Note:   The From Wave File block does not support .wav file names that contain a + character. To read .wav files that have a + character in the file name, use the From Multimedia File block.

For an audio file containing C channels, the block's output is an M-by-C matrix containing one frame (M consecutive samples) of audio data from each channel. 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

Tfo=MFs

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 (LM). 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.

Use the Data type parameter to specify the data type of the block's output. Your choices are double, single, uint8, or int16.

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.

Use the Number of times to play file parameter to enter the number of times to play the file. The number you enter must be a positive integer or inf, to play the file until you stop the simulation.

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. When you select immediately after last sample, the samples repeat immediately. When 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 start-of-file indicator parameter to determine when the first audio sample in the file is output from the block. When you select this check box, a Boolean output port labeled SOF appears on the block. The output from the SOF port is 1 when the first audio sample in the file is output from the block. Otherwise, the output from the SOF port is 0.

Use the Output end-of-file indicator parameter to determine when the last audio sample in the file is output from the block. When you select this check box, a Boolean output port labeled EOF appears on the block. The output from the EOF port is 1 when the last audio sample in the file is output from the block. Otherwise, the output from the EOF 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

File name

Enter the path and name of the file to read. Paths can be relative or absolute.

    Note:   The From Wave File block does not support .wav file names that contain a + character. To read .wav files that have a + character in the file name, use the From Multimedia File block.

Samples per output frame

Enter the number of samples in each output frame, M. When the value of this parameter is 1, the block outputs a sample-based signal.

Minimum number of samples for each read from file

Enter the number of consecutive samples to acquire from the file with each file access, L.

Data type

Select the output data type: double, single, uint8, or int16. The data type setting determines the output's amplitude range.

Loop

Select this check box if you want to play the file more than once.

Number of times to play file

Enter the number of times you want to play the file.

Samples restart

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

Output start-of-file indicator

Use this check box to determine whether the output contains the first audio sample in the file.

Output end-of-file indicator

Use this check box to determine whether the output contains the last audio sample in the file.

Supported Data Types

  • Double-precision floating point

  • Single-precision floating point

  • 16-bit signed integer

  • 8-bit unsigned integer

See Also

From Audio DeviceDSP System Toolbox
Signal From WorkspaceDSP System Toolbox
To Multimedia FileDSP System Toolbox
wavreadMATLAB

Was this topic helpful?