From 7fd138aca69d98fd4584404f802930ca6c892f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C4=99k?= Date: Tue, 10 Dec 2024 13:45:56 +0100 Subject: [PATCH] fix: correct buffer lengths on real ios devices (#231) --- .../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