Author Topic: Audio Lag, or why does my audio output have a ~1000ms delay  (Read 26570 times)

Offline Sholid

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #15 on: July 22, 2013, 12:28:00 PM »
@Tomi, as you can see in github issue #147 I referenced above, several devices are known to have audio latency.  What was unusual about this thread is that it was reported for the OUYA, a device that I also own and for which I have not noticed anywhere near 1 second audio latency.

Could I get you guys to check if this problem is only the audio, or if it also involves input?  On other words, when you press A, does it take some time for Mario to jump, or does he jump immediately and it takes some time to make the sound?

On my OUYA, you hit jump, then about halfway into the air, he finally shouts. When you suddenly turn the opposite way, you see the dust come out, then the screeching noise (don't know how else to describe it) finally comes out.

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #16 on: July 22, 2013, 12:43:55 PM »
@Sholid @x3ro

This is very strange.  Like Paul I have not experienced any of these issues on my OUYA.  If we're all running the same version of the app on identical hardware, it would seem the issue is at least partially related to something external.  A few questions:

 - Have you side-loaded any apps?  If so, what are they?
 - Have you modified the ouya firmware in any way?
 - Have you tried adjusting your HDTV settings?
     * HDTV video scaling
     * HDTV audio config
 - Are you playing audio through an external receiver?
 - Are you using an HDMI switch between the OUYA and HDTV?
 - Do you have a reliable network/wireless/bluetooth connection?
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Sholid

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #17 on: July 22, 2013, 01:00:43 PM »
@Sholid @x3ro

This is very strange.  Like Paul I have not experienced any of these issues on my OUYA.  If we're all running the same version of the app on identical hardware, it would seem the issue is at least partially related to something external.  A few questions:

 - Have you side-loaded any apps?  If so, what are they?
 - Have you modified the ouya firmware in any way?
 - Have you tried adjusting your HDTV settings?
     * HDTV video scaling
     * HDTV audio config
 - Are you playing audio through an external receiver?
 - Are you using an HDMI switch between the OUYA and HDTV?
 - Do you have a reliable network/wireless/bluetooth connection?


The only thing there, that I'm pretty sure there's no problem with, that I haven't tried, adjusted, or thought about is the network. The thing about that is that the network comes straight from the cable modem wirelessly. So, nothing I can change.

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #18 on: July 22, 2013, 01:28:31 PM »
The only thing there, that I'm pretty sure there's no problem with

Just to clarify, are you assuming there's not a problem, or are you saying you actually tested all those things with the HDTV/receiver settings?

So you don't have a single side-loaded app?


The thing about that is that the network comes straight from the cable modem wirelessly. So, nothing I can change.
The network is a long shot, but you could try disabling the OUYA's wireless connection just to be 100% sure.

Some more questions I forgot to ask
 - Do you experience audio lag with any other games/emulators on the OUYA?
 - Have you tried changing any of the mupen audio settings (Settings->Audio)?
 - Have you tried resetting all your mupen settings back to their defaults (Settings->Reset)?
 - Have you tried resetting your game (rather than resuming) from the Play menu?

2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Sholid

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #19 on: July 22, 2013, 02:11:23 PM »
The only thing there, that I'm pretty sure there's no problem with

Just to clarify, are you assuming there's not a problem, or are you saying you actually tested all those things with the HDTV/receiver settings?

So you don't have a single side-loaded app?


The thing about that is that the network comes straight from the cable modem wirelessly. So, nothing I can change.
The network is a long shot, but you could try disabling the OUYA's wireless connection just to be 100% sure.

Some more questions I forgot to ask
 - Do you experience audio lag with any other games/emulators on the OUYA?
 - Have you tried changing any of the mupen audio settings (Settings->Audio)?
 - Have you tried resetting all your mupen settings back to their defaults (Settings->Reset)?
 - Have you tried resetting your game (rather than resuming) from the Play menu?



I checked for side apps and only the OUYA default stuff is going on.

I tested the GBA emulator... and it has the same problem. I believe the SNES does too. So I guess it's an all around thing.

EDIT: All of the regular games are fine. Bard's Tale, Ravensword, etc.
« Last Edit: July 22, 2013, 02:38:58 PM by Sholid »

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Sholid

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #21 on: July 22, 2013, 07:17:21 PM »
Are your ROMs stored on an external drive by any chance?  Are you guys using zipped ROMs?

This issue is looking to be much larger than Mupen:

http://ouyaforum.com/showthread.php?4053-Ouya-Audio-Delay
http://en.reddit.com/r/ouya/comments/1ii30h/is_the_ouya_capable_of_low_latency_audio/
http://www.youtube.com/watch?v=p6y0Hsqqg-Y
http://ouyaforum.com/showthread.php?4680-Universal-audio-Lag

External drive. That's probably the reason. Nothing I've skimmed by on the sites "fixes" it though.

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #22 on: July 22, 2013, 07:19:41 PM »
Copy them over the internal storage ("sdcard") and then try running them from there rather than the external drive.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Sholid

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #23 on: July 22, 2013, 07:50:57 PM »
Copy them over the internal storage ("sdcard") and then try running them from there rather than the external drive.

Just did that. Played Super Mario Bros 3 on GBA for five minutes (Advance 4). Still delayed... CONFUSED. It seems the OUYA is punishing me for emulating (even though I already own these games. I just want them in high-res without the PC on).

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #24 on: July 22, 2013, 08:24:17 PM »
Reading up on this some more, it seems like the recommendation is to use Open SL ES when possible.  Not sure how difficult this would be to work in conjunction with the SDL port, though.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline Sholid

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #25 on: July 23, 2013, 11:40:13 AM »
I'm not sure what you are talking about there... is it something I can do?

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #26 on: July 23, 2013, 04:29:40 PM »
I'm not sure what you are talking about there... is it something I can do?

Paul's comment was directed at the dev team.

Reading up on this some more, it seems like the recommendation is to use Open SL ES when possible.  Not sure how difficult this would be to work in conjunction with the SDL port, though.

I've never studied the audio plugin, but I notice it's a relatively small chunk of code.  If it's not too hard to port the existing plugin to SLES, we could just make it a new plugin altogether... have our cake and eat it too.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline vgf89

  • bit
  • Posts: 2
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #27 on: August 03, 2013, 06:24:46 PM »
On my Note 10.1, I have audio lag somewhere around 500ms (didn't actually measure it), and it's extremely noticeable and somewhat annoying in both Mario 64 and Banjo Kazooie, as well as other games. Some other emulators have this lag but it doesn't seem nearly as bad.

Interestingly, the audio lag is substantially reduced while running the game at 250% speed. It's probably around half of the lag than when running at normal speed. That doesn't sound like an Android issue to me... sounds more like an audio implementation issue with the emulator.

Is there maybe some A/V syncing code that's being overbearing, kind of how Vsync usually increases video lag a lot on PCs, but instead with Audio? Or maybe an audio buffer that's larger than it needs to be (maybe make something like that adjustable)?

If I knew next to anything about programming for Android, emulators, or audio streaming and video rendering, I would try to help.
« Last Edit: August 03, 2013, 06:53:14 PM by vgf89 »

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #28 on: August 03, 2013, 07:51:38 PM »
Again, the fact that this is happening on more than one emulator, each of which was written by entirely different teams of developers, suggests that the issue is related to something larger than just the emulators.  Are your game ROMs for Mupen and the other emulators located on an external drive, by any chance?  I've heard some anecdotes that the OUYA stutters when running things off an external drive.  Of course that's not the same thing as latency, but I thought I'd throw it out there.

@devs - Do you think the other emulators use SDL?  Or any other common libraries?  What do they all have in common?
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Audio Lag, or why does my audio output have a ~1000ms delay
« Reply #29 on: August 03, 2013, 08:55:29 PM »
Probably the main thing they have in common is they are sending audio across JNI from the native side to play in Java.  If this is the cause, I think an audio plugin that uses SLES on the native side (visible in the plugins section and default when the Android version is 2.3 or higher) would be the solution.

I'm going to do some research tomorrow and maybe start an experimental branch on github if it looks relatively straight-forward (not sure how complicated an audio plugin is -- seems pretty small at first glance, but never know until you get down in the weeds)
« Last Edit: August 03, 2013, 08:57:20 PM by Paul »
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted