AUKit
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
aukit::Audio Class Reference

The aukit.Audio class represents a chunk of audio with variable channels and sample rate. More...

Public Member Functions

number channels ()
 Returns the number of channels in the audio object.
 
aukit Audio combine (aukit.Audio ...)
 Combines the channels of this audio object with another, adding the new channels on the end of the new object, resampling the new channels to match this one (if necessary), and extending any channels that are shorter than the longest channel with zeroes.
 
aukit Audio concat (aukit.Audio ...)
 Concatenates this audio object with another, adding the contents of each new channel to the end of each old channel, resampling the new channels to match this one (if necessary), and inserting silence in any missing channels.
 
string dfpwm (boolean? interleaved)
 Converts the audio data to DFPWM. All channels share the same encoder, and channels are stored sequentially uninterleaved if interleaved is false, or in one interleaved string if interleaved is true. if interleaved is true)
 
number len ()
 Returns the length of the audio object in seconds.
 
aukit Audio mix (number ¦ Audio amplifier, aukit.Audio ...)
 Mixes two or more audio objects into a single object, amplifying each sample with a multiplier (before clipping) if desired, and clipping any values outside the audio range ([-1, 1]). Channels that are shorter are padded with zeroes at the end, and non-existent channels are replaced with all zeroes. Any audio objects with a different sample rate are resampled to match this one.
 
aukit Audio mono ()
 Mixes down all channels to a new mono-channel audio object.
 
number❲❳ ¦ nil pcm (number? bitDepth,("float" ¦ "signed" ¦ "unsigned")? dataType, boolean? interleaved)
 Converts the audio data to raw PCM samples.
 
aukit Audio rep (number count)
 Returns a new audio object that repeats this audio a number of times.
 
aukit Audio resample (number sampleRate,("cubic" ¦ "linear" ¦ "none")? interpolation)
 Creates a new audio object with the data resampled to a different sample rate. If the target rate is the same, the object is copied without modification.
 
aukit Audio reverse ()
 Returns a reversed version of this audio.
 
aukit Audio split (number❲❳ ...)
 Splits this audio object into one or more objects with the specified channels. Passing a channel that doesn't exist will throw an error.
 
function‚ number stream (number? chunkSize, number? bitDepth,("float" ¦ "signed" ¦ "unsigned")? dataType)
 Returns a function that can be called to encode PCM samples in chunks. This is useful as a for iterator, and can be used with aukit.play. chunks of each channel's data as arrays of signed 8-bit 48kHz PCM, as well as the current position of the audio in seconds.
 
aukit Audio sub (number? start, number? last)
 Takes a subregion of the audio and returns a new audio object with its contents. This takes the same arguments as string.sub, but positions start at 0.
 
string wav (number? bitDepth)
 Coverts the audio data to a WAV file.
 

Public Attributes

number❲❳❲❳ data
 The samples in each channel.
 
❴ bitDepth→ number ¦ nil‚ dataType→ string ¦ nil ❵ info
 Stores any decoder-specific information, including bitDepth and dataType.
 
table metadata
 Stores any metadata read from the file if present.
 
number sampleRate
 The sample rate of the audio.
 

Detailed Description

The aukit.Audio class represents a chunk of audio with variable channels and sample rate.

Member Function Documentation

◆ channels()

number aukit::Audio::channels ( )

Returns the number of channels in the audio object.

Returns
(number) The number of channels

◆ combine()

aukit Audio aukit::Audio::combine ( aukit. Audio ...)

Combines the channels of this audio object with another, adding the new channels on the end of the new object, resampling the new channels to match this one (if necessary), and extending any channels that are shorter than the longest channel with zeroes.

Parameters
...(aukit.Audio) The audio objects to combine with
Returns
(aukit.Audio) The new combined audio object

◆ concat()

aukit Audio aukit::Audio::concat ( aukit. Audio ...)

Concatenates this audio object with another, adding the contents of each new channel to the end of each old channel, resampling the new channels to match this one (if necessary), and inserting silence in any missing channels.

Parameters
...(aukit.Audio) The audio objects to concatenate
Returns
(aukit.Audio) The new concatenated audio object

◆ dfpwm()

string aukit::Audio::dfpwm ( boolean? interleaved)

Converts the audio data to DFPWM. All channels share the same encoder, and channels are stored sequentially uninterleaved if interleaved is false, or in one interleaved string if interleaved is true. if interleaved is true)

Parameters
interleaved(boolean?) Whether to interleave the channels
Returns
(string) The resulting DFPWM data for each channel (only one string

◆ len()

number aukit::Audio::len ( )

Returns the length of the audio object in seconds.

Returns
(number) The audio length

◆ mix()

aukit Audio aukit::Audio::mix ( number ¦ Audio amplifier,
aukit. Audio ... )

Mixes two or more audio objects into a single object, amplifying each sample with a multiplier (before clipping) if desired, and clipping any values outside the audio range ([-1, 1]). Channels that are shorter are padded with zeroes at the end, and non-existent channels are replaced with all zeroes. Any audio objects with a different sample rate are resampled to match this one.

Parameters
amplifier(number ¦ Audio) The multiplier to apply, or the first audio object
...(aukit.Audio) The objects to mix with this one
Returns
(aukit.Audio) The new mixed audio object

◆ mono()

aukit Audio aukit::Audio::mono ( )

Mixes down all channels to a new mono-channel audio object.

Returns
(aukit.Audio) A new audio object with the audio mixed to mono

◆ pcm()

number❲❳ ¦ nil aukit::Audio::pcm ( number? bitDepth,
("float" ¦ "signed" ¦ "unsigned")? dataType,
boolean? interleaved )

Converts the audio data to raw PCM samples.

dataType:
| "signed"
| "unsigned"
| "float"
Parameters
bitDepth(number?) The bit depth of the audio (8, 16, 24, 32)
dataType(("float" ¦ "signed" ¦ "unsigned")?) The type of each sample
interleaved(boolean?) Whether to interleave each channel
Returns
(number❲❳ ¦ nil) The resulting audio data

◆ rep()

aukit Audio aukit::Audio::rep ( number count)

Returns a new audio object that repeats this audio a number of times.

Parameters
count(number) The number of times to play the audio
Returns
(aukit.Audio) The repeated audio

◆ resample()

aukit Audio aukit::Audio::resample ( number sampleRate,
("cubic" ¦ "linear" ¦ "none")? interpolation )

Creates a new audio object with the data resampled to a different sample rate. If the target rate is the same, the object is copied without modification.

interpolation:
| "none"
| "linear"
| "cubic"
Parameters
sampleRate(number) The new sample rate in Hertz
interpolation(("cubic" ¦ "linear" ¦ "none")?) The interpolation mode to use
Returns
(aukit.Audio) A new audio object with the resampled data

◆ reverse()

aukit Audio aukit::Audio::reverse ( )

Returns a reversed version of this audio.

Returns
(aukit.Audio) The reversed audio

◆ split()

aukit Audio aukit::Audio::split ( number❲❳ ... )

Splits this audio object into one or more objects with the specified channels. Passing a channel that doesn't exist will throw an error.

local left, right = stereo:split({1}, {2})
Parameters
...(number❲❳) The lists of channels in each new object
Returns
(aukit.Audio) The new audio objects created from the channels in each list

◆ stream()

function‚ number aukit::Audio::stream ( number? chunkSize,
number? bitDepth,
("float" ¦ "signed" ¦ "unsigned")? dataType )

Returns a function that can be called to encode PCM samples in chunks. This is useful as a for iterator, and can be used with aukit.play. chunks of each channel's data as arrays of signed 8-bit 48kHz PCM, as well as the current position of the audio in seconds.

dataType:
| "signed"
| "unsigned"
| "float"
Parameters
chunkSize(number?) The size of each chunk
bitDepth(number?) The bit depth of the audio (8, 16, 24, 32)
dataType(("float" ¦ "signed" ¦ "unsigned")?) The type of each sample
Returns
(fun()→number❲❳❲❳ ¦ nil‚ number ¦ nil) An iterator function that returns
(number) The total length of the audio in seconds

◆ sub()

aukit Audio aukit::Audio::sub ( number? start,
number? last )

Takes a subregion of the audio and returns a new audio object with its contents. This takes the same arguments as string.sub, but positions start at 0.

Parameters
start(number?) The start position of the audio in seconds
last(number?) The end position of the audio in seconds (0 means end of file)
Returns
(aukit.Audio) The new split audio object

◆ wav()

string aukit::Audio::wav ( number? bitDepth)

Coverts the audio data to a WAV file.

Parameters
bitDepth(number?) The bit depth of the audio (1 = DFPWM, 8, 16, 24, 32)
Returns
(string) The resulting WAV file data

The documentation for this class was generated from the following file: