- Home /
Producing seamless looping MP3s
I'm using Unity 3.0 targeting iOS devices. I'm having trouble getting my background music to loop without seamlessly without artifacting. The music is made up of many short clips (15 - 30 seconds long) that fit together seamlessly. The clips will be looped some number of times and then will move into a different randomly selected clip based on various game events. However, I can't get the MP3s to loop without either skipping a small portion of the sound or having some amount of silence at the end of the track when it loops, making the loop point clearly audible.
The Unity documentation says, 'On mobile platforms compressed audio is encoded as MP3 for speedier decompression. Beware that this compression can remove samples at the end of the clip and potentially break a "perfect-looping" clip. Make sure the clip is right on a specific MP3 sample boundary to avoid sample clipping (Tools to perform this is widely available).' I assume this is the problem I'm having, but it's not clear from this documentation what I should do to fix it. What exactly are you supposed to do to your sound clip to ensure seamless looping? Does anyone know the name of one of these 'widely-available' tools?
Answer by Dreamora 1 · Oct 12, 2010 at 09:10 PM
you will need to make them decompress on load, if you use streaming you won't be able to overcome the problem.
also as per 3.0 there are still problems on the sound handling. the whole system changed for U3 so you can now use multiple compressed sounds at the price of having them on the cpu and isn't fully working atm
Thanks for the response. So nothing special needs to be done to the original WAV beyond making sure it loops seamlessly before dropping it into Unity and setting it as a compressed sound?
$$anonymous$$y understanding is that "Decompress on Load" effectively converts the sound back to WAV in memory, so to avoid the lossy compression, it sounds like I should just have my clips as WAV and deal with the higher memory use. Is that what you'd recommend?
Answer by DannyJax.du · Oct 13, 2010 at 03:01 AM
I worked on a project where I had to have a background of the beach and it seam seamless.
I used Sony Soundforge and 4 different files. I made them fade in and out over a 30 second time and there were about 3 points where there is almost silence and one place where it is silent form fades in and out. Also at the beginning of the file it fades in over a 1.25 second time and at the end if fades out over 1.75 seconds so my file in visual format looks like this. Each clip is on its own layer in the project but is a single layer mp3 when exported. Layer 1 BeachWaves, Layer 2 Seagul1, Layer 3 wind, Layer 4 Seagul2 w/Waves
Layer 1 FadeIn 1.25-------.5 fadeDown--------.25 fadeUp-----.25 fadeDown-----1.75 FadeOut
Layer 2 FadeIn 1.25---.75 fadeDown--------.5 FadeUp---------.33 fadeDown-----1.75 FadeOut
Layer 3 FadeIn 1.25-------.25 fadeDown-------.5 fadeUp------.25 fadeDown-----2.0 FadeOut
Layer 4 FadeIn .5----------1.5 fadeDown---.33 fadeUp-----.25---- fadeDown-----1.50 FadeOut
The client loved it. No matter what files I tried before that were generated for endless loop did not work, there was always a noticeable silence for a split second. I played with that silence and duplicated it 3 times within my project in various lengths so when it did come, you did not know thats what it was. Part of 1 is at the beginning and the other part is at the end, the other two are in the 1/3 and 2/3 locations.
I hope you realize that you hacked around the problem without actually making a seamless looping clip. Fading in and out to do the looping is not a solution for most games.
Answer by paulrahme · Jan 05, 2014 at 11:53 AM
Just a comment on decompress-on-load: If the mp3 file has chopped off the last split-second of audio to round it down into a frame of encoding, the decompressed .wav version will still have this silence but just be padded out.
You need to chop the audio's loop point at both a musical "zero db" boundary (to avoid pops esp if you're switching to / interchanging segments of songs), and also on an mp3 frame boundary - which is the tricky part - to ensure it does not chop off the last few milliseconds or pad it out with blank.
There is an article & tool that explains more here: http://www.compuphase.com/mp3/mp3loops.htm
Your answer
Follow this Question
Related Questions
Gapless looping on iOS 2 Answers
Gapless looping on iOS 1 Answer
Load songs from iOS Music Player? 2 Answers
mp3 files giving ios memory warning 0 Answers