I have a side project that turns a folder of tracks into a continuous DJ mix. It analyses each track, orders the set, beat-matches everything and renders a mastered file. For a long time the result was technically correct and still sounded like a machine made it. Every track was in time. Every blend was clean. You could still hear the seams.
The fix was not a better crossfade. It was choosing where the crossfade happens.
Correct is not the same as musical
The old renderer used a fixed transition length for the whole set, and it picked the mix-out point of each track on its own, without looking at the track coming in next. That gives you transitions that are beat-locked and still wrong. A loud outro lands on a quiet intro. A blend starts in the middle of a phrase, so the incoming track arrives on a bar where nothing musical happens. Every transition takes the same amount of time, which no human DJ would do.
None of those are bugs a test catches. The beats line up. The levels are fine. It just does not sound like someone chose it.
Dance music is built in phrases: blocks of bars where the arrangement changes at the boundary. A drum fill, a new layer, a drop. A DJ mixes on those boundaries because that is where the listener expects change. My mixer knew where the downbeats were. It did not use that to decide where a transition should start and end.
Measure the energy, bar by bar
The first step was giving the renderer something to compare. I added a per-bar energy envelope: the loudness of every bar on the detected beat grid, in decibels. It is cheap to compute from the audio the renderer already loads, and it turns a track into a curve you can line up against another curve.
With that in place, the transition stops being a constant and becomes a search. For every pair of consecutive tracks, the mixer looks at candidate windows that start and end on phrase boundaries: where to leave the outgoing track, where to enter the incoming one, and how long to overlap. Only phrase-aligned candidates are allowed, so every option is musically plausible by construction.
Each candidate gets a score. The incoming head should sit at the energy level the outgoing tail is at. Both sides should be steady across the window, so a blend does not straddle a drop. The search should not throw away a large part of a track just to find a nice spot. And when everything else is equal, it falls back to a classic medium-length blend. All of that is a plain function of the envelopes and the grid, with no randomness, so the same set renders the same way every time.
Then the renderer had to honour the answer. The streaming mix used to assume one overlap for every transition. I changed it so each transition carries its own overlap length, and wired the window search into the main render path, with a flag that switches back to the fixed window for A/B listening.
Render the options, then listen with code
A scored window is still a prediction. Energy curves do not hear a kick drum landing slightly off, or a click at the splice. So the next step was to stop predicting and render.
The render-and-pick harness takes a transition, renders a few nearby versions of it, and scores the actual audio at the seam. It looks for a jump in frame energy across the splice, a loudness step and phase misalignment, and keeps the version with the smallest discontinuity. It sits behind a CLI flag and has its own tests. Then I wired it, together with tempo ramping, into the live render pipeline. When the tempo gap between tracks is big enough, the change now happens gradually during the transition instead of being applied up front, which is how a DJ rides the pitch fader.
A scored window is still a prediction.
Around the same time I added a set of smoothing passes for the blend itself: a loudness ride across the overlap, staggered stem swaps, a staged crossfade and transient alignment. I kept them as options. The point of this whole round was that I could now compare versions of the same transition instead of arguing with myself about which sounded better.
What it cost
The search makes rendering slower, because every track has to be loaded once before the mix starts to build its envelope. Render-and-pick is slower again, because it renders transitions more than once. That is fine for a mix I render overnight. It would not be fine for anything live.
It also needed a fallback. Short or odd tracks do not have enough phrases to search over, so the mixer drops back to the old cue points and the fixed length for those. A search that can fail needs a boring default behind it.
And the scores are proxies. Energy continuity is a guess at what a listener cares about. The seam score is a guess at what a click sounds like. Neither replaces listening. What they do is narrow a large space of possible transitions down to a few worth listening to, which is the part I could not do by hand across a whole set.
The lesson
Coding agents got this project to a correct mixer fast. Beat detection, key detection, tempo matching and mastering are well-trodden problems, and the agent wrote solid versions of all of them. The part that made the mix sound human was not on that list. It was a decision that every DJ makes without thinking: where in the music does this change belong.
That decision had to become something the code could measure and search. Once it was a measured, searchable thing, the agent built the search, the harness and the wiring in quick succession. Until then, no amount of polish on the crossfade would have fixed it.