Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411507 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 04:13:17 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Seamless MP3 Looping
Pages: [1]
Print
Author Topic: Seamless MP3 Looping  (Read 2571 times)
RichVreeland
Guest
« on: June 10, 2008, 07:57:37 PM »

Hey guys,

I did music for the game Rescue: The Beagles in the PG Competition, and I've been talking with nenad the developer and we're trying to figure out how to remove the gaps in the actual MP3 files so that they will loop seamlessly during gameplay.

Does anyone know of a way to do this?

Alternatively, is it possible to simply find out how many samples of gap there are at the beginning and/or end of an mp3 so that we can simply specify where the loop should start and end? I was under the impression that maybe the gap wasn't silent samples added but something else...

Thanks in advance for all help.
Logged
mewse
Level 6
*



View Profile WWW
« Reply #1 on: June 10, 2008, 10:11:10 PM »

I'm not a real expert on mp3 formats, but I did dabble in them for a little while, mostly in regards to streaming them over the net.

My vague memory is that mp3 files operate in "frames", which each cover a short duration of time (fraction of a second;  typically this is around 30ms, but can be higher or lower depending on the mp3's encoding rate).  Removing the "gap" from a recording becomes difficult because the mp3 format imposes that "frame" limit;  you have to play complete "frames" of mp3 data, you can't just jump from one bit of the mp3 to another in mid-frame, or have half of a frame of audio data dangling at the end of your file;  the mp3 will be padded out with silence to finish that final frame.

As to how to recognise silence.. the only way that I'm aware of is to decompress the mp3 into audio samples as though you were going to play it, and then examine that decompressed data.  It's not too difficult to recognise silence when you've got the decompressed audio data.
Logged
Annabelle Kennedy
Awesomesauce
Level 8
*


♥Android Love♥


View Profile
« Reply #2 on: June 11, 2008, 02:35:51 PM »

i hear MP3 is extremely difficult to loop.  OGG loops better i think/hear.
Logged
RichVreeland
Guest
« Reply #3 on: June 11, 2008, 05:11:16 PM »

thanks for the tips guys! appreciate it.
Logged
mechacrash
Level 1
*


It's almost like I'm actually being productive!


View Profile
« Reply #4 on: June 27, 2008, 05:25:26 AM »

ive had problems with audio looping with mp3 format aswell. I personally cant be bothered to make .ogg format compatable with my library so currently i get a 1 second gap at the end of the .mp3 song when its meant to loop. I fixed this by making 2 layers (my system streams music so lots of layers is ok but laggy) that would play one after each other on the same song - 2 streams that alternate. I use ruby so this was easy but using 2 streams is ok for those thinking (oh teh noes, epic lag), one stops then the other plays - i just use a system that tells me the length of the song in milliseconds and the current position in the same, compare the two and when the latter is a certain amount less that the former, switch streams (it pretty much stops the last gap of the song by playing the song again from a pre-created stream, it works good but needs lots of testing per song to get each ones gap - i also fixed this problem by adding a gap to each song - 2 seconds - so it only ever has to switch at one time)

if this heps then thats cool although you will need the functions to multi-layer stream and return positions which dont come usually for free (im just lucky XD)
Logged

PaulMorel
Level 1
*



View Profile WWW
« Reply #5 on: June 27, 2008, 05:56:00 AM »

Why are you using mp3s?

Personally, rather than compressing my music, I just convert it to mono, 16-bit wav files.  These are usually small enough, and getting them to loop properly is easy as pie (when you get to the end of the buffer, start reading from the front ... basically).

I don't know anything about compressed formats, but in a wav file, it's incredibly easy to spot true silence (no sound in the file whatsoever).  I think that true silence will be a value of 0x00000000 in uncompressed formats.  Either that, or the file will contain a chunk called the Silent Chunk, which may have another value, but it will be garbage:

Silent Chunk - "slnt"
A silent chunk is used to specify a segment of silence that will last some duration of samples. It is always contained within a wave list chunk. While this chunk represents silence, it does not necessarily define a zero volume or baseline sample. It actually holds the last sample value present in the preceding data chunk in the wave list chunk. If there is no preceding data chunk in the wave list chunk, a baseline value should be used (127 for 8-bit data, 0 for 16-bit or higher data). This may seem trivial, but if not followed, may cause undesired clicks and pops in the audio signal.

More here: http://www.sonicspot.com/guide/wavefiles.html

Like I said though, I only ever work with wav files, so none of this may apply to mp3s.  If you guys want some wav-playing source in .Net, java or C, send me a PM, and I will shoot you what I have.
Logged

my computer music blog: http://www.thisisnotalabel.com
mechacrash
Level 1
*


It's almost like I'm actually being productive!


View Profile
« Reply #6 on: June 27, 2008, 06:23:15 AM »

my system is orientated around many formats though which is why i went to unecessary levels ( i think i can play 7 formats including .psm and other emulated music)
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #7 on: June 28, 2008, 12:21:42 PM »

Using MP3 is a bad idea anyway -- there are license issues. If a game has more than 5000 downloads and uses MP3 it has to buy some sort of expensive license (similar to how .gif used to work). I'd suggest .ogg's, they sound better and are free to use for any purpose.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic