Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SampleRateConversionQuality as Medium by default #2024

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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