vidmake v0.2.1
Download

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

00:00.0 · f 000
The four audio variables as live meters: amp, bass and beat as bars, beats as a counter (sound on)Download
variablerangemeaning
amp0..1loudness of the whole mix
bass0..1loudness of the low end, below roughly 150 Hz
beat0..11 on each detected beat, decaying to near 0 within about 0.3 s
beats0, 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:

  1. Mix. All clips are mixed down to mono at their positions on the timeline.
  2. Measure. For each video frame, amp is the RMS level of the mix during that frame. bass is 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.
  3. Normalize. Both are divided by the track's own 98th-percentile level, then capped at 1. So 1 means "as loud as this track gets", not an absolute level, and a quietly mastered track still uses the whole 0..1 range.
  4. 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.
  5. Smooth. amp and bass rise instantly and fall back over about 0.1 seconds, so they don't flicker frame to frame. beat jumps 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
$ 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:

json
"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:

json
"opacity": "=0.25 + 0.75 * bass"

Advance on each beat. Discrete changes such as colors, words or positions:

json
"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:

json
"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:

00:00.0 · f 000
The waveform layer's three modes on the same track: bars, mirror and line (sound on)Download
blog-audio-waveform.jsonjson
{  "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 } }    ]  }]}
  • bars is 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. bars sets the count, gap the space between them (0..1 of each slot), and cornerRadius rounds them.
  • mirror is the same spectrum with each bar centered vertically, which is the classic podcast-player look.
  • line is an oscilloscope: the raw waveform around the current moment, drawn with the layer's stroke.

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

00:00.0 · f 000
A music visualizer: 96 bars driven by bass and noise, a disc that pulses on beat, and a beat counter (sound on)Download

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:

json
"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:

  • timeline lists every audio clip with its start, length, trim and rate under an Audio: heading, which is the first thing to check when the beats seem late.
  • trace on 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 --at with times on and between beats (here --at 0s,0.2s,1s,1.2s) shows the extremes of every pulse side by side.
  • render --draft gives a quick full-length preview with sound for the final check of sync.

Note

Since 0.2.1, vidmake analyze music.mp3 (or vidmake analyze project.json) prints the beat times, tempo and amp/bass curves 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.

View .md Ask Claude Ask ChatGPT

Keep reading

showcasemotion

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

releasemotion

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.

Read

releaseaudio

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.

Read