Seamless Audio Loop Maker
Operator: Abdulla Al Fahad. How tools are built and checked
A loop clicks or lurches when the audio at its end does not carry on into the audio at its start. Finding two points where it does is a search problem: for a start point, which of thousands of later points has the most similar music after it? The page answers by comparing the 0.4 seconds after the start with the 0.4 seconds after every possible end, and listing the best five.
A repeating piece matches itself at its own period and at every multiple of it, so a drum pattern that repeats every 2 seconds returns loops at 2, 4 and 6 seconds with the same score. The list shows the shortest first, with each length, and the page then lines the waveform up at both points and blends the seam before you hear it.
Key features
- Two searches: the whole file, trimming the start and end by up to the amounts you set, or from a start point you place on the waveform
- A list of the best five candidates with start, end, length and a match percentage, each with a button to use it
- A crossfade from 0 to 2,000 ms, equal power or linear, and a waveform of the seam with the step across it measured
- WAV with an optional loop marker, or MP3, with the loop written up to 32 times in the file
How loop points are searched and the seam is blended
The file may last from 1 second to 10 minutes. The loop must be at least 0.2 seconds long, and the search compares a 0.4 second window on each side. Everything is held as decoded audio at the file's own sample rate, so the loop points are exact sample positions.
The WAV is 16-bit PCM. With the marker option it carries a smpl chunk with one forward loop that runs from the first sample to the last, plays forever, and has MIDI unity note 60; samplers and some game engines read it and loop the file on their own. A WAV cannot pass 4 GB, so the number of repeats is limited by the loop's length.
How it works
For the search the audio is reduced to about 8 kHz by averaging. The 0.4 second after the start is compared with the 0.4 second after every possible end using normalised cross-correlation, computed with an FFT, and the five strongest peaks at least 0.1 seconds apart are kept. Each is then refined at the full sample rate within two reduced samples either side, using a 0.15 second window.
Both points are then moved by up to 8 ms to the nearest rising zero crossing, a sample that is negative or zero followed by a positive one, so the jump lands at the same phase going the same way. The score is the average of the correlation of the windows after the two points and of the 0.4 seconds before them. Equal scores list the shorter loop first. The whole-file search tries starts every 50 ms in the part you allow to trim and ends in the allowed tail.
The seam is blended by crossfading the last part of the loop with the audio that comes just before the start point, because that is what the start naturally follows. If there is not enough audio before the start, the first part is blended with the audio after the end instead. If neither side has enough, the fade is cut to what exists.
Step at the seam is the jump from the loop's last sample to its first, in dB relative to the loop's own level, so a loop that joins cleanly reads far below zero.
Typical uses
- A 90-second ambient bed for a game level: search the whole file, trimming up to 2 seconds from the start and 3 from the end, and take the candidate with the highest match, with a 500 ms equal-power crossfade across the seam.
- A 16-bar drum pattern at 120 BPM is 64 beats, or 32 seconds. With the tempo field set, the page prints the beat count of the loop you have selected, so you can step through the candidates and keep the one that reads 64.00 beats over one that reads 63.94 and scored a point higher.
Building one
- Drop the audio file and look at the waveform.
- Choose Whole file, or From my start point and drag the start handle to a beat.
- Press Find loop points and read the candidates; press Use this loop on one.
- Set the crossfade length, or leave it at 40 ms, and check the seam picture.
- Press Hear the seam, 4 times, then Hear the loop repeat.
- Export WAV with the loop marker, or WAV or MP3 plain.
Example
A 4-bar drum pattern at 120 BPM, 44.1 kHz stereo, with the loop set from 0.000 s to 8.000 s
Crossfade 50 ms, equal power, tempo field 120, one repeat, WAV with the loop marker onWhat the page reports and writes
The loop is 352,800 samples, and the last 2,205 samples (50 ms) are blended with the audio before the start, or with the audio after the end if the start is at 0.000 s
8.000 s at 120 BPM is 16.00 beats, 4.00 bars of 4/4
The WAV is 1,411,244 bytes; the loop marker adds 68, and runs from sample 0 to sample 352,799Tips for best results
- Put the start handle on a downbeat before searching from your start point. The page matches what follows the start, so a start on a beat finds ends on a beat.
- Enter the tempo and prefer a candidate that is a whole number of bars; the beat count is shown beside the length of the selected loop.
- For pads and drones, lengthen the crossfade to 500 to 2,000 ms. A short fade is for rhythmic material where a long one would smear the beat.
Things to check before you rely on it
Music with a changing tempo or a rubato feel has no exact loop, and every candidate scores low. A score under about 70% means the repeats really differ.
The match score compares a short window of waveform, not musical structure. Two ends can match by waveform and still land in a different bar; listen before trusting a number.
A crossfade with the audio before the start needs that audio to exist. A loop that starts at 0.00 seconds has none, so the page blends with the audio after the end, and a file that has neither gets a plain cut.
Common errors and how to fix them
- This file is longer than 10 minutes
- Cut the stretch that holds the loop first; a loop is normally found in a short piece.
- No candidate was found
- Try a longer length range, a larger trim, or a start point where the music is playing, not in a silent intro.
Why rising zero crossings
A click is a jump in the waveform. Moving both points to a place where the waveform crosses zero rising means the sample before the jump and the sample after it are both near zero, and the slope has the same sign. On a loud low note a jump to a random point could be half the full scale; at a zero crossing it is a fraction of that.
Compressed files and gapless loops
An MP3 or AAC file has priming samples at its start and padding at its end, so even a perfectly cut loop can play with a gap in a player that does not remove them. Use the WAV for game engines and samplers, and treat the MP3 as a preview or for players known to loop MP3 without a gap.
Frequently asked questions
Why do several candidates have the same score, and how is this different from cutting in Audio Cutter?
A repeating piece matches itself at every multiple of its period, so 2, 4 and 6 seconds can all score the same, and the list puts the shortest first. Audio Cutter on this site trims and fades a file but does not check whether two cut points match, which is the search this page adds.
Why is the step at the seam not exactly zero?
The two ends are separate samples, so the first and last values differ by a small amount even at a zero crossing. The page reports the size of that step against the loop's level, and the crossfade makes it smaller still.