Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

dsp.AudioFileReader System object

Package: dsp

Stream from audio file

Description

The AudioFileReader object reads audio samples from an audio file.

To read audio samples from an audio file:

  1. Define and set up your audio file reader object. See Construction.

  2. Call step to read audio samples according to the properties of dsp.AudioFileReader. The behavior of step is specific to each object in the toolbox.

    Note:   Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj) and y = obj() perform equivalent operations.

Construction

H = dsp.AudioFileReader returns an audio file reader System object, H that reads audio from an audio file.

H = dsp.AudioFileReader('PropertyName',PropertyValue,...) returns an audio file reader System object, H, with each specified property set to the specified value.

H = dsp.AudioFileReader(Filename,'PropertyName',PropertyValue,...) returns an audio file reader object, H, with Filename property set to FILENAME and other specified properties set to the specified values.

Properties

Filename

Name of audio file from which to read

Specify the name of an audio file as a character vector. Specify the full path for the file only if the file is not on the MATLAB® path. The default is speech_dft.mp3.

PlayCount

Number of times to play file

Specify a positive integer as the number of times to play the file. The default is 1.

SampleRate

Sampling rate of the audio file

This read-only property displays the sampling rate, in Hz, of the audio file.

SamplesPerFrame

Number of samples in audio frame

Specify the number of samples in an audio frame as a positive, scalar integer value. The default value is 1024.

OutputDataType

Data type of output

Set the data type of the audio data output from the audio file reader object. Specify the data type as double| single | int16 | uint8. The default is double.

Supported Platforms and File Types

The following table lists the supported audio file formats:

PlatformsFile Name Extensions
Windows®.wav, .wma, .avi, .aif, .aifc, .aiff, .mp3, .au, .snd, .mp4, .m4a, .flac, .ogg
Non-Windows.avi, .mp3, .mp4, .m4a, .wav, .flac, .ogg, .aif, .aifc, .aiff, .au, .snd

Methods

cloneCreate audio file reader object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs of step method
infoInformation about specific audio file
isDoneEnd-of-file status (logical)
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
resetReset internal states of audio file reader to read from beginning of file
stepRead audio samples from audio file

Examples

expand all

This example shows how to read and play back an audio file using the standard audio output device.

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For dsp.AudioFileReader System object™, myObject() becomes step(myObject). For all other objects, myObject(x) becomes step(myObject,x).

hmfr = dsp.AudioFileReader('speech_dft.mp3');
hap = audioDeviceWriter('SampleRate', hmfr.SampleRate);

while ~isDone(hmfr)
    audio = hmfr();
    hap(audio);
end
release(hmfr);
release(hap);

Algorithms

This object implements the algorithm, inputs, and outputs described on the From Multimedia File block reference page. The object properties correspond to the block parameters, except:

  • The object has no corresponding property for the Inherit sample time from file block parameter. The object always inherits the sample time from the file.

  • The object has no corresponding property for the Output end-of-file indicator parameter. The object always outputs EOF as the last output.

  • The object has no corresponding property for the Multimedia Outputs parameter because audio is the only supported output.

  • The object has no corresponding property for the Image signal block parameter.

  • The object has no corresponding property for the Output color format parameter.

  • The object has no corresponding property for the Video output data type parameter.

Introduced in R2012a

Was this topic helpful?