std.audio
Sounds: a Player plays them on the speakers of the computer or of the phone, as many together as the program starts, each with its volume, once or again and again as a music. A Sound is read from the bytes of a WAV or Ogg Vorbis file, those of a file or those that embed puts in the program.
import std.audio
audio.Player player = audio.Player()
audio.Sound coin = audio.Sound(embed("coin.wav"))
audio.Sound music = audio.load("theme.ogg")
player.loop(music, 0.5) // again and again, at half its volume
player.play(coin) // over the musicThe guide: Sounds.
Generata dalla documentazione nei sorgenti della libreria, che è in inglese.
#Tipi
#Sound
struct SoundA sound, ready to be played: a short one is decoded when it is made, and a long one in Ogg Vorbis, as a music, while it plays. It is not copied, only moved; a player that is playing it keeps what it needs of it until the end.
Sound(list<u8> bytes)Reads the sound from the bytes of a WAV or Ogg Vorbis file, as embed and fs.readBytes give them. Bytes that are not a sound that can be read throw an Error with the reason.
#Sound.seconds
f64 seconds() constHow long the sound is, in seconds.
#Voice
struct VoiceA sound that a player is playing, from Player.play and Player.loop: the player stops it, changes its volume and says whether it still plays.
#Player
struct PlayerWhat plays the sounds, on the device that the system uses for them. Each sound started is a voice, mixed with the others. On a computer without a device for the sounds the player is silent: its methods do nothing, and ready says so. It is not copied, only moved, and its voices stop when it ends.
Player()Opens the device of the system for the sounds.
#Player.ready
bool ready() constWhether the player has a device: false on a computer without one.
#Player.play
Voice play(Sound sound) constPlays the sound once, at its volume, over what is playing.
#Player.playAt
Voice playAt(Sound sound, f32 volume) constPlays the sound once at a volume: 1 is its own, 0.5 half of it, and more than 1 louder. A volume below 0 is a panic.
#Player.loop
Voice loop(Sound sound, f32 volume) constPlays the sound again and again, as a music, at a volume, until stop.
#Player.stop
void stop(Voice voice) constStops a voice; one that ended already is left alone.
#Player.stopAll
void stopAll() constStops all the voices.
#Player.setVoiceVolume
void setVoiceVolume(Voice voice, f32 volume) constChanges the volume of a voice that is playing. A volume below 0 is a panic.
#Player.playing
bool playing(Voice voice) constWhether a voice still plays: false once its sound has ended, or after stop.
#Player.setVolume
void setVolume(f32 volume) constSets the volume of all that the player plays: 1 by default, 0 for silence. A volume below 0 is a panic.
#Player.pause
void pause() constHolds all the voices where they are, as when a game is paused.
#Player.resume
void resume() constLets the voices go on after pause.
#Funzioni
#load
Sound load(string path)Reads a sound from a WAV or Ogg Vorbis file. Throws an Error when the file cannot be read or is not a sound.