AudioTools - Maple Programming Help

AudioTools

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

Parameters

 fileName - string; the pathname of the audio file to read optArray - (optional) Array, Vector, or Matrix to read the audio into format=fmtDesc - (optional) specification of the audio file format

Description

 • The Read command reads an audio file in one of the supported formats and returns an Array containing the audio.
 • If optArray is specified, it must be a dense, rectangular, one or two dimensional Array, Vector, or Matrix with datatype=float[8]. If not specified, the Read command will allocate an Array appropriate for the audio data being read.
 • If the option format=fmtDesc is specified, fmtDesc must correspond to one of the values in AudioTools[Formats]. If not specified, the Read attempts to determine the format from the fileName.
 If the audio data has a single channel, the Array will have only one dimension. If the audio data has more than one channel, the Array will have two dimensions.  The second dimension will range from 1 to C where C is the number of channels, 1 for mono, 2 for stereo, and so on.
 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.
 • When Read is passed and Array, Vector, or Matrix, it must be writable and have one or two dimensions. The first dimension must correspond to the length of the audio data, for example $M..M+\mathrm{length}-1$.
 If the second (possibly omitted) dimension does not correspond to the number of channels in the audio data, it will be converted appropriately while being read. For example, reading Stereo audio into a Vector or one-dimensional Array will produce Mono audio data.
 • Sample values are stored in the audio Array, Vector, or Matrix as floating point values ranging from -1.0 to 1.0.
 • On return from Read, the returned Array, Vector, or Matrix will have three numeric attributes describing the data. The first is the sample rate, in samples per second. The second is the number of bits per sample that were recorded in the file. The third is the sub-format of the file, if applicable (or zero otherwise - some file formats, like ".WAV", have a number of sub-formats, like PCM and ADPCM).
 • For compressed formats such as an ADPCM ".WAV" file, Read decompresses the data. The resulting Array, Vector, or Matrix will contain the decompressed data, although the attributes will still reflect the origin of the data. For example, an ADPCM file sampled at 11.025kHz will have attributes $11025,4,2$, since ADPCM records 4 bits per sample, and is sub-format 2.

Examples

 > $\mathrm{audiofile}≔\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/audio/stereo.wav"\right):$
 > $\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]$ (1)
 > $\mathrm{attributes}\left(\mathrm{aud}\right)$
 ${22050}{,}{8}{,}{1}$ (2)
 > ${\mathrm{aud}}_{2000}$
 $\left[\begin{array}{cc}{-}{0.312500000000000}& {0.771653543307087}\end{array}\right]$ (3)
 > $\mathrm{mono}≔\mathrm{ToMono}\left(\mathrm{aud}\right)$
 ${\mathrm{mono}}{:=}\left[\begin{array}{c}{\mathrm{1 .. 19962}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (4)
 > ${\mathrm{mono}}_{2000}$
 ${0.229576771653543}$ (5)