Page 1 of 3

Looping audio problem

Posted: Fri Jan 25, 2013 9:58 pm
by celynwalters
I'm trying to make a looping ambient noise for a menu, but I can never get a perfectly clean loop.
I've made a file in Audacity, which loops seamlessly.
I discovered that mp3 files usually insert a silence at the beginning, so I can't use mp3.
I'm on a mac, and I read on the forums that .wav files don't play properly (true).
So I have to use an .ogg. I'd be fine with this, but it's still making a pop on the seam.
I've tried "stream" and "static" (static works better).
Any pointers/info?
Thanks!

Re: Looping audio problem

Posted: Fri Jan 25, 2013 10:26 pm
by Lafolie
Could you post some code/.love so that we can see how you're handling this? I've created looping OGG audio on OS X before and it worked fine.

Re: Looping audio problem

Posted: Sat Jan 26, 2013 12:45 am
by Boolsheet
mp3 is a bit tricky because it has to pad the data to make it fit into the transform or something like that. Certain encoders (LAME) save the exact sample number in metadata. If a decoder is aware of it (like mpg123, the one LÖVE is using), it should properly truncate it to its original length. However, I think the decoder that Audacity uses does not recognize the metadata.

So yeah, ogg vorbis all the way.

It would indeed be easier to help if you share the problematic code and audio file. It can also be a short example that shows the same behaviour.

Re: Looping audio problem

Posted: Sat Jan 26, 2013 2:10 am
by celynwalters
Boolsheet wrote:It would indeed be easier to help if you share the problematic code and audio file. It can also be a short example that shows the same behaviour.
Argh! Yes, of course, thank you.
I tend to put all the code in one file (not such a great idea), so here is only what I need to reproduce the problem.
I dunno, it could work fine on another computer, maybe..
looping.love
(83.51 KiB) Downloaded 218 times

Re: Looping audio problem

Posted: Sat Jan 26, 2013 5:23 am
by Boolsheet
Source:setLooping expects a boolean. Passing nil is probably interpreted as false.

You only have to call play once and the Source will loop forever. Calling play on an already playing source has no effect (except maybe trigger a bug in 0.8.0 that causes it to go into a very long loop if you call it too many times in a short time).

What happens in your code is that the source plays from start to end and it will be started again with the play call in love.update. If the frame rate is around 60, you may have up to 16 ms of silence (plus the play function overhead) because the Source could have stopped at any point in this time window.

Re: Looping audio problem

Posted: Sat Jan 26, 2013 1:24 pm
by celynwalters
Ahhh..
Yeah, I guess as it looped anyway, I must have thought that "sfx_menu:setLooping()" must have done the trick.
Yet another mystery solved. Thanks! again.

Re: Looping audio problem

Posted: Sat Jan 26, 2013 10:45 pm
by IndieKid
Hey, I also use OGG that I created on Mac. It works awful. I have disabled audio for my game, because it had ultimate-lags. Do you know what can cause that? The game also crashes randomly. By the way I used to have a lot of audio files in it.

Re: Looping audio problem

Posted: Sun Jan 27, 2013 12:29 am
by celynwalters
Ogg seems to work very well for me (now it's all fine).
If your game is crashing even with all audio disabled, perhaps the root of the problem is somewhere there?
Have you tried playing your oggs in a new empty project?

Re: Looping audio problem

Posted: Sun Jan 27, 2013 8:56 am
by IndieKid
celynwalters wrote:Ogg seems to work very well for me (now it's all fine).
If your game is crashing even with all audio disabled, perhaps the root of the problem is somewhere there?
Have you tried playing your oggs in a new empty project?
I mean, the game crashes sometimes and I can't get why. No when audio disabled the game works perfect. So there is no problem in the code. Maybe I miss something on how to use OGG and audio at all, but why the heck it works then. Can you send me your example please? And what is the bitrate of your OGG, I use 192 Kbps but still can hear some dirty noise.

Re: Looping audio problem

Posted: Sun Jan 27, 2013 12:50 pm
by celynwalters
You might have to use headphones to hear it, it's a bit lower than I wanted it.
When I exported it with Audacity, I only got an option of quality, 1-10, so I chose 10.
VLC says it is 499 kb/s... whoah.
The audio file is about 3 seconds long, don't know what to suggest if this one doesn't work.
looping2.love
(83.52 KiB) Downloaded 188 times