Skip to content

Audio

An Object representing an audio.


properties

Data : {buffer}

The data represented as a table of 32bit float buffers.
Each buffer represents 1 audio channel.

SampleRate : number

The sample rate in hz.

Frames : number

The ammount of frames per channel.

Duration : number

The duration of the audio in seconds.

Channels : number

The ammount of audio channels in the audio.


methods

Encode -> buffer

Image:Encode(format: AudioFormat): buffer

Encodes the audio into a certain audio format.

Clone -> Audio

Image:Clone(self): Audio  

Clones your audio.

Reverse -> Audio

Image:Reverse(self): Audio  

Reverses the audio data.

Amplify -> Audio

Image:Amplify(decibel: number): Audio  

Increases the volume by a set gain.

Normalise -> Audio

Image:Normalise(decibel: number?): Audio  

Does a peak normalisation targetting the provided decibel level. If no target was provided then it will target 0 dBFS.

FadeIn -> Audio

Image:FadeIn(duration: number): Audio  

Adds a linear fade in that lasts for the given duration.

FadeOut -> Audio

Image:FadeOut(duration: number): Audio  

Adds a linear fade out at the end of the audio that lasts for the given duration.

Trim -> Audio

Image:Trim(
    start: number,
    stop: number?
): Audio      

Trims down the audio to be between a start and a optional stop time.

Lowpass -> Audio

Image:Lowpass(
    frequency: number,
    q: number?
): Audio      

Applies a lowpass filter over the audio.

Highpass -> Audio

Image:Highpass(
    frequency: number,
    q: number?
): Audio      

Applies a highpass filter over the audio.

Notch -> Audio

Image:Notch(
    center_hz: number,
    q: number?
): Audio      

Applies a notch filter over the audio.

Resample -> Audio

Image:Resample(
    sample_rate: number,
    filter: AudioResampleFilter
): Audio      

Resamples the audio to the provided sample rate; Interpolation filters supported:

  • HERMITE - interpolates from 4 points and their gradients.
  • LINEAR - linear interpolation between 2 points
  • LANCZOS3 - interpolation using 6 points

Append -> Audio

Image:Append(
    other: Audio,
    start: number?,
    stop: number?,
    crossfade: number?
): Audio 

Appends another audio file to the end of this audio file.

Overlay -> Audio

Image:Overlay(
    other: Audio,
    position: number?,
    loop : boolean?
): Audio 

overlays two audio files together.

HardClip -> Audio

Image:HardClip(threshold: number): Audio 

Strictly clamps the audio to below the threshold.

SoftClip -> Audio

Image:SoftClip(threshold: number): Audio 

Clamps the audio to below the threshold while preserving peaks.

Saturate -> Audio

Image:Saturate(
    drive: number,
    mode : AudioSaturationMode?
): Audio 

Saturates the audio using a drive parameter. modes supported:

  • TANH - warmer and smoother saturations.
  • ARCTAN - more aggressive saturations.

Compress -> Audio

Image:Compress(config: AudioCompressConfig): Audio 

Compresses the dynamic range of the audio, making quiet sounds louder and loud sounds quieter.


metamethods

__tostring -> string

Converts the audio into a string in the format audio [Channels]ch [SampleRate]Hz [Frames] frames


types

AudioFormat

type AudioFormat = "WAV" | "FLAC"

AudioResampleFilter

type AudioResampleFilter = "HERMITE" | "LINEAR" | "LANCZOS3"

AudioSaturationMode

type AudioSaturationMode = "TANH" | "ARCTAN"

AudioCompressConfig

type AudioCompressConfig = {
    -- Ammount of gain to add before compressing.
    Input : number?,
    -- Ammount of gain to add after compressing.
    Output : number?,
    -- Volume level (in decibels) to start compressing.
    Threshold : number?,
    -- Ammount to compress by as a ratio.
    Ratio : number?,
    -- How long it takes for the compressor to react.
    Attack : number?,
    -- How long it takes for the compressor to decompress.
    Release : number?,
    -- Softens the transition between uncompressed and compressed.
    Knee : number?
}