From a0d1198cc145fa2ad5f66ac8f4429b6ea3a4ea48 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Sun, 4 Aug 2024 19:59:17 -0700 Subject: [PATCH] MixIntoBuffer optimization Reduced risk of error as well, improved readability as well as improved performance due to removing a repeated calculation. --- src/arch/Sound/RageSoundDriver_Generic_Software.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/arch/Sound/RageSoundDriver_Generic_Software.cpp b/src/arch/Sound/RageSoundDriver_Generic_Software.cpp index ac95775739..a977952aa7 100644 --- a/src/arch/Sound/RageSoundDriver_Generic_Software.cpp +++ b/src/arch/Sound/RageSoundDriver_Generic_Software.cpp @@ -48,16 +48,17 @@ int RageSoundDriver::DecodeThread_start( void *p ) return 0; } -static int g_iTotalAhead = 0; +static std::int64_t g_iTotalAhead = 0; static int g_iTotalAheadCount = 0; RageSoundMixBuffer &RageSoundDriver::MixIntoBuffer( int iFrames, std::int64_t iFrameNumber, std::int64_t iCurrentFrame ) { ASSERT_M( m_DecodeThread.IsCreated(), "RageSoundDriver::StartDecodeThread() was never called" ); - if( iFrameNumber - iCurrentFrame + iFrames > 0 ) + std::int64_t frameDifference = iFrameNumber - iCurrentFrame + static_cast(iFrames); + if (frameDifference > 0) { - g_iTotalAhead += (int) (iFrameNumber - iCurrentFrame + iFrames); + g_iTotalAhead += frameDifference; ++g_iTotalAheadCount; }