Module for audio loading and playback.
opaque Sound
type Sound* = struct { _: ^struct{} }
Represents an instance of a playable sound. It is an opaque structure.
enum LoadFlag
type LoadFlag* = enum (uint32) {
none = 0
// Streams the audio, only saving 2 seconds into memory.
stream = 1
// Loads the sound in async. Use `audio.waitForLoad` to wait for the
// sounds to load.
async = 4
}
fn load
fn load*(path: str, flags: LoadFlag = LoadFlag.none): (Sound, std::Err) {
Loads a sounds at path, if there is an error, the underlying pointer
will be NULL
and validate
will return false.
fn Sound.validate
fn (s: ^Sound) validate*(): bool {
Returns true
if s
loaded correctly.
fn Sound.copy
fn (s: ^Sound) copy*(): (Sound, std::Err) {
Copies the sound. This will create another sound which can be configured and played independently from the original sound.
fn Sound.isPlaying
fn (s: ^Sound) isPlaying*(): bool {
Returns true if the sound is still playing.
fn Sound.play
fn (s: ^Sound) play*() {
Plays the sound.
fn Sound.start
fn (s: ^Sound) start*(): (^Sound, std::Err) {
The start function allows you to play a single sound multiple times. It will create a copy and return a pointer to it, so you can controll it while it is playing. The returned pointer can be discarded.
fn Sound.stop
fn (s: ^Sound) stop*() {
Stops the sound, but keeps the progress. If you want to start from the
begginning, use audio.Sound.seekToFrame(0)
.
fn Sound.setVol
fn (s: ^Sound) setVol*(vol: real32) {
Sets the volume as a multiplier of the base volume.
fn Sound.setPan
fn (s: ^Sound) setPan*(pan: real32) {
Sets the pan of the sound.
fn Sound.setPitch
fn (s: ^Sound) setPitch*(pitch: real32) {
Sets the pitch of the sound.
fn Sound.setLooping
fn (s: ^Sound) setLooping*(looping: bool) {
Sets whether the sound will loop upon finishing.
fn Sound.seekToFrame
fn (s: ^Sound) seekToFrame*(frame: uint) {
Seeks to a specified PCM frame.
fn Sound.frameCount
fn (s: ^Sound) frameCount*(): uint {
Returns length of the sound in PCM frames.
fn Sound.lengthMs
fn (s: ^Sound) lengthMs*(): uint {
Returns length of the sound in ms.
fn Sound.setStartTimeMs
fn (s: ^Sound) setStartTimeMs*(t: uint) {
fn Sound.setStopTimeMs
fn (s: ^Sound) setStopTimeMs*(t: uint) {