diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index c87d454973..8efaa3bee4 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -878,11 +878,18 @@ int RageSoundReader_MP3::SetPosition_toc( int ms, bool Xing ) if(percent >= 0) { int bytepos = -1; - if( Xing && percent < 100 ) + if( Xing ) + { + if( percent < 100 ) + { + int jump = mad->xingtag.toc[percent]; + bytepos = mad->filesize * jump / 256; + } + else + bytepos = 2000000000; /* force EOF */ + } + else if( percent < 200 ) { - int jump = mad->xingtag.toc[percent]; - bytepos = mad->filesize * jump / 256; - } else if(percent < 200) { /* Find the last entry <= percent that we actually have an entry for; * this will get us as close as possible. */ while( percent >= 0 && mad->toc[percent] == -1 ) @@ -1026,17 +1033,10 @@ int RageSoundReader_MP3::SetPosition_Accurate( int ms ) /* Seek using our own internal (accurate) TOC. */ int ret = SetPosition_toc( ms, false ); if( ret <= 0 ) - { - MADLIB_rewind(); return ret; /* it set the error */ - } /* Align exactly. */ - ret = SetPosition_hard( ms ); - if( ret <= 0 ) - MADLIB_rewind(); - - return ret; + return SetPosition_hard( ms ); } int RageSoundReader_MP3::SetPosition_Fast( int ms ) @@ -1050,19 +1050,11 @@ int RageSoundReader_MP3::SetPosition_Fast( int ms ) /* We can do a fast jump in VBR with Xing with more accuracy than without Xing. */ if( mad->has_xing ) - { - int ret = SetPosition_toc( ms, true ); - if( ret <= 0 ) - MADLIB_rewind(); - return ret; - } + return SetPosition_toc( ms, true ); /* Guess. This is only remotely accurate when we're not VBR, but also * do it if we have no Xing tag. */ - int ret = SetPosition_estimate( ms ); - if( ret <= 0 ) - MADLIB_rewind(); - return ret; + return SetPosition_estimate( ms ); } int RageSoundReader_MP3::GetLengthInternal( bool fast ) diff --git a/stepmania/src/RageSoundReader_Vorbisfile.cpp b/stepmania/src/RageSoundReader_Vorbisfile.cpp index 8998faf90e..f3686709b9 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.cpp +++ b/stepmania/src/RageSoundReader_Vorbisfile.cpp @@ -88,6 +88,7 @@ SoundReader_FileReader::OpenResult RageSoundReader_Vorbisfile::Open(CString file } avail = 0; + eof = false; return OPEN_OK; } @@ -113,16 +114,19 @@ int RageSoundReader_Vorbisfile::GetLength_Fast() const int RageSoundReader_Vorbisfile::SetPosition(int ms, bool accurate) { avail = 0; + eof = false; -#if defined(INTEGER_OGG) - const int to = ms; -#else - const float to = ms/1000.0f; -#endif + const ogg_int64_t sample = ogg_int64_t(ms) * GetSampleRate() / 1000; - int ret = ov_time_seek( vf, to ); + int ret = ov_pcm_seek( vf, sample ); if(ret < 0) { + /* Returns OV_EINVAL on EOF. */ + if( ret == OV_EINVAL ) + { + eof = true; + return 0; + } SetError( ov_ssprintf(ret, "ogg: SetPosition failed") ); return -1; } @@ -132,6 +136,9 @@ int RageSoundReader_Vorbisfile::SetPosition(int ms, bool accurate) int RageSoundReader_Vorbisfile::Read(char *buf, unsigned len) { + if( eof ) + return 0; + int bytes_read = 0; while(len) { diff --git a/stepmania/src/RageSoundReader_Vorbisfile.h b/stepmania/src/RageSoundReader_Vorbisfile.h index 87af04dde3..9a5cc4f3fc 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.h +++ b/stepmania/src/RageSoundReader_Vorbisfile.h @@ -9,6 +9,7 @@ class RageSoundReader_Vorbisfile: public SoundReader_FileReader { OggVorbis_File *vf; char buffer[4096*4]; unsigned avail; + bool eof; int SetPosition(int ms, bool accurate); CString filename; diff --git a/stepmania/src/RageSoundReader_WAV.cpp b/stepmania/src/RageSoundReader_WAV.cpp index 2b7dbc81c9..b0bc3a5ba7 100644 --- a/stepmania/src/RageSoundReader_WAV.cpp +++ b/stepmania/src/RageSoundReader_WAV.cpp @@ -188,6 +188,10 @@ int RageSoundReader_WAV::seek_sample_fmt_normal( Uint32 ms ) int rc = fseek( this->rw, pos, SEEK_SET ); BAIL_IF_MACRO(rc == -1, strerror(errno), -1); + /* If we seek past end of ifle, leave the cursor there, so subsequent reads will return EOF. */ + if( pos >= (int) GetFileSizeInBytes( filename ) ) + return 0; + return ms; } @@ -343,8 +347,13 @@ Uint32 RageSoundReader_WAV::read_sample_fmt_adpcm(char *buf, unsigned len) bw += this->fmt.adpcm_sample_frame_size; if( !first_sample_in_block && adpcm.samples_left_in_block ) + { if (!decode_adpcm_sample_frame()) + { + adpcm.samples_left_in_block = 0; return bw; + } + } } return bw; @@ -364,15 +373,13 @@ int RageSoundReader_WAV::seek_sample_fmt_adpcm( Uint32 ms ) /* The offset we need is in this block, so we need to decode to there. */ rc = offset % bpb; /* bytes into this block we need to decode */ + adpcm.samples_left_in_block = 0; + if( rc == 0 ) - { - adpcm.samples_left_in_block = 0; return ms; - } if (!read_adpcm_block_headers(adpcm)) { - fseek(this->rw, fmt.data_starting_offset, SEEK_SET); adpcm.samples_left_in_block = 0; return 0; } @@ -387,7 +394,6 @@ int RageSoundReader_WAV::seek_sample_fmt_adpcm( Uint32 ms ) if (!decode_adpcm_sample_frame()) { - fseek(this->rw, fmt.data_starting_offset, SEEK_SET); adpcm.samples_left_in_block = 0; return 0; }