LDJam user 271014

Ludum Dare 51

How to edit audio files to loop seamlessly

Hi everyone!

Our game for this jam, Resonance, relies extensively on audio to set the intended mood and ambience for the player. Music and sound effects are powerful ways to immerse your player in your game, but a bad loop or audio pop can take them out just as quickly. Since I had to re-learn how to edit audio files to loop properly for this jam, I figured I'd take a minute to document the techniques I used. I hope you find this helpful!

The only software you need to do any of these edits is Audacity, which is free and open-source.

Eliminating pops and crackles

Here's an example of a sample that will pop every time it loops:

pop.png

The reason (outlined in red) is that the start and end of the sample are at different amplitudes. Audio generally likes to exist as a clean, connected wave, but if you try to loop a sample like this, the wave gets broken at the loop point:

pop_loop.png

The solution is simple: don't break the wave! The easiest way to do this is to make sure the start and end of the sample both happen at a zero-crossing, which is a point where the wave crosses the axis (and has an amplitude of 0):

zero_crossing.png

In Audacity, we can find zero-crossings easily. Pressing [Z] will move the cursor from it's current position to the nearest zero-crossing. We can use this to trim off a bit of the start and end of the sample like so:

good_loop.png

This sample will loop properly without popping! Note that while the wave doesn't look "perfect", it will still loop properly because there's no break at the loop point. The wave goes from zero to zero.

You can easily test the "loopability" of a sample in Audacity by copying the entire sample, moving the cursor to the end, and pasting it. (You might want to do this several times if your sample is really short.) If you find that the sample still doesn't loop right after some edits, try cutting more or less from each end until it sounds better. There's no hard and fast rule here; just experiment until you get something you're happy with.

Another, lazier way to do this is to apply a short fade [Effect -> Fade In/Out] to the beginning and end of the sample, which will accomplish the same thing, but might alter how it sounds:

fade_loop.png

Cutting a shorter loop from a longer sample

Sometimes, you'll have a sample that's close to what you need, but doesn't loop quite right. This can often be the case for persistent sounds, like drones or hums. As an example, here's the raw audio Gnocchi gave me for the hum sound that the player hears when they get close to a deadly laser:

laser_raw.png

This sample sounded awesome, but it didn't loop well. Notice how the amplitude of the file ebbs and flows over its 3.5 second duration. This pattern was audible, and was quite noticeable and distracting when looped. I fixed this by simply taking a tiny piece of the hum and trimming it to the nearest zero-crossings:

laseremwith/emsample.png

The final sample was only 0.1 seconds long, but it faithfully represented the original sound while looping perfectly. I had to experiment with the length of the sample to get it just right, but in the end it was well worth it!

Looping music

Getting music to loop seamlessly (i.e. without starting and stopping) is a bit trickier. In general, music that loops needs to be intentionally composed to do so. These tips will assume you already have some made-for-looping music, and that you just need to get it to sound right.

Step 1) Trim off any silence at the beginning of the track. It should go without saying, but you should be doing this for every audio file in your project:

cutemstart/emsilence.png

Step 2) Check to see if there's a reverb-tail at the end of the track. This should contain the decaying echo of the end of the track. It might look something like this:

tail.png

If you got the music from a member of your team, you can ask them to re-export the track with a few measures of silence at the end. If there still isn't a tail, or if you got the music from outside your team, just trim the silence and move on to Step 3.

Cut the tail off and move it to a separate track like so:

chopped_tail.png

Mix the audio down to a single file (File --> Export). Keep this version with the tracks separated open, just in case you need to tweak it.

Step 3) Test the loop! Just like with a sample, copy the entire track, move the cursor to the end, and paste it. Listen as the cursor crosses the loop point. If it sounds good, then you're done!

If something sounds off, check that the start and end of the track are both at zero-crossings. If you cut/pasted a reverb tail, you might have to go back to the separate-track version and adjust where you cut the tail. Remember, as a last resort, you can always use fades [Effect -> Fade In/Out] to get something passable.

Closing thoughts

Thanks for reading! If you found anything here incorrect or misleading, or if you have additional knowledge that could be helpful, leave a comment. If you need some ratings for your game, check out our game and leave a comment with your thoughts. We'll make sure to check out your game as well!