Documentation

dsp.AudioFileWriter System object

Package: dsp

Write audio samples 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.

Construction

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

The following platform specific restrictions apply when writing these files:

Windows® 7Mac OS X
  • Only sample rates of 44100 and 48000 Hz are supported.

  • Only mono or stereo outputs are allowed.

  • Only mono or stereo outputs 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 must be written to the MPEG-4 AAC file.

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

H = dsp.AudioFileWriter(FILENAME,'PropertyName',PropertyValue,...) returns an audio file writer System object, H. 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 string. 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 Mac OS X 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

cloneCreate audio file writer object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs of step method
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
stepWrite one frame of audio output samples

Examples

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

hmfr = dsp.AudioFileReader('OutputDataType',...
   'double');
hfirdec = dsp.FIRDecimator; % decimate by 2
hmfw = dsp.AudioFileWriter...
   ('speech_dft.wav', ...
   'SampleRate', hmfr.SampleRate/2);

while ~isDone(hmfr)
     audio = step(hmfr);
     audiod = step(hfirdec, audio);
     step(hmfw, audiod);
end

release(hmfr);
release(hmfw);

Troubleshooting

Running an Executable Outside MATLAB

To run your generated standalone executable application in Shell, you need to set your environment to the following:

PlatformCommand
Macsetenv DYLD_LIBRARY_PATH $LD_LIBRARY_PATH: $MATLABROOT/bin/maci64 (csh/tcsh)

export DYLD_LIBRARY_PATH $LD_LIBRARY_PATH: $MATLABROOT/bin/maci64 (Bash)

Linuxsetenv LD_LIBRARY_PATH $LD_LIBRARY_PATH: $MATLABROOT/bin/glnxa64 (csh/tcsh)

export LD_LIBRARY_PATH $LD_LIBRARY_PATH: $MATLABROOT/bin/glnxa64 (Bash)

Windowsset PATH = $MATLABROOT\bin\win32;%PATH%

set PATH = $MATLABROOT\bin\win64;%PATH%

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.

Was this topic helpful?