reskate.audio plays two kinds of sound. play_ui plays one of the game’s menu sounds and needs the audio.ui permission. play, set, stop, playing and preload play your plugin’s own WAV files, or a synthesised motor, at a place in the level, and need audio.
Menu sounds
reskate.audio.play_ui(name)
Plays one of the game’s menu sounds, as its own menus do.
Needs
audio.ui. At most 10 a second; past them it returns false. Raises an error for a name that is not one of the five.Your own sounds
Your sounds play through the game’s positioned sound, the one other players’ voices use, so the level’s mix and echo apply. They play only in a level: out of one,play fails, and leaving a level ends every sound playing.
How loud a sound is depends on how far it is from the camera: it is at its volume at the camera and fades to silence at range metres.
Sound files
A sound is a WAV file in your package:- RIFF WAVE, 8, 16, 24 or 32-bit PCM, 32-bit float, or 4-bit IMA ADPCM (format
0x11, the layout ffmpeg’sadpcm_ima_wavwrites); - 1 to 8 channels, 4,000 to 192,000 samples a second;
- at most 30 seconds long, and at most 8 MB.
Sounds held
A plugin can play any number of different files over a session. It holds at most 96 of them (32 up to ReSkate 2.1.4), read and turned into 48 kHz mono, and at most 128 MB of their samples (64 MB up to ReSkate 2.1.4), at once. Past either, the file played longest ago that no sound is playing now is let go. It is read from your package again if you play it again. Only when every file the plugin holds is still playing doesplay raise an error for a new one: a plugin holds at most 96 different sounds (128 MB) at once, and all it holds are playing.
At 48 kHz mono, 128 MB is about 22 minutes of sound.
reskate.audio.play(sound, options)
Starts a sound and returns its id.
A WAV file’s path in your package (see package paths), at most 200 characters, or
"motor" for a synthesised motor: four rotors and a rush of wind, whose note follows throttle and wind follows speed.Why not, when
id is false: “more than 20 sounds in a second”, or “it plays 128 sounds already, or there is no level”.Options
A number outside its range raises an error (“volume is 0 to 1”).
Needs
audio. A plugin plays at most 128 sounds at once (and all plugins 256; 8 and 48 up to ReSkate 2.1.4), and starts at most 20 in a second; past those, it returns false and why. Raises an error for a file that is not in the package, cannot be read, is not a WAV it can play or is longer than 30 seconds, for a new file while every file the plugin holds is playing (see sounds held), and for an option out of its range.reskate.audio.set(id, options)
Changes a sound while it plays.
Any of
volume, pitch, range, throttle, speed and position, with the ranges above. Options you leave out keep their values. loop cannot be changed.true when it was changed; false when the sound has finished, was stopped, or is not this plugin’s.Needs
audio. Raises an error for an id that is not a whole number of 1 or more, and for an option out of its range.reskate.audio.stop(id)
Stops a sound. It goes silent at once. A sound that has finished, or is not this plugin’s, is ignored.
Needs
audio.reskate.audio.playing(id)
Whether a sound still plays.
true while it plays; false once a WAV that does not loop has played out, after stop, after leaving the level, or for a sound that is not this plugin’s.Needs
audio.Preloading a sound
A sound file is read and decoded the first time you play it, inside that call. On a hard disk, that first read of a big sound in a tick can take long enough to be warned about, or even stopped (see limits).preload reads it ahead on a thread of its own, so play finds it held instead of reading it.
reskate.audio.preload(path, fn)
Starts reading and decoding a WAV file in your package, off the game’s thread.
The sound’s path in your package, such as
"sounds/song.wav", at most 200 characters. Only a package file can be preloaded.Called as
fn(ok, why) in a later tick, once the sound is held or cannot be: ok is true when it is held, and otherwise why says why not. Leave it out when you need no answer.fncomes at the start of a tick, before its timers and tick handlers.- A sound your plugin holds already is not read again.
fnstill comes, in the next tick. - A path being read already is read once. Each call’s
fncomes when it is done. - When the sound is handed over, it is held like one you played, under the same limits (see sounds held). When every sound your plugin holds is playing,
fngetsfalseand"a plugin holds at most 96 different sounds (128 MB) at once, and all it holds are playing". A preloaded sound can be let go later to make room, like any other. - A file that cannot be read gets
falseand"it cannot be read: "and the reason, such asnot foundoris larger than 8 MB. One that is not a WAV it can play gets"it cannot be played: "and the reason. - If your plugin stops or unloads first, the read is dropped and
fnnever comes.
Needs
audio. At most 8 preloads wait at once, clips and sounds together; past that it returns false and why. "motor" raises motor: only a file in the plugin's own package is preloaded, and so do a path longer than 200 characters or outside your package, and an fn that is not a function.