From 6d9fac2370d0b144757075cb2b75129ac490ca5b Mon Sep 17 00:00:00 2001 From: Robert Wu <85952307+robertwu1@users.noreply.github.com> Date: Thu, 23 May 2024 15:59:16 -0700 Subject: [PATCH] set SampleRateConversionQuality as Medium by default --- docs/FullGuide.md | 4 ---- include/oboe/AudioStreamBase.h | 2 +- tests/testStreamOpen.cpp | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/FullGuide.md b/docs/FullGuide.md index c53a35447..405e48f20 100644 --- a/docs/FullGuide.md +++ b/docs/FullGuide.md @@ -491,10 +491,6 @@ builder.setDataCallback(myCallback); builder.setPerformanceMode(PerformanceMode::LowLatency); ``` -### Setting the Sample Rate Conversion Quality - -If your streams use different sample rates to the hardware device sample rates then you may experience additional latency in your streams. This is due to the fact the audio buffer must be resampled to/from the the hardware format to your desired software format. This latency can be particularly large if the Sample Rate Conversion Quality is left to the default setting of `oboe::SampleRateConversionQuality::None` as system level APIs (or the hardware itself) will handle the resampling which is MUCH slower and will not be reported as part of the `calculateLatencyMillis()` value. To rectify this (particularly important for the input stream), you should set the following when constructing your stream - `setSampleRateConversionQuality(oboe::SampleRateConversionQuality::Fastest)`. - ## Thread safety The Oboe API is not completely [thread safe](https://en.wikipedia.org/wiki/Thread_safety). diff --git a/include/oboe/AudioStreamBase.h b/include/oboe/AudioStreamBase.h index 6222e4480..c2cf88f34 100644 --- a/include/oboe/AudioStreamBase.h +++ b/include/oboe/AudioStreamBase.h @@ -307,7 +307,7 @@ class AudioStreamBase { // Control whether Oboe can convert data formats to achieve optimal results. bool mFormatConversionAllowed = false; // Control whether and how Oboe can convert sample rates to achieve optimal results. - SampleRateConversionQuality mSampleRateConversionQuality = SampleRateConversionQuality::None; + SampleRateConversionQuality mSampleRateConversionQuality = SampleRateConversionQuality::Medium; /** Validate stream parameters that might not be checked in lower layers */ virtual Result isValidConfig() { diff --git a/tests/testStreamOpen.cpp b/tests/testStreamOpen.cpp index 6a7d8ec98..4fb1287a5 100644 --- a/tests/testStreamOpen.cpp +++ b/tests/testStreamOpen.cpp @@ -145,6 +145,7 @@ TEST_F(StreamOpenOutput, ForOpenSLESDefaultChannelCountIsUsed){ TEST_F(StreamOpenOutput, OutputForOpenSLESPerformanceModeShouldBeNone){ // We will not get a LowLatency stream if we request 16000 Hz. mBuilder.setSampleRate(16000); + mBuilder.setSampleRateConversionQuality(SampleRateConversionQuality::None); mBuilder.setPerformanceMode(PerformanceMode::LowLatency); mBuilder.setDirection(Direction::Output); mBuilder.setAudioApi(AudioApi::OpenSLES); @@ -156,6 +157,7 @@ TEST_F(StreamOpenOutput, OutputForOpenSLESPerformanceModeShouldBeNone){ TEST_F(StreamOpenInput, InputForOpenSLESPerformanceModeShouldBeNone){ // We will not get a LowLatency stream if we request 16000 Hz. mBuilder.setSampleRate(16000); + mBuilder.setSampleRateConversionQuality(SampleRateConversionQuality::None); mBuilder.setPerformanceMode(PerformanceMode::LowLatency); mBuilder.setDirection(Direction::Input); mBuilder.setAudioApi(AudioApi::OpenSLES);