Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

The AudioFile class describes the properties of audio files.

On this page:

Classes

AudioFile Class

Description

The AudioFile.open function creates an AudioFile object of the specified audio file. The AudioFile object can be used to retrieve information from the audio file, for example, the sample rate, bit depth, length in samples,etc. The AudioFile object has the following fields.

All fields of the AudioFile object are read only.

Available in: Controller.

Fields

.validThis field indicates if the file is a valid audio file and whether it could be opened or not.boolean
.fileNameThe file name that has been used for opening the audio file.string
.rateThe sample rate of the audio file. Returns nil if the audio file could not be opened or is invalid.number
.bitsThe bit depth of the audio file. Returns nil if the audio file could not be opened or is invalid.number
.channelsThe number of channels of the audio file. Returns nil if the audio file could not be opened or is invalid.number
.lengthThe number of samples in the audio file. Returns nil if the audio file could not be opened or is invalid.number
.rootKeyThe root key stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.keyLowThe lowest key of the key range stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.keyHighThe highest key of the key range stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.velLowThe lowest velocity of the velocity range stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.velHighThe highest velocity of the velocity range stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.detuneThe tune offset in cents stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.levelThe level offset in dB stored in the sampler chunk of the audio file. Returns nil if the audio file does not contain an appropriate sampler chunk or could not be opened or is invalid.number
.tempoThe tempo in bpm stored in a data chunk of the audio file. Returns nil if the audio file does not contain an appropriate data chunk or could not be opened or is invalid.number
.beatsThe number of beats stored in a data chunk of the audio file. Returns nil if the audio file does not contain an appropriate data chunk or could not be opened or is invalid.number
.signatureA pair of values for the numerator and denumerator of the signature stored in a data chunk of the audio file. The values are nil if the audio file does not contain an appropriate data chunk or could not be opened or is invalid.number, number
.sampleStartThe position of the sample start in samples stored in a data chunk of the audio file. Returns nil if the audio file does not contain an appropriate data chunk or could not be opened or is invalid.number
.sampleEndThe position of the sample end in samples stored in a data chunk of the audio file. Returns nil if the audio file does not contain an appropriate data chunk or could not be opened or is invalid.number
.loopsThe loop start and end positions in samples stored in a data chunk of the audio file. The returned table is an array that contains tables with the fields loopStart and loopEnd for each loop. Returns nil if the audio file does not contain an appropriate data chunk or could not be opened or is invalid.table

Example

-- open an audio file from Skylab
fname = "vstsound://F29C895D6D8E4D6C9BCBBA5198412192/.samples/Ambient Pad 01/Ambient Pad 01 - C3.tg3c"
af = AudioFile.open(fname)
-- print information from the audio file
if af.valid then
  print(fname, "opened.")
  print("Sample Rate: ", af.rate)
  print("Bit Depth: ", af.bits)
  print("Channels: ", af.channels)
  print("Sample Length: ", af.length)
else
  print(fname, "does not exist.")
end

Jump to Top

Methods

getPeak

getPeak(start, length, rms)

Description

Available in: Controller.

Arguments

startThe start position in samples.number
lengthThe duration in samples. Set this to equal to or less than 0 to use all samples from the specified start to the end of the file.number
rmsIf this is set to 0, the peak level of the specified range will be returned. If this is set to a value above 0, the RMS level over the specified range will be calculated.number

Return Values

Returns the level of the specifed range as a linear value. The example shows how to convert the value from linear to dB.

Example

function lin2db(lin)
  return 20 * math.log(lin) / math.log(10)
end
fname = "vstsound://F29C895D6D8E4D6C9BCBBA5198412192/.samples/Ambient Pad 01/Ambient Pad 01 - C3.tg3c" 
af = AudioFile.open(fname)
-- analyze the peak level in the first 1000 samples
attpeak = af:getPeak(0, 1000, 0)
-- analyze the RMS level in the range from 1000 samples till the end of the file
susrms = af:getPeak(1000, -1, 1)
print("Attack Peak:", attpeak, "(", lin2db(attpeak), "dB )")
print("Sustain RMS:", susrms, "(", lin2db(susrms), "dB )")

Jump to Top

  • No labels