int RageSoundReader_Chain::SetPosition_Accurate( int ms ) { /* Clear m_apActiveSounds. */ while( !m_apActiveSounds.empty() ) ReleaseSound( 0 ); m_iCurrentFrame = int( int64_t(ms) * m_iActualSampleRate / 1000 ); /* Run through all sounds in the chain, and activate all sounds which have data * at ms. */ for( unsigned i = 0; i < m_Sounds.size(); ++i ) { sound &sound = m_Sounds[i]; /* If this sound is in the future, skip it. */ if( sound.iOffsetMS > ms ) continue; /* Find the SoundReader. */ int n = ActivateSound( sound ); SoundReader *pSound = m_apActiveSounds[n].pSound; int iOffsetMS = ms - sound.iOffsetMS; if( pSound->SetPosition_Accurate(iOffsetMS) == 0 ) { /* We're past the end of this sound. */ ReleaseSound( n ); continue; } } m_iNextSound = GetNextSoundIndex(); /* If no sounds were started, and we have no sounds ahead of us, we've seeked * past EOF. */ if( m_apActiveSounds.empty() && m_iNextSound == m_Sounds.size() ) return 0; return ms; }