by Jack Menhorn (Part 3)
Many sorts of sounds in a game one be one-off/one-shot sounds but in fact be played continuously in a loop. The sound of a city in a game might be one looping sound or many loops of cars driving, people talking, planes overhead, construction equipment, emergency sirens and more.
Having these sounds fit and function properly is not as easy as checking the “Loop” box properly on an Audio Source in Unity. The sounds must be edited so that the end of the file seamlessly transitions into the beginning as if there is no actual end of beginning.
If we take our freezer sound from above; we can edit it in just a few steps to acquire a decent and smooth looping sound.
If we listen to the sound on loop in a wave editor as-is it still has the pop at the beginning and its quite obvious when the sound loops back around. (file contains 3 repeats of the loop)
If we find a nice place in the middle of the file that has a crossing at 0 and then cut the file into two halves:
Then take the second half and put it before the first half with a crossfade between what used to be the end and the beginning of the file:
Make sure to remove any silence at the beginning and end of the file. Also make sure the file begins and ends on 0. Once take care of that let’s take a listen (file contains 3 repeats of the sound).
And now we have a seamless loop!
While edits and fades can remove or reduce the volume of unwanted of parts of a sound; if the volume of a sound is way too loud then new unwanted sounds will be introduced in the form of clip distortion. When playing a file in a waveform editor and the VU Meter goes into the red; then there is a good chance that some unwanted things are going on. Lowering the volume, adding a compressor/limiter are possible options to fix the issue (simply lowering the volume is a safe bet).
You don’t want your files to look like this (note the green VU meter at the top with bright red on it’s end to let you know there is some clipping):
Typically even cheap and/or amateur sounds found on the internet will not have much in the way of clip distortion. Mostly one needs to worry about introducing it themselves when raising the gain/volume of a file in a wave editor like Audacity or Sound Forge. Often times one will want to increase the volume of a sound so that once it is imported into Unity the sound’s volume can be lowered/then raised through the use of the engine’s own controls. Unfortunately (or fortunately) Unity or any other game engine cannot just raise the volume of a file, so a rule of thumb is to import the file with the volume set at the level it would be played back at its loudest in game. So in the case of a First Person game; any 3d sound would be imported at the loudness/volume it would be if the player was right on top of the sound source. For example: the above freezer recording would be imported at the volume it would be heard at in game if the player was right in front of the freezer with the door open; that way the Unity engine would realistically lower the volume and add audio filters to the file as the player moved away from the sound source to simulate the amount of distance the player is from the freezer.
Proper preparation of the files before importing into your project will make everyone’s lives easier later in the project. Keep in mind the audio can be edited even after having been imported into Unity, so the above aspects of sound editing are relevant for the entire project. Next time we will look at importing the audio into Unity and what settings and implementation commonly make the most sense.