Skip to content
IsaacShelton edited this page Nov 13, 2022 · 6 revisions

audio

2.7/audio.adept defines a basic API for playing .ogg and .wav files.

This file is only officially supported on Windows and MacOS.

Structs

struct Sound (buffer_id uint, loop bool, volume float)
  • func load(filename String, looping bool, volume float) successful

    Creates a new sound buffer and loads a sound from a file into it.

    [view src]

  • func load(this *Sound, filename *ubyte, looping bool, volume float) successful

    Creates a new sound buffer and loads a sound from a file into it.

    [view src]

  • func create(this *Sound) void

    Creates a sound buffer.

    [view src]

  • func create(this *Sound, buffer_id uint) void

    Sets the sound buffer to an existing OpenAL buffer.

    [view src]

  • func destroy(this *Sound) void

    Destroys the internal sound buffer of a Sound.

    [view src]

struct SoundPlayer (source_id uint, volume float)
  • func create(this *SoundPlayer) successful

    Initializes a SoundPlayer.

    [view src]

  • func destroy(this *SoundPlayer) void

    Destroys a SoundPlayer.

    [view src]

  • func bindSound(this *SoundPlayer, sound Sound) void

    Sets the target Sound for a SoundPlayer.

    [view src]

  • func play(this *SoundPlayer) void

    Plays the Sound of a SoundPlayer.

    [view src]

  • func play(this *SoundPlayer, sound Sound) void

    Sets the Sound of a SoundPlayer and then plays it.

    [view src]

  • func pause(this *SoundPlayer) void

    Pauses a SoundPlayer.

    [view src]

  • func stop(this *SoundPlayer) void

    Stops a SoundPlayer.

    [view src]

  • func isPlaying(this *SoundPlayer) bool

    Returns whether a SoundPlayer is playing a sound.

    [view src]

  • func setVolume(this *SoundPlayer, new_volume_multiplier float) void

    Sets the volume of a SoundPlayer.

    [view src]

  • func setVolumeRaw(this *SoundPlayer, new_volume float) void

    Sets the volume of a SoundPlayer without multiplying it by the initial volume.

    [view src]

struct SoundMixer (
    player SoundPlayer,
    volume_multiplier, target_volume_multiplier float,
    fade_speed float,
    fade SoundMixerFade,
    amplifier float
)
  • func create(this *SoundMixer) successful

    Initializes a SoundMixer.

    [view src]

  • func destroy(this *SoundMixer) void

    Destroys a SoundMixer.

    [view src]

  • func setFadeSpeed(this *SoundMixer, fade_speed float) void

    Sets the fading speed of a SoundMixer. fade_speed is a multiplier with 1.0f being the default.

    [view src]

  • func bindSound(this *SoundMixer, sound Sound) void

    Sets the target Sound of a SoundMixer.

    [view src]

  • func play(this *SoundMixer) void

    Plays the target Sound of a SoundMixer.

    [view src]

  • func play(this *SoundMixer, sound Sound) void

    Sets the target Sound of a SoundMixer and then plays it.

    [view src]

  • func playFadingIn(this *SoundMixer, sound Sound) void

    Sets the target Sound of a SoundMixer and then plays it while fading in.

    [view src]

  • func pause(this *SoundMixer) void

    Pauses a SoundMixer.

    [view src]

  • func stop(this *SoundMixer) void

    Stops a SoundMixer.

    [view src]

  • func isPlaying(this *SoundMixer) bool

    Returns whether a SoundMixer is playing a sound.

    [view src]

  • func update(this *SoundMixer) void

    Updates a SoundMixer with a fixed time-step.

    [view src]

  • func update(this *SoundMixer, delta float) void

    Updates a SoundMixer with a variable time-step.

    [view src]

  • func update(this *SoundMixer, delta float) void

    Updates a SoundMixer with a variable time-step.

    [view src]

  • func fadeOut(this *SoundMixer) void

    Tells a SoundMixer to fade out.

    [view src]

  • func fadeIn(this *SoundMixer) void

    Tells a SoundMixer to fade in from a volume multiplier of 0.0f.

    [view src]

  • func fadeIn(this *SoundMixer, start_from_zero_percent bool) void

    Tells a SoundMixer to fade in. If start_from_zero_percent , then the fade in will be from a volume multiplier of 0.0f otherwise the fade in will be from the current volume.

    [view src]

  • func fadeIntoVolume(this *SoundMixer, volume_multiplier float) void

    Tells a SoundMixer to fade into a different volume multiplier.

    [view src]

  • func setVolume(this *SoundMixer, new_volume_multiplier float) void

    Sets the volume multiplier of a SoundMixer.

    [view src]

  • func setVolumeAmplifier(this *SoundMixer, amplifier float) void

    Sets the volume amplifier of a SoundMixer. The volume amplifier will remain during transitions.

    [view src]

  • func isSilent(this *SoundMixer) bool

    Returns whether the volume multiplier of a SoundMixer is zero.

    [view src]

struct PlayableSound (sound Sound, player SoundPlayer)
  • func destroy(this *PlayableSound) void

    Destroys a PlayableSound.

    [view src]

  • func load(this *PlayableSound, filename String, looping bool, volume float) void

    Loads a sound from a file to create a PlayableSound.

    [view src]

  • func load(this *PlayableSound, filename *ubyte, looping bool, volume float) void

    Loads a sound from a file to create a PlayableSound.

    [view src]

  • func play(this *PlayableSound) void

    Plays a PlayableSound.

    [view src]

  • func stop(this *PlayableSound) void

    Stops a PlayableSound.

    [view src]

  • func isPlaying(this *PlayableSound) bool

    Returns whether a PlayableSound is playing a sound.

    [view src]

Enums

enum SoundMixerFade (NONE, IN, OUT)

Functions

  • func audioInit() void

    Initializes the audio API.

    [view src]

  • func audioTerminate() void

    De-initializes the audio API.

    [view src]

Settings

#default audio_print_errors true
#default audio_use_stb_vorbis true

Usage Example


import audio
import where
import basics

func main {
    // Initialize the audio API
    audioInit()

    // Don't forget to de-initialize the audio API
    defer audioTerminate()

    // Load the sound as a directly playable sound
    sound PlayableSound
    sound.load(where() + "file.wav", /*looping*/ false, /*initial volume*/ 1.0f)

    // Don't forget to destroy the sound when we're done
    defer sound.destroy()

    // Play the sound
    sound.play()

    // Wait for the sound to finish playing
    while sound.isPlaying() {}
}
Clone this wiki locally