battlecore::audio
The audio module controls the device audio pack, master volume, and the playback of named tracks, synthesised tones and audio groups. Include its declarations with include "./battlecore/audio.bst";.
getIsPlaying
Returns whether a track is currently playing.
native bool battlecore::audio.getIsPlaying ();getAudioPack / setAudioPack
Gets or sets the audio pack by name. Track names are looked up inside the pack in use.
native string battlecore::audio.getAudioPack ();
native bool battlecore::audio.setAudioPack (string newVal);getMasterVolume / setMasterVolume
Gets or sets the speaker volume, 0 to 255. This is the same value as battlecore::device.getVolume and setVolume. A change made by a script lasts until the device restarts.
native uint battlecore::audio.getMasterVolume ();
native bool battlecore::audio.setMasterVolume (uint newVal);trackStart
Plays a named track from the audio pack, at volume (0 to 255) on the given layer.
native uint battlecore::audio.trackStart (string trackName, uint volume = 255, uint layerId = 0);It is declared to return a track id, but the firmware returns 0 today.
groupStart / groupStop
Starts or stops one of the audio groups built into the firmware, by number. With onlyIfNotPlaying set, groupStart does nothing while that group is already playing.
native uint battlecore::audio.groupStart (uint groupNumber, bool onlyIfNotPlaying = false);
native uint battlecore::audio.groupStop (uint groupNumber, uint fadeOutMs = 0);groupStop does not pass fadeOutMs on yet, so the group stops at once.
countdownStart / countdownStop
Speaks a countdown in the audio pack's voice, in time with its deadline. It says each whole second from speakFrom(at most 30) down to one. When the countdown is longer than that, it says "thirty" and "twenty" first. At zero it plays finalTrack ("" for none).
A number that would be more than 600 ms late is skipped. countdownStartreturns the countdown's id, and countdownStop silences it. Leaving the game silences every countdown.
native uint battlecore::audio.countdownStart (int seconds, int speakFrom = 10, string finalTrack = "");
native bool battlecore::audio.countdownStop (uint countdownId);The firmware speaks the start countdown itself: its last ten seconds, then "starting-game.wav". The shipped games speak a respawn's last five seconds, and CTF speaks a dropped flag's pass window. None of them speaks in the first second, which belongs to the sound the moment plays. All of these follow the game's countdownVoice setting:
bool countdownVoice = battlecore::config.get("countdownVoice", true);
int respawnCountdown = 0;
state StateEnum.RESPAWNING {
module ModuleEnum.FSM {
event EventEnum.EXIT (EventData evt) => {
battlecore::audio.countdownStop(respawnCountdown);
}
event EventEnum.ENTER (EventData evt) => {
battlecore::audio.trackStart("respawning.wav");
if (countdownVoice) {
respawnCountdown = battlecore::audio.countdownStart(battlecore::player.getRespawnTimeSecs(), 5);
}
}
}
}trackStop, toneStart and toneStop
These are declared, but the firmware does not support them yet. Calling one returns an error and plays or stops nothing.
native bool battlecore::audio.trackStop (uint trackId);
native uint battlecore::audio.toneStart (uint waveform, float freqHz, uint volume = 255, uint duration = -1, bool isIntermittent = false, uint onTimeMs = 100, uint offTimeMs = 300);
native bool battlecore::audio.toneStop (uint toneId);