audio
Sound playback, mixing, music, procedural sound effects and 3D spatial sound.
Import
ts
import { SfxPreset, Wave, Sfx, SoundGroup, ... } from "audio";Needs the "audio" permission in thicket.json.
SoundPlayOptions class
ts
class SoundPlayOptionsType only: the runtime hands you instances; you never construct it yourself.
Playback options for a SoundChannel.
SoundPlayOptions.volume
ts
volume?: float64Volume; 0 is silent, 1 is normal.
SoundPlayOptions.pitch
ts
pitch?: float64Speed multiplier; 1.0 is normal speed.
SoundPlayOptions.pan
ts
pan?: float64Stereo pan; -1 is left, 0 is center, 1 is right.
SoundPlayOptions.loop
ts
loop?: booleanWhether playback repeats when it reaches the end.
SoundPlayOptions.group
ts
group?: intSound group identifier; see SoundGroup constants.
SoundChannel class
ts
class SoundChannelType only: the runtime hands you instances; you never construct it yourself.
SoundChannel.volume
ts
volume: float64Playback volume; 0 is silent, 1 is normal.
SoundChannel.pitch
ts
pitch: float64Playback speed multiplier; 1.0 is normal speed.
SoundChannel.pan
ts
pan: float64Stereo pan; -1 is left, 0 is center, 1 is right.
SoundChannel.spatialized
ts
spatialized: booleanWhether this sound uses 3D spatial positioning.
SoundChannel.position
ts
position: Vec3 | float643D position in world space or 2D distance fallback.
SoundChannel.velocity
ts
velocity: Vec33D velocity in world space for Doppler effect.
SoundChannel.minDistance
ts
minDistance: float64Closest distance for spatial attenuation falloff in world units.
SoundChannel.maxDistance
ts
maxDistance: float64Farthest distance for spatial attenuation falloff in world units.
SoundChannel.rolloff
ts
rolloff: float64Exponent for distance attenuation curve; typically 0.0–2.0.
SoundChannel.attenuation
ts
attenuation: intSpatial attenuation model; see Attenuation constants.
SoundChannel.position2D
ts
position2D: float642D stereo pan when spatialized is false; -1 to 1.
SoundChannel.isPlaying
ts
readonly isPlaying: booleanTrue if the sound is currently playing. Read-only.
SoundChannel.playbackPosition
ts
readonly playbackPosition: float64The voice's live decoder cursor in seconds. Zero after it ends or is stolen.
SoundChannel.stop
ts
stop(): voidStops playback immediately.
SoundChannel.pause
ts
pause(): voidPauses playback; call resume() to continue.
SoundChannel.resume
ts
resume(): voidResumes playback after pause().
SoundChannel.onComplete
ts
onComplete(callback: () => void): voidRuns once on the main thread in the frame after natural playback completion.
Sound class
ts
class SoundType only: the runtime hands you instances; you never construct it yourself.
Sound.duration
ts
readonly duration: float64The decoded source length in seconds.
Sound.play
ts
play(options?: SoundPlayOptions): SoundChannelBegins playback and returns a SoundChannel for real-time control.
Sound.unload
ts
unload(): voidFrees decoded audio and invalidates all SoundChannels from this sound.
MusicTrack class
ts
class MusicTrackType only: the runtime hands you instances; you never construct it yourself.
A streamed music asset returned by Audio.loadMusic(path).
MusicTrack.unload
ts
unload(): voidStops playback and frees resources.
SfxPreset static class
ts
static class SfxPresetNamed procedural sound-effect recipes.
ts
static readonly COIN: int
static readonly LASER: int
static readonly EXPLOSION: int
static readonly POWERUP: int
static readonly HIT: int
static readonly JUMP: int
static readonly BLIP: int
static readonly RANDOM: intWave static class
ts
static class WaveOscillator wave shapes for Sfx.tone.
ts
static readonly SINE: int
static readonly SQUARE: int
static readonly TRIANGLE: int
static readonly SAWTOOTH: int
static readonly NOISE: intSfx static class
ts
static class SfxStatic procedural sound-effect synthesizer.
Sfx.generate
ts
static generate(preset: int, seed?: int): SoundGenerate a reusable Sound asset from a named preset and optional deterministic seed.
Parameters
preset: A SfxPreset constant.seed: Optional deterministic seed; omitted or 0 for random variation.
Returns: A new Sound asset that can be played multiple times.
Sfx.play
ts
static play(preset: int, seed?: int): voidPlay a preset immediately as a one-shot effect.
Parameters
preset: A SfxPreset constant.seed: Optional deterministic seed; omitted or 0 for random variation.
Sfx.tone
ts
static tone(frequency: float64, durationMs: int, wave?: int): voidPlay an oscillator tone for the given duration.
Parameters
frequency: Frequency in Hz.durationMs: Duration in milliseconds.wave: Optional Wave constant; defaults to SINE.
AudioListener class
ts
class AudioListenerType only: the runtime hands you instances; you never construct it yourself.
ts
position: Vec3
direction: Vec3SoundGroup static class
ts
static class SoundGroupTop-level sound mix-group constants.
SoundGroup.Music
ts
static readonly Music: intDeprecated
Use MUSIC.
SoundGroup.Voice
ts
static readonly Voice: intDeprecated
Use VOICE.
SoundGroup.Ambient
ts
static readonly Ambient: intDeprecated
Use AMBIENT.
Other members of SoundGroup
ts
static readonly SFX: int
static readonly MUSIC: int
static readonly VOICE: int
static readonly AMBIENT: int
static readonly UI: intAttenuation static class
ts
static class AttenuationTop-level spatial attenuation constants.
Attenuation.None
ts
static readonly None: intDeprecated
Use NONE.
Attenuation.InverseDistance
ts
static readonly InverseDistance: intDeprecated
Use INVERSE.
Attenuation.LinearDistance
ts
static readonly LinearDistance: intDeprecated
Use LINEAR.
Attenuation.ExponentialDistance
ts
static readonly ExponentialDistance: intDeprecated
Use EXPONENTIAL.
Other members of Attenuation
ts
static readonly NONE: int
static readonly INVERSE: int
static readonly LINEAR: int
static readonly EXPONENTIAL: intAudio static class
ts
static class AudioAudio.SoundGroup
ts
static readonly SoundGroup: anyDeprecated
Use top-level SoundGroup.
Audio.AttenuationModel
ts
static readonly AttenuationModel: anyDeprecated
Use top-level Attenuation.
Audio.loadSound
ts
static loadSound(path: string, group?: int): Promise<Sound>
static loadSound(buffer: Buffer, group?: int): Promise<Sound>Loads a sound asset from a project or bundled path.
Parameters
path: Project or bundled asset path.group: Optional sound group; seeSoundGroupconstants.
Returns: Promise that resolves to a loaded Sound.
Example
ts
import { Audio, Sound } from "audio";
const click: Sound = await Audio.loadSound("assets/click.wav");
Audio.play(click);Audio.play
ts
static play(sound: Sound | int, options?: SoundPlayOptions | float64, pitch?: float64, loop?: boolean): SoundChannel | voidBegins playback of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.options: Optional SoundPlayOptions or volume (float64).pitch: Optional speed multiplier.loop: Optional boolean for looping playback.
Returns: SoundChannel if sound is a Sound object, void if a handle.
Audio.unloadSound
ts
static unloadSound(sound: Sound | int): voidStops playback and frees resources for the given sound.
Parameters
sound: Sound object or numeric handle.
Audio.stop
ts
static stop(sound: Sound | int): voidStops playback of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.
Audio.setSoundVolume
ts
static setSoundVolume(sound: Sound | int, volume: float64): voidSets the volume of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.volume: Volume; 0 is silent, 1 is normal.
Audio.soundVolume
ts
static soundVolume(sound: Sound | int): float64Reads the current volume of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.
Returns: Current volume in range 0..1.
Audio.setSoundPitch
ts
static setSoundPitch(sound: Sound | int, pitch: float64): voidSets the pitch (speed) of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.pitch: Speed multiplier; 1.0 is normal speed.
Audio.soundPitch
ts
static soundPitch(sound: Sound | int): float64Reads the current pitch of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.
Returns: Current pitch multiplier.
Audio.setSoundPan
ts
static setSoundPan(sound: Sound | int, pan: float64): voidSets the pan (left/right balance) of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.pan: Stereo pan; -1 is left, 0 is center, 1 is right.
Audio.soundPan
ts
static soundPan(sound: Sound | int): float64Reads the current pan of a sound or sound channel.
Parameters
sound: Sound object or numeric handle.
Returns: Current pan in range -1..1.
Audio.playPanned
ts
static playPanned(sound: Sound | int, pan: float64, volume?: float64, pitch?: float64, loop?: boolean): voidPlays a sound with a specific pan and volume.
Parameters
sound: Sound object or numeric handle.pan: Stereo pan; -1 is left, 0 is center, 1 is right.volume: Optional volume; 0 is silent, 1 is normal.pitch: Optional speed multiplier.loop: Optional boolean for looping playback.
Audio.loadMusic
ts
static loadMusic(path: string): Promise<MusicTrack>Streams a music asset from a project or bundled path.
Parameters
path: Project or bundled asset path.
Returns: Promise that resolves to a loaded MusicTrack.
Audio.unloadMusic
ts
static unloadMusic(track: MusicTrack | int): voidStops playback and frees resources for the given music track.
Parameters
track: MusicTrack object or numeric handle.
Audio.playMusicHandle
ts
static playMusicHandle(track: MusicTrack, volume?: float64, loop?: boolean, startSeconds?: float64): void
static playMusicHandle(id: int, volume?: float64, loop?: boolean, startSeconds?: float64): voidBegins playback of a music track.
Parameters
track: MusicTrack object to play.volume: Optional volume; 0 is silent, 1 is normal.loop: Optional boolean for looping playback.startSeconds: Optional start point in seconds (default 0), e.g. a savedmusicPosition().
Example
ts
import { Audio, MusicTrack } from "audio";
const theme: MusicTrack = await Audio.loadMusic("assets/theme.ogg");
Audio.playMusicHandle(theme, 0.8, true);Audio.crossfadeTo
ts
static crossfadeTo(track: MusicTrack, durationMs: int, volume?: float64, loop?: boolean): void
static crossfadeTo(id: int, durationMs: int, volume?: float64, loop?: boolean): voidCrossfades to a new music track over a specified duration.
Parameters
track: MusicTrack object to crossfade to.durationMs: Crossfade duration in milliseconds.volume: Optional target volume; 0 is silent, 1 is normal.loop: Optional boolean for looping playback.
Audio.stopMusic
ts
static stopMusic(fadeMs?: int): voidStops music playback with optional fade-out.
Parameters
fadeMs: Optional fade-out duration in milliseconds.
Audio.pauseMusic
ts
static pauseMusic(): voidPauses music playback.
Audio.resumeMusic
ts
static resumeMusic(): voidResumes music playback after pauseMusic().
Audio.musicPlaying
ts
static musicPlaying(): booleanReturns true if music is currently playing.
Audio.activeMusic
ts
static activeMusic(): intReturns the numeric handle of the currently playing track, or 0 if none.
Audio.musicPosition
ts
static musicPosition(): float64Playback position of the active music track in seconds (playing or paused), or 0 if none.
Audio.masterVolume
ts
static masterVolume: float64Master mixer gain, clamped to 0..1.
Audio.sfxVolume
ts
static sfxVolume: float64Sound-effects mix-group gain, clamped to 0..1.
Audio.musicVolume
ts
static musicVolume: float64Music mix-group gain, clamped to 0..1.
Audio.listener
ts
static readonly listener: AudioListenerThe 3D listener's position and orientation for spatial audio. Read-only.
Audio.setMasterVolume
ts
static setMasterVolume(volume: float64): voidDeprecated
Assign masterVolume.
Audio.setSfxVolume
ts
static setSfxVolume(volume: float64): voidDeprecated
Assign sfxVolume.
Audio.setMusicVolume
ts
static setMusicVolume(volume: float64): voidDeprecated
Assign musicVolume.
Audio.setGroupVolume
ts
static setGroupVolume(group: int, volume: float64): voidSets the volume for a sound group.
Parameters
group: A SoundGroup constant.volume: Volume; 0 is silent, 1 is normal.
Audio.groupVolume
ts
static groupVolume(group: int): float64Reads the volume for a sound group.
Parameters
group: A SoundGroup constant.
Returns: Current volume in range 0..1.
Audio.setListenerPosition
ts
static setListenerPosition(x: float64, y: float64, z: float64): voidSets the 3D listener position for spatial audio.
Parameters
x: World x coordinate.y: World y coordinate.z: World z coordinate.
Audio.setListenerDirection
ts
static setListenerDirection(fx: float64, fy: float64, fz: float64, ux?: float64, uy?: float64, uz?: float64): voidSets the 3D listener orientation for spatial audio.
Parameters
fx: Forward vector x component.fy: Forward vector y component.fz: Forward vector z component.ux: Optional up vector x; defaults to 0.uy: Optional up vector y; defaults to 1.uz: Optional up vector z; defaults to 0.
Audio.listenerPosition
ts
static listenerPosition(): Vec3Reads the 3D listener position.
Returns: Current listener position as Vec3.
Audio.setSoundPosition
ts
static setSoundPosition(sound: Sound | int, x: float64, y: float64, z: float64): voidSets the 3D world position of a sound.
Parameters
sound: Sound object or numeric handle.x: World x coordinate.y: World y coordinate.z: World z coordinate.
Audio.setSoundSpatialized
ts
static setSoundSpatialized(sound: Sound | int, enabled: boolean): voidEnables or disables 3D spatial positioning for a sound.
Parameters
sound: Sound object or numeric handle.enabled: True to use 3D positioning, false for 2D panning only.
Audio.setSoundDistanceRange
ts
static setSoundDistanceRange(sound: Sound | int, minDist: float64, maxDist: float64): voidSets the distance range for spatial attenuation.
Parameters
sound: Sound object or numeric handle.minDist: Minimum distance in world units; no attenuation closer than this.maxDist: Maximum distance in world units; silent beyond this.
Audio.setSoundRolloff
ts
static setSoundRolloff(sound: Sound | int, rolloff: float64): voidSets the rolloff factor for distance attenuation.
Parameters
sound: Sound object or numeric handle.rolloff: Rolloff exponent; typical range 0.0–2.0.
Audio.soundRolloff
ts
static soundRolloff(sound: Sound | int): float64Reads the rolloff factor of a sound.
Parameters
sound: Sound object or numeric handle.
Returns: Current rolloff exponent.
Audio.setSoundDopplerFactor
ts
static setSoundDopplerFactor(sound: Sound | int, factor: float64): voidSets the Doppler effect factor for a sound.
Parameters
sound: Sound object or numeric handle.factor: Doppler factor; 1.0 is realistic, 0.0 disables the effect.
Audio.soundDopplerFactor
ts
static soundDopplerFactor(sound: Sound | int): float64Reads the Doppler effect factor of a sound.
Parameters
sound: Sound object or numeric handle.
Returns: Current Doppler factor.
Audio.setSoundVelocity
ts
static setSoundVelocity(sound: Sound | int, x: float64, y: float64, z: float64): voidSets the 3D velocity of a sound for Doppler effects.
Parameters
sound: Sound object or numeric handle.x: Velocity x component.y: Velocity y component.z: Velocity z component.
Audio.setSoundAttenuationModel
ts
static setSoundAttenuationModel(sound: Sound | int, model: int): voidSets the spatial attenuation model for a sound.
Parameters
sound: Sound object or numeric handle.model: An Attenuation constant.
Audio.soundAttenuationModel
ts
static soundAttenuationModel(sound: Sound | int): intReads the spatial attenuation model of a sound.
Parameters
sound: Sound object or numeric handle.
Returns: Current Attenuation constant.
Audio.playSpatial
ts
static playSpatial(sound: Sound | int, x: float64, y: float64, z: float64, minDist?: float64, maxDist?: float64, volume?: float64, pitch?: float64, loop?: boolean): voidPlays a sound at a 3D position with optional attenuation.
Parameters
sound: Sound object or numeric handle.x: World x coordinate.y: World y coordinate.z: World z coordinate.minDist: Optional minimum distance for attenuation.maxDist: Optional maximum distance for attenuation.volume: Optional volume; 0 is silent, 1 is normal.pitch: Optional speed multiplier.loop: Optional boolean for looping playback.
Music static class
ts
static class MusicGlobal background-music playback. Audio's music methods remain aliases.
Music.volume
ts
static volume: float64Music volume; 0 is silent, 1 is normal.
Music.isPlaying
ts
static readonly isPlaying: booleanTrue if music is currently playing. Read-only.
Music.current
ts
static readonly current: intNumeric handle of the currently playing track, or 0 if none. Read-only.
Music.play
ts
static play(track: int | MusicTrack): voidBegins playback of a music track.
Parameters
track: MusicTrack object or numeric handle.
Music.crossfade
ts
static crossfade(track: int | MusicTrack, ms: int): voidCrossfades to a new music track over a specified duration.
Parameters
track: MusicTrack object or numeric handle to crossfade to.ms: Crossfade duration in milliseconds.
Music.pause
ts
static pause(): voidPauses music playback.
Music.resume
ts
static resume(): voidResumes music playback after pause().
Music.stop
ts
static stop(fadeMs?: int): voidStops music playback with optional fade-out.
Parameters
fadeMs: Optional fade-out duration in milliseconds.
audio const
ts
const audio: anyDeprecated
Use Audio.
Generated from lang/types/audio.d.tks in the ThicketScript repository.