problems with looping sounds

Anything libgdx related goes here!

problems with looping sounds

Postby dm5 » Sat Apr 14, 2012 10:15 am

Hi! I'm developing a game with libgdx, and I've run into multiple problems with looping sounds on android device (Asus Transformer). All of them have to do with android's SoundPool, but since it is what libgdx uses for sound I guess it can be considered its problem as well.

1. The worst of all, when a sound ends and then starts again there is a very noticeable and annoying click. I.e. the sounds are not looping seamlessly. I should say that the sounds themselves are okay, they loop seamlessly in Audacity. I've tried both wav and ogg formats. I dunno it might be a problem with Transformer but I've heard of the same issues on Samsung Galaxy Tab as well.

2. There can also be clicks when looping sounds start playing or are stopped.

3. When a bunch of new sounds start playing, the "old" looping sounds are kicked out (i.e. stop playing). I think this is flawed logic (or bad logic if you prefer ;) ) in SoundPool. Looping sounds should have priority. Maybe I could fix this by further limiting the number of simultaneously playing sounds but now I'm not sure I should even bother.

4. The one problem I've been able to resolve. By cutting and lowering the quality of the sounds which is not really nice, too. My game plays a lot of sounds, and I used to get a lot of "Audioslinger cannot create audio track" errors. This had to do with the 1MB limit on uncompressed sounds in SoundPool. Since I'm working on an HD game this seems unnecessarily restrictive. This is not strictly related to looping sounds but I thought I'd write anyway.

I wonder if anyone might have some advice for me. I don't really like the idea of giving up on the looping sounds.
Also I've heard that it's possible to write your own mixer which will take care of these issues. Is there a chance that something like that might be implemented in libgdx?
dm5
 
Posts: 10
Joined: Sat Apr 14, 2012 7:54 am

Re: problems with looping sounds

Postby mzechner » Sat Apr 14, 2012 10:32 am

I think i remember some issues with clicking sounds as well, didn't experience that myself, but others reported it to me. There was a solution to it, but i can't remember what it was :/

The problem with writting your own mixer is that it is taking away a ton of CPU processing time and burns a hole into the battery. SoundPool and MediaPlayer will deligate audio playback to the hardware if possible, which "solves" this problem. So, for the time being i'm afraid we won't add our own mixer :/

Audio on Android is seriously broken in many regards. Lots of developers raised that issue over the last few years, but we have yet to see a solution being implemented. OpenSL ES support is not it.
mzechner
Site Admin
 
Posts: 4713
Joined: Sat Jul 10, 2010 3:50 pm

Re: problems with looping sounds

Postby dm5 » Sat Apr 14, 2012 4:23 pm

Thanks for the reply. I guess I will have to make a tough decision whether I should further try to minimize these sound problems and accept it won't be ideal, or to drop these looping sounds altogether(
If anyone knows of a solution to these problems please let me know.
dm5
 
Posts: 10
Joined: Sat Apr 14, 2012 7:54 am

Re: problems with looping sounds

Postby dm5 » Wed Apr 18, 2012 3:21 pm

For anyone who might be having the same problems.. I've found a solution that seems to work well for me.
Instead of setting sounds to loop I now crossfade them. That is, play two instances of the sound with a small overlap where the first instance fades out and the second instance fades in.
Preparation of the sounds for this is quite easy for highly uniform, noise-type sounds. For other sounds there may be special considerations.
This solution has some benefits of its own. First, if a looping sound gets kicked out (see problem 3) it will resume playing after a while. Second, you don't have to bother with making seamlessly looping sounds.
dm5
 
Posts: 10
Joined: Sat Apr 14, 2012 7:54 am

Re: problems with looping sounds

Postby mzechner » Wed Apr 18, 2012 7:52 pm

This sounds like an excellent solution. Let me make this a sticky.
mzechner
Site Admin
 
Posts: 4713
Joined: Sat Jul 10, 2010 3:50 pm

Re: problems with looping sounds

Postby dud3z » Tue May 08, 2012 4:10 pm

dm5 wrote:That is, play two instances of the sound with a small overlap where the first instance fades out and the second instance fades in.


I had the same problem and still have it for my engine's sound in my racing game, but i solved it on the drifting sound, the process involves splitting the samples exactly at zero-crossing and fading the samples with some trial and error. It can be done, but it's a very lengthy operation since you need to test until its perfect, so if you can, avoid it :)

Your solution works well, as you said, for noise-type sounds but, for example, my drifting sound is synched to the car's lateral forces thus the fading solution is somewhat difficult to achieve in this case, fortunately i already solved that.

One thing i remeber though, is to use OGG samples instead of MP3s, since the latter always prepend a gap at start!
dud3z
 
Posts: 123
Joined: Wed Jan 04, 2012 1:10 pm

Re: problems with looping sounds

Postby AlkalineLabs » Sat May 19, 2012 2:26 pm

Not sure if your using "Sound" or "Music" instances, but I use both heavily in two separate apps and have not experienced this problem. That said I have a degree in Music Technology so I know how to get the best out of audio. If you try out either of my guitar apps you will notice the sound quality is good, yet each sound is less than 20kb in size, 0gg format. If this clicking is the result of excessive memory use or something, I believe you can really cut down on file size without sacrificing quality. I do all my Android sound management through a program called Cubase, although I have used Audacity plenty in the past. I wouldn't rule out that the problems are part to blame from Audacity.
AlkalineLabs
 
Posts: 182
Joined: Fri Jul 29, 2011 11:15 pm

Re: problems with looping sounds

Postby mzechner » Mon May 21, 2012 5:59 pm

You should totally write up your experience of audio development on Android.
mzechner
Site Admin
 
Posts: 4713
Joined: Sat Jul 10, 2010 3:50 pm

Re: problems with looping sounds

Postby daniel.weck » Mon May 21, 2012 6:24 pm

Side note regarding audio development: I've been porting some FMOD demos to LibGDX lately. I know that the underlying hardware access still occurs through the same AudioTrack/OpenSL interface that is used with pure Java coding (i.e. the latency issues don't magically go away), but the C/C++ FMOD API provides really powerful features for game/app development.

http://www.fmod.org/fmod-downloads.html

I had to tweak the native linker's parameters in the ANT XML builds (so that I could link my own native code against the existing libfmodex.so/dll/dylib), but this is all done via LibGDX's wonderful Java-based ANT generator/executor. It is really nice to be able to bundle all the platform libs into a single JAR and to use LibGDX's "native lib loader" (which automatically extracts the correct library at runtime). I also enjoy using the "JNI code parser/builder" which enables embedded C/C++ code declared for each Java native method signatures...one major caveat is that Eclipse code reformating completely corrupts the native code because of comment markup (/* */ versus //), but this is easily avoidable by dedicating Java classes to *only* native code.

I also briefly investigated Bass for Android, but FMOD seems a lot more mature:

http://www.un4seen.com/forum/?topic=13225.0

Anyway, sorry to hijack the discussion thread, but it seemed appropriate to share this information here :)
Cheers, Dan
daniel.weck
 
Posts: 57
Joined: Mon Mar 21, 2011 8:18 am

Re: problems with looping sounds

Postby mzechner » Tue May 22, 2012 10:01 am

Wow, someone uses jni-gen.

can you share your fmod experiments? Maybe on github? what's the licensing status of fmod, i don't think it's free for commercial use.
mzechner
Site Admin
 
Posts: 4713
Joined: Sat Jul 10, 2010 3:50 pm

Next

Return to Libgdx

Who is online

Users browsing this forum: No registered users and 10 guests