AudioTools[Read] - reads audio data from a file into an Array, Vector, or Matrix
|
Calling Sequence
|
|
Read(fileName, optArray, format=fmtDesc)
|
|
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 .
|
|
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 , since ADPCM records 4 bits per sample, and is sub-format 2.
|
|
|
Examples
|
|
>
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
|
|