-
-
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) successfulCreates a new sound buffer and loads a sound from a file into it.
-
func load(this *Sound, filename *ubyte, looping bool, volume float) successfulCreates a new sound buffer and loads a sound from a file into it.
-
func create(this *Sound) voidCreates a sound buffer.
-
func create(this *Sound, buffer_id uint) voidSets the sound buffer to an existing OpenAL buffer.
-
func destroy(this *Sound) voidDestroys the internal sound buffer of a
Sound.
struct SoundPlayer (source_id uint, volume float)
-
func create(this *SoundPlayer) successfulInitializes a
SoundPlayer. -
func destroy(this *SoundPlayer) voidDestroys a
SoundPlayer. -
func bindSound(this *SoundPlayer, sound Sound) voidSets the target
Soundfor aSoundPlayer. -
func play(this *SoundPlayer) voidPlays the
Soundof aSoundPlayer. -
func play(this *SoundPlayer, sound Sound) voidSets the
Soundof aSoundPlayerand then plays it. -
func pause(this *SoundPlayer) voidPauses a
SoundPlayer. -
func stop(this *SoundPlayer) voidStops a
SoundPlayer. -
func isPlaying(this *SoundPlayer) boolReturns whether a
SoundPlayeris playing a sound. -
func setVolume(this *SoundPlayer, new_volume_multiplier float) voidSets the volume of a
SoundPlayer. -
func setVolumeRaw(this *SoundPlayer, new_volume float) voidSets the volume of a
SoundPlayerwithout 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) successfulInitializes a
SoundMixer. -
func destroy(this *SoundMixer) voidDestroys a
SoundMixer. -
func setFadeSpeed(this *SoundMixer, fade_speed float) voidSets the fading speed of a
SoundMixer.fade_speedis a multiplier with1.0fbeing the default. -
func bindSound(this *SoundMixer, sound Sound) voidSets the target
Soundof aSoundMixer. -
func play(this *SoundMixer) voidPlays the target
Soundof aSoundMixer. -
func play(this *SoundMixer, sound Sound) voidSets the target
Soundof aSoundMixerand then plays it. -
func playFadingIn(this *SoundMixer, sound Sound) voidSets the target
Soundof aSoundMixerand then plays it while fading in. -
func pause(this *SoundMixer) voidPauses a
SoundMixer. -
func stop(this *SoundMixer) voidStops a
SoundMixer. -
func isPlaying(this *SoundMixer) boolReturns whether a
SoundMixeris playing a sound. -
func update(this *SoundMixer) voidUpdates a
SoundMixerwith a fixed time-step. -
func update(this *SoundMixer, delta float) voidUpdates a
SoundMixerwith a variable time-step. -
func update(this *SoundMixer, delta float) voidUpdates a
SoundMixerwith a variable time-step. -
func fadeOut(this *SoundMixer) voidTells a
SoundMixerto fade out. -
func fadeIn(this *SoundMixer) voidTells a
SoundMixerto fade in from a volume multiplier of0.0f. -
func fadeIn(this *SoundMixer, start_from_zero_percent bool) voidTells a
SoundMixerto fade in. Ifstart_from_zero_percent, then the fade in will be from a volume multiplier of0.0fotherwise the fade in will be from the current volume. -
func fadeIntoVolume(this *SoundMixer, volume_multiplier float) voidTells a
SoundMixerto fade into a different volume multiplier. -
func setVolume(this *SoundMixer, new_volume_multiplier float) voidSets the volume multiplier of a
SoundMixer. -
func setVolumeAmplifier(this *SoundMixer, amplifier float) voidSets the volume amplifier of a
SoundMixer. The volume amplifier will remain during transitions. -
func isSilent(this *SoundMixer) boolReturns whether the volume multiplier of a
SoundMixeris zero.
struct PlayableSound (sound Sound, player SoundPlayer)
-
func destroy(this *PlayableSound) voidDestroys a
PlayableSound. -
func load(this *PlayableSound, filename String, looping bool, volume float) voidLoads a sound from a file to create a
PlayableSound. -
func load(this *PlayableSound, filename *ubyte, looping bool, volume float) voidLoads a sound from a file to create a
PlayableSound. -
func play(this *PlayableSound) voidPlays a
PlayableSound. -
func stop(this *PlayableSound) voidStops a
PlayableSound. -
func isPlaying(this *PlayableSound) boolReturns whether a
PlayableSoundis playing a sound.
enum SoundMixerFade (NONE, IN, OUT)
-
func audioInit() voidInitializes the audio API.
-
func audioTerminate() voidDe-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() {}
}