diff --git a/modules/juce_audio_devices/native/juce_android_Oboe.cpp b/modules/juce_audio_devices/native/juce_android_Oboe.cpp index 41bac4a1ac..35000cb29d 100644 --- a/modules/juce_audio_devices/native/juce_android_Oboe.cpp +++ b/modules/juce_audio_devices/native/juce_android_Oboe.cpp @@ -42,7 +42,7 @@ struct OboeAudioIODeviceBufferHelpers static constexpr int bitDepth() { return 16; } - static void referAudioBufferDirectlyToOboeIfPossible (int16*, AudioBuffer&, int) {} + static bool referAudioBufferDirectlyToOboeIfPossible (int16*, AudioBuffer&, int) { return false; } static void convertFromOboe (const int16* srcInterleaved, AudioBuffer& audioBuffer, int numSamples) { @@ -78,20 +78,21 @@ struct OboeAudioIODeviceBufferHelpers static constexpr int bitDepth() { return 32; } - static void referAudioBufferDirectlyToOboeIfPossible (float* nativeBuffer, AudioBuffer& audioBuffer, int numSamples) + static bool referAudioBufferDirectlyToOboeIfPossible (float* nativeBuffer, AudioBuffer& audioBuffer, int numSamples) { if (audioBuffer.getNumChannels() == 1) + { audioBuffer.setDataToReferTo (&nativeBuffer, 1, numSamples); + return true; + } + + return false; } static void convertFromOboe (const float* srcInterleaved, AudioBuffer& audioBuffer, int numSamples) { // No need to convert, we instructed the buffer to point to the src data directly already - if (audioBuffer.getNumChannels() == 1) - { - jassert (audioBuffer.getWritePointer (0) == srcInterleaved); - return; - } + jassert (audioBuffer.getWritePointer (0) != srcInterleaved); for (int i = 0; i < audioBuffer.getNumChannels(); ++i) { @@ -107,11 +108,7 @@ struct OboeAudioIODeviceBufferHelpers static void convertToOboe (const AudioBuffer& audioBuffer, float* dstInterleaved, int numSamples) { // No need to convert, we instructed the buffer to point to the src data directly already - if (audioBuffer.getNumChannels() == 1) - { - jassert (audioBuffer.getReadPointer (0) == dstInterleaved); - return; - } + jassert (audioBuffer.getReadPointer (0) != dstInterleaved); for (int i = 0; i < audioBuffer.getNumChannels(); ++i) { @@ -769,7 +766,6 @@ private: // only output stream should be the master stream receiving callbacks jassert (stream->getDirection() == oboe::Direction::Output && stream == outputStream->getNativeStream()); - //----------------- // Read input from Oboe inputStreamSampleBuffer.clear(); inputStreamNativeBuffer.calloc (static_cast (numInputChannels * bufferSize)); @@ -789,11 +785,13 @@ private: if (result) { - OboeAudioIODeviceBufferHelpers::referAudioBufferDirectlyToOboeIfPossible (inputStreamNativeBuffer.get(), - inputStreamSampleBuffer, - result.value()); + auto referringDirectlyToOboeData = OboeAudioIODeviceBufferHelpers + ::referAudioBufferDirectlyToOboeIfPossible (inputStreamNativeBuffer.get(), + inputStreamSampleBuffer, + result.value()); - OboeAudioIODeviceBufferHelpers::convertFromOboe (inputStreamNativeBuffer.get(), inputStreamSampleBuffer, result.value()); + if (! referringDirectlyToOboeData) + OboeAudioIODeviceBufferHelpers::convertFromOboe (inputStreamNativeBuffer.get(), inputStreamSampleBuffer, result.value()); } else { @@ -804,24 +802,24 @@ private: inputLatency = getLatencyFor (*inputStream); } - //----------------- // Setup output buffer - outputStreamSampleBuffer.clear(); + auto referringDirectlyToOboeData = OboeAudioIODeviceBufferHelpers + ::referAudioBufferDirectlyToOboeIfPossible (static_cast (audioData), + outputStreamSampleBuffer, + numFrames); - OboeAudioIODeviceBufferHelpers::referAudioBufferDirectlyToOboeIfPossible (static_cast (audioData), - outputStreamSampleBuffer, - numFrames); + if (! referringDirectlyToOboeData) + outputStreamSampleBuffer.clear(); - //----------------- // Process // NB: the number of samples read from the input can potentially differ from numFrames. owner.process (inputStreamSampleBuffer.getArrayOfReadPointers(), numInputChannels, outputStreamSampleBuffer.getArrayOfWritePointers(), numOutputChannels, numFrames); - //----------------- // Write output to Oboe - OboeAudioIODeviceBufferHelpers::convertToOboe (outputStreamSampleBuffer, static_cast (audioData), numFrames); + if (! referringDirectlyToOboeData) + OboeAudioIODeviceBufferHelpers::convertToOboe (outputStreamSampleBuffer, static_cast (audioData), numFrames); if (isOutputLatencyDetectionSupported) outputLatency = getLatencyFor (*outputStream);