Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.AudioFileWriter System object

Stream to audio file

Description

The AudioFileWriter object writes audio samples to an audio file.

To write audio samples to an audio file:

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

  2. Call step to write audio samples according to the properties of dsp.AudioFileWriter. 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,x) and y = obj(x) perform equivalent operations.

Construction

afw = dsp.AudioFileWriter returns an audio file writer System object, afw. This object writes audio samples to an audio file.

The following platform-specific restrictions apply when writing these files:

Windows® 7macOS
  • Only sample rates of 44,100 Hz and 48,000 Hz are supported for MPEG-4 AAC file format. For other file formats, there is no restriction on the sample rate.

  • Only mono or stereo outputs are allowed for MPEG-4 AAC file format. For all other formats, more than two audio output channels are allowed.

  • Only mono or stereo outputs are allowed for MPEG-4 AAC file format. For all other formats, more than two audio output channels are allowed.

  • The output data is padded on both the front and back of the signal, with extra samples of silence.

    Windows AAC encoder places sharp fade-in and fade-out on audio signal, causing signal to be slightly longer in samples when written to disk.

  • Not all sampling rates are supported, although the Mac Audio Toolbox API do not explicitly specify a restriction.

  • A minimum of 1025 samples per channel must be written to the MPEG-4 AAC file.

afw = dsp.AudioFileWriter('PropertyName',PropertyValue,...) returns an audio file writer System object, afw, with each specified property set to the specified value.

afw = dsp.AudioFileWriter(FILENAME,'PropertyName',PropertyValue,...) returns an audio file writer System object, afw. This object has the Filename property set to FILENAME and other specified properties set to the specified values.

Properties

Filename

Name of audio file to which to write

Specify the name of the audio file as a character vector. The default is output.wav.

FileFormat

Audio file format

Specify which audio file format the object writes. On Microsoft® platforms, select one of AVI | WAV | FLAC | OGG | MPEG4 | WMA. On Linux® platforms, select one of AVI | WAV | FLAC | OGG. On macOS platforms, select one of AVI | WAV | FLAC | OGG | MPEG4. These abbreviations correspond to the following file formats:

  • AVI: Audio-Video Interleave

  • WAV: Microsoft WAVE Files

  • WMA: Windows Media® Audio

  • FLAC: Free Lossless Audio Codec

  • OGG: Ogg/Vorbis Compressed Audio File

  • MPEG4: MPEG-4 AAC File — You can use both .m4a and .mp4 extensions

The default is WAV.

SampleRate

Sampling rate of audio data stream

Specify the sampling rate of the input audio data as a positive, numeric scalar value. The default is 44100.

Compressor

Algorithm that compresses audio data

Specify the type of compression algorithm the audio file writer uses to compress the audio data. Compression reduces the size of the audio file. Select None (uncompressed) to save uncompressed audio data to the file. The other options available reflect the audio compression algorithms installed on your system. You can use tab completion to query valid Compressor options for your computer by typing H.Compressor = ' and then pressing the tab key. This property applies when writing WAV or AVI files on Windows platforms.

DataType

Data type of the uncompressed audio

Specify the type of uncompressed audio data written to the file as one of inherit, int16, int24, single, or uint8. This property only applies when writing uncompressed WAV files. The default value of this property is int16.

Methods

stepWrite one frame of audio output samples
Common to All System Objects
clone

Create System object with same property values

getNumInputs

Expected number of inputs to a System object

getNumOutputs

Expected number of outputs of a System object

isLocked

Check locked states of a System object (logical)

release

Allow System object property value changes

Examples

expand all

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 example, myObject(x) becomes step(myObject,x).

Decimate an audio signal, and write it to disk as a WAV file.

afr = dsp.AudioFileReader('OutputDataType',...
   'double');
firdec = dsp.FIRDecimator; % decimate by 2
afw = dsp.AudioFileWriter...
   ('speech_dft.wav', ...
   'SampleRate', afr.SampleRate/2);

while ~isDone(afr)
     audio = afr();
     audiod = firdec(audio);
     afw(audiod);
end

release(afr);
release(afw);

Algorithms

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

  • The object FileFormat property does not support video-only file formats.

  • The object has no corresponding property for the Write parameter. The object writes only audio content to files.

  • The object has no corresponding property for the Video compressor parameter.

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

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

Extended Capabilities

Introduced in R2012a

Was this topic helpful?