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