cromo La guida di Cromo
Scarica PDF EN

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.

cromo
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 music

The guide: Sounds.

Generata dalla documentazione nei sorgenti della libreria, che è in inglese.

#Tipi

#Sound

cromo
struct Sound

A 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.

cromo
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

cromo
f64 seconds() const

How long the sound is, in seconds.

#Voice

cromo
struct Voice

A 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

cromo
struct Player

What 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.

cromo
Player()

Opens the device of the system for the sounds.

#Player.ready

cromo
bool ready() const

Whether the player has a device: false on a computer without one.

#Player.play

cromo
Voice play(Sound sound) const

Plays the sound once, at its volume, over what is playing.

#Player.playAt

cromo
Voice playAt(Sound sound, f32 volume) const

Plays 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

cromo
Voice loop(Sound sound, f32 volume) const

Plays the sound again and again, as a music, at a volume, until stop.

#Player.stop

cromo
void stop(Voice voice) const

Stops a voice; one that ended already is left alone.

#Player.stopAll

cromo
void stopAll() const

Stops all the voices.

#Player.setVoiceVolume

cromo
void setVoiceVolume(Voice voice, f32 volume) const

Changes the volume of a voice that is playing. A volume below 0 is a panic.

#Player.playing

cromo
bool playing(Voice voice) const

Whether a voice still plays: false once its sound has ended, or after stop.

#Player.setVolume

cromo
void setVolume(f32 volume) const

Sets the volume of all that the player plays: 1 by default, 0 for silence. A volume below 0 is a panic.

#Player.pause

cromo
void pause() const

Holds all the voices where they are, as when a game is paused.

#Player.resume

cromo
void resume() const

Lets the voices go on after pause.

#Funzioni

#load

cromo
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.