Drumkit soundboard: audio lags screen touch

Anything libgdx related goes here!

Drumkit soundboard: audio lags screen touch

Postby tescott » Sat Apr 16, 2011 5:03 pm

I'm having a bit of trouble with getting my app to behave as I want it to, using libgdx and thought I'd post here for insight others might have.

I'm relatively new to libgdx and today I thought it would be fun to whip up a drum kit sound board to learn about audio and user input handling. I've got a total of four OGG samples defined: bass, snare, high hat, and crash cymbal. The idea behind the app is that when the user hits a certain part of the screen it makes a sound. Simple enough!

My app's main class implements the ApplicationListener and InputProcessor interfaces. All the create() method does is use Gdx.app.getAudio().newSound() to define some Sounds. The render() method is completely empty. I've got the touchDown() method setup to define the screen into four quadrants -- depending on which quadrant you touch defines which sound gets played.

It works great on the desktop and is really responsive to mouse clicks. On my HTC Incredible, however, there's a noticeable delay between the time that the screen is hit to the point where sound starts playing. It's bad enough that you can't keep any sort of rhythm going.

Does anybody have recommendations on how to zero in on what may be incurring the delay (or better yet -- get rid of it)? I see two areas where it could be occurring: 1) from the point the user touches the screen to the point that the touchDown() method is invoked, and 2) from the point the Sound's .play() method is invoked to the point that it actually starts to play. I guess another area of influence is just the general speed of the phone itself...

Anybody run into similar problems with lag between the user input and sound effects? What did you do to correct it?

I think my other option is to bail on libgdx for this application and try using the Android APIs for sound pool and motion events to see if the same behavior is present. That'd at least point to the phone's speed as the issue vs. an underlying frameworks issue.

Thanks!
--tim
edit: corrected spelling mistakes...
Last edited by tescott on Sat Apr 16, 2011 5:46 pm, edited 1 time in total.
tescott
 
Posts: 487
Joined: Tue Apr 12, 2011 2:32 am

Re: Drumkit soundboard: audio lags screen touch

Postby mzechner » Sat Apr 16, 2011 5:20 pm

Welcome to Android, home of the most atrocious audio lag in existence. We directly use SoundPool and the touch API. You can try go the pure Android route, but chances are that you'll arrive at the same problem again.

Android's audio system is known for its high latency and there's nothing we can do about it. OpenSL, introduced in 2.3.3, doesn't solve the problem either. There are not minimum requirements imposed on the audio hardware by Google, so manufacturers seem to not care that much. The audio sub-system has its own share of problems as well.

Relevant b.android.com issue http://code.google.com/p/android/issues/detail?id=3434
Here's a condensed version http://mindtherobot.com/blog/555/androi ... opensl-es/
You can also find out more about the issue on the android platform group and other sources.

tl;dr: audio on Android is broken, we can't have low-latency, no matter which way we go (AudioTrack, SoundPool, OpenSL)
mzechner
Site Admin
 
Posts: 4875
Joined: Sat Jul 10, 2010 3:50 pm

Re: Drumkit soundboard: audio lags screen touch

Postby tescott » Sat Apr 16, 2011 5:36 pm

Well that just sucks!

Thanks for the quick reply and the informative links.

--tim
tescott
 
Posts: 487
Joined: Tue Apr 12, 2011 2:32 am


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot] and 10 guests