Music and sound
A cinematic fades its music in over the map's (and the map's back after), plays stingers, sounds, voices and video, and can turn a bus down for a stretch. Every sound is a clip held in time with the cinematic's clock.
Quick start
cut.audio.music('battle', { crossfade: 2, volume: 0.8 }) // a track or several; null for none
cut.audio.stinger('horn') // a short piece over the music
cut.audio.sound('drum', { at: 'drummer' }) // on a unit, followed as it moves
cut.audio.voice('commander.go')
cut.audio.volume('ambience', 0.2, 0.5) // the bus to 20%, eased over 0.5 sBattle music crossfades in, a horn sounds, a drum follows the drummer, and the ambience drops while the commander speaks.
Common tasks
Shape a sound
{ "at": 2, "for": 6, "id": "radio", "voice": "pilot.mayday", "highpass": 400, "lowpass": 3500, "in": 0.2, "out": 1 }A radio voice: filtered, faded in and out.
Control a sound from a script
const wind = cut.audio.sound('wind', { loop: true, lowpass: 500, in: 2 })
wind?.lowpass(4000, 3) // the door opens
await cut.wait(5)
wind?.stop(1.5)Add Web Audio nodes of your own
hooks: {
'item:radio:start': (_cut, { clip }) => {
const sound = clip!.handle as CutSound
const crackle = sound.context.createWaveShaper()
crackle.curve = Float32Array.from({ length: 256 }, (_, i) => Math.tanh(((i - 128) / 128) * 4))
const remove = sound.insert(crackle) // after the filters
void sound.ended.then(remove)
sound.output.connect(meter) // an analyser beside it
}
}Play a video
const corner = cut.video('letter.mp4', {
for: 4,
x: 0.6, y: 0.05, width: 0.35, height: 0.35,
in: { kind: 'wipe', seconds: 0.6, from: 'left', ease: 'outQuad' },
out: { kind: 'iris', seconds: 0.5 },
sepia: 1, to: { sepia: 0 }, radius: 12, border: 2
})
await corner?.done
const film = cut.video('battle.mp4', { in: 1, chroma: '#00ff00', id: 'battle' }) // green screen keyed out
cut.video('flare.mp4', { layer: 'hud', blend: 'screen', for: 1 }) // over the HUD, its black let go
await film?.endedA video in a corner, wiped in, going from sepia to colour; then a full-screen film; then a flare over everything.
Upload a sound or video
In the Inspector's sound, music or video field, Upload takes an MP3 (or MP4/WebM) into the game's folder (sounds/, sounds/music/ or videos/) and names it in the field (editor.importMedia(file, 'sound' | 'music')). You can also drop one from the Assets panel, and ▶ plays it.
Editor
- Add an Audio lane and double-click it for a clip.
- Pick its sound, music, stinger or voice from the list of the game's files.
- Set Fade in, Fade out, Ease, Start, Rate, Loop, Pan, Low-pass, High-pass, Reverb, Echo, and the End values to ease to.
- The clip shows the file's waveform; the preview plays it as the game would.
- For video, add a Video lane: the file, its box, fit, opacity, volume, bus, transitions in and out, its look, and a chroma key.
Reference
Audio clips
{ at, music, crossfade, volume }, { at, stinger }, { at, sound, on }, { at, voice }, { at, for, bus, level, crossfade }. A sound is a take of sounds/<name>_N.mp3, music a track in sounds/music/. Only MP3s.
A sound's shape (SoundShape)
| Field | What |
|---|---|
volume | how loud (1) |
in, out | fade in at its start, out before its end, along the clip's ease |
start | seconds into the file it begins |
rate | speed and pitch (1; 2 an octave up), times the cinematic's rate |
pan | −1 to 1, over where it is heard from (on) |
loop | over and over for its for |
lowpass, highpass | filter cutoffs in Hz |
reverb | how much room, 0 to 1 |
echo | seconds to its echo, each a third as loud |
to: { volume, pan, rate, lowpass, highpass } | eased to over the clip |
whole | lasts as long as its file (As long as its file) |
How sounds keep time
- A clip with
forlasts that long; withwhole, until its file ends; with neither, it is heard once as its moment is reached (not on a seek). - The clock leads: a sound is put back where it drifts more than an eighth of a second, pauses with the cinematic and slows in slow motion. A line that holds the clock doesn't hold the voice.
- Seeked into, a clip with
fororwholestarts that far into its file. - On a unit (
on), it follows the unit, as loud as the game's sound would be from the camera. - Music:
crossfadefades it in over the music before; a music clip withforandoutlets go at its end, else it plays until another clip or the cinematic's end gives the map's back. - Nothing plays before the player's first click or key (the browser's rule). A muted game still plays it, silent, so timing holds.
CutSound
stop(fade?), pause(), resume(), seek(seconds), volume(level, seconds?, ease?), fade(level, seconds?, ease?), rate, pan, lowpass, highpass; duration, currentTime, playing, started, ended; at(spot); raw: context, buffer, source, input, gain, output, nodes (highpass, lowpass, post, envelope, near, side, reverb, echo); insert(input, output?).
source → fader → input → highpass → lowpass → (insert) → post ┬→ envelope → gain → near → side → output (pan) → bus
├→ reverb → wet ┘
└→ echo ⟲ → wet ┘A clip's handle is RunningClip.handle; music is a CutMusic (cut.audio.musicNow()). The stage plays sounds through StageAudio.play(name, SoundPlay) (the client's SoundPlayer.sound; PlayedSound is its CutSound). SoundPlayer.setMusic(tracks, { crossfade, volume }) and SoundPlayer.scale(bus, level, seconds) underlie music and bus levels.
Video clips
| Field | What |
|---|---|
video | a file in videos/ (MP4 or WebM), or an address |
layer | picture (default: drawn in the picture, under the screen's fade and bars), screen (an element over the picture), hud (over everything) |
x, y, width, height | its box, in shares of the screen from the top left |
fit | contain (default), cover, fill |
opacity, z | |
start, rate, loop | in time with the cinematic's clock (nudged when it drifts a sixth of a second) |
volume, bus | heard through the game's mixer (effects by default) |
in, out | seconds of a fade, or { kind, seconds, from, ease }: fade, slide, zoom, wipe, iris (at), blur, flip |
| look | brightness, contrast, saturate, grayscale, sepia, invert, hue, radius, rotate, scale, border, borderColor; on the page only: blur, blend, shadow, shadowColor, class, css |
chroma, chromaThreshold, chromaSoft | a colour keyed out (picture layer only) |
to | box, opacity and look at the clip's end |
A clip with no for lasts as long as its file once its length is known. In the picture, the video is a VideoTexture drawn by a pass of its own just before the screen's blur and frame, after the picture's grade and lens. From code, a CutVideo: element, plane (StageVideoPlane, its texture and pass), clip, time, playing, ended, done, stop(), and sound (a CutMediaSound: source, gain, volume, insert, bus, context). Find one with cut.running({ lane: 'video' }) or cut.runningOf(id). A video from another address needs its server's CORS leave. A 1080p video keeps 60 fps on the sandbox.
Not yet: a waveform of a video's sound, a video on a model in the world, compression of videos.