Get level music that loops without a click or a gap: how to prompt for loopable tracks, find the loop point by BPM, trim with FFmpeg and set loops in Unity and Godot.
01Why generated tracks do not loop on their own
Most generated tracks are written like songs: an intro, a development and an ending. Played on repeat, the ending crashes into the intro. You fix it in two steps: ask for a track that is easy to loop, then cut it on a bar line. If you still need the track itself, start with the AI game music generator.
02Prompt for loopability
- Give an exact tempo
"exactly 120 BPM". It makes the bar length predictable. - Ask for a steady groove
"steady, no tempo changes, no big ending". - Avoid dramatic structure words like climax, finale or fade out.
Exploration music for a fantasy forest level, harp and flute over a soft drone, exactly 100 BPM, steady, no big ending, no fade out, instrumental, loopable.
03Find the loop point with math
One bar in 4/4 lasts 240 ÷ BPM seconds. At 100 BPM a bar is 2.4 s, so 16 bars last 38.4 s. Skip the intro (often 2 or 4 bars), then cut a section whose length is a whole number of bars. Start and end on the same chord, and the loop is invisible.
- 90 BPM
2.667 s per bar, 16 bars = 42.67 s. - 100 BPM
2.4 s per bar, 16 bars = 38.4 s. - 120 BPM
2 s per bar, 16 bars = 32 s. - 140 BPM
1.714 s per bar, 16 bars = 27.43 s.
04Trim it with FFmpeg
This cuts 16 bars at 100 BPM after a 4-bar intro (9.6 s) and exports OGG for the engine:
ffmpeg -i forest.mp3 -ss 9.6 -t 38.4 -c:a libvorbis -q:a 6 forest_loop.ogg
05Set the loop in your engine
- Godot 4
select the file, open the Import tab, enable Loop (and a Loop Offset if you kept an intro), then Reimport. - Unity
tick Loop on the AudioSource. For intro + loop, schedule the loop clip with AudioSource.PlayScheduled at the exact end time of the intro. - Web Audio API
set source.loop = true and use loopStart / loopEnd in seconds. HTML <audio loop> often leaves a small gap with MP3.
06Avoid the click
If you hear a tiny click at the seam, the waveform is not at zero there. Move the cut a few milliseconds, or add a 5–10 ms crossfade in your editor. OGG is also better than MP3 for loops, because MP3 encoders add a small silence at the start of the file.













