diff --git a/modules/juce_audio_devices/juce_audio_devices.h b/modules/juce_audio_devices/juce_audio_devices.h index cb641ec512..b3653eb6f6 100644 --- a/modules/juce_audio_devices/juce_audio_devices.h +++ b/modules/juce_audio_devices/juce_audio_devices.h @@ -143,6 +143,15 @@ #define JUCE_USE_ANDROID_OBOE 0 #endif +/** Config: JUCE_USE_OBOE_STABILIZED_CALLBACK + If JUCE_USE_ANDROID_OBOE is enabled, enabling this will wrap output audio + streams in the oboe::StabilizedCallback class. This class attempts to keep + the CPU spinning to avoid it being scaled down on certain devices. +*/ +#ifndef JUCE_USE_ANDROID_OBOE_STABILIZED_CALLBACK + #define JUCE_USE_ANDROID_OBOE_STABILIZED_CALLBACK 0 +#endif + /** Config: JUCE_USE_ANDROID_OPENSLES Enables OpenSLES devices (Android only). */ diff --git a/modules/juce_audio_devices/native/juce_android_Oboe.cpp b/modules/juce_audio_devices/native/juce_android_Oboe.cpp index 605ffca2b7..3b24acba33 100644 --- a/modules/juce_audio_devices/native/juce_android_Oboe.cpp +++ b/modules/juce_audio_devices/native/juce_android_Oboe.cpp @@ -513,7 +513,16 @@ private: builder.setFormat (format); builder.setSampleRate (newSampleRate); builder.setPerformanceMode (oboe::PerformanceMode::LowLatency); + + #if JUCE_USE_ANDROID_OBOE_STABILIZED_CALLBACK + if (newCallback != nullptr) + { + stabilizedCallback = std::make_unique (newCallback); + builder.setCallback (stabilizedCallback.get()); + } + #else builder.setCallback (newCallback); + #endif JUCE_OBOE_LOG (String ("Preparing Oboe stream with params:") + "\nAAudio supported = " + String (int (builder.isAAudioSupported())) @@ -564,6 +573,9 @@ private: } oboe::AudioStream* stream = nullptr; + #if JUCE_USE_ANDROID_OBOE_STABILIZED_CALLBACK + std::unique_ptr stabilizedCallback; + #endif oboe::Result openResult; };