Log inGet started
World

Downbeat: Rhythm Game Kit with Beat Clock, Note Highways and Timing Judgement

Branchmain
Branchesmain
Commitda2e134ac2

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 on entity, the voice audio.voice(entity.id) reports and the beat clock reads, on the engine music channel, at its volume times soundstage's music group level and ducks (Mix.gain("music")), so a game's soundstage mix, ducking and Music slider apply. The track has play, pause, stop and setVolume. 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 sfx group.
  • Hit sounds (Sound.hit("don" | "ka" | "tick" | "miss", clip?)) play through soundstage.sfx as the downbeat bank on the sfx group, 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 }), then Sound.update() every frame after clock: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 an audio.stream at 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 through soundstage.sfx on 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().sound carries 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.