stay synched through partial blocks
This commit is contained in:
@@ -356,15 +356,30 @@ int RageSoundReader_Chain::Read( char *pBuffer, int iFrames )
|
|||||||
{
|
{
|
||||||
RageSoundReader *pSound = m_apActiveSounds[i]->pSound;
|
RageSoundReader *pSound = m_apActiveSounds[i]->pSound;
|
||||||
ASSERT( pSound->GetNumChannels() == m_iChannels ); // guaranteed by ActivateSound and Finish
|
ASSERT( pSound->GetNumChannels() == m_iChannels ); // guaranteed by ActivateSound and Finish
|
||||||
int iFramesRead = pSound->Read( (char *) Buffer, iFrames );
|
|
||||||
if( iFramesRead < 0 )
|
/* If we receive less than we were asked for, keep asking for more data. Most
|
||||||
|
* filters would simply return what they have in this situation, but we want
|
||||||
|
* to deal transparently with separate sounds returning differently-sized partial
|
||||||
|
* blocks. */
|
||||||
|
int iFramesRead = 0;
|
||||||
|
while( iFramesRead < iFrames )
|
||||||
{
|
{
|
||||||
ReleaseSound( m_apActiveSounds[i] );
|
int iGotFrames = pSound->Read( (char *) Buffer, iFrames - iFramesRead );
|
||||||
continue;
|
if( iGotFrames < 0 )
|
||||||
|
{
|
||||||
|
iFramesRead = iGotFrames;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
mix.SetWriteOffset( iFramesRead * pSound->GetNumChannels() );
|
||||||
|
mix.write( Buffer, iFramesRead * pSound->GetNumChannels() );
|
||||||
|
iFramesRead += iGotFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
mix.write( Buffer, iFramesRead * pSound->GetNumChannels() );
|
if( iFramesRead < 0 )
|
||||||
++i;
|
ReleaseSound( m_apActiveSounds[i] );
|
||||||
|
else
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read mixed frames into the output buffer. */
|
/* Read mixed frames into the output buffer. */
|
||||||
|
|||||||
Reference in New Issue
Block a user