Skip to content

kira

stable

Audio playback and mixing powered by the Kira library, supporting static sound files with per-sound volume, panning, playback rate, and looping controls.

use plugin kira::{AudioManager.new, AudioManager.load_sound, AudioManager.play, …}
18 functions Audio & Media
/ filter jk navigate Esc clear
Functions (18)
  1. AudioManager.new Create a new audio manager
  2. AudioManager.load_sound Load a sound file from disk
  3. AudioManager.play Play a loaded sound
  4. AudioManager.main_track Get the main mixing track
  5. AudioManager.close Close and release the audio manager
  6. SoundHandle.pause Pause a playing sound
  7. SoundHandle.resume Resume a paused sound
  8. SoundHandle.stop Stop a sound
  9. SoundHandle.set_volume Set playback volume
  10. SoundHandle.set_playback_rate Set playback rate (pitch)
  11. SoundHandle.set_panning Set stereo panning
  12. SoundHandle.state Get playback state string
  13. SoundHandle.position Get current playback position in seconds
  14. SoundHandle.seek_to Seek to an absolute position
  15. SoundHandle.seek_by Seek relative to current position
  16. SoundHandle.set_loop_region Set or clear the loop region
  17. TrackHandle.set_volume Set the main track volume
  18. TrackHandle.add_effect Add an effect to the track (stub)

Create a new audio manager

Creates a new audio manager and opens the system audio device. The optional config table is accepted but currently ignored — default settings are always used. Only one audio manager should be active at a time.

use plugin kira::{AudioManager}

let mgr = AudioManager.new()

Load a sound file from disk

Loads a static sound file from the given file path. Supports common formats such as WAV, OGG, and FLAC. Returns a SoundData handle that can be passed to play multiple times.

use plugin kira::{AudioManager}

let mgr = AudioManager.new()
let sound = mgr.load_sound("assets/music.ogg")

Play a loaded sound

Plays a loaded sound and returns a SoundHandle for controlling playback. The optional config table supports keys: volume (float), playback_rate (float), panning (float -1.0 to 1.0), and loop_start (float seconds).

use plugin kira::{AudioManager}

let mgr = AudioManager.new()
let sound = mgr.load_sound("assets/shoot.wav")

let handle = mgr.play(sound)

let looping = mgr.play(sound, #{"volume": 0.8, "loop_start": 0.0})

Get the main mixing track

Returns a proxy handle to the audio manager's main mixing track. Use this to control the master volume of all playing sounds.

use plugin kira::{AudioManager}

let mgr = AudioManager.new()
let track = mgr.main_track()
track.set_volume(0.5)

Close and release the audio manager

Closes the audio manager and releases the audio device. After calling this, any further use of the manager or its handles will error.

use plugin kira::{AudioManager}

let mgr = AudioManager.new()
mgr.close()

Pause a playing sound

Pauses the sound. The optional tween table controls the fade duration and easing: #{"duration": 0.5, "easing": "linear"}. Supported easing values: "linear", "in_quad", "out_quad", "in_out_quad", "in_cubic", "out_cubic", "in_out_cubic".

use plugin kira::{AudioManager}

let mgr = AudioManager.new()
let snd = mgr.load_sound("assets/bg.ogg")
let h = mgr.play(snd)
h.pause(#{"duration": 0.3, "easing": "out_quad"})

Resume a paused sound

Resumes a paused sound, with optional fade-in tween.

h.resume(#{"duration": 0.3})

Stop a sound

Stops the sound entirely. After stopping, the handle can no longer be used to resume playback.

h.stop(#{"duration": 1.0})

Set playback volume

Sets the playback volume as an amplitude multiplier (1.0 = original, 0.5 = half volume). Optionally smoothed with a tween.

h.set_volume(0.5)
h.set_volume(0.0, #{"duration": 2.0})

Set playback rate (pitch)

Sets the playback rate (1.0 = normal speed, 2.0 = double speed, 0.5 = half speed). Also affects pitch.

h.set_playback_rate(1.5)

Set stereo panning

Sets stereo panning: -1.0 is full left, 0.0 is center, 1.0 is full right.

h.set_panning(-0.5)

Get playback state string

Returns the current playback state as one of: "playing", "pausing", "paused", "stopping", or "stopped".

let s = h.state()
print("State: {s}")

Get current playback position in seconds

Returns the current playback position in seconds.

let pos = h.position()
print("At {pos} seconds")

Seek to an absolute position

Seeks to an absolute position in seconds.

h.seek_to(30.0)

Seek relative to current position

Seeks forward or backward by amount seconds relative to the current position.

h.seek_by(10.0)
h.seek_by(-5.0)

Set or clear the loop region

Sets the loop region starting at start seconds and looping to the end of the file. Pass nil to disable looping.

h.set_loop_region(4.0)
h.set_loop_region(nil)

Set the main track volume

Sets the master volume of the main mixing track, affecting all currently playing sounds.

use plugin kira::{AudioManager}

let mgr = AudioManager.new()
let track = mgr.main_track()
track.set_volume(0.25)

Add an effect to the track (stub)

Reserved for adding audio effects to the track. Currently a stub — returns nil without applying any effect, as Kira 0.9 requires effects to be added at track construction time.

track.add_effect(#{"type": "reverb"})
enespt-br