This commit is contained in:
Glenn Maynard
2006-12-09 03:40:55 +00:00
parent 3583b1cf10
commit 0e72d6d08c
2 changed files with 27 additions and 27 deletions
+23 -23
View File
@@ -65,11 +65,11 @@ bool RageSoundReader_Chain::AddSound( RString sPath, float fOffsetSecs, float fP
m_apLoadedSounds[sPath] = pReader; m_apLoadedSounds[sPath] = pReader;
} }
sound s; Sound s;
s.sPath = sPath; s.sPath = sPath;
s.iOffsetMS = lrintf( fOffsetSecs * 1000 ); s.iOffsetMS = lrintf( fOffsetSecs * 1000 );
s.fPan = fPan; s.fPan = fPan;
m_Sounds.push_back( s ); m_aSounds.push_back( s );
return true; return true;
} }
@@ -95,14 +95,14 @@ int RageSoundReader_Chain::GetSampleRateInternal() const
void RageSoundReader_Chain::Finish() void RageSoundReader_Chain::Finish()
{ {
/* Remove any sounds that don't have corresponding SoundReaders. */ /* Remove any sounds that don't have corresponding SoundReaders. */
for( unsigned i = 0; i < m_Sounds.size(); ) for( unsigned i = 0; i < m_aSounds.size(); )
{ {
sound &sound = m_Sounds[i]; Sound &sound = m_aSounds[i];
map<RString, RageSoundReader *>::iterator it = m_apLoadedSounds.find( sound.sPath ); map<RString, RageSoundReader *>::iterator it = m_apLoadedSounds.find( sound.sPath );
if( it == m_apLoadedSounds.end() ) if( it == m_apLoadedSounds.end() )
{ {
m_Sounds.erase( m_Sounds.begin()+i ); m_aSounds.erase( m_aSounds.begin()+i );
continue; continue;
} }
@@ -116,8 +116,8 @@ void RageSoundReader_Chain::Finish()
m_iChannels = max( m_iChannels, it->second->GetNumChannels() ); m_iChannels = max( m_iChannels, it->second->GetNumChannels() );
/* If any sounds have a non-0 pan, we're stereo. */ /* If any sounds have a non-0 pan, we're stereo. */
for( unsigned i = 0; i < m_Sounds.size(); ++i ) for( unsigned i = 0; i < m_aSounds.size(); ++i )
if( fabs(m_Sounds[i].fPan) > 0.0001f ) if( fabs(m_aSounds[i].fPan) > 0.0001f )
m_iChannels = 2; m_iChannels = 2;
/* /*
@@ -148,7 +148,7 @@ void RageSoundReader_Chain::Finish()
} }
/* Sort the sounds by start time. */ /* Sort the sounds by start time. */
sort( m_Sounds.begin(), m_Sounds.end() ); sort( m_aSounds.begin(), m_aSounds.end() );
} }
int RageSoundReader_Chain::SetPosition_Accurate( int ms ) int RageSoundReader_Chain::SetPosition_Accurate( int ms )
@@ -161,9 +161,9 @@ int RageSoundReader_Chain::SetPosition_Accurate( int ms )
/* Run through all sounds in the chain, and activate all sounds which have data /* Run through all sounds in the chain, and activate all sounds which have data
* at ms. */ * at ms. */
for( unsigned i = 0; i < m_Sounds.size(); ++i ) for( unsigned i = 0; i < m_aSounds.size(); ++i )
{ {
sound &sound = m_Sounds[i]; Sound &sound = m_aSounds[i];
/* If this sound is in the future, skip it. */ /* If this sound is in the future, skip it. */
if( sound.iOffsetMS > ms ) if( sound.iOffsetMS > ms )
@@ -186,13 +186,13 @@ int RageSoundReader_Chain::SetPosition_Accurate( int ms )
/* If no sounds were started, and we have no sounds ahead of us, we've seeked /* If no sounds were started, and we have no sounds ahead of us, we've seeked
* past EOF. */ * past EOF. */
if( m_apActiveSounds.empty() && m_iNextSound == m_Sounds.size() ) if( m_apActiveSounds.empty() && m_iNextSound == m_aSounds.size() )
return 0; return 0;
return ms; return ms;
} }
unsigned RageSoundReader_Chain::ActivateSound( const sound &s ) unsigned RageSoundReader_Chain::ActivateSound( const Sound &s )
{ {
RageSoundReader *pSound = m_apLoadedSounds[s.sPath]; RageSoundReader *pSound = m_apLoadedSounds[s.sPath];
@@ -264,11 +264,11 @@ float RageSoundReader_Chain::GetStreamToSourceRatio() const
return iRate; return iRate;
} }
/* Find the next sound we'll need to start, if any. m_Sounds is sorted by time. */ /* Find the next sound we'll need to start, if any. m_aSounds is sorted by time. */
unsigned RageSoundReader_Chain::GetNextSoundIndex() const unsigned RageSoundReader_Chain::GetNextSoundIndex() const
{ {
unsigned iNextSound = 0; unsigned iNextSound = 0;
while( iNextSound < m_Sounds.size() && m_iCurrentFrame > m_Sounds[iNextSound].GetOffsetFrame(m_iActualSampleRate) ) while( iNextSound < m_aSounds.size() && m_iCurrentFrame > m_aSounds[iNextSound].GetOffsetFrame(m_iActualSampleRate) )
++iNextSound; ++iNextSound;
return iNextSound; return iNextSound;
} }
@@ -277,10 +277,10 @@ int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames )
{ {
/* How many samples should we read before we need to start up a sound? */ /* How many samples should we read before we need to start up a sound? */
int iFramesToRead = INT_MAX; int iFramesToRead = INT_MAX;
if( m_iNextSound < m_Sounds.size() ) if( m_iNextSound < m_aSounds.size() )
{ {
int iStartFrame = m_iCurrentFrame; int iStartFrame = m_iCurrentFrame;
int iOffsetFrame = m_Sounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate); int iOffsetFrame = m_aSounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate);
ASSERT_M( iOffsetFrame >= iStartFrame, ssprintf("%i %i", iOffsetFrame, iStartFrame) ); ASSERT_M( iOffsetFrame >= iStartFrame, ssprintf("%i %i", iOffsetFrame, iStartFrame) );
iFramesToRead = iOffsetFrame - iStartFrame; iFramesToRead = iOffsetFrame - iStartFrame;
} }
@@ -362,7 +362,7 @@ int RageSoundReader_Chain::Read( char *pBuffer, unsigned iLength )
int iTotalFramesRead = 0; int iTotalFramesRead = 0;
/* If we have no sources, and no more sounds to play, EOF. */ /* If we have no sources, and no more sounds to play, EOF. */
while( iNumFramesToRead > 0 && (!m_apActiveSounds.empty() || m_iNextSound < m_Sounds.size()) ) while( iNumFramesToRead > 0 && (!m_apActiveSounds.empty() || m_iNextSound < m_aSounds.size()) )
{ {
int iFramesRead = ReadBlock( (int16_t *) pBuffer, iNumFramesToRead ); int iFramesRead = ReadBlock( (int16_t *) pBuffer, iNumFramesToRead );
if( iFramesRead == -1 ) if( iFramesRead == -1 )
@@ -373,9 +373,9 @@ int RageSoundReader_Chain::Read( char *pBuffer, unsigned iLength )
iTotalFramesRead += iFramesRead; iTotalFramesRead += iFramesRead;
pBuffer += iFramesRead * sizeof(int16_t) * m_iChannels; pBuffer += iFramesRead * sizeof(int16_t) * m_iChannels;
while( m_iNextSound < m_Sounds.size() && m_iCurrentFrame == m_Sounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate) ) while( m_iNextSound < m_aSounds.size() && m_iCurrentFrame == m_aSounds[m_iNextSound].GetOffsetFrame(m_iActualSampleRate) )
{ {
sound &sound = m_Sounds[m_iNextSound]; Sound &sound = m_aSounds[m_iNextSound];
ActivateSound( sound ); ActivateSound( sound );
++m_iNextSound; ++m_iNextSound;
} }
@@ -387,9 +387,9 @@ int RageSoundReader_Chain::Read( char *pBuffer, unsigned iLength )
int RageSoundReader_Chain::GetLength() const int RageSoundReader_Chain::GetLength() const
{ {
int iLength = 0; int iLength = 0;
for( unsigned i = 0; i < m_Sounds.size(); ++i ) for( unsigned i = 0; i < m_aSounds.size(); ++i )
{ {
const sound &sound = m_Sounds[i]; const Sound &sound = m_aSounds[i];
const RageSoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second; const RageSoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second;
int iThisLength = pSound->GetLength(); int iThisLength = pSound->GetLength();
if( iThisLength ) if( iThisLength )
@@ -401,9 +401,9 @@ int RageSoundReader_Chain::GetLength() const
int RageSoundReader_Chain::GetLength_Fast() const int RageSoundReader_Chain::GetLength_Fast() const
{ {
int iLength = 0; int iLength = 0;
for( unsigned i = 0; i < m_Sounds.size(); ++i ) for( unsigned i = 0; i < m_aSounds.size(); ++i )
{ {
const sound &sound = m_Sounds[i]; const Sound &sound = m_aSounds[i];
const RageSoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second; const RageSoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second;
int iThisLength = pSound->GetLength_Fast(); int iThisLength = pSound->GetLength_Fast();
if( iThisLength ) if( iThisLength )
+4 -4
View File
@@ -50,15 +50,15 @@ private:
map<RString, RageSoundReader *> m_apLoadedSounds; map<RString, RageSoundReader *> m_apLoadedSounds;
struct sound struct Sound
{ {
RString sPath; RString sPath;
int iOffsetMS; int iOffsetMS;
float fPan; float fPan;
int GetOffsetFrame( int iSampleRate ) const { return int( int64_t(iOffsetMS) * iSampleRate / 1000 ); } int GetOffsetFrame( int iSampleRate ) const { return int( int64_t(iOffsetMS) * iSampleRate / 1000 ); }
bool operator<( const sound &rhs ) const { return iOffsetMS < rhs.iOffsetMS; } bool operator<( const Sound &rhs ) const { return iOffsetMS < rhs.iOffsetMS; }
}; };
vector<sound> m_Sounds; vector<Sound> m_aSounds;
unsigned GetNextSoundIndex() const; unsigned GetNextSoundIndex() const;
/* Read state: */ /* Read state: */
@@ -71,7 +71,7 @@ private:
bool operator< ( const ActiveSound &rhs ) const { return pSound < rhs.pSound; } bool operator< ( const ActiveSound &rhs ) const { return pSound < rhs.pSound; }
}; };
vector<ActiveSound> m_apActiveSounds; vector<ActiveSound> m_apActiveSounds;
unsigned ActivateSound( const sound &s ); unsigned ActivateSound( const Sound &s );
void ReleaseSound( unsigned n ); void ReleaseSound( unsigned n );
}; };