google / oboe

Oboe is a C++ library that makes it easy to build high-performance audio apps on Android.
Apache License 2.0
3.71k stars 569 forks source link

Consistent input glitching with LiveEffect on SM-A715F #1312

Open chrismanchester opened 3 years ago

chrismanchester commented 3 years ago

Android version(s): 11 Android device(s): SM-A715F Oboe version: 1.6.0 App name used for testing: LiveEffect

Short description Output monitored through headphones is distorted (consistent "crackle" over voice).

Steps to reproduce Open LiveEffect with headset or headphones attached. Select AAudio or OpenSL ES. Press start and talk into the mic.

Expected behavior Input is echoed to output with reasonable fidelity.

Actual behavior Output through headphones is badly distorted.

Device SM-A715F (Samsung A71)

$   for p in \
>       ro.product.brand ro.product.manufacturer ro.product.model \
>       ro.product.device ro.product.cpu.abi ro.build.description \
>       ro.hardware ro.hardware.chipname ro.arch "| grep aaudio";
>       do echo "$p = $(adb shell getprop $p)"; done
ro.product.brand = samsung
ro.product.manufacturer = samsung
ro.product.model = SM-A715F
ro.product.device = a71
ro.product.cpu.abi = arm64-v8a
ro.build.description = a71naxx-user 11 RP1A.200720.012 A715FXXS4BUC1 release-keys
ro.hardware = qcom
ro.hardware.chipname = SM7150
ro.arch = 
| grep aaudio = 

Any additional context

This device shipped with Android 10, but I only was able to reproduce the problem after upgrading it to Android 11. While it reproduces with either Open SL ES or AAudio, if I use oboe::PerformanceMode::None in LiveEffect the distortion is fixed.

From adding some debug logging to LiveEffect I can see we're frequently reading fewer frames than we ask for here: https://github.com/google/oboe/blob/f126f79fd3d9cbfac78f6e8d8e8bc1cd9f4db849/samples/LiveEffect/src/main/cpp/FullDuplexStream.cpp#L65, and occasionally we don't get anything from that call.

Since this seems so device specific I'm not expecting we can fix it in Oboe per-se, but I would be happy to provide any more info that might be helpful or try any potential workarounds that might be effective. Thank you very much!

dturner commented 3 years ago

It sounds like the input stream is frequently underrunning. @philburk has some questions.

philburk commented 3 years ago

Thanks for the detailed bug report!

Can you please try the Oboetester app? https://play.google.com/store/apps/details?id=com.mobileer.oboetester It has a "ECHO INPUT TO OUTPUT" test similar to LiveEffect. It also has "RECORD AND PLAY" which will let you capture audio and share the WAV file in an email. If you can capture the distorted audio please attach a short WAV file that we can analyze.

chrismanchester commented 3 years ago

I was able to reproduce with the OboeTester. "ECHO INPUT TO OUTPUT" reproduces the distortion less frequently than LiveEffect (which reproduces 100% of the time with near constant distortion). "RECORD AND PLAY" reproduces least frequently, although I have captured an instance of the distortion, which is subjectively similar to the glitches in LiveEffect: https://soundcloud.com/user-628463338/oboe-recording-20210626-034846 (distortion starts around 3 seconds).

philburk commented 3 years ago

Thanks for posting the recording. It sounds like there are periods where the sound is good for several seconds. Then occasional short glitches. We can rule out channel mismatch. In other words it is not a mono stream being treated as stereo.

Also, because the glitches are in the recording, we know it is an input glitch and not an output glitch.

Unfortunately the recording is compressed, not downloadable, and not a WAV file. So I cannot analyze it in detail. We normally use Audacity to examine the glitches and count the number of frames. We also look at the edges to see if there is any ringing.

Open LiveEffect with headset or headphones attached.

Does the headset use 3.5mm, USB or Bluetooth? Do you hear the glitches if you use the mic and speakers?

While it reproduces with either Open SL ES or AAudio,

If it happens with OpenSL ES then it is not MMAP related.

philburk commented 3 years ago

@chrismanchester - Please try testing with WiFI disabled. See #1178 It was fixed by moving from Android 10 to 11. But that was on a different device.

chrismanchester commented 3 years ago

Thanks for posting the recording. It sounds like there are periods where the sound is good for several seconds. Then occasional short glitches. We can rule out channel mismatch. In other words it is not a mono stream being treated as stereo.

Also, because the glitches are in the recording, we know it is an input glitch and not an output glitch.

Unfortunately the recording is compressed, not downloadable, and not a WAV file. So I cannot analyze it in detail. We normally use Audacity to examine the glitches and count the number of frames. We also look at the edges to see if there is any ringing.

Sorry about that. I set the recording to downloadable and even verified it was sample-identical to my upload, but this doesn't seem to be available when logged out. I can share the original over email, however I don't see evidence of input underruns in the recorded output, which I documented by logging in LiveEffect, so this may not have the same underlying cause.

Open LiveEffect with headset or headphones attached.

Does the headset use 3.5mm, USB or Bluetooth? Do you hear the glitches if you use the mic and speakers?

Glitches are present with the mic and speakers.

While it reproduces with either Open SL ES or AAudio,

If it happens with OpenSL ES then it is not MMAP related.

chrismanchester commented 3 years ago

@chrismanchester - Please try testing with WiFI disabled. See #1178 It was fixed by moving from Android 10 to 11. But that was on a different device.

The issue reproduces with WiFi disabled. I have attached a perfetto trace from the phone while the glitching is occurring in case that is informative: a71_trace.txt

chrismanchester commented 3 years ago

Hi @philburk, is there anything to be learned from the trace file I posted? Are there any more tests for this device I can provide information with? Thank you!