Mp3 looping issue

he …
@will & @max … about looping mp3s versus wav.

https://playcanvas.com/project/740754/overview/looptest

the examples should iullstrate the problem. afaik it’s not a playcanvas problem but rather how mp3s are handled in different browsers - they often insert silence at playback start (or end?) and thereby at the beginning of every loopcycle. on most pc browsers using .ogg does the trick which won’t run on ios then. so to make loops work propperly on ios you need to use wavs. we also had the issues for our adidas dancing game recently.

being able to loop sound seamlessly can be useful to reduce overall weight as well as for syncing sound and visuals or even mix/sequence sound propperly (as done at my website). as said i don’t think there can anything be done on your side. so the only solution is using .ogg on pc (and maybe android) and give ios users .wav nevertheless.

it’s also not impossible i’m just missing a checkbox or something …

It looks like you can use the utility here: https://www.compuphase.com/mp3/mp3loops.htm
to make the mp3 loop. Unless I botched something up it seems to work in firefox, untested in others.
https://playcanvas.com/project/741090/overview/looptesttest

1 Like

he thanks… i’m gonna give it a shot. though as i remember my devs told me that it is not due to wrong encoding or something but rather a browser problem. i’ll update as soon as i tested it.

1 Like

@Crefossus

he … sorry for getting back to this again … i used that software you suggested but when i open up the mp3 in audacity afterwards i still see silence which is not there in the wav. maybe i do something wrong here but the tool is pretty straight forward without any options.

This is part of the way the data is encoded into mp3 format. If you want a loop without a silence gap in the beginning, you should encode it to another format, like ogg or wav.

@LeXXik

yep this is what i’ve learned as well … something with the mp3 getting divided in ‘frames’. and i was asking this because people advised me to use .mp3’s instead of .wav for looping sound. the problem with .ogg is that it’s not supported by every browser (i.e. safari on ios) …

my problem was here: https://www.rtz23.de if you click the sound button it sarts mixing different loops together so the music gets rearranged randomly as the graphical content does.that can not be done as suggested with mp3 at least not consistently in every browser.

It looks like you are using wav format. Is it not suitable for you?

I generated a white noise mp3, about 1 second in length, but it has no gaps on loop:
https://playcanvas.com/editor/project/755313

Do you have a problematic mp3 I could test?

@LeXXik

yep your example works … how did you create an mp3 without gaps? i tryed using adobe media encoder, audacity encoding (based on lame_enc) and also the tool that @Crefossus suggested in the beginning of this thread. all result in having a gap at beginning and end:

as i understood it and as you pointed out as well it’s due to the way mp3s are created. i pretty much believe that the loop would work perfect if i haven’t had a gap. but i have …

Right, mp3 is not suitable for seamless loops. My white noise sample was probably too simple, and had not generated enough data to cause the gap. You won’t be able to get rid of it. You can of course remove it in the audio editing tool, but if you export the new track as mp3, it should generate it again in the exported file. There is nothing you can do about it, except changing the format.

@LeXXik

thanks. i think it is now very much clarified :slight_smile:

1 Like

MP3Loop should be working fine to create seamless mp3 loop playback. I forked your og project and ran your wav through the tool. The link to that project is in the first reply if you want to verify it. I don’t have an ios device to test on, but the mp3 looped fine on pc.

Did you try testing your result mp3 to see if loops acceptably in playcanvas? I haven’t dug too deeply, but I think MP3Loop is doing something tricky with decoder delay (and many other tricks) and it might look like the looping would fail, but it should be fine. “…This decoder delay will only happen in the very first iteration…” ( see header The approach to gapless looping https://www.compuphase.com/mp3/mp3loops.htm )

They also describe a solution, but it is not in their tool. I think your use case should work though and it’s worth a shot.

@Crefossus

you’re right. i’ve used the exact loops i had in the website as a test now. i did only inspect it in audacity and had a significantly visible silence. seeing this i agree that the playback/looping is more elaborate than i thought and presumably skips the silence.

i didn’t bring that up for nothing though. i remember working on a client project a few years ago this was a major problem we faced and could not find a satisfying solution other than using much bigger .wav files.

As a way to mitigate this, slightly shortening the duration and offsetting the start time can help

eg