Android Question LibGDX Sound problem

melonZgz

Active Member
Licensed User
Longtime User
Hello there.
I'm facing a problem since I started to add sounds to my game.
It's like a micro freeze some times I play a sound, but not allways.
I've seen this thread, but doesn't help me:
I'm playing ogg files, whatever the bitrate I use the problem is still there (and with 96KHz in some devices there is no sound)
I'm using a MotoG as my development phone, and I've seen this.

As suggested there, I'm looping some sound with no volume

B4X:
      dumbsound.Repeat2(0)

Doing this the stutter almost dissapears, but I'm sure there must be a better solution than being allways looping a sound.
I say almost dissapears because once in a while I get a micro stutter. It may be my code (lots of sprites, parallax background with 3 hd layers and many Box2d bodies...) but if I remove all the sounds the game is allways smooth.
What could be happening here?
 

Informatix

Expert
Licensed User
Longtime User
Hello there.
I'm facing a problem since I started to add sounds to my game.
It's like a micro freeze some times I play a sound, but not allways.
I've seen this thread, but doesn't help me:
I'm playing ogg files, whatever the bitrate I use the problem is still there (and with 96KHz in some devices there is no sound)
I'm using a MotoG as my development phone, and I've seen this.

As suggested there, I'm looping some sound with no volume

B4X:
      dumbsound.Repeat2(0)

Doing this the stutter almost dissapears, but I'm sure there must be a better solution than being allways looping a sound.
I say almost dissapears because once in a while I get a micro stutter. It may be my code (lots of sprites, parallax background with 3 hd layers and many Box2d bodies...) but if I remove all the sounds the game is allways smooth.
What could be happening here?
1) You should manage your sounds by enabling priorities. Playing 20 sounds at the same time is a very good method to kill the performance of your game.
2) I developed my game "Diktatour" mainly on a MotoG and there are a lot of sounds and musics played (some sounds are played by the mediaplayer instead of soundpool because of the sound length but most sounds are played by soundpool, i.e. lgSound). I saw no issues. I converted all my sounds to ogg with Audacity and most of them are monophonic 44khz (stereo is not of great use on a phone/tablet).
 
Upvote 0

melonZgz

Active Member
Licensed User
Longtime User
Hi.
Sorry for the delay, but I've been trying a lot of things to see if I can solve this, with no success at all.
I have been testing the game in a lot of devices and if I remove the sounds the game runs at constant 60fps in every hardware tested, even in old tablets.
The problem I'm facing is that even with only one sound used I can see the micro freeze.
If you google soundpool lag you can see many people is having a similar issue.
I have tried adding 1 sec to every sound (as suggested here) but with no luck.
I've used your OpenSL library but same result.
Converted all sounds to 44KHz, but same result
Thinking it can be a poor optimization of my game I've been doing many things (atlas instead of single textures, downscaled the background images, reduced the points of my box2d objects, filters to nearest...) no luck, same behavior
In my case sometimes I see a micro freeze when the sound stops playing. Weird.
The only solution I see is repeating a sound. Right now I'm playing a 90ms empty sound every 100ms, and stutter is gone. It's curious that if I play the same sound every 200ms the stutter becomes horrible. It looks like if something is playing the stutter dissapears. (before this I was soing it with the repeat2 function but sometimes it stopped playing, stuttering again until the next call, maybe when I reached max simultaneous sounds)
With the mute sound playing I get stable 60fps in my moto G. But I have 59fps with little drops on a Nexus5 and same in a S4, wich are powerful devices, but a stable 60fps in crappy old tablet!. Not very noticeable, but I can see then (some friends of mine say I don't have to worry, they barely can notice it, but I think it's a problem if a game isn't smooth)
My game is an Angry birds like game. With a catapult. So when I launch a stone the camera starts following the stone. And that's when the launching sound stops playing and when I see the micro freeze. If the micro freeze where in any other moment of the game I wouldn´t care that much, but the moment the camera starts moving is very important for the game to see a freeze.
I'm very discouraged right now...
 
Upvote 0

melonZgz

Active Member
Licensed User
Longtime User
Could you create a very simple project that triggers this sound (and exhibits the issue)?
Yeah, I'll try to make one for tomorrow (I'm not at home right now)
BTW, and just to test, searching for libGDX in the play store, I've found one sample game where you can reproduce this issue.
https://play.google.com/store/apps/details?id=com.gamerald.canyonbunny
It's a very simple game, and in the options menu you can add a FPS counter.
In this game, sometimes (not allways), when you jump, and when the jump sound stops I can see the micro freeze, and when that happens the FPS goes from 60-61 to around 57, and that is exactly what happens in my phone (Moto G first gen with 5.1)
If I disable the sounds the FPS shows a constant framerate and no stutter is visible.
Maybe it can be my phone?
 
Upvote 0

melonZgz

Active Member
Licensed User
Longtime User
Did you try to switch to the other media player in the dev settings of your device? NuPlayer <-> AwesomePlayer
I don't know whether it is involved in the issue but it's worth trying.
Same behavior in both.
I've discovered something that I sould have tried looong before: If I don't play the background music and only play the sound effects the game is completely smooth!
Both music and sounds are ogg 44.1Khz 16 bits PCM. using lgsound for sound effects and lgmusic for music
 
Upvote 0

melonZgz

Active Member
Licensed User
Longtime User
Ok. I've written a very simple project to show this (libGDX + BOX2d + Music + Sound)
https://www.dropbox.com/s/3jwx42e4p8js52c/sample.zip?dl=0
You just have to touch the screen to jump.
There is music and there is a jump sound.
I've added a FPS counter to visualize it better.
Not allways (I'd say once 10 jumps) there is a micro freeze, wich makes the FPS counter go to around 56-57 FPS. In normal state there should de 60FPS.
It can look insignificant, but imagine in a game where there is a scroll, then the effect becomes more noticeable.
If I disable the music (line 131) then the freezes are gone. Same if I disable the sound.
Thank you for your time!
 
Upvote 0
Top