From d428b7d8d27fba4d4ae4e9b03a7beea055dab952 Mon Sep 17 00:00:00 2001 From: Michal Sek Date: Tue, 10 Dec 2024 12:47:46 +0100 Subject: [PATCH] fix: correct buffer lengths on real ios devices --- .../common/cpp/core/AudioDestinationNode.cpp | 1 + .../common/cpp/core/BaseAudioContext.cpp | 2 +- packages/react-native-audio-api/ios/AudioPlayer/AudioPlayer.m | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-native-audio-api/common/cpp/core/AudioDestinationNode.cpp b/packages/react-native-audio-api/common/cpp/core/AudioDestinationNode.cpp index 80fd3b52..0ef82dd2 100644 --- a/packages/react-native-audio-api/common/cpp/core/AudioDestinationNode.cpp +++ b/packages/react-native-audio-api/common/cpp/core/AudioDestinationNode.cpp @@ -31,6 +31,7 @@ void AudioDestinationNode::renderAudio( } context_->getNodeManager()->preProcessGraph(); + destinationBus->zero(); AudioBus *processedBus = processAudio(destinationBus, numFrames); diff --git a/packages/react-native-audio-api/common/cpp/core/BaseAudioContext.cpp b/packages/react-native-audio-api/common/cpp/core/BaseAudioContext.cpp index a50c92b5..a9a644e2 100644 --- a/packages/react-native-audio-api/common/cpp/core/BaseAudioContext.cpp +++ b/packages/react-native-audio-api/common/cpp/core/BaseAudioContext.cpp @@ -120,7 +120,7 @@ std::shared_ptr BaseAudioContext::decodeAudioDataSource( #endif std::function BaseAudioContext::renderAudio() { - if (isClosed()) { + if (!isRunning()) { return [](AudioBus *, int) {}; } diff --git a/packages/react-native-audio-api/ios/AudioPlayer/AudioPlayer.m b/packages/react-native-audio-api/ios/AudioPlayer/AudioPlayer.m index 3f245c85..ba9ff43b 100644 --- a/packages/react-native-audio-api/ios/AudioPlayer/AudioPlayer.m +++ b/packages/react-native-audio-api/ios/AudioPlayer/AudioPlayer.m @@ -62,7 +62,8 @@ - (int)getBufferSizeInFrames // which is safer to base our internal AudioBus sizes. // Buut no documentation => no guarantee :) // If something is crackling when it should play silence, start here 📻 - return (int)(self.audioSession.preferredIOBufferDuration * self.audioSession.sampleRate); + double maxBufferDuration = fmax(0.02, fmax(self.audioSession.IOBufferDuration, self.audioSession.preferredIOBufferDuration)); + return (int)(maxBufferDuration * self.audioSession.sampleRate + 1); } - (void)start