From d4b513db161258a84a340612135080989fa82d54 Mon Sep 17 00:00:00 2001 From: Shaji Khan Date: Tue, 27 Feb 2024 14:33:17 +0530 Subject: [PATCH] latency tuner --- app/src/main/cpp/Engine.cpp | 20 +++++++++++--------- app/src/main/cpp/Engine.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/cpp/Engine.cpp b/app/src/main/cpp/Engine.cpp index f3ebdb0c..5cb800a1 100644 --- a/app/src/main/cpp/Engine.cpp +++ b/app/src/main/cpp/Engine.cpp @@ -144,6 +144,9 @@ oboe::Result Engine::openStreams() { OUT ; return result; } + + latencyTunerOut = new oboe::LatencyTuner ( *mPlayStream); + latencyTunerOut->tune(); warnIfNotLowLatency(mRecordingStream); mFullDuplexPass.setInputStream(mRecordingStream); @@ -511,15 +514,14 @@ std::string Engine::tuneLatency () { latencyTuner->requestReset(); oboe::Result result = latencyTuner->tune() ; - char tmp [10]; + latencyTunerOut->requestReset(); + oboe::Result resultOut = latencyTunerOut->tune() ; + char tmp [400]; // hello, old friend - sprintf (tmp, "%f", mRecordingStream->getXRunCount()); - std::string str = std::string ("Tuner: " + - std::to_string(static_cast(result)) + - ", Buffer: " + std::to_string(mRecordingStream->getBufferSizeInFrames()) - + ", Xruns: " + std::string (tmp)); - - LOGD ("%s",str.c_str()); + sprintf (tmp, "Tuner: %d/%d, Xruns: %d/%d, Buffer size in frames: %d/%d", result, resultOut, + mRecordingStream->getXRunCount(),mPlayStream->getXRunCount(), + mRecordingStream->getBufferSizeInFrames(), mPlayStream->getBufferSizeInFrames()); + LOGD ("%s",tmp); OUT - return str ; + return std::string (tmp) ; } \ No newline at end of file diff --git a/app/src/main/cpp/Engine.h b/app/src/main/cpp/Engine.h index cb24d41e..66209436 100644 --- a/app/src/main/cpp/Engine.h +++ b/app/src/main/cpp/Engine.h @@ -76,7 +76,7 @@ class Engine : public oboe::AudioStreamCallback { int32_t mRecordingDeviceId = oboe::kUnspecified; int32_t mPlaybackDeviceId = oboe::kUnspecified; oboe::AudioApi mAudioApi = oboe::AudioApi::AAudio; - oboe::LatencyTuner *latencyTuner; + oboe::LatencyTuner *latencyTuner, *latencyTunerOut; oboe::Result openStreams(); void closeStreams();