superpoweredSDK / Low-Latency-Android-iOS-Linux-Windows-tvOS-macOS-Interactive-Audio-Platform

🇸Superpowered Audio, Networking and Cryptographics SDKs. High performance and cross platform on Android, iOS, macOS, tvOS, Linux, Windows and modern web browsers.
https://superpowered.com
1.34k stars 285 forks source link

SuperpoweredAndroidAudioIO 200ms input latency #604

Closed romanbsd closed 4 years ago

romanbsd commented 4 years ago

I'm creating an instance of SuperpoweredAndroidAudioIO:

io = new SuperpoweredAndroidAudioIO(sampleRate, bufferSize, true, true, audioProcessingCallback, this, inputStreamType, SL_ANDROID_STREAM_MEDIA);

Where inputStreamType is either SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION or SL_ANDROID_RECORDING_PRESET_UNPROCESSED, and sampleRate and bufferSize are those returned by AudioManager in Java.

In the callback I'm writing both the produced audio and received samples. When I open the audio in Sonic Visualiser, there's a 200ms delay between samples sent to speaker and received from microphone.

SuperpoweredLatency reports 44ms latency.

I tried using oboe with the same settings and the samples recorded in this scenario show ~40ms latency (just as SuperpoweredLatency predicted).

What might be the reason for such huge delay?

P.S. Only OpenSLES was evaluated, AAudio wasn't used.

gaborszanto commented 4 years ago

Please replace SuperpoweredAndroidAudioIO.cpp with the attached experimental build and let me know the results. SuperpoweredAndroidAudioIO.cpp.zip

gaborszanto commented 4 years ago

Is anybody there?

romanbsd commented 4 years ago

I'll try it tomorrow

On Tue, Nov 26, 2019, 18:32 Gabor Szanto notifications@github.com wrote:

Is anybody there?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/superpoweredSDK/Low-Latency-Android-iOS-Linux-Windows-tvOS-macOS-Interactive-Audio-Platform/issues/604?email_source=notifications&email_token=AAAMD7H6MTWNOTEJ2WTFBE3QVVFSFA5CNFSM4JPULUO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFGUCAI#issuecomment-558711041, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMD7HLT6HPOICFHIGM7W3QVVFSFANCNFSM4JPULUOQ .

gaborszanto commented 4 years ago

Tomorrow?

romanbsd commented 4 years ago

Sorry, I got busy with other things. Yes, tomorrow I'll get to it.

romanbsd commented 4 years ago

Tested. Same thing. Also, the new version uses AAudio, so might be not exactly apples to apples. I suspect that you have some internal buffers that add to latency.

gaborszanto commented 4 years ago

No, there are no internal buffering at all. You can check the source, it's open.

What are the input and output stream type settings? AAudio is used only if:

romanbsd commented 4 years ago

But I assume that there has to be some buffer since the callbacks arrive in different times? I'll try it later on a blank slate project.

gaborszanto commented 4 years ago

All buffers are coming from the operating system. There is no additional buffering.

gaborszanto commented 4 years ago

Are you still working on this?

romanbsd commented 4 years ago

No, sorry. Too busy with other stuff :(

gaborszanto commented 4 years ago

No worries, i will close this now and when you have time you can comment.