AudioTools - Maple Programming Help

Home : Support : Online Help : Programming : Audio Processing : AudioTools/Write

AudioTools

 Write
 writes audio data from an Array, Matrix, or Vector into a file

 Calling Sequence Write(fileName, audArray, format=fmtDesc)

Parameters

 fileName - string; the pathname of the audio file to write to audArray - the Array, Matrix, or Vector containing the audio data to write format=fmtDesc - (optional) specification of the audio file format

Description

 • The Write command writes audio data from an Array, Matrix, or Vector into a file in one of the supported formats.
 • The audArray parameter must be a dense, rectangular, one or two dimensional Array, Matrix, or Vector with datatype=float[8].
 • If the option format=fmtDesc is specified, fmtDesc must correspond to one of the values in AudioTools[Formats]. Currently, the AudioTools package supports only WAVE files.  If not specified, the Write command attempts to determine the format from the fileName.
 • Write returns the number of bytes written.
 • If the audArray has one dimension, the audio data is assumed to be monophonic, and is written to the file accordingly. A two-dimensional audArray is written as stereo (or more channels), according to the size of the second dimension.
 The first dimension of the Array corresponds to the length, in samples, of the audio data. A single channel occupies a single column in the Array.
 • Samples values in the audArray are assumed to range from -1.0 to 1.0, and are scaled to the sample size when written into the file. Sample values less than -1.0 become the lowest allowed sample value.  Values greater than 1.0 become the highest allowed sample value.
 • The attributes of the audArray provide additional information on how the data is to be written to the file.
 The first attribute specifies the number of samples per second that the data in the audArray represents.
 The second attribute specifies the number of bits per sample that should be used when writing to the file, by default, this is set to the number of bits per sample of the file the data was read from originally. For file formats that do not allow the number of bits per sample to be specified, this is ignored.
 The third attribute specifies the sub-format to use. For file formats that have no sub-formats, this is ignored.
 • Write currently does not support writing any compressed formats. Only uncompressed (PCM) WAVE format is supported. If writing audio data that was originally Read in compressed (ADPCM) WAVE format, Write will save it in uncompressed format, and issue a warning.

Examples

 > $\mathrm{audiofile}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/audio/stereo.wav"\right)$
 ${\mathrm{audiofile}}{≔}{"/usr/local/repository/build/rdgetroll1/maple/slot1/data/audio/stereo.wav"}$ (1)
 > $\mathrm{with}\left(\mathrm{AudioTools}\right):$
 > $\mathrm{aud}≔\mathrm{Read}\left(\mathrm{audiofile}\right)$
 ${\mathrm{aud}}{≔}\left[\begin{array}{c}{\mathrm{1..19962 x 1..2}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (2)
 > $\mathrm{Write}\left(\mathrm{cat}\left(\mathrm{getenv}\left("TESTERTMP"\right),"/copy_of_stereo.wav"\right),\mathrm{aud}\right)$
 ${39968}$ (3)
 > $\mathrm{aud}≔\mathrm{Resample}\left(\mathrm{ToMono}\left(\mathrm{aud}\right),11025\right)$
 ${\mathrm{aud}}{≔}\left[\begin{array}{c}{\mathrm{1 .. 9981}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (4)
 > $\mathrm{Write}\left(\mathrm{cat}\left(\mathrm{getenv}\left("TESTERTMP"\right),"/small_stereo.wav"\right),\mathrm{aud}\right)$
 ${10025}$ (5)