Journal/audio · motion · tutorialEntry 08 / 10
Audio-reactive visuals
How amp, bass, beat and beats are computed from the soundtrack, what the waveform layer draws, and a complete music visualizer built from one repeated bar.

▸ blog-audio-visualizer1280×720 · 30 fps · 0:06.0Rendered by vidmake
Motion that follows the music is one of those effects that is easy to describe and fiddly to build. Usually someone exports the audio, runs an analysis script, writes the results to a keyframe file and imports it. vidmake 0.2 skips those steps: four expression variables carry the soundtrack's loudness, low end and beats, and any numeric or color field can use them.
This post explains exactly what those variables measure, then builds up to a full visualizer. All the demos here use the same 12-second test track that ships with vidmake's examples, so turn the sound on when you play them.
#The four variables
{ "fonts": [ { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }, { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" } ], "compositions": [{ "id": "meters", "description": "The four audio variables as live meters: amp, bass and beat as bars, beats as a counter (sound on)", "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea", "layers": [ { "id": "music", "type": "audio", "src": "assets/music.mp3" }, { "id": "title", "type": "text", "text": "the soundtrack, as numbers", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 60, "letterSpacing": -2.8, "fill": "#161412", "y": 120 }, { "id": "name", "type": "text", "text": "${pick(i, ['amp', 'bass', 'beat'])}", "font": "JetBrains Mono", "fontSize": 22, "fill": "#161412", "anchor": "left", "x": 180, "y": 340, "repeat": { "count": 3, "layout": "column", "spacing": 110 } }, { "id": "track", "type": "rect", "anchor": "left", "x": 340, "y": 340, "width": 640, "height": 14, "fill": "#e9e4d8", "repeat": { "count": 3, "layout": "column", "spacing": 110 } }, { "id": "level", "type": "rect", "anchor": "left", "x": 340, "y": 340, "height": 14, "repeat": { "count": 3, "layout": "column", "spacing": 110 }, "width": "=14 + 626 * pick(i, [amp, bass, beat])", "fill": "=pick(i, ['#161412', '#4a4640', '#c92a26'])" }, { "id": "readout", "type": "text", "text": "${pick(i, [amp, bass, beat]):2}", "font": "JetBrains Mono", "fontSize": 22, "fill": "#8a857a", "anchor": "right", "x": 1100, "y": 340, "repeat": { "count": 3, "layout": "column", "spacing": 110 } }, { "id": "beats-name", "type": "text", "text": "beats", "font": "JetBrains Mono", "fontSize": 22, "fill": "#161412", "anchor": "left", "x": 180, "y": 560 }, { "id": "pip", "type": "ellipse", "width": 22, "x": 500, "y": 560, "repeat": { "count": 8, "layout": "row", "spacing": 44 }, "fill": "=i < beats ? lerp('#161412', '#c92a26', beat * (i == beats - 1)) : '#e9e4d8'" }, { "id": "beats-count", "type": "text", "text": "${beats}", "font": "JetBrains Mono", "fontSize": 22, "fill": "#8a857a", "anchor": "right", "x": 1100, "y": 560 } ] }]}| variable | range | meaning |
|---|---|---|
amp | 0..1 | loudness of the whole mix |
bass | 0..1 | loudness of the low end, below roughly 150 Hz |
beat | 0..1 | 1 on each detected beat, decaying to near 0 within about 0.3 s |
beats | 0, 1, 2… | number of beats detected so far |
They are computed once per render from everything audible in the composition: every audio layer and the sound of every video layer that isn't muted, after their volume curves and fades. The analysis only runs when some expression or text template in the project actually mentions one of the four names, so projects that don't use them pay nothing. When nothing is playing, all four are 0, and if a project uses them but has no audio at all, validate and timeline say so with a warning instead of leaving you to wonder why nothing moves.
Here is what happens under the hood, in the order the analysis runs:
- Mix. All clips are mixed down to mono at their positions on the timeline.
- Measure. For each video frame,
ampis the RMS level of the mix during that frame.bassis the same measurement on a copy of the mix passed twice through a ~150 Hz low-pass filter, which keeps kick drums and bass lines and drops almost everything else. - Normalize. Both are divided by the track's own 98th-percentile level, then capped at 1. So
1means "as loud as this track gets", not an absolute level, and a quietly mastered track still uses the whole 0..1 range. - Find beats. A beat is a frame where a low-end-weighted energy (70%
bass, 30%amp) peaks, clearly above its average over the previous 0.4 seconds, and at least 0.18 seconds after the previous beat. - Smooth.
ampandbassrise instantly and fall back over about 0.1 seconds, so they don't flicker frame to frame.beatjumps to 1 at each onset and decays exponentially with a 0.15-second time constant.
That decay is easiest to see as numbers. trace prints a text layer's content at each sample, and the third readout in the meters demo prints beat:
$ vidmake trace blog-audio-meters.json -l readout.2 --every 3 --to 1.2s
FRAME TIME X Y W H ROT SCALE OPAC NOTES
0 0.00s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "1.00"
3 0.10s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.51"
6 0.20s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.26"
9 0.30s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.14"
12 0.40s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.07"
15 0.50s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.04"
18 0.60s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.02"
21 0.70s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.01"
24 0.80s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.00"
27 0.90s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.00"
30 1.00s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "1.00"
33 1.10s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.51"
36 1.20s 1100.0 450.0 52.8 26.4 0.0 1.00 1.00 "0.26"The test track's beats land at 0, 1 and 1.5 seconds and then repeat every two seconds, which is why the readout jumps back to 1.00 at frame 30. beats counts from the start of the composition, not from the start of the layer that reads it, so it's safe to use for anything that should advance with the music, like pick(beats, [...]) for colors or slides.
#Recipes
Most audio-reactive motion is one of four shapes. All of these are single expressions.
Pulse on the beat. Scale, glow or brightness that kicks and relaxes:
"scale": "=1 + 0.08 * beat"Follow the energy. Sizes, opacity and blur that breathe with the music. bass gives a heavier, slower feel than amp:
"opacity": "=0.25 + 0.75 * bass"Advance on each beat. Discrete changes such as colors, words or positions:
"fill": "=pick(beats, ['#161412', '#c92a26', '#1f5fb0'])"Shape the decay. beat falls off fast. Raising 1 - beat to a power turns it into an expanding ripple that starts slow and accelerates, which reads as a shockwave rather than a flash:
"width": "=240 + 900 * pow(1 - beat, 2)", "height": "=240 + 900 * pow(1 - beat, 2)", "opacity": "=beat"The release notes have a demo that combines all four on one word.
#The waveform layer
Expressions get a few numbers per frame. When you want the shape of the sound itself, use the waveform layer. It reads its own src (an audio or video file, synced to the layer's time plus trimStart) and draws it in one of three modes:
{ "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }], "compositions": [{ "id": "waveform", "description": "The waveform layer's three modes on the same track: bars, mirror and line (sound on)", "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea", "layers": [ { "id": "music", "type": "audio", "src": "assets/music.mp3" }, { "id": "label", "type": "text", "text": "${pick(i, ['bars', 'mirror', 'line'])}", "font": "JetBrains Mono", "fontSize": 15, "letterSpacing": 1.8, "uppercase": true, "fill": "#8a857a", "anchor": "left", "x": 100, "y": 360, "repeat": { "count": 3, "layout": "column", "spacing": 210 } }, { "id": "bars", "type": "waveform", "src": "assets/music.mp3", "mode": "bars", "bars": 40, "gap": 0.3, "width": 900, "height": 150, "x": 690, "y": 150, "cornerRadius": 3, "fill": "#161412" }, { "id": "mirror", "type": "waveform", "src": "assets/music.mp3", "mode": "mirror", "bars": 64, "gap": 0.35, "width": 900, "height": 150, "x": 690, "y": 360, "cornerRadius": 2, "fill": { "type": "linear", "angle": 90, "stops": ["#8a857a", "#161412"] } }, { "id": "scope", "type": "waveform", "src": "assets/music.mp3", "mode": "line", "width": 900, "height": 150, "x": 690, "y": 570, "stroke": "#c92a26", "strokeWidth": 2.5 }, { "id": "divider", "type": "rect", "width": 1080, "height": 1, "fill": "#d8d1c1", "x": 640, "y": 360, "repeat": { "count": 2, "layout": "column", "spacing": 210 } } ] }]}barsis a spectrum. Each bar measures one frequency, spaced logarithmically from 40 Hz on the left to 8 kHz on the right, over a 60 dB range.barssets the count,gapthe space between them (0..1 of each slot), andcornerRadiusrounds them.mirroris the same spectrum with each bar centered vertically, which is the classic podcast-player look.lineis an oscilloscope: the raw waveform around the current moment, drawn with the layer'sstroke.
The test track is made of almost pure tones, so its spectrum is a few narrow peaks rather than the dense mountain range you'd get from a real recording. That's an honest picture of the file. With music, bars and mirror fill out.
Note the difference in sources: the waveform layer draws whatever file you point it at, whether or not it's audible, while amp, bass, beat and beats always describe the composition's actual mix. You can visualize a muted stem, or drive everything from the final mix and not draw a waveform at all.
#A visualizer, start to finish
{ "fonts": [ { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }, { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" } ], "compositions": [{ "id": "visualizer", "description": "A music visualizer: 96 bars driven by bass and noise, a disc that pulses on beat, and a beat counter (sound on)", "width": 1280, "height": 720, "fps": 30, "duration": "6s", "background": "#131210", "grain": 0.04, "layers": [ { "id": "music", "type": "audio", "src": "assets/music.mp3", "fadeOut": "0.6s" }, { "id": "bloom", "type": "ellipse", "width": 900, "height": 900, "opacity": "=0.25 + 0.75 * bass", "fill": { "type": "radial", "stops": ["#f05a4e30", "#f05a4e00"] } }, { "id": "ring", "type": "group", "rotation": "=t * 10", "chromaticAberration": "=6 * beat", "children": [ { "id": "bar", "type": "rect", "width": 5, "height": 30, "anchor": "bottom", "repeat": { "count": 96, "layout": "radial", "radius": 178, "rotate": true }, "scaleY": "=0.4 + 5 * bass * (0.35 + 0.65 * noise2(i * 0.4, t * 1.5))", "fill": "=lerp('#efebe2', '#f05a4e', clamp(bass * noise2(i * 0.4, t * 1.5) * 1.6, 0, 1))" } ] }, { "id": "disc", "type": "ellipse", "width": 300, "scale": "=1 + 0.07 * beat", "fill": { "type": "radial", "center": [0.5, 0.35], "stops": ["#1d1b18", "#131210"] }, "stroke": "#efebe255", "strokeWidth": 1.5, "glow": { "radius": 30, "strength": "=0.4 + beat", "color": "#f05a4e" } }, { "id": "count", "type": "text", "text": "${pad(beats, 2)}", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 120, "letterSpacing": -5, "fill": "=lerp('#efebe2', '#f05a4e', beat)", "y": "47%", "scale": "=1 + 0.07 * beat" }, { "id": "unit", "type": "text", "text": "beats", "font": "JetBrains Mono", "fontSize": 13, "letterSpacing": 2.4, "uppercase": true, "fill": "#8f8a7f", "y": "59%" }, { "id": "floor", "type": "waveform", "src": "assets/music.mp3", "mode": "mirror", "bars": 120, "gap": 0.5, "width": 1280, "height": 70, "y": 680, "fill": "#efebe2", "opacity": 0.35 } ] }]}It looks busy, but the whole project is eight layers, counting the audio, and all 96 bars of the ring are one of them.
The ring is a single 5×30 px rect, repeated 96 times around a 178 px radius with "rotate": true so each copy points outward, and "anchor": "bottom" so it grows away from the center. Its length is:
"scaleY": "=0.4 + 5 * bass * (0.35 + 0.65 * noise2(i * 0.4, t * 1.5))"bass sets the overall energy. noise2(i * 0.4, t * 1.5) is smooth 2D noise in which neighboring bars (close i) get similar values and the pattern drifts over time, so the ring has organic peaks instead of 96 identical bars. The same noise term blends each bar's color from off-white to red with lerp, so the tallest bars run hottest. The ring is wrapped in a group that rotates slowly (=t * 10) and gets a chromaticAberration of 6 * beat, a few pixels of RGB split that flashes on each beat.
The disc in the middle scales with 1 + 0.07 * beat, and its red glow has strength 0.4 + beat, so it flares on the beat and settles.
The counter prints ${pad(beats, 2)} and blends its color toward red with lerp('#efebe2', '#f05a4e', beat).
The bloom behind everything is a large radial gradient with opacity 0.25 + 0.75 * bass: the whole frame warms up when the low end hits. The floor is a mirror waveform across the bottom at 35% opacity, and the composition's grain adds texture.
None of these values are keyframed, and none of them reference the track's tempo. Swap assets/music.mp3 for another song and the visualizer follows it.
#Checking audio-driven motion
Audio-reactive projects are harder to check by eye, because a still frame says nothing about timing. The tools still help:
timelinelists every audio clip with its start, length, trim and rate under anAudio:heading, which is the first thing to check when the beats seem late.traceon a text layer that prints the variable you're using, as above, shows exactly when beats land. Add a temporary readout layer like"text": "${beats} ${bass:2}"and trace it, then delete it.storyboard --atwith times on and between beats (here--at 0s,0.2s,1s,1.2s) shows the extremes of every pulse side by side.render --draftgives a quick full-length preview with sound for the final check of sync.
Note
Since 0.2.1,
vidmake analyze music.mp3(orvidmake analyze project.json) prints the beat times, tempo andamp/basscurves directly, and warns when a variable sits at 1 for long stretches. See analyze.
The audio-reactive reference has the variable definitions, and waveform covers the layer's fields.
Keep reading

Four reels, thirty seconds each
A Swiss poster, a piece of generative op-art, a data poem and a risograph collage. Each is a single vidmake JSON file, written, checked and rendered by an agent, using nothing but the four stock assets.
Read
What's new in vidmake 0.5
Markers name the beats of a video, decoration draws underlines, strike-throughs and highlights from the glyphs, design tokens and named easings bring a brand's system into a project, and WOFF2 fonts, synthetic italics, skewX, themed SVG icons, repeat origins and wipe edges close the gaps an agent hit making a 20-second ad.

What's new in vidmake 0.2.1
vidmake analyze shows the beats and loudness curves that audio-reactive expressions will see, rich-text spans take fontWeight, italic and font, drawMode: "total" draws many strokes with one pen, and source builds report the right version.