section_logo

Android audio APIs sucks

08-10-2010 at 21:55:41 | no comments

This love couldn't be forever... and I just got pissed when I found out that Android audio API is competly crap.

I was playing around with the three available APIs: AudioTrack, MediaPlayer and SoundPool. My idea was to make just a simple music sequencer, with the idea to try to do some little softsynth in the future :)

So after making the first tests I got an incredible deception because of the lack of timing. I started to create a simple metronome just playing a sound continously in a loop, and I got the same results: lag from time to time.

I started to search on internet for possible solutions, maybe I was doing something completely wrong. But I didn't found almost anything, so I decided to try to download some high ranked metronome from Android Market to check if they suffer from this kind of problem.

I got surprised when I found that all of them that I downloaded they got some delay from time to time comparing them with real metronome (Some of them got this lag earlier and It was quite easy to recognize even without comparison with real one, others got it softer and later). I even found one visual metronome with the following description: A simple metronome using flashing lamps. It does NOT click, since the effort of clicking seems to make some Android metronomes lose time.

I thought: "Ok... I think it's time to go to NDK and do this things in native code". Could be nice if the NDK would support audio :) but it seems they've just focused more in graphics.

I've read in many places that they'll give NDK support for audio in Android 3.0, but noone of those comments were offical, so just cross the finger and keep praying

Regarding the current API, I've tried all the combinations I could: using the three APIs, creating threads for audio at high priority, creating task with handler, generating a lot of messages at fixed step time... but noone of them work enough good.

It seems that GC just appears to say hello from time to time and help with this mess.

I think that developing this kind of mobiles it looks like developing in computers some years ago where good perfomance, keeping an eye on resources and having enough stability was the main goal.

Now in desktop computers almost noone care about those things as we have enough resources and speed for everything you almost could program, and I think this philosophy has come also to this devices. It could be much better to have the native API in high perfomance language such as C or C++ for example, and then add an extra layer for those who doesn't want to care about it but prefer more academic language programming :_)

Anyway, after crying a little bit, I go back to code :D

08-10-2010 at 21:55:41 | no comments

Collision detection on Android with fixed timestep

06-10-2010 at 23:34:35 | 1 comment

Last days I've spent some time making some tests with collision detection on Android. It could be easy to use the simple approach to test if two circles overlap on each frame using the simplest game loop:

while (playing)
{
	updateGame();
	draw();
}

But I've bought my phone for fun, to enjoy doing hard things :D or at least trying to make them in the good way. So I started to read about proper game loop design.

I must say it's quite hard to find nice articles, most of them just present a buggy deltatime based model, but fortunately I found two very nice articles about it:

Regarding the collision detection I also found two articles, quite old but still useful: Pool Hall Lessons: Fast, Accurate Collision Detection Between Circles or Spheres and Simple Intersection Tests For Games

When you try to check on each frame if two objects collide, you could get into error very easy if the objects move at high speed. It happens if the distance they'll move from one frame to another is bigger than the size of then so they just jump/pass through each other like a ghost :)

To prevent it I check the movement from the last frame to the current one to to see if the objects collide between the frames.

06-10-2010 at 23:34:35 | 1 comment

Hello Android Market

27-09-2010 at 20:15:20 | 1 comment

It has been a week since I got my android phone, and I've already manage to create a little application trying to fit together basic functionality on it

It's just a game where you should touch the last circle that appears on the screen. Quite simple but enough for the beginning :)

It features:

  • Basic canvas drawing
  • Sound playing and vibration on success or fail
  • Save game preferences: username, play sounds, vibration
  • Download and upload hiscores from an online server

As I said it's quite enough to start playing with it.

I hope you'll enjoy it (and also I hope to beat Dubito score :\)

Here you'll go directly to the android market, otherwise you could try to find Visual memory from bitkore (More about that in the future :))

27-09-2010 at 20:15:20 | 1 comment