Skip to content

Commit

Permalink
set SampleRateConversionQuality as Medium by default (#2024)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 authored Jun 5, 2024
1 parent 854e0d4 commit 88f9c11
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 0 additions & 4 deletions docs/FullGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion include/oboe/AudioStreamBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions tests/testStreamOpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 88f9c11

Please sign in to comment.