From aa4be6dffb6f9cef4e2555c1dc4aa0390ecec7e6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 21 Dec 2006 05:07:49 +0000 Subject: [PATCH] Return 1 from SetPosition(n) on success, 0 on seek past EOF, not "the position seeked to". This fixes a special case: SetPosition(n) returning 0 was EOF except when SetPosition(0). The returned value on success was always n, anyway; we never seek to a different position and return success. --- stepmania/src/RageSound.cpp | 7 +++---- stepmania/src/RageSoundReader_Chain.cpp | 2 +- stepmania/src/RageSoundReader_MP3.cpp | 14 +++++++------- stepmania/src/RageSoundReader_Resample_Good.cpp | 4 +--- stepmania/src/RageSoundReader_Vorbisfile.cpp | 2 +- stepmania/src/RageSoundReader_WAV.cpp | 4 ++-- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 51e9e7d66a..9fe6be6f6f 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -152,7 +152,7 @@ class RageSoundReader_Silence: public RageSoundReader public: int GetLength() const { return 0; } int GetLength_Fast() const { return 0; } - int SetPosition( int iFrame ) { return 0; } + int SetPosition( int iFrame ) { return 1; } int Read( char *buf, int iFrames ) { return 0; } RageSoundReader *Copy() const { return new RageSoundReader_Silence; } int GetSampleRate() const { return 44100; } @@ -754,10 +754,9 @@ bool RageSound::SetPositionFrames( int iFrames ) m_iStoppedSourceFrame = iFrames; } - if( iRet == 0 && iFrames != 0 ) + if( iRet == 0 ) { - /* We were told to seek somewhere, and we got 0 instead, which means - * we passed EOF. This could be a truncated file or invalid data. */ + /* Seeked past EOF. */ LOG->Warn( "SetPositionFrames: %i samples is beyond EOF in %s", iFrames, GetLoadedFilePath().c_str() ); diff --git a/stepmania/src/RageSoundReader_Chain.cpp b/stepmania/src/RageSoundReader_Chain.cpp index ec5ccb52ce..1e447cabdc 100644 --- a/stepmania/src/RageSoundReader_Chain.cpp +++ b/stepmania/src/RageSoundReader_Chain.cpp @@ -206,7 +206,7 @@ int RageSoundReader_Chain::SetPosition( int iFrame ) RageSoundReader *pReader = pSound->pSound; int iOffsetFrames = iFrame - iOffsetFrame; - if( iOffsetFrames > 0 && pReader->SetPosition(iOffsetFrames) == 0 ) + if( pReader->SetPosition(iOffsetFrames) == 0 ) { /* We're past the end of this sound. */ ReleaseSound( pSound ); diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index c7ad96afb2..c45338d020 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -854,13 +854,13 @@ int RageSoundReader_MP3::SetPosition_toc( int iFrame, bool Xing ) mad_timer_set( &desired, 0, iFrame, SampleRate ); if( mad->tocmap.empty() ) - return iFrame; /* don't have any info */ + return 1; /* don't have any info */ /* Find the last entry <= iFrame that we actually have an entry for; * this will get us as close as possible. */ madlib_t::tocmap_t::iterator it = mad->tocmap.upper_bound( desired ); if( it == mad->tocmap.begin() ) - return iFrame; /* don't have any info */ + return 1; /* don't have any info */ --it; mad->Timer = it->first; @@ -882,7 +882,7 @@ int RageSoundReader_MP3::SetPosition_toc( int iFrame, bool Xing ) synth_output(); } - return iFrame; + return 1; } int RageSoundReader_MP3::SetPosition_hard( int iFrame ) @@ -894,7 +894,7 @@ int RageSoundReader_MP3::SetPosition_hard( int iFrame ) /* If we're already exactly at the requested position, OK. */ if( mad_timer_compare(mad->Timer, desired) == 0 ) - return 0; + return 1; /* We always come in here with data synthed. Be careful not to synth the * same frame twice. */ @@ -939,7 +939,7 @@ int RageSoundReader_MP3::SetPosition_hard( int iFrame ) * we're currently always using AUDIO_S16SYS. */ mad->outpos = samples * 2 * this->Channels; mad->outleft -= samples * 2 * this->Channels; - return iFrame; + return 1; } /* Otherwise, if the desired time will be in the *next* decode, then synth @@ -1003,7 +1003,7 @@ int RageSoundReader_MP3::SetPosition_estimate( int iFrame ) int ms = (get_this_frame_byte(mad) - mad->header_bytes) / (mad->bitrate / 8 / 1000); mad_timer_set(&mad->Timer, 0, ms, 1000); - return iFrame; + return 1; } int RageSoundReader_MP3::SetPosition( int iFrame ) @@ -1024,7 +1024,7 @@ int RageSoundReader_MP3::SetPosition( int iFrame ) if( !iFrame ) { MADLIB_rewind(); - return 0; /* ok */ + return 1; /* ok */ } /* We can do a fast jump in VBR with Xing with more accuracy than without Xing. */ diff --git a/stepmania/src/RageSoundReader_Resample_Good.cpp b/stepmania/src/RageSoundReader_Resample_Good.cpp index 7d0871592e..320db812f7 100644 --- a/stepmania/src/RageSoundReader_Resample_Good.cpp +++ b/stepmania/src/RageSoundReader_Resample_Good.cpp @@ -679,9 +679,7 @@ int RageSoundReader_Resample_Good::SetPosition( int iFrame ) { Reset(); iFrame = (int) SCALE( iFrame, 0, (int64_t) m_iSampleRate, 0, (int64_t) m_pSource->GetSampleRate() ); - iFrame = m_pSource->SetPosition( iFrame ); - iFrame = (int) SCALE( iFrame, 0, (int64_t) m_pSource->GetSampleRate(), 0, (int64_t) m_iSampleRate ); - return iFrame; + return m_pSource->SetPosition( iFrame ); } int RageSoundReader_Resample_Good::Read( char *pBuf_, int iFrames ) diff --git a/stepmania/src/RageSoundReader_Vorbisfile.cpp b/stepmania/src/RageSoundReader_Vorbisfile.cpp index 60f477c6ec..6a5cac5969 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.cpp +++ b/stepmania/src/RageSoundReader_Vorbisfile.cpp @@ -157,7 +157,7 @@ int RageSoundReader_Vorbisfile::SetPosition( int iFrame ) } read_offset = (int) ov_pcm_tell(vf); - return iFrame; + return 1; } int RageSoundReader_Vorbisfile::Read( char *buf, int iFrames ) diff --git a/stepmania/src/RageSoundReader_WAV.cpp b/stepmania/src/RageSoundReader_WAV.cpp index a47d728727..031ccc9ca5 100644 --- a/stepmania/src/RageSoundReader_WAV.cpp +++ b/stepmania/src/RageSoundReader_WAV.cpp @@ -116,7 +116,7 @@ struct WavReaderPCM: public WavReader } m_File.Seek( iByte+m_WavData.m_iDataChunkPos ); - return iFrame; + return 1; } // XXX: untested @@ -369,7 +369,7 @@ public: return 0; } - return iFrame; + return 1; } // XXX: untested