All work

Case study 02 / Working system, broadcasting 24/7

Auto DJ: an AI that analyzes, plans, mixes, and grades a set.

Point it at a music library. It measures every track, turns the measurements into words for a calibrated judgment model, plans a set that can never break a harmonic rule, renders each transition the way a DJ would, and grades the result from the audio before anything ships.

Private repository. Walkthrough on request. Architected and shipped by me, directing a team of coding agents.

Auto DJ figures: the Camelot wheel with the legal moves from 3A highlighted, a kick envelope under a fitted beat grid, and the volume, bass, and reverb lanes of a transition.
01 / The problem

The problem

Turn a folder of songs into a set a working DJ would sign off on: every blend in time, in key, and on phrase, with taste, for hours, and proven to sound right.

A DJ makes a hundred small calls a minute on top of millisecond timing: when to bring the next song in, where its bass takes over, which song should come next, and whether the room is still with them. Auto DJ has to make every one of those calls, for a five-hour set, with nobody at the decks.

02 / What made it hard

What made it hard

Six things have to be right at once, and each one breaks the mix on its own.

  1. 01

    Millisecond timing

    Kicks more than about 5 ms apart flam. A neural beat tracker lands within tens of milliseconds.

  2. 02

    Harmony

    Clashing keys ruin a blend even when the beats are perfect, and single key detectors often disagree.

  3. 03

    The shape of a song

    Mixing on phrase means knowing where the verse, build, and drop start, to the bar.

  4. 04

    Taste

    Among the technically legal ways to mix two songs, a few feel right. That is hard to write as a rule.

  5. 05

    Order over hours

    Hundreds of songs, every neighbour legal, one tempo, and still a shape to the night.

  6. 06

    Knowing it worked

    A plan can look right and still flam, clash, or stack two basslines once it is rendered.

03 / How we solved it

How we solved it

One fix per hard part, each owned by a component with a narrow contract and its own test.

  1. 01

    Millisecond timing

    Fit one straight-line grid through the tracker's beats, nudge it onto the kick transients, then render each blend, measure it, and correct it until it locks.

    Median offset between decks: 0.3 ms.

  2. 02

    Harmony

    Three key profiles vote. The Camelot rule (same key, one step, or the relative key) is enforced in the candidate query and checked again on the keys playing in the blend bars.

    No song pair is ever planned outside the rule.

  3. 03

    The shape of a song

    Segment on 4, 8, and 16-bar phrase lines, find drops where the song gets suddenly louder and fuller, and let Jev label each section.

    Cues and blends land on real phrase lines.

  4. 04

    Taste

    Jev chooses among options that already pass every rule, and its answer counts for 30%.

    Judgment where it helps, never where it can break something.

  5. 05

    Order over hours

    Score every legal pair once, seed the loop with the hardest-to-place songs first, then search the whole cycle at once.

    Transitions at risk of drifting fell from 28 to 3.

  6. 06

    Knowing it worked

    Grade every rendered transition from its own audio. A transition that will not lock within 2 ms is banned and the set is re-planned.

    Nothing ships on the plan alone.

04 / How it works

How it works

Nine stages, one plan. The same plan drives the audio render, the Rekordbox cues, and the grade, so they can never disagree.

How it works, end to end

Audio becomes measurements, measurements become words for Jev, and hard rules bound every choice. The gold badges mark where Jev makes a decision. A transition that fails the render gate sends its pair back to the planner, never to be used again.

Libraryaudio files, any formatAnalyzebeat_this, Essentia, DemucsDescribemeasurements as wordsJudgesections, genre, key tiesJevCueshot cues A to H, countdownsHard rules bound every choice: key-legal moves only, one tempo, one bassline at a time, lock within 2 ms or re-planOutputsmix, Rekordbox XML, streamGradenine-part scorecardGatelock within 2 msRenderEQ, key-lock stretch, syncJevPlanlegal pairs, loop searchJevfails the gate: the pair is banned and the set is re-planned

Analyze: a grid you can mix on

A neural beat tracker finds beats and downbeats. Auto DJ fits one straight line through them, snaps the tempo to the whole BPM a producer used, and nudges the grid onto the kick drum. Three key detectors vote on the key. Stem separation says, bar by bar, whether drums, bass, and vocals are playing.

Kick drum envelope over four bars with the fitted beat grid: thin lines on every beat and gold lines on each bar, the chorus starting on the third bar.
Four bars at a chorus. The kick drum's energy for "Don't Trade the Locket" (125 BPM, 3A) with the fitted grid on top. Every gold bar line sits on a kick; the chorus starts on the third bar.

Structure: where the song goes

Sections start on phrase lines, so the segmentation prefers boundaries every 4, 8, and 16 bars. The drop is where the song suddenly gets louder, fuller, and busier. Jev reads the measurements as words and labels each section.

The same song over 125 bars: colored section bands for intro, verse, pre-chorus, chorus, and outro; blue bars for how much changes at each bar; a gold energy line; and lanes showing when drums, bass, and vocals play.
The shape of one song. Section bands on top, how much changes at each bar in blue, the song's energy as the gold line, and when drums, bass, and vocals are playing underneath. The two choruses are the energy peaks.

Plan: legal, then good

Candidates come from a query that only returns key-legal, tempo-safe songs. Each legal pair gets a value from key, tempo, phrase fit, and energy, plus Jev's choice. For a five-hour loop, every legal pair is scored once and the whole cycle is searched at once, shaping the night toward a target energy curve.

Two target energy curves across a set: a party arc that climbs to a peak near three quarters and lands, and a looping concert with three waves that end where they start.
The shape of the night. The party arc climbs to a peak about three quarters of the way through. A looping concert runs three waves that end where they start, so the loop joins cleanly.
Camelot wheel with 3A highlighted, its legal neighbours shaded gold, and the two energy-boost moves outlined.
The Camelot wheel. From 3A, the only legal moves are the same key, one step either way on the same ring, or straight across to the relative key. The dashed boosts exist only in a looser mode.

Render: mix the way a DJ does

Volume, a three-band EQ, and one reverb, nothing more. In the house drop-swap, the outgoing song's bass is gone within a quarter bar, the incoming song's bass arrives on its drop downbeat, so two basslines never play at once. Each deck is rendered, measured against the other, and corrected until the beats lock.

Volume, bass EQ, and reverb curves for two decks over an eight-bar transition, with a vertical line at the incoming song's drop.
One transition, lane by lane. The outgoing deck washes out in reverb while the incoming deck's build rises. On the drop downbeat its bass comes in, its reverb is cut, and the other song is gone.
Auto DJ transition review sheet: bar-by-bar low, mid, and high energy lanes for two songs, with section labels, vocal activity, volume, bass EQ, and reverb automation, marking the blend start, bass swap, build, and drop.
A real transition, as the system draws it. Both songs' sections and energy bands, the automation lanes, the bass swap, the build, and the drop.
05 / Rendering in the cloud

Rendering in the cloud

A five-hour set with video is far too much for a laptop. In the cloud it has to be fast, cheap, and impossible to leave running.

Plan locally, render in the cloud

The laptop plans; one Spot VM, as large as the region will give, mixes, gates, grades, and renders in parallel; the verified master stays in the cloud and only the stream copy comes down to a tiny 24/7 relay. A safety loop makes sure nothing is left running.

Before the renderPlan (laptop)mix plan and a 7,420-cut edit listLibrary bucketAutoclass, same region, free readsCapacity ladder180 → 90 → 60 → 56 → 32 vCPUsRun limitsized from the measured workOne Spot VM, up to 180 vCPUsPinned toolchainstatic ffmpeg 7.1 and uv, sha256-checkedParallel mixevery core, 48 kHz / 24-bit, cut where one song plays aloneMix gateeach blend within 2 ms and 3 LU, or swap and re-renderGrade each source oncecolor graded, then cached for every chunk that uses it653 video chunksabout 30 s each, one ffmpeg graph, encoded onceAfter the renderScratch bucketchunks, heartbeat, DONE / FAILED, 14-day expiryVerify and assemble587,381 frames must match the timelineJoin and QAno re-encode, audio muxed bit-identicallyMaster24 GB, stays putStream copy5.3 GB, comes down24/7 relaye2-micro, copies bytes to YouTube and TwitchSafety loop, always onA heartbeat reports progress, CPU, and memory. Silent for 15 minutes: the VM is replaced. Spot preempted: a new VMresumes and skips every chunk already uploaded. Status polling retries. A failed chunk stops the job.VMs delete themselves; the run limit is the backstop; a janitor runs before and after every render.A budget kill switch deletes every render VM and blocks new renders. Scratch expires in 14 days. AI generation has its own caps.
  • A 5.4-hour video in 14.1 minutesGraded and rendered on one 180-vCPU Spot VM at 23× real time, every one of 587,381 frames accounted for. 33 to 39 minutes end to end.
  • A 5.4-hour mix in 8.3 minutesEvery blend within 2 ms and 3 LU, mastered at 48 kHz / 24-bit to −12 LUFS and −1 dBTP.
  • About $2.20 a renderAt list price, and about $0.60 of that is the download. The 24 GB master never leaves the cloud.
One 5.4-hour set, rendered once
Edit list7,420 cuts, timed to the music
Video chunks653, about 30 seconds each
Frames587,381, checked against the timeline
Grade and render14.1 min on 180 vCPUs: 23× real time, 7.8 vCPU-seconds per second of video
Mix8.3 min, then loudness, loop trim, and lossless and MP3 encodes
End to end33 to 39 min, upload to verified master
What comes downthe 5.3 GB stream copy only; the 24 GB master stays in the cloud
Costabout $2.20 at list price, about $0.60 of it download
Before and after
StepBefore: one 32-vCPU VMNow: up to 180 vCPUs
Video5 h in 45 min (6.7× real time)5.4 h in 14.1 min (23× real time)
Mix5 h in 12 min5.4 h in 8.3 min
Saved plan to live streamabout 4 habout 1 to 1.5 h

One big machine, not a cluster

Chunked ffmpeg on a single Spot VM keeps every intermediate on one local disk and needs no scheduler or container registry, so going faster means asking for a bigger machine. A capacity ladder asks for 180 vCPUs first and steps down through 90, 60, 56, and 32 when the region is out of capacity, waiting on quota instead of failing. The run limit is sized from the measured work, so a stuck VM dies soon after it should have finished.

Cut where nothing changes

Video chunks are about 30 seconds, each one ffmpeg graph encoded once and uploaded the moment it is done; they join without re-encoding and the audio is muxed bit-identically. The mix is cut only where one song plays alone, so the parallel render matches a one-at-a-time render. A 12-song mix rendered in the cloud gave the same sync verdicts, level rides, loudness, and peaks as the laptop.

Do the expensive work once

Each source is color graded once and cached for every chunk that uses it. The stream copy is encoded once, at a constant 2 Mbps with x264's slowest preset, so the 24/7 broadcast only has to copy bytes.

Download is the real cost

The library lives in a same-region bucket with Autoclass, so reads are free and files nobody touches get cheaper on their own. Only the 5.3 GB stream copy comes down; the 24 GB master stays in the cloud.

Fail loudly, resume quietly

A heartbeat reports progress, CPU, and memory; a VM that goes silent for 15 minutes is replaced. If Spot reclaims the VM, a new one skips every chunk already uploaded. Every chunk's frame count is checked, the total must match the timeline exactly, and a blend that misses the gate is swapped and re-rendered automatically.

Nothing left running

VMs delete themselves, and a janitor runs before and after every render. A budget alert triggers a kill switch that deletes every render VM and blocks new renders; scratch storage expires after 14 days, and AI song generation has its own spend caps. Rendering runs in its own project with narrow custom roles, and the toolchain is pinned and checksum-verified.

The 24/7 broadcast

A free-tier e2-micro VM relays the finished stream copy to YouTube and Twitch around the clock. Because nothing is re-encoded, the smallest machine is enough, and the whole broadcast costs about $40 a month, almost all of it egress. An ingest checker confirms each platform is actually receiving, and a watchdog restarts the relay if it stops.

Saved plan to live, in about an hour

Going from a saved plan to a live stream used to take about four hours on 32 cores. It now takes about one to one and a half.

How I chose the machines: the same 20-minute slice on each (Spot, one region)
MachinevCPUs20 min of video inSpeedPer hour of video
c3d-highcpu-18018045 s26.5× real time$0.062
c2d-highcpu-32323.4 min6.0× real time$0.103
n4-highcpu-32323.7 min5.4× real time$0.129
c4d-highcpu-16164.5 min4.5× real time$0.057
c3d-highcpu-16166.0 min3.3× real time$0.044
06 / How a mix gets graded

How a mix gets graded

Two grades, for two decisions: one picks the set before anything is rendered, and one decides what ships after.

How a mix gets graded

Two grades. Before rendering, every legal pair gets a value that decides the set order: code-owned signals, Jev's choices, and the transition's own rule score, minus a risk term. After rendering, every transition is graded from its own audio, and the gate decides whether it ships.

Before rendering: decides the setKey compatibilitysame, ±1, or relative keyTempo changehow far B is stretchedPhrase alignmentverses line up, lands on a buildEnergy flowdistance to the night's targetTransition qualitybest legal window's rule scorePair value code 55%: key, tempo, phrase, energyJev choice 30%, rule score 15%minus sync riskJev flow verdicteach run of 3 songs: weak, fine, greatLoop searchevery pair legal, whole cycleSet orderkey-legal, on phrase, shapedAfter rendering: decides what shipsRendered blendA alone, overlap, BScorecard from the audiobeat lock 0.17harmony 0.17level glide 0.14arrival 0.14vocal overlap 0.12drop impact 0.11density 0.09brightness 0.06Gatelocked within 2 msshipsbanned, re-plan

Before rendering

Every legal pair gets a value. Code scores what it can measure: how smooth the key move is, how far the next song is stretched, whether the verses line up and the mix lands on a build, and how close the next song sits to the night's target energy. Jev adds the taste: which legal song should come next, and whether each run of three songs flows. The transition's own rule score and a sync-risk penalty finish it, and the loop search picks the order with the best total.

After rendering

Each transition is graded from the audio that was made: four bars of the outgoing song, the blend, and four bars of the incoming song into its drop. Beat lock and harmony weigh the most. Anything that fails the gate is banned from future plans and the set is planned again. Across 216 transitions, the whole-loop plan averaged 0.823, against 0.810 for planning one song at a time.

One thing we tested and dropped: asking Jev to re-score these measured facts added nothing. Its strength is judgment from words, so grading the audio stays in code.

07 / The Jev decision system

The Jev decision system

Jev, TypeSafe's calibrated judgment model, makes the taste calls. It never sees an option the rules would reject, and low confidence never acts on its own.

Where Jev decides

Four decision points, each a typed question over options the rules already allow. Every answer comes back as probabilities with a confidence, and code decides how much it counts.

AnalyzeTrack judgechoicewhich part is each sectionyes / nodoes the drop kick in hereyes / nodoes this lead into itchoicegenre, vibe, key tie-breakscorefamiliarity, set slotpooled 70/30 with the rule priorPlanNext songchoicewhich song follows30% of the pair valuePlanFlow of threescoredoes the run flowsteers search off weak runsRenderTransition criticchoicewhich window sounds best30%; the rules keep 70%Hard rules filter every option first, so no answer can make a clash, a double bassline, or an unlockable blend.
What Jev is asked, and what its answer can change
DecisionTyped questionHow the answer is usedWhen it is not trusted
Section labelsChoice among nine section types, plus yes-or-no: does the drop kick in here, does this lead into itPooled with the rule-based label: p=0.7 pJev+0.3 prulesp=0.7\,p_{\text{Jev}}+0.3\,p_{\text{rules}}A cue section under 0.2 confidence goes to a Needs review playlist
Key tie-breakChoice among the detectors' own candidates, never a free answerOverrides the voteOnly at 0.6 confidence or more
Next songChoice among the top 24 legal next songs30% of the pair value, next to 55% code and a lookaheadOn any error the planner uses its own score
Flow of threeScore: is this three-song run weak, fine, or greatSteers five rounds of loop search away from weak runsUnrated runs take the average
Transition windowChoice among up to four legal windows within reach of the best30% of the pick; the rule score keeps 70%Fewer than two options or any error: the rule pick stands

How confidence gates a decision

Measurements go in as words, Jev answers typed questions with probabilities and a confidence, and code decides what that answer may change. Low confidence never acts on its own: it falls back to the rule answer, sends the track to review, or leaves the plan as it was.

Measurements as wordsdrums full, bass none, vocals inTyped questionsscoreposition on a rubricchoiceone of N optionsyes / noP(true)Jev (TypeSafe)probability + confidenceCode-owned weightscomposite in codeConfidence gatelow: soften or skipActionlabel sectionpick a windowflag reviewtimeout, rate limit, malformedDeterministic path: the rule-based order or router takes overJev informs the decision. Thresholds and actions stay in tested code.A property test with a random critic proves the hard rules hold whatever Jev answers.
  • Rules first. Every option Jev sees already passes the key, tempo, bass, and sync rules.
  • Code owns the weights.Jev's share is 30% or pooled at 70/30, and it is set in code, not by the model.
  • Proven by test. A property test swaps in a random critic and checks that every hard guarantee still holds.
  • Cached and pinned. Every question and answer is cached by content, so a re-plan never pays twice.
08 / Results

Results

Mixes that lock, sets that stay in key, and a system that plays and broadcasts around the clock.

A five-hour mix on one page at 124 BPM in half-hour rows, each song labeled with its Camelot key above low and mid energy lanes, blend windows, and drop markers.
A planned five-hour set on one page.Half-hour rows, every song's key, its energy, the blend windows, and the drops.
  • A mastered mixLoudness matched to -12 LUFS under a -1 dBTP true-peak limiter, every blend locked or re-planned.
  • Rekordbox cuesHot cues A to H and 8 and 4-bar countdowns to each drop, so a human can play the same set by hand.
  • A 24/7 broadcastPre-rendered mixes loop to YouTube and Twitch behind ingest checks and a watchdog.

The songs can come from my AI music pipeline, which generates and quality-gates them before they are ever analyzed.