tckmn / semitone

tuner, metronome, and piano for Android
GNU General Public License v3.0
83 stars 26 forks source link

Piano: sound stutters under Android 10 #27

Open scheunengeist opened 3 years ago

scheunengeist commented 3 years ago

Hi! First off, thanks for this app, it's a really nice helper tool for musical needs on the go.

Issue:

Device: Samsung Galaxy S5 System: LineageOS 17.1 (Android 10) Semitone: 1.3 from F-Droid (seems to only require one permission (microphone), which is granted)

I couldn't find any relevant info on the web, and there doesn't seem a similar issue here on github. Can anyone confirm this, and/or provide a hint how to solve it? Thanks!

scheunengeist commented 3 years ago

Having read a bit more, it was suggested somewhere that latency issues may be caused by battery optimizations. Tested: turning off battery optimization for Semitone -> no effect. Additionally increasing performance profile to highest level (most performance, least power saving) -> no effect.

somebelse commented 2 years ago

I have this problem as well.

I just found out, when there is already a source playing audio, when opening the app, the stuttering is gone. The other media source can be turned off and the problem stays fixed as long as Semitone isn't closed. Tonality has the same Problem for me and the same workaround works.

Semitone 1.3 (Google Playstore) Tonality 1.2 (Google Playstore)

Motorola Moto G8 plus running Android 10

Android security patch level October 1, 2021

Google Play system update 2021-11-01 Q

baseband version M6125_43.45.03.48R DOHA_ROWNDSDS_CUST

kernel version 4.14.117-perf+

1 Wed Sep 29 03:14:30 CDT 2021

build number QPIS30.28-Q3-28-26-4-1-7

somebelse commented 2 years ago

Rotating the keyboard while no other audio is present resets the workaround, so that it stutters again

somebelse commented 2 years ago

You can also start the workaround while playing audio and then rotating the keyboard

benrg commented 2 years ago

I've reproduced this on two devices, one running Android 10 (stock) and the other Android 9 (Lineage). It happens with both the piano and the metronome, and with both the synthesized and mp3 piano modes.

The audio output of one device looks like this:

i.e., alternating 20 ms of audio and 20 ms of silence. The output of the other is 20 ms of audio and 4 ms of silence.

The Oboe library uses AAudio as a backend by default with OpenSLES as a fallback. This problem seems to be specific to AAudio. The reason it showed up in a 9-to-10 upgrade in the original report may be that LineageOS 16 didn't have AAudio, or it failed to initialize for some reason. The reason it can be worked around by opening the app while playing other audio may be that that also prevents AAudio from initializing.

You could work around it by adding asb.setAudioApi(oboe::AudioApi::OpenSLES); to PianoEngine::init(), though I suppose it would be better to fix whatever is keeping AAudio from working. I looked through the code and see no obvious bugs.