Learn · Loops
Making AI-generated audio loop without a click
By Anand “Andy” Padia · 30 November 2026 · 5 min read
In short
- Generated audio almost always fades in and out, and the loudness drifts from take to take.
- I trim 1.5 seconds off each end, normalise to −24 LUFS, and bake a 3-second equal-power crossfade into the file.
- MP3 keeps the exact sample length. AAC pads the end, and you hear that padding as a click on every loop.
Every continuous sound in mutd that came out of a model goes through one script, scripts/process-stems.py. It exists because a raw generation, played on loop, gives you three problems: a dip in volume where the model faded, a jump where the end meets the start, and sometimes a click. Here is what the script does, in order, with the numbers it uses.
- trim at each end
- 1.5 strim at each end
- bed loudness
- −24 LUFSbed loudness
- crossfade
- 3 scrossfade
- MP3, stereo
- 96 kbpsMP3, stereo
1. Trim the fades
Even with “no fade in, no fade out” in the prompt, most takes ease in over the first second and out over the last. Cutting 1.5 seconds from each end removes that in nearly every take I have generated. If a take still swells after that, I regenerate it rather than cutting deeper.
2. Normalise loudness
I run ffmpeg's loudnorm filter to bring every bed to −24 LUFS integrated, with true peak at −2 dB and a loudness range of 7. Events go to −20 LUFS, a little louder, because they are short and have to cut through a bed. With every file at the same level, the volume sliders in mutd mean the same thing for every sound, and a mood's mix levels stay balanced.
atrim=1.5:<length − 1.5>, asetpts=PTS-STARTPTS,
loudnorm=I=-24:TP=-2:LRA=73. Bake the crossfade
This is the step that makes it loop. Call the trimmed file's length L and the crossfade XF, which is 3 seconds. The script cuts the file into three pieces and puts two of them back together:
- The body: from XF to L − XF.
- The tail: the last XF seconds, fading out.
- The head: the first XF seconds, fading in.
Tail and head are mixed on top of each other and placed after the body. The file now ends on audio that blends into its own opening, and the body starts exactly where the head left off, so the end runs straight back into the start.
[0]atrim=3:L-3, asetpts=PTS-STARTPTS [body];
[0]atrim=L-3:L, asetpts=PTS-STARTPTS, afade=t=out:d=3:curve=qsin [t];
[0]atrim=0:3, asetpts=PTS-STARTPTS, afade=t=in:d=3:curve=qsin [h];
[t][h] amix=inputs=2:normalize=0 [x];
[body][x] concat=n=2:v=0:a=1 [out]Two details matter. The fade curve is qsin, a quarter sine, which gives an equal-power crossfade: with uncorrelated sound like rain, the overlap keeps the same loudness instead of dipping in the middle, as a straight linear fade would. And normalize=0 stops amix from halving each input, which would also cause a dip.
4. Encode to MP3, not AAC
AAC is the better codec for most things, but it adds padding samples at the start and end of the stream. Many decoders do not remove all of them, so a looped AAC file has a few milliseconds of silence at the seam, which you hear as a tick. MP3 encoded with LAME writes a gapless header that browsers use to decode the exact original length. mutd uses 96 kbps for stereo and 64 kbps for mono. A 39-second bed comes out at about 305 KB.
5. One more crossfade in the browser
Belt and braces: when the engine in src/lib/engine.ts decodes a file under 900 KB, it blends the last 1.2 seconds into the first before looping it, in case a browser's decoder adds anything. It also starts each loop at a random offset, so the seam lands at a different time for every sound in your mix.
Try it
Switch on Monsoon on tin or Summer cicadas in the player and listen for the 39-second mark. If you can hear the loop, write to me.The other half of a clean loop is the prompt: the fewer fades and one-off sounds the model gives you, the less the script has to fix. That is the subject of prompting for no-fade ambience.
Hear it
Everything here is playing in mutd right now.
373 sounds, 23 one-tap moods, no account. Free in your browser; the iOS and Android apps are coming soon.