-
-
Notifications
You must be signed in to change notification settings - Fork 9
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.
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.
-
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.
-
func create(this *Sound) void
Creates a sound buffer.
-
func create(this *Sound, buffer_id uint) void
Sets the sound buffer to an existing OpenAL buffer.
-
func destroy(this *Sound) void
Destroys the internal sound buffer of a
Sound
.
struct SoundPlayer (source_id uint, volume float)
-
func create(this *SoundPlayer) successful
Initializes a
SoundPlayer
. -
func destroy(this *SoundPlayer) void
Destroys a
SoundPlayer
. -
func bindSound(this *SoundPlayer, sound Sound) void
Sets the target
Sound
for aSoundPlayer
. -
func play(this *SoundPlayer) void
Plays the
Sound
of aSoundPlayer
. -
func play(this *SoundPlayer, sound Sound) void
Sets the
Sound
of aSoundPlayer
and then plays it. -
func pause(this *SoundPlayer) void
Pauses a
SoundPlayer
. -
func stop(this *SoundPlayer) void
Stops a
SoundPlayer
. -
func isPlaying(this *SoundPlayer) bool
Returns whether a
SoundPlayer
is playing a sound. -
func setVolume(this *SoundPlayer, new_volume_multiplier float) void
Sets the volume of a
SoundPlayer
. -
func setVolumeRaw(this *SoundPlayer, new_volume float) void
Sets the volume of a
SoundPlayer
without multiplying it by the initial volume.
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
. -
func destroy(this *SoundMixer) void
Destroys a
SoundMixer
. -
func setFadeSpeed(this *SoundMixer, fade_speed float) void
Sets the fading speed of a
SoundMixer
.fade_speed
is a multiplier with1.0f
being the default. -
func bindSound(this *SoundMixer, sound Sound) void
Sets the target
Sound
of aSoundMixer
. -
func play(this *SoundMixer) void
Plays the target
Sound
of aSoundMixer
. -
func play(this *SoundMixer, sound Sound) void
Sets the target
Sound
of aSoundMixer
and then plays it. -
func playFadingIn(this *SoundMixer, sound Sound) void
Sets the target
Sound
of aSoundMixer
and then plays it while fading in. -
func pause(this *SoundMixer) void
Pauses a
SoundMixer
. -
func stop(this *SoundMixer) void
Stops a
SoundMixer
. -
func isPlaying(this *SoundMixer) bool
Returns whether a
SoundMixer
is playing a sound. -
func update(this *SoundMixer) void
Updates a
SoundMixer
with a fixed time-step. -
func update(this *SoundMixer, delta float) void
Updates a
SoundMixer
with a variable time-step. -
func update(this *SoundMixer, delta float) void
Updates a
SoundMixer
with a variable time-step. -
func fadeOut(this *SoundMixer) void
Tells a
SoundMixer
to fade out. -
func fadeIn(this *SoundMixer) void
Tells a
SoundMixer
to fade in from a volume multiplier of0.0f
. -
func fadeIn(this *SoundMixer, start_from_zero_percent bool) void
Tells a
SoundMixer
to fade in. Ifstart_from_zero_percent
, then the fade in will be from a volume multiplier of0.0f
otherwise the fade in will be from the current volume. -
func fadeIntoVolume(this *SoundMixer, volume_multiplier float) void
Tells a
SoundMixer
to fade into a different volume multiplier. -
func setVolume(this *SoundMixer, new_volume_multiplier float) void
Sets the volume multiplier of a
SoundMixer
. -
func setVolumeAmplifier(this *SoundMixer, amplifier float) void
Sets the volume amplifier of a
SoundMixer
. The volume amplifier will remain during transitions. -
func isSilent(this *SoundMixer) bool
Returns whether the volume multiplier of a
SoundMixer
is zero.
struct PlayableSound (sound Sound, player SoundPlayer)
-
func destroy(this *PlayableSound) void
Destroys a
PlayableSound
. -
func load(this *PlayableSound, filename String, looping bool, volume float) void
Loads a sound from a file to create a
PlayableSound
. -
func load(this *PlayableSound, filename *ubyte, looping bool, volume float) void
Loads a sound from a file to create a
PlayableSound
. -
func play(this *PlayableSound) void
Plays a
PlayableSound
. -
func stop(this *PlayableSound) void
Stops a
PlayableSound
. -
func isPlaying(this *PlayableSound) bool
Returns whether a
PlayableSound
is playing a sound.
enum SoundMixerFade (NONE, IN, OUT)
-
func audioInit() void
Initializes the audio API.
-
func audioTerminate() void
De-initializes the audio API.
#default audio_print_errors true
#default audio_use_stb_vorbis true
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() {}
}