From 322ec7b231219715c2db2577fef7b0ecac191520 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Mon, 12 Aug 2024 01:29:32 -0700 Subject: [PATCH] Removing bApproximate (part 1) bApproximate is left over from long ago when the method to retrieve the system time might be 32-bit only or need correction. This is no longer needed, and already commented out of several sections of the sm5.1 base code. It can't be removed all at once just by deleting every instance of bApproximate, because it often refers to pointers that go elsewhere. so, this is the first part of a multi-stage removal process. Other changes: remove samplerate() macro from RageSound, change some implicit casts to explicit. --- src/RageSound.cpp | 48 ++++++++++++++++------------------------- src/RageSoundPosMap.cpp | 7 ------ 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/RageSound.cpp b/src/RageSound.cpp index 072dca0d7a..c7c602357f 100644 --- a/src/RageSound.cpp +++ b/src/RageSound.cpp @@ -39,8 +39,6 @@ #include #include -#define samplerate() m_pSource->GetSampleRate() - RageSoundParams::RageSoundParams(): m_StartSecond(0), m_LengthSeconds(-1), m_fFadeInSeconds(0), m_fFadeOutSeconds(0), m_Volume(1.0f), m_fAttractVolume(1.0f), @@ -331,7 +329,7 @@ void RageSound::StartPlaying() ASSERT( !m_bPlaying ); // Move to the start position. - SetPositionFrames( static_cast((m_Param.m_StartSecond * samplerate())) + 0.5 ); + SetPositionFrames(static_cast(m_Param.m_StartSecond * m_pSource->GetSampleRate() + 0.5)); /* If m_StartTime is in the past, then we probably set a start time but took too * long loading. We don't want that; log it, since it can be unobvious. */ @@ -385,10 +383,10 @@ void RageSound::SoundIsFinishedPlaying() return; } - /* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver - * calls with our mutex locked (driver mutex < sound mutex). */ - if( !m_HardwareToStreamMap.IsEmpty() && !m_StreamToSourceMap.IsEmpty() ) - m_iStoppedSourceFrame = (int) GetSourceFrameFromHardwareFrame( iCurrentHardwareFrame ); + // Update the stopped source frame using the current hardware frame, + // but only if the hardware-to-stream and stream-to-source maps are not empty + if (!m_HardwareToStreamMap.IsEmpty() && !m_StreamToSourceMap.IsEmpty()) + m_iStoppedSourceFrame = static_cast(GetSourceFrameFromHardwareFrame(iCurrentHardwareFrame)); // LOG->Trace("set playing false for %p (SoundIsFinishedPlaying) (%s)", this, this->GetLoadedFilePath().c_str()); m_bPlaying = false; @@ -480,14 +478,11 @@ int RageSound::GetSourceFrameFromHardwareFrame( std::int64_t iHardwareFrame, boo if( m_HardwareToStreamMap.IsEmpty() || m_StreamToSourceMap.IsEmpty() ) return 0; - bool bApprox; - std::int64_t iStreamFrame = m_HardwareToStreamMap.Search( iHardwareFrame, &bApprox ); - if( bApproximate && bApprox ) - *bApproximate = true; - std::int64_t iSourceFrame = m_StreamToSourceMap.Search( iStreamFrame, &bApprox ); - if( bApproximate && bApprox ) - *bApproximate = true; - return (int) iSourceFrame; + // TODO(sukibaby): The nullptrs passed to the functions below are part of a gradual + // procedure to remove bApproximate from the code base. Until it's fully removed, + // this will remain nullptr for now. In the future, these nullptr's should be removed. + std::int64_t iStreamFrame = m_HardwareToStreamMap.Search( iHardwareFrame, nullptr ); + return static_cast(m_StreamToSourceMap.Search( iStreamFrame, nullptr )); } /* If non-nullptr, approximate is set to true if the returned time is approximated because of @@ -499,33 +494,28 @@ int RageSound::GetSourceFrameFromHardwareFrame( std::int64_t iHardwareFrame, boo */ float RageSound::GetPositionSeconds( bool *bApproximate, RageTimer *pTimestamp ) const { - /* Get our current hardware position. */ - std::int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition( pTimestamp ); + // Get our current hardware position. + std::int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition(pTimestamp); - /* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver - * calls with our mutex locked (driver mutex < sound mutex). */ - LockMut( m_Mutex ); + // Lock the mutex after calling SOUNDMAN->GetPosition(). + LockMut(m_Mutex); - if( bApproximate ) - *bApproximate = false; + // cast the sample rate to be used for the remainder of the function. + float fSampleRate = static_cast(m_pSource->GetSampleRate()); /* If we're not playing, just report the static position. */ - float sampleRate = static_cast(samplerate()); if( !IsPlaying() ) - return m_iStoppedSourceFrame / sampleRate; + return static_cast(m_iStoppedSourceFrame) / fSampleRate; /* If we don't yet have any position data, CommitPlayingPosition hasn't yet been called at all, * so guess what we think the real time is. */ if( m_HardwareToStreamMap.IsEmpty() || m_StreamToSourceMap.IsEmpty() ) { - // LOG->Trace( "no data yet; %i", m_iStoppedSourceFrame ); - if( bApproximate ) - *bApproximate = true; - return m_iStoppedSourceFrame / sampleRate; + return static_cast(m_iStoppedSourceFrame) / fSampleRate; } int iSourceFrame = GetSourceFrameFromHardwareFrame( iCurrentHardwareFrame, bApproximate ); - return iSourceFrame / sampleRate; + return static_cast(iSourceFrame) / fSampleRate; } diff --git a/src/RageSoundPosMap.cpp b/src/RageSoundPosMap.cpp index bc11207a77..455d8ab227 100644 --- a/src/RageSoundPosMap.cpp +++ b/src/RageSoundPosMap.cpp @@ -110,13 +110,8 @@ void pos_map_impl::Cleanup() std::int64_t pos_map_queue::Search( std::int64_t iSourceFrame, bool *bApproximate ) const { - if( bApproximate ) - *bApproximate = false; - if( IsEmpty() ) { - if( bApproximate ) - *bApproximate = true; return 0; } @@ -168,8 +163,6 @@ std::int64_t pos_map_queue::Search( std::int64_t iSourceFrame, bool *bApproximat LOG->Trace("Audio frame was out of range of the data sent - possible buffer underflow? This is not always an error, however if you see it frequently there could be sound buffer problems."); } - if( bApproximate ) - *bApproximate = true; return iClosestPosition; }