diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index c1d100c68c..0eee1e74ac 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -998,6 +998,14 @@ int RageSoundReader_MP3::SetPosition_Fast( int ms ) return SetPosition_estimate( ms ); } +// XXX: untested +int RageSoundReader_MP3::GetNextStreamFrame() const +{ + mad_timer_t now( mad->Timer ); + mad_timer_multiply( &now, mad->Frame.header.samplerate ); + return now.seconds; +} + int RageSoundReader_MP3::GetLengthInternal( bool fast ) { if( mad->has_xing && mad->length != -1 ) diff --git a/stepmania/src/RageSoundReader_MP3.h b/stepmania/src/RageSoundReader_MP3.h index afa4477487..2910d95cf3 100644 --- a/stepmania/src/RageSoundReader_MP3.h +++ b/stepmania/src/RageSoundReader_MP3.h @@ -19,6 +19,7 @@ public: int SetPosition_Fast(int ms); int Read(char *buf, unsigned len); int GetSampleRate() const { return SampleRate; } + int GetNextStreamFrame() const; RageSoundReader_MP3(); ~RageSoundReader_MP3(); diff --git a/stepmania/src/RageSoundReader_Vorbisfile.cpp b/stepmania/src/RageSoundReader_Vorbisfile.cpp index cf83f79fc5..dc357a5422 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.cpp +++ b/stepmania/src/RageSoundReader_Vorbisfile.cpp @@ -255,6 +255,14 @@ int RageSoundReader_Vorbisfile::GetSampleRate() const return vi->rate; } +int RageSoundReader_Vorbisfile::GetNextStreamFrame() const +{ + ASSERT(vf); + + int iFrame = ov_pcm_tell( vf ); + return iFrame; +} + RageSoundReader_Vorbisfile::RageSoundReader_Vorbisfile() { vf = NULL; diff --git a/stepmania/src/RageSoundReader_Vorbisfile.h b/stepmania/src/RageSoundReader_Vorbisfile.h index 8f2f677938..74c2d45a3c 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.h +++ b/stepmania/src/RageSoundReader_Vorbisfile.h @@ -21,6 +21,7 @@ public: int Read(char *buf, unsigned len); int GetSampleRate() const; unsigned GetNumChannels() const { return channels; } + int GetNextStreamFrame() const; RageSoundReader_Vorbisfile(); ~RageSoundReader_Vorbisfile(); RageSoundReader_Vorbisfile *Copy() const; diff --git a/stepmania/src/RageSoundReader_WAV.cpp b/stepmania/src/RageSoundReader_WAV.cpp index f627ef4a55..efd6fad6b5 100644 --- a/stepmania/src/RageSoundReader_WAV.cpp +++ b/stepmania/src/RageSoundReader_WAV.cpp @@ -46,6 +46,7 @@ struct WavReader virtual int GetLength() const = 0; virtual bool Init() = 0; virtual int SetPosition( int iMS ) = 0; + virtual int GetNextStreamFrame() const = 0; RString GetError() const { return m_sError; } protected: @@ -115,6 +116,14 @@ struct WavReaderPCM: public WavReader m_File.Seek( iByte+m_WavData.m_iDataChunkPos ); return int((int64_t(iByte) * 1000) / iBytesPerSec); } + + // XXX: untested + int GetNextStreamFrame() const + { + int iByte = m_File.Tell() - m_WavData.m_iDataChunkPos; + int iFrame = iByte / (m_WavData.m_iChannels * m_WavData.m_iBitsPerSample / 8); + return iFrame; + } }; struct WavReaderADPCM: public WavReader @@ -352,6 +361,20 @@ public: return iMS; } + + // XXX: untested + int GetNextStreamFrame() const + { + int iByte = m_File.Tell() - m_WavData.m_iDataChunkPos; + int iBlock = iByte / m_WavData.m_iBlockAlign; + int iFrame = iBlock * m_iFramesPerBlock; + + int iBufferRemainingBytes = m_iBufferAvail - m_iBufferUsed; + int iBufferRemainingFrames = iBufferRemainingBytes / (m_WavData.m_iChannels * sizeof(int16_t)); + iFrame -= iBufferRemainingFrames; + + return iFrame; + } }; RString ReadString( RageFile &f, int iSize, RString &sError ) @@ -500,6 +523,12 @@ int RageSoundReader_WAV::SetPosition( int ms ) return m_pImpl->SetPosition( ms ); } +int RageSoundReader_WAV::GetNextStreamFrame() const +{ + ASSERT( m_pImpl != NULL ); + return m_pImpl->GetNextStreamFrame(); +} + int RageSoundReader_WAV::Read( char *buf, unsigned len ) { ASSERT( m_pImpl != NULL ); diff --git a/stepmania/src/RageSoundReader_WAV.h b/stepmania/src/RageSoundReader_WAV.h index 3aaec677e1..d5c871e4e9 100644 --- a/stepmania/src/RageSoundReader_WAV.h +++ b/stepmania/src/RageSoundReader_WAV.h @@ -19,6 +19,7 @@ public: int Read( char *buf, unsigned len ); int GetSampleRate() const { return m_WavData.m_iSampleRate; } unsigned GetNumChannels() const { return m_WavData.m_iChannels; } + int GetNextStreamFrame() const; RageSoundReader_WAV(); ~RageSoundReader_WAV(); RageSoundReader_WAV( const RageSoundReader_WAV & ); /* not defined; don't use */