Downbeat: Rhythm Game Kit with Beat Clock, Note Highways and Timing Judgement
README.md
sound
Downbeat's audio, routed through the soundstage package: the song, the calibration click track, the hit sounds and an in-play metronome. downbeat.rhythm and downbeat.calibrate call it; a game only needs it to change levels, swap sounds or read what was measured.
- Music (
Sound.track(entity, clip, { group = "music", volume })): the song plays on a voice of its own onentity, the voiceaudio.voice(entity.id)reports and the beat clock reads, on the enginemusicchannel, at its volume times soundstage'smusicgroup level and ducks (Mix.gain("music")), so a game's soundstage mix, ducking and Music slider apply. The track hasplay,pause,stopandsetVolume. soundstage's own music decks are not used for the song: they are shared between players, loop, crossfade and cannot pause or start on an exact sample, which a chart timed to the song needs. - Calibration clicks use the same kind of track on the
sfxgroup. - Hit sounds (
Sound.hit("don" | "ka" | "tick" | "miss", clip?)) play throughsoundstage.sfxas thedownbeatbank on thesfxgroup, with a 30 ms cooldown so a chord or a duplicated one-shot (#15080) plays once. The kit's own (Sound.builtinHitSounds()) were made with the engine's audio generator and cut so the transient starts within 1 ms of sample 0. - Metronome (
Sound.begin({ chart, clock, metronome = true }), thenSound.update()every frame afterclock:tick();Sound.setMetronome(on)): a click on every beat of the chart's tempo map (tempo changes included), accented on the first beat of each bar (meter:in the chart), count-in included. Clicks are mixed into anaudio.streamat the sample where each beat falls, scheduled ahead of the mixer from the beat clock, so they sound on the beat rather than on the next frame. Where no stream can be opened it plays them throughsoundstage.sfxon the first frame after the beat and reports the lateness.Sound.setMetronomeClips({ click, accent })swaps the sounds. Sound.stats()reports the metronome mode, clicks, how far the click stream sits from the music voice (alignMeanMs,alignMaxMs) and hit sounds played;Rhythm.diagnostics().soundcarries it.Sound.configure{ hitVolume = 0.5, metronomeVolume = 0.7, hitCooldown = 0.03, latencyMs = 100 }.
soundstage is looked up the first time it is needed and again at most once a second while it is missing (in a browser the dependency can load after this module). Without it everything still plays, on plain Audio voices on the same channels.
Sound.beatsBetween(chart, t0, t1) and Sound._render(...) are pure, which is how the test suite checks beat placement without an audio device.