cyxigo
December 31, 2023, 8:57am
1
Godot Version
4.2
Question
On android the sound plays with a noticeable delay, or when the bus volume is changed there is also a delay. Is there any way to fix this through the code or somewhere in the project settings?
i don’t think anything can be optimised in the engine yet, a different api would have to be used
opened 07:55PM - 27 Nov 23 UTC
closed 04:29PM - 28 Dec 23 UTC
archived
platform:android
topic:porting
topic:audio
### Godot version
4.1.3, 4.2.0rc1
### System information
Android 11
### Issu… e description
AudioStreamPlayer plays sounds with a noticable latency (>0.5s) on mobile devices. It makes triggerable sounds not line up with the events on the screen that cause the sounds.
### Steps to reproduce
1. Create a clickable button, and make the button call AudioStreamPlayer.play() after clicking the button
2. Export game to mobile, and install the game on your device
3. Play game, click button. Notice the delay between clicking the button and the sound being played.
### Minimal reproduction project
[AudioStreamPlayer Issue Project.zip](https://github.com/godotengine/godot/files/13479567/AudioStreamPlayer.Issue.Project.zip)
opened 01:36AM - 26 Feb 21 UTC
topic:audio
platform:android
### Describe the project you are working on
Godot Audio on Android
### Des… cribe the problem or limitation you are having in your project
Godot's audio setup on Android currently uses [OpenSL ES](https://developer.android.com/ndk/guides/audio/opensl), 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](https://developer.android.com/ndk/guides/audio/aaudio/aaudio) API introduced in Android API 26.
### Describe the feature / enhancement and how it helps to overcome the problem or limitation
[Oboe](https://github.com/google/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](https://github.com/google/oboe/blob/master/docs/OpenSLESMigration.md).
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](https://source.android.com/devices/audio/latency/measure#larsenTest) 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](https://github.com/godotengine/godot-demo-projects/tree/master/audio/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
cyxigo
December 31, 2023, 10:14pm
3
This may be a very stupid question, but how to use a different api?
Godot Engine must be reprogrammed, or perhaps it already has GdExtensions.
system
Closed
October 4, 2024, 9:29pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.