Skip to main content

Module audio

Module audio 

Source
Expand description

The audio manifest: every sound and music cue a game can play, the music pools, and the credits for every third-party work. Screens name cues; the platform layer plays the files.

The game says where the files are (Files): sounds are usually in the bundle, and music in a folder shipped next to the game, which the game itself may not be able to read. from_source checks what it can see, including each track’s length_ms against its file (ogg_length_ms).

As formats (ADR-0007): a sound file’s header is the Sound kind (Wav, OggVorbis), a music track’s the MusicTrack kind (OggVorbisTrack), and the manifest is read by AudioManifestRon.

Structs§

AudioManifest
The validated audio manifest. Build it with default() and assign its fields (ADR-0039).
AudioManifestRon
The audio manifest (audio-manifest, .ron), checked as from_source says. Its sound files are named from its own folder and read from the bundle beside it (audio/audio.ron names sfx/a.wav, audio/sfx/a.wav). The music folder isn’t in the bundle, so its tracks aren’t read here: a tool that can see the folder checks them with from_source.
Credit
One third-party work, for the credits screen (audio.md rule 3).
Files
How to read the referenced files, and how errors name them. music is None where the music folder can’t be seen (the game itself, which does no file I/O). Build it with Files::new (ADR-0039).
MusicCue
A music track.
MusicSwitch
How one music track gives way to the next (ADR-0054): the old one fades out over out_ms, and the new one fades in over in_ms, starting as the old one begins to fade (overlap, a crossfade) or once it has stopped. Build it with new, after_fade or crossfade (ADR-0039).
MusicTrack
A music track’s header, and how long it plays.
OggVorbis
OGG Vorbis (ogg-vorbis, .ogg), read for a sound.
OggVorbisTrack
OGG Vorbis (ogg-vorbis, .ogg), read for a music track: a whole file, whose last page gives its length (ogg_length_ms).
Sound
A sound file’s header: what the engine knows of a sound before the platform plays it. Every one is mono or stereo, at SAMPLE_RATE.
SoundCue
A sound effect: one of its files plays each time. Build it with SoundCue::new (ADR-0039).
Wav
WAV, PCM or float (wav, .wav).

Enums§

CreditRef
Who made a sound or a track.

Constants§

BAKED_MUSIC_DIR
Where a music file goes in a package whose target bakes its audio.
BAKED_SOUND_DIR
Where a sound file goes in a package whose target bakes its audio (the .pdx): sfx/x.wav is audio/sfx/x there.
LENGTH_TOLERANCE_MS
How far a music cue’s length_ms may be from its file’s real length, in milliseconds.
LICENSES
Licenses a credit may have (game ADR-0013, game ADR-0027). Own is work we made.
MAX_SOUND_BYTES
The most bytes a sound or music file may have: 64 MiB, six minutes of stereo WAV at SAMPLE_RATE.
MAX_VOLUME
Highest cue volume, in percent of the file’s own loudness.
OWN
The license of work we made ourselves.
SAMPLE_RATE
The sample rate every file must have: quad-snd (native) plays at 44.1 kHz and resamples anything else crudely (game ADR-0026).

Functions§

format_problem
Why bytes (a file named name) isn’t something the game can play: its content must match its extension (OGG Vorbis for .ogg, PCM or float WAV for .wav), with one or two channels at SAMPLE_RATE. quad-snd panics on native, and never finishes loading on the web, on a file it can’t read, so this runs before any file ships.
from_source
Parses and validates manifest source, attributing errors to file.
ogg_length_ms
How long an OGG Vorbis file plays, in milliseconds (to the nearest): the granule position of its last page, which for Vorbis is the number of samples in the stream, over the sample rate in its header. None if bytes isn’t a whole OGG Vorbis file.
without_extension
file without its extension, as a device that bakes its audio opens it.

Type Aliases§

Bytes
A file’s contents, or None if it’s missing.