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

Replace the current audio driver with Oboe on Android #2358

Open
mattkwang opened this issue Feb 26, 2021 · 12 comments · May be fixed by godotengine/godot#86776
Open

Replace the current audio driver with Oboe on Android #2358

mattkwang opened this issue Feb 26, 2021 · 12 comments · May be fixed by godotengine/godot#86776

Comments

@mattkwang
Copy link

Describe the project you are working on

Godot Audio on Android

Describe the problem or limitation you are having in your project

Godot's audio setup on Android currently uses OpenSL ES, an older audio API supported on Android API 9 and above. This API has high device coverage, but is bulkier and less suitable for low-latency applications compared to the native AAudio API introduced in Android API 26.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Oboe is Android's recommended modern audio API, acting as a C++ wrapper library that chooses between OpenSL ES and AAudio depending on device support and best performance. Oboe is compatible with API 16 onwards (covers 99% of Android devices). We expect this to modernize Godot's audio setup on Android, with lower audio latency and minimal loss of device coverage.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

We will create a class AudioDriverOboe housed under godot/platform/android, which will take the place of AudioDriveOpenSL in OS_Android. Much of its functionality will mirror AudioDriverOpenSL, informed by Oboe's migration guide.

Steps:

  1. Add Oboe to godot/thirdparty and link with SCons build system.
  2. Implement AudioDriverOboe with the set of methods inherited from AudioDriver, and modify os_android.h to use it. More implementation details are available if requested.
  3. Develop test apps for latency measurement and potentially device coverage.

AudioDriverOboe Member variables:

Mutex *mutex
static AudioDriverOboe *s_ad (singleton)
AudioStream player
AudioStream recorder
bool active
bool pause

AudioDriverOboe Implemented API:

const char *get_name()
Error init()
void start()
int get_mix_rate()
SpeakerMode get_speaker_mode()
void lock()
void unlock()
void finish()
void set_pause(bool p_pause)
Error capture_start()
Error capture_stop()
Constructor AudioDriverOboe()

For latency testing, the simplest version is the Larsen test with two AudioStreamPlayer nodes, one that records audio input and one that plays the input continuously. By measuring the time between sounds, we capture the sum of input and output latency, with some device/engine overhead. This should serve as an adequate measure for approximate latency improvement.

For testing device coverage, we should have a test app that covers audio features on Godot. This may be using the mic_record demo or some variation upon it which will use both input and output. If run on some device farm or set of devices, we may use app crashes or bad sound behavior to verify minimal loss in coverage.

If this enhancement will not be used often, can it be worked around with a few lines of script?

N/A. This is expected to be used for all Godot games exported for Android.

Is there a reason why this should be core and not an add-on in the asset library?

This proposal changes the audio (a core element of the engine) intending to impact all games for the Android platform.

Android Games DevTech Team @ Google

@BastiaanOlij
Copy link

Sounds like a good enhancement to me. Oboe is under an Apache 2.0 license? So shouldn't be anything in our way to include it.

@Calinou Calinou changed the title Integrate Oboe for audio on Android Replace the OpenSL ES audio driver with Oboe on Android Oct 25, 2021
@Calinou Calinou added this to the 4.x milestone Oct 25, 2021
@Calinou Calinou changed the title Replace the OpenSL ES audio driver with Oboe on Android Replace the current audio driver with Oboe on Android Oct 25, 2021
@dvdfu
Copy link

dvdfu commented Jun 21, 2024

Just seconding to say I'd love to see this coming to Godot 4.x! I'm interested in developing music-playing apps with Godot, but haven't been able to achieve Android audio latency shorter than 240ms, which is a dealbreaker for these kinds of applications.

@Calinou
Copy link
Member

Calinou commented Jun 21, 2024

@dvdfu Can you test godotengine/godot#86776 on your project to see if it improves latency?

@dvdfu
Copy link

dvdfu commented Jul 5, 2024

@dvdfu Can you test godotengine/godot#86776 on your project to see if it improves latency?

Sorry, I hadn't read this reply until now, and it seems like the artifacts are no longer available for download. Happy to test again if they are!

@Calinou
Copy link
Member

Calinou commented Jul 7, 2024

Sorry, I hadn't read this reply until now, and it seems like the artifacts are no longer available for download. Happy to test again if they are!

I built a release Android export template APK from that PR: android_release.apk.zip

You should be able to specify it in the custom export template section of your Android export presets.

@dvdfu
Copy link

dvdfu commented Jul 7, 2024

If I download that file and reference it in Android Export > Options > Custom Template > Release (or Debug), the project will build, but the application won't load (appears as a black screen). Removing it allows building like normal.

@kus04e4ek
Copy link

kus04e4ek commented Jul 8, 2024

If I download that file and reference it in Android Export > Options > Custom Template > Release (or Debug), the project will build, but the application won't load (appears as a black screen). Removing it allows building like normal.

What Godot version are you using? The PR is close to the 4.3 dev 4 version, quickly checked that version and it seems compatible with Calinou's build

@jruiz94
Copy link

jruiz94 commented Aug 11, 2024

Hello! Just stumbled across this issue when exporting my game for Android. Does anyone know if this will get shipped to 4.3. Just curious, sending all my support for the huge work of the people involved in this development ❤️

@Calinou
Copy link
Member

Calinou commented Aug 11, 2024

Does anyone know if this will get shipped to 4.3.

4.3 is in release freeze, so new features can only be merged in 4.4 at the earliest.

@HiroDane
Copy link

I built a release Android export template APK from that PR: android_release.apk.zip

Does this work on any dev version of godot currently?

I am having an issue where mic access is getting cut off after a few seconds on android even when app is in foreground. Got reffered to this proposal from a reddit post. Was hoping this could fix it.

@Alex2782
Copy link

Alex2782 commented Aug 24, 2024

I built a release Android export template APK from that PR: android_release.apk.zip
Does this work on any dev version of godot currently?

should also work with v4.3.stable.official

Bildschirmfoto 2024-08-24 um 18 14 38

image

@kus04e4ek
Copy link

kus04e4ek commented Aug 25, 2024

I am having an issue where mic access is getting cut off after a few seconds on android even when app is in foreground. Got reffered to this proposal from a reddit post. Was hoping this could fix it.

See godotengine/godot#86428 and related PRs. The PR that closes this proposal doesn't solve this issue

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

Successfully merging a pull request may close this issue.

9 participants