diff --git a/stepmania/src/RageSoundReader_Chain.cpp b/stepmania/src/RageSoundReader_Chain.cpp index aae3a46e93..35384a2859 100644 --- a/stepmania/src/RageSoundReader_Chain.cpp +++ b/stepmania/src/RageSoundReader_Chain.cpp @@ -224,6 +224,35 @@ bool RageSoundReader_Chain::IsStreamingFromDisk() const return false; } +int RageSoundReader_Chain::GetNextStreamFrame() const +{ + return m_iCurrentFrame; +/* int iPosition = m_apActiveSounds[0].pSound->GetPosition(); + for( unsigned i = 1; i < m_apActiveSounds.size(); ) + { + if( m_apActiveSounds[i].pSound->GetPosition() != iPosition ) + LOG->Warn( "RageSoundReader_Chain: sound positions moving at different rates" ); + } + + return iPosition; +*/ +} + +float RageSoundReader_Chain::GetStreamToSourceRatio() const +{ + if( m_apActiveSounds.empty() ) + return 1.0f; + + float iRate = m_apActiveSounds[0].pSound->GetStreamToSourceRatio(); + for( unsigned i = 1; i < m_apActiveSounds.size(); ) + { + if( m_apActiveSounds[i].pSound->GetStreamToSourceRatio() != iRate ) + LOG->Warn( "RageSoundReader_Chain: sound rates changing differently" ); + } + + return iRate; +} + /* Find the next sound we'll need to start, if any. m_Sounds is sorted by time. */ unsigned RageSoundReader_Chain::GetNextSoundIndex() const { diff --git a/stepmania/src/RageSoundReader_Chain.h b/stepmania/src/RageSoundReader_Chain.h index 13ee94ee72..78d42d6828 100644 --- a/stepmania/src/RageSoundReader_Chain.h +++ b/stepmania/src/RageSoundReader_Chain.h @@ -36,6 +36,8 @@ public: int GetSampleRate() const { return m_iActualSampleRate; } unsigned GetNumChannels() const { return m_iChannels; } bool IsStreamingFromDisk() const; + int GetNextStreamFrame() const; + float GetStreamToSourceRatio() const; private: int ReadBlock( int16_t *pBuffer, int iFrames ); diff --git a/stepmania/src/RageSoundReader_Preload.cpp b/stepmania/src/RageSoundReader_Preload.cpp index 7bc44117f6..2b5cfc58a0 100644 --- a/stepmania/src/RageSoundReader_Preload.cpp +++ b/stepmania/src/RageSoundReader_Preload.cpp @@ -4,7 +4,7 @@ #include "global.h" #include "RageSoundReader_Preload.h" -#define samplesize (2 * m_iChannels) /* 16-bit */ +#define samplesize (sizeof(int16_t) * m_iChannels) /* 16-bit */ /* If a sound is smaller than this, we'll load it entirely into memory. */ const unsigned max_prebuf_size = 1024*256; @@ -39,6 +39,7 @@ bool RageSoundReader_Preload::Open( SoundReader *pSource ) ASSERT( pSource ); m_iSampleRate = pSource->GetSampleRate(); m_iChannels = pSource->GetNumChannels(); + m_fRate = pSource->GetStreamToSourceRatio(); /* Check the length, and see if we think it'll fit in the buffer. */ int iLen = pSource->GetLength_Fast(); @@ -55,6 +56,10 @@ bool RageSoundReader_Preload::Open( SoundReader *pSource ) while(1) { + /* If the rate changes, we won't preload it. */ + if( pSource->GetStreamToSourceRatio() != m_fRate ) + return false; /* Don't bother trying to preload it. */ + char buffer[1024]; int iCnt = pSource->Read(buffer, sizeof(buffer)); @@ -109,6 +114,11 @@ int RageSoundReader_Preload::SetPosition_Fast( int iMS ) return SetPosition_Accurate( iMS ); } +int RageSoundReader_Preload::GetNextStreamFrame() const +{ + return m_iPosition / samplesize; +} + int RageSoundReader_Preload::Read( char *pBuffer, unsigned iLen ) { const unsigned bytes_avail = m_Buffer->size() - m_iPosition; diff --git a/stepmania/src/RageSoundReader_Preload.h b/stepmania/src/RageSoundReader_Preload.h index f09c753139..afd2a2fe3a 100644 --- a/stepmania/src/RageSoundReader_Preload.h +++ b/stepmania/src/RageSoundReader_Preload.h @@ -21,6 +21,8 @@ public: int GetSampleRate() const { return m_iSampleRate; } unsigned GetNumChannels() const { return m_iChannels; } bool IsStreamingFromDisk() const { return false; } + int GetNextStreamFrame() const; + float GetStreamToSourceRatio() const { return m_fRate; } /* Return the total number of copies of this sound. (If 1 is returned, * this is the last copy.) */ @@ -42,6 +44,7 @@ private: int m_iSampleRate; unsigned m_iChannels; + float m_fRate; }; #endif