Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for bluetooth headset audio stutter #8846

Closed
wants to merge 1 commit into from

Conversation

MrColdbird
Copy link
Contributor

It's the same issue we've had before on the NVidia Shield (and to an similiar extend on the OnePlus 3), just on a bigger scale.

This merge fixes bluetooth audio once and for all.
It also has the nice side-effect of fixing some smaller stutters on the OnePlus 3 when using the built-in speakers or wired headphones.

I know it's shooting pidgeons with cannons, but at least it works.

@hrydgard
Copy link
Owner

hrydgard commented Jul 4, 2016

Ah, right.

I'd like to set the low watermark adaptively based on the system-provided buffer size though, maybe a simple factor. You are right that it's probably set a little too low right now though...

@unknownbrackets
Copy link
Collaborator

unknownbrackets commented Jul 4, 2016

These values right?
https://github.com/hrydgard/ppsspp/blob/master/android/jni/native_audio.cpp#L24

Note that it's clamped to 512:

if (framesPerBuffer > 512) {

Just need to provide them into NativeApp somewhere, and we could adapt. I assume they will be related to bluetooth when it's plugged in... but what happens when bluetooth is connected during gameplay? Do we need to handle re-adapting? It might already be a problem in hitting the fast path there?

Note: on a Nexus 5:
optimalFramesPerBuffer = 240
optimalSampleRate = 48000
=200 buffers/second optimal
=5ms per buffer optimal

Guessing bluetooth provides initially a larger value, like 4096?

-[Unknown]

@hrydgard
Copy link
Owner

hrydgard commented Jul 5, 2016

Right, for the low watermark we should probably stick to the optimalFramesPerBuffer but without clamping to 512, maybe multiplied by a small factor. I think that should be enough.

As for changing at runtime, that would indeed be a concern - but if we can notice the change, changing the low watermark at runtime should not be an issue.

@MrColdbird
Copy link
Contributor Author

If it is any help, Bluetooth output issues are a daily phenomenom for latency-optimized applications of all kind.

For example pretty much every OpenSL based application (which does use the system-provided values for providing low-latency output) suffers from identical symptoms.

From what I've read up the accepted workaround so far seems to be upping the buffer size to 2048x4... which is exactly what my commit does.

I don't think the system provided values actually update when a Bluetooth headset is present, so there might not be a easy way around this issue other than doing what I've already done in the pull request.

The only alternative way of doing this would be to install a permanently listening BroadcastReceiver (in a background service for example) and monitoring for Bluetooth connect and disconnect events, which would then change the audio settings as needed.

@DouDaWitzki
Copy link

Hello
I'm sorry for posting like almost 2 months late, but im having this issue and i cant find StereoResampler.h my phone.
SHould I Add it ? If yes, where ?

Thanks for taking time to read.

@hrydgard
Copy link
Owner

hrydgard commented Sep 11, 2016

I'm going to apply half of this change (MAX_SAMPLES). the other change (watermark) will increase latency for everyone so it'll need an option or autodetection. There seems to be some gnarly ways to detect the presence of bluetooth headphones on Android, but that might have to wait until after 1.3.0.

@gigabyte-1000
Copy link

I have a few android devices, mostly with Snapdragon processors, and I noticed a trend here, on ALL my snapdragon devices I get Bluetooth lag or stuttering in ppsspp even with 100% speed (the fix above does fix or improve it), I tested on a Snapdragon 800 and Snapdraon 650,

However on my other cheap device that has a Rockchip rk3188 the bluetooth has no lags or delays in ppsspp at 100% speed, so I am wondering if these lags are related to the hardware, if that's the case it might be simpler to add an option like Snapdragon BT fix or Mediatek BT fix.

we would need people with different CPU types (mediatek, snapdragon, exynos, rockchip,..etc) to report if their device is effected.

@MrColdbird
Copy link
Contributor Author

@hyakki- Interesting find. I can't really confirm it myself as all my devices are snapdragon based but if what you say is true then this might be another reason to make this an toggle in the menu.

@hrydgard
Copy link
Owner

hrydgard commented Oct 20, 2016

Yup, I'm going to make it a toggle soon, that will also help investigation I guess. Been a bit swamped with other things, but it's coming :)

@hrydgard
Copy link
Owner

hrydgard commented Dec 1, 2016

Well, I said soon, it wasn't - but now it's done. See (and please test) #9138. Closing this.

@hrydgard hrydgard closed this Dec 1, 2016
@gigabyte-1000
Copy link

you must of read my mind!, just installed the beta yesterday and I didn't see the option, then today option added, anyways I quickly tested and audio is working fine with my bt headphones, I will do some more testing tonight on a few other devices, so far so good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants