Much faster RageSoundReader_MP3::FindOffsetFix

This commit is contained in:
Glenn Maynard
2003-10-03 22:55:41 +00:00
parent ee9c02ea4e
commit 802d8c7aff
+22 -23
View File
@@ -439,8 +439,6 @@ int RageSoundReader_MP3::do_mad_frame_decode()
* so we can emulate that sync offset. */ * so we can emulate that sync offset. */
int RageSoundReader_MP3::FindOffsetFix() int RageSoundReader_MP3::FindOffsetFix()
{ {
int i;
/* Do a fake rewind. */ /* Do a fake rewind. */
if( fseek(this->rw, 0, SEEK_SET) == -1 ) if( fseek(this->rw, 0, SEEK_SET) == -1 )
{ {
@@ -461,8 +459,8 @@ int RageSoundReader_MP3::FindOffsetFix()
mad->first_frame = true; mad->first_frame = true;
/* Read a couple frames, to make sure we're synced. */ /* Read a couple frames, to make sure we're synced. */
bool Silent = true; int FramesToRead = 5;
for( i = 0; Silent || i < 5; ++i ) while( FramesToRead-- )
{ {
int ret = do_mad_frame_decode(); int ret = do_mad_frame_decode();
if( ret == 0 ) if( ret == 0 )
@@ -473,24 +471,28 @@ int RageSoundReader_MP3::FindOffsetFix()
if( ret == -1 ) if( ret == -1 )
return false; /* it set the error */ return false; /* it set the error */
synth_output();
/* If this frame is silent, it's not an appropriate sample. Find /* If this frame is silent, it's not an appropriate sample. Find
* a frame with actual sound in it. */ * a frame with actual sound in it. */
Silent = true; if( !FramesToRead )
for( unsigned j = 0; Silent && j < mad->outleft; ++j ) {
if( mad->outbuf[j] ) /* We've read enough frames. Now, make sure this frame isn't silent. */
Silent=false; bool Silent = true;
} for( int j = 0; j < 2; ++j )
for( int k = 0; k < 36; ++k )
for( int l = 0; l < 32; ++l )
if( mad->Frame.sbsample[j][k][l] )
Silent=false;
/* If it's silent, it's not an appropriate sample. Find a frame
* with actual sound in it. */
if( Silent )
++FramesToRead;
}
if( Silent )
{
/* The sound didn't have any non-silent frames. */
MADLIB_rewind();
return true;
} }
/* Clear the TOC cache. We might have cached bogus values. */ /* Clear the TOC cache. We might have cached bogus values. */
int i;
for( i = 0; i < 200; ++i) for( i = 0; i < 200; ++i)
mad->toc[i] = -1; mad->toc[i] = -1;
@@ -498,10 +500,9 @@ int RageSoundReader_MP3::FindOffsetFix()
* we decoded the last frame. */ * we decoded the last frame. */
mad_timer_t Apparent = mad->Timer; mad_timer_t Apparent = mad->Timer;
/* Save the last frame's PCM data. */ /* Save the last frame's subband samples. */
unsigned size = mad->outleft; mad_fixed_t cpy[2][36][32];
char *cpy = new char[size]; memcpy( cpy, mad->Frame.sbsample, sizeof(mad->Frame.sbsample) );
memcpy( cpy, mad->outbuf, size );
/* Do a real rewind. */ /* Do a real rewind. */
MADLIB_rewind(); MADLIB_rewind();
@@ -520,8 +521,7 @@ int RageSoundReader_MP3::FindOffsetFix()
if( ret == -1 ) if( ret == -1 )
return false; /* it set the error */ return false; /* it set the error */
synth_output(); if( !memcmp( cpy, mad->Frame.sbsample, sizeof(mad->Frame.sbsample) ) )
if( mad->outleft == size && !memcmp( cpy, mad->outbuf, mad->outleft ) )
{ {
/* Found it. Record that frame's real timestamp. */ /* Found it. Record that frame's real timestamp. */
Actual = mad->Timer; Actual = mad->Timer;
@@ -540,7 +540,6 @@ int RageSoundReader_MP3::FindOffsetFix()
else else
this->OffsetFix = 0; this->OffsetFix = 0;
delete [] cpy;
MADLIB_rewind(); MADLIB_rewind();
return true; return true;
} }