Hello,
I’m looking into making a cross platform audio metronome app using Codename One. I have made a few music related Java Applets using MIDI but this will be my first audio program and also my first mobile app. I’ve done a bit of research already into working with audio in Java, but Codename One seems to work with audio quite differently than Java. From what I can tell by going through the Codename One API, it appears that Media and MediaManager are the only options for working with audio...is that correct?
Media:https://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/com/codename1/media/Media.html
If so, I have a few questions just to make sure that my metronome app will be possible to create using Codename One:
1) I’ve seen from different sources that low latency audio is very difficult to do on mobile devices and it seems to be a reoccurring theme that many people making mobile metronomes end up with severe time drift. Accuracy is of top priority, so will Media/MediaManager provide a way to play sounds consistently in time? What kind of latency will this have?
2) Will the accuracy and timing of playing audio with Media/MediaManager depend on the device, or will it be consistent among devices? For example, would android have stable time while the iPhone has time shifts, or vice versa?
I know there are accurate metronomes made for all kinds of devices, but they are written using native code. I haven’t seen any cross platform metronomes like what I’m hoping to do, so I am wondering if it will even be possible to do without writing native code for each device. That would be extremely difficult for me as I’m not that experienced of a programmer and most of my experience is with Java.
3) Can Media/MediaManager play multiple sounds
simultaneously? The features I want to implement in the metronome will require
occasionally playing more than one sound at the same time (for subdivisions,
polyrhythms, etc)
3b) If Media/MediaManager cannot play multiple sounds simultaneously, what would be the best method to do that with Codename One? It will also need to have the option of being able to combine sounds that do not start and end at the same time but still have the sounds overlap.
4) This is unrelated to the audio side, but in Java you can use the method System.getnanotime() to time things based on nanoseconds, is there a way to do this in Codename One? I didn’t see a nanoseconds option in the API. I want to base the timing off of nanoseconds instead of milliseconds, because at certain tempos it would either speed up or slow down way too much using milliseconds.
Also, I’d prefer not to use thread.sleep() for timing, as I’ve heard that this is unreliable and it doesn’t always return exactly at the specified time so it’s not good to use for a metronome.
I’ll probably have more questions down the road as I get
going on this, but this should be enough to know if Codename One is the right
path for me to continue on. Thanks!
PS. I have to say Codename One looks VERY impressive having watched several demonstration videos of it on youtube. I strongly hope that it will work for my project!
Hi Shai,
That’s interesting that Media/MediaManager can play multiple sounds simultaneously, I was kind of expecting to hear that it wouldn’t be able to.
And just to clarify, you are saying that with Media/MediaManager the latency could change each time it plays a sound file? Because even if the latency was ridiculously high, I think it should be ok as long as it was consistent and always takes the same amount of time to start playing the sound, since every click would simply be delayed by the same amount. Once the metronome starts it just needs to stay in time with itself from whenever starts playing. But it would be a problem if it took 50ms to play the first click, then 40ms for the next, then 60ms the next, etc...would that end up being the case with Media/MediaManager?
If it is at all possible to use Media/MediaManager that would be extremely helpful for sure, but If I do have to code a native low level audio player for each device using Codename One’s native interface that you mentioned...then essentially I would have to program the native audio player in Objective-C for IOS, Java for Android, C# for Windows phone, etc. is that correct?
And here I thought that all of the advanced features I have in mind were going to be the difficult part of this project...looks like just getting a simple ‘click’ to stay in time may be just as difficult. lol
Thanks!