Creating Looping Sounds
When creating addons, you might need a sound file that is looping, but you are either too lazy to write a Lua hack to loop the sound, or you want to do it properly.
This tutorial will show you how do it properly, by altering the sound file.
You'll need software capable of adding looping points to audio files.
For the sake of this tutorial we will be using Wavosaur, its portable, and most importantly, its free.
Audacity, unfortunately, will not suffice.
Not any sound can be made looping and still sound good. You'll always have to keep this in mind when searching for sounds.
This tutorial will only work on .wav sounds. Converting .mp3 to .wav is not so hard and can be done using Wavosaur, but be aware that it will inflate the filesize of your audio file.
Once you have downloaded Wavosaur, open it.
This is the screen you'll see:
Now find your audio file and open it in Wavosaur, you can do it by drag'n'dropping the file onto the window.
If your sound file is initially meant to be looping, then all you have to do is press the "Create loop points" button.
This will automatically place Loop Start point at the beginning of the audio file, and Loop End point at the end.
The end result will look like this:
To preview the loop from Wavosaur, you must make sure first, that sound playback is looped:
Then just hit play, and the whole sound file will play looped, regardless of whether you have loop points set or not. This will also work for a part of the sound.
Now comes the hardest part. If your sound file is not meant to be looping i.e. it sounds bad ( clicks, noises, abrupt sound level changes ) when played over and over again, it'll be very hard to make the loop sound 'natural'. This is where you might need other software, such as Audacity ( or whichever you prefer ), to cut or modify the file to sound more or less 'natural' when playing in a loop.
This is what you can't do step-by-step, so you'll have to figure it out on your own. It is always easier for yourself to simply find already looping sounds, or at least sounds that are looped but without looping points.
Not really 'advanced', but you can select a part of the sound file to be looped. An example of this would be the HL2 jeep sounds, which have only the last part of the sound looped.
In this example the sound will play from the beginning, reaches Loop End, and then continues playing from Loop Start point. This is where the loop previews come in really handy.
To do this, simply select a part of the sound and press the "Create Loop Points" button. Make sure to preview the loop before saving!
Once you are done looping, go to File > Save As... and save your sound file as .wav.
Please note that resaving a looped file in other programs may erase your looping points. So make sure to add the looping points the last, after you have done all editing, if any were necessary.
The best function to handle looping sounds in Lua is CreateSound. It allows you to play and stop the sound on demand.