From 7385c1f4c1539b30e7507b73593d03e478b3b096 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 10 Dec 2006 08:59:13 +0000 Subject: [PATCH] merge SetPosition_Accurate and SetPosition_Fast. Use a property instead. --- stepmania/src/RageSound.cpp | 11 +--- stepmania/src/RageSound.h | 3 - stepmania/src/RageSoundReader.h | 3 +- .../src/RageSoundReader_ChannelSplit.cpp | 5 +- stepmania/src/RageSoundReader_ChannelSplit.h | 3 +- stepmania/src/RageSoundReader_Filter.h | 3 +- stepmania/src/RageSoundReader_MP3.cpp | 55 ++++++++++++------- stepmania/src/RageSoundReader_MP3.h | 5 +- stepmania/src/RageSoundReader_Preload.cpp | 14 ++--- stepmania/src/RageSoundReader_Preload.h | 3 +- .../src/RageSoundReader_Resample_Good.cpp | 13 +---- stepmania/src/RageSoundReader_Resample_Good.h | 3 +- stepmania/src/RageSoundReader_SpeedChange.cpp | 14 +---- stepmania/src/RageSoundReader_SpeedChange.h | 3 +- stepmania/src/RageSoundReader_Vorbisfile.cpp | 2 +- stepmania/src/RageSoundReader_Vorbisfile.h | 4 +- stepmania/src/RageSoundReader_WAV.h | 5 +- stepmania/src/ScreenEdit.cpp | 2 +- stepmania/src/ScreenGameplay.cpp | 5 +- 19 files changed, 63 insertions(+), 93 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 82bdca7a1b..6cb9b0e211 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -48,7 +48,6 @@ RageSoundParams::RageSoundParams(): m_Volume = 1.0f; m_fPitch = 1.0f; m_fSpeed = 1.0f; - m_bAccurateSync = false; StopMode = M_AUTO; m_bIsCriticalSound = false; } @@ -154,8 +153,7 @@ class RageSoundReader_Silence: public RageSoundReader public: int GetLength() const { return 0; } int GetLength_Fast() const { return 0; } - int SetPosition_Accurate( int iFrame ) { return 0; } - int SetPosition_Fast( int iFrame ) { return 0; } + int SetPosition( int iFrame ) { return 0; } int Read( char *buf, int iFrames ) { return 0; } RageSoundReader *Copy() const { return new RageSoundReader_Silence; } int GetSampleRate() const { return 44100; } @@ -745,12 +743,7 @@ bool RageSound::SetPositionFrames( int iFrames ) int iSeekFrames = max( iFrames, 0 ); - int iRet; - if( m_Param.m_bAccurateSync ) - iRet = m_pSource->SetPosition_Accurate( iSeekFrames ); - else - iRet = m_pSource->SetPosition_Fast( iSeekFrames ); - + int iRet = m_pSource->SetPosition( iSeekFrames ); if( iRet == -1 ) { Fail( m_pSource->GetError() ); diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index 64a50b4d99..62f9edf7dc 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -46,9 +46,6 @@ struct RageSoundParams float m_fPitch; float m_fSpeed; - /* If enabled, file seeking will prefer accuracy over speed. */ - bool m_bAccurateSync; - /* Optional driver feature: time to actually start playing sounds. If zero, or if not * supported, the sound will start immediately. */ RageTimer m_StartTime; diff --git a/stepmania/src/RageSoundReader.h b/stepmania/src/RageSoundReader.h index d917eee213..1ef850c602 100644 --- a/stepmania/src/RageSoundReader.h +++ b/stepmania/src/RageSoundReader.h @@ -8,8 +8,7 @@ class RageSoundReader public: virtual int GetLength() const = 0; /* ms */ virtual int GetLength_Fast() const { return GetLength(); } /* ms */ - virtual int SetPosition_Accurate( int iSample ) = 0; - virtual int SetPosition_Fast( int iSample ) { return SetPosition_Accurate(iSample); } + virtual int SetPosition( int iSample ) = 0; virtual int Read( char *pBuf, int iFrames ) = 0; virtual ~RageSoundReader() { } virtual RageSoundReader *Copy() const = 0; diff --git a/stepmania/src/RageSoundReader_ChannelSplit.cpp b/stepmania/src/RageSoundReader_ChannelSplit.cpp index 900da120d1..fdfafc0ab5 100644 --- a/stepmania/src/RageSoundReader_ChannelSplit.cpp +++ b/stepmania/src/RageSoundReader_ChannelSplit.cpp @@ -62,7 +62,6 @@ public: int RageSoundReader_Split::GetLength() const { return m_pImpl->m_pSource->GetLength(); } int RageSoundReader_Split::GetLength_Fast() const { return m_pImpl->m_pSource->GetLength_Fast(); } -int RageSoundReader_Split::SetPosition_Fast( int iFrame ) { return SetPosition_Accurate( iFrame ); } int RageSoundReader_Split::GetSampleRate() const { return m_pImpl->m_pSource->GetSampleRate(); } unsigned RageSoundReader_Split::GetNumChannels() const { return m_iNumOutputChannels; } bool RageSoundReader_Split::IsStreamingFromDisk() const { return m_pImpl->m_pSource->IsStreamingFromDisk(); } @@ -97,7 +96,7 @@ RageSoundReader_Split::~RageSoundReader_Split() RageSoundSplitterImpl::Release( m_pImpl ); } -int RageSoundReader_Split::SetPosition_Accurate( int iFrame ) +int RageSoundReader_Split::SetPosition( int iFrame ) { m_iPositionFrame = iFrame; return iFrame; @@ -174,7 +173,7 @@ int RageSoundSplitterImpl::ReadBuffer() if( iMinFrameRequested != m_iBufferPositionFrames ) { - int iFrame = m_pSource->SetPosition_Accurate( iMinFrameRequested ); + int iFrame = m_pSource->SetPosition( iMinFrameRequested ); m_iBufferPositionFrames = iFrame; m_sBuffer.clear(); } diff --git a/stepmania/src/RageSoundReader_ChannelSplit.h b/stepmania/src/RageSoundReader_ChannelSplit.h index 5b7273c0e1..9d711d221a 100644 --- a/stepmania/src/RageSoundReader_ChannelSplit.h +++ b/stepmania/src/RageSoundReader_ChannelSplit.h @@ -16,8 +16,7 @@ public: virtual int GetLength() const; virtual int GetLength_Fast() const; - virtual int SetPosition_Accurate( int iFrame ); - virtual int SetPosition_Fast( int iFrame ); + virtual int SetPosition( int iFrame ); virtual int Read( char *pBuf, int iFrames ); virtual int GetSampleRate() const; virtual unsigned GetNumChannels() const; diff --git a/stepmania/src/RageSoundReader_Filter.h b/stepmania/src/RageSoundReader_Filter.h index 36fbfb576d..6ca2e0be57 100644 --- a/stepmania/src/RageSoundReader_Filter.h +++ b/stepmania/src/RageSoundReader_Filter.h @@ -15,8 +15,7 @@ public: virtual int GetLength() const { return m_pSource->GetLength(); } virtual int GetLength_Fast() const { return m_pSource->GetLength_Fast(); } - virtual int SetPosition_Accurate( int iFrame ) { return m_pSource->SetPosition_Accurate( iFrame ); } - virtual int SetPosition_Fast( int iFrame ) { return m_pSource->SetPosition_Fast( iFrame ); } + virtual int SetPosition( int iFrame ) { return m_pSource->SetPosition( iFrame ); } virtual int Read( char *pBuf, int iFrames ) { return m_pSource->Read( pBuf, iFrames ); } virtual int GetSampleRate() const { return m_pSource->GetSampleRate(); } virtual unsigned GetNumChannels() const { return m_pSource->GetNumChannels(); } diff --git a/stepmania/src/RageSoundReader_MP3.cpp b/stepmania/src/RageSoundReader_MP3.cpp index 166bb9aba2..c7ad96afb2 100644 --- a/stepmania/src/RageSoundReader_MP3.cpp +++ b/stepmania/src/RageSoundReader_MP3.cpp @@ -627,6 +627,7 @@ int RageSoundReader_MP3::resync() RageSoundReader_MP3::RageSoundReader_MP3() { mad = new madlib_t; + m_bAccurateSync = false; mad_stream_init( &mad->Stream ); mad_frame_init( &mad->Frame ); @@ -710,6 +711,7 @@ RageSoundReader_MP3 *RageSoundReader_MP3::Copy() const bool b = ret->file.Open( filename ); ASSERT( b ); + ret->m_bAccurateSync = m_bAccurateSync; ret->mad->filesize = mad->filesize; ret->mad->bitrate = mad->bitrate; ret->SampleRate = SampleRate; @@ -1004,33 +1006,46 @@ int RageSoundReader_MP3::SetPosition_estimate( int iFrame ) return iFrame; } -int RageSoundReader_MP3::SetPosition_Accurate( int iFrame ) +int RageSoundReader_MP3::SetPosition( int iFrame ) { - /* Seek using our own internal (accurate) TOC. */ - int ret = SetPosition_toc( iFrame, false ); - if( ret <= 0 ) - return ret; /* it set the error */ - - /* Align exactly. */ - return SetPosition_hard( iFrame ); + if( m_bAccurateSync ) + { + /* Seek using our own internal (accurate) TOC. */ + int ret = SetPosition_toc( iFrame, false ); + if( ret <= 0 ) + return ret; /* it set the error */ + + /* Align exactly. */ + return SetPosition_hard( iFrame ); + } + else + { + /* Rewinding is always fast and accurate, and SetPosition_estimate is bad at 0. */ + if( !iFrame ) + { + MADLIB_rewind(); + return 0; /* ok */ + } + + /* We can do a fast jump in VBR with Xing with more accuracy than without Xing. */ + if( mad->has_xing ) + return SetPosition_toc( iFrame, true ); + + /* Guess. This is only remotely accurate when we're not VBR, but also + * do it if we have no Xing tag. */ + return SetPosition_estimate( iFrame ); + } } -int RageSoundReader_MP3::SetPosition_Fast( int iFrame ) +bool RageSoundReader_MP3::SetProperty( const RString &sProperty, float fValue ) { - /* Rewinding is always fast and accurate, and SetPosition_estimate is bad at 0. */ - if( !iFrame ) + if( sProperty == "AccurateSync" ) { - MADLIB_rewind(); - return 0; /* ok */ + m_bAccurateSync = (fValue > 0.001f); + return true; } - /* We can do a fast jump in VBR with Xing with more accuracy than without Xing. */ - if( mad->has_xing ) - return SetPosition_toc( iFrame, true ); - - /* Guess. This is only remotely accurate when we're not VBR, but also - * do it if we have no Xing tag. */ - return SetPosition_estimate( iFrame ); + return RageSoundReader_FileReader::SetProperty( sProperty, fValue ); } int RageSoundReader_MP3::GetNextSourceFrame() const diff --git a/stepmania/src/RageSoundReader_MP3.h b/stepmania/src/RageSoundReader_MP3.h index 1fb74bb215..4e2b6bfcfb 100644 --- a/stepmania/src/RageSoundReader_MP3.h +++ b/stepmania/src/RageSoundReader_MP3.h @@ -15,12 +15,12 @@ public: void Close(); int GetLength() const { return GetLengthConst(false); } int GetLength_Fast() const { return GetLengthConst(true); } - int SetPosition_Accurate( int iSample ); - int SetPosition_Fast( int iSample ); + int SetPosition( int iSample ); int Read( char *pBuf, int iFrames ); unsigned GetNumChannels() const { return Channels; } int GetSampleRate() const { return SampleRate; } int GetNextSourceFrame() const; + bool SetProperty( const RString &sProperty, float fValue ); RageSoundReader_MP3(); ~RageSoundReader_MP3(); @@ -30,6 +30,7 @@ public: private: int SampleRate; int Channels; + bool m_bAccurateSync; RString filename; RageFile file; diff --git a/stepmania/src/RageSoundReader_Preload.cpp b/stepmania/src/RageSoundReader_Preload.cpp index b70f93a511..a6a0adf116 100644 --- a/stepmania/src/RageSoundReader_Preload.cpp +++ b/stepmania/src/RageSoundReader_Preload.cpp @@ -15,7 +15,7 @@ bool RageSoundReader_Preload::PreloadSound( RageSoundReader *&pSound ) if( !pPreload->Open(pSound) ) { /* Preload failed. It read some data, so we need to rewind the reader. */ - pSound->SetPosition_Fast( 0 ); + pSound->SetPosition( 0 ); delete pPreload; return false; } @@ -70,9 +70,8 @@ bool RageSoundReader_Preload::Open( RageSoundReader *pSource ) SetError(pSource->GetError()); return false; } - - if( !iCnt ) - break; /* eof */ + if( iCnt == END_OF_FILE ) + break; /* Add the buffer. */ m_Buffer.Get()->append( buffer, buffer+iCnt*iBytesPerFrame ); @@ -96,7 +95,7 @@ int RageSoundReader_Preload::GetLength_Fast() const return GetLength(); } -int RageSoundReader_Preload::SetPosition_Accurate( int iFrame ) +int RageSoundReader_Preload::SetPosition( int iFrame ) { m_iPosition = iFrame; m_iPosition = lrintf(m_iPosition / m_fRate); @@ -110,11 +109,6 @@ int RageSoundReader_Preload::SetPosition_Accurate( int iFrame ) return iFrame; } -int RageSoundReader_Preload::SetPosition_Fast( int iFrame ) -{ - return SetPosition_Accurate( iFrame ); -} - int RageSoundReader_Preload::GetNextSourceFrame() const { return lrintf(m_iPosition * m_fRate); diff --git a/stepmania/src/RageSoundReader_Preload.h b/stepmania/src/RageSoundReader_Preload.h index e1835dc91b..7be26480b8 100644 --- a/stepmania/src/RageSoundReader_Preload.h +++ b/stepmania/src/RageSoundReader_Preload.h @@ -15,8 +15,7 @@ public: bool Open( RageSoundReader *pSource ); int GetLength() const; int GetLength_Fast() const; - int SetPosition_Accurate( int iFrame ); - int SetPosition_Fast( int iFrame ); + int SetPosition( int iFrame ); int Read( char *pBuffer, int iLength ); int GetSampleRate() const { return m_iSampleRate; } unsigned GetNumChannels() const { return m_iChannels; } diff --git a/stepmania/src/RageSoundReader_Resample_Good.cpp b/stepmania/src/RageSoundReader_Resample_Good.cpp index 1a30d5b675..7d0871592e 100644 --- a/stepmania/src/RageSoundReader_Resample_Good.cpp +++ b/stepmania/src/RageSoundReader_Resample_Good.cpp @@ -675,20 +675,11 @@ int RageSoundReader_Resample_Good::GetLength_Fast() const } /* iFrame is in the destination rate. Seek the source in its own sample rate. */ -int RageSoundReader_Resample_Good::SetPosition_Accurate( int iFrame ) +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_Accurate( iFrame ); - iFrame = (int) SCALE( iFrame, 0, (int64_t) m_pSource->GetSampleRate(), 0, (int64_t) m_iSampleRate ); - return iFrame; -} - -int RageSoundReader_Resample_Good::SetPosition_Fast( int iFrame ) -{ - Reset(); - iFrame = (int) SCALE( iFrame, 0, (int64_t) m_iSampleRate, 0, (int64_t) m_pSource->GetSampleRate() ); - iFrame = m_pSource->SetPosition_Fast( iFrame ); + iFrame = m_pSource->SetPosition( iFrame ); iFrame = (int) SCALE( iFrame, 0, (int64_t) m_pSource->GetSampleRate(), 0, (int64_t) m_iSampleRate ); return iFrame; } diff --git a/stepmania/src/RageSoundReader_Resample_Good.h b/stepmania/src/RageSoundReader_Resample_Good.h index 14e3b8b4f3..8fc8e0bc6c 100644 --- a/stepmania/src/RageSoundReader_Resample_Good.h +++ b/stepmania/src/RageSoundReader_Resample_Good.h @@ -16,8 +16,7 @@ public: RageSoundReader_Resample_Good( const RageSoundReader_Resample_Good &cpy ); int GetLength() const; int GetLength_Fast() const; - int SetPosition_Accurate( int iFrame ); - int SetPosition_Fast( int iFrame ); + int SetPosition( int iFrame ); int Read( char *pBuf, int iFrames ); virtual ~RageSoundReader_Resample_Good(); RageSoundReader_Resample_Good *Copy() const; diff --git a/stepmania/src/RageSoundReader_SpeedChange.cpp b/stepmania/src/RageSoundReader_SpeedChange.cpp index 6397ddf24d..9596a47d92 100644 --- a/stepmania/src/RageSoundReader_SpeedChange.cpp +++ b/stepmania/src/RageSoundReader_SpeedChange.cpp @@ -289,24 +289,14 @@ int RageSoundReader_SpeedChange::Read( char *buf, int iFrames ) /* We prefer to be able to seek precisely, so seeking to a position produces data * equal to what you'd get if you read data up to that point. This filter can't do * that, because the exact selection of slices is dependent on the previous selection. */ -int RageSoundReader_SpeedChange::SetPosition_Accurate( int iFrame ) +int RageSoundReader_SpeedChange::SetPosition( int iFrame ) { Reset(); int64_t iScaled = (int64_t(iFrame) * GetWindowSizeFrames()) / m_iDeltaFrames; iFrame = (int) iScaled; - return RageSoundReader_Filter::SetPosition_Accurate( iFrame ); -} - -int RageSoundReader_SpeedChange::SetPosition_Fast( int iFrame ) -{ - Reset(); - - int64_t iScaled = (int64_t(iFrame) * GetWindowSizeFrames()) / m_iDeltaFrames; - iFrame = (int) iScaled; - - return RageSoundReader_Filter::SetPosition_Fast( iFrame ); + return RageSoundReader_Filter::SetPosition( iFrame ); } bool RageSoundReader_SpeedChange::SetProperty( const RString &sProperty, float fValue ) diff --git a/stepmania/src/RageSoundReader_SpeedChange.h b/stepmania/src/RageSoundReader_SpeedChange.h index 68d8e14600..541756d96c 100644 --- a/stepmania/src/RageSoundReader_SpeedChange.h +++ b/stepmania/src/RageSoundReader_SpeedChange.h @@ -10,8 +10,7 @@ class RageSoundReader_SpeedChange: public RageSoundReader_Filter public: RageSoundReader_SpeedChange( RageSoundReader *pSource ); - virtual int SetPosition_Accurate( int iFrame ); - virtual int SetPosition_Fast( int iFrame ); + virtual int SetPosition( int iFrame ); virtual int Read( char *pBuf, int iFrames ); virtual RageSoundReader_SpeedChange *Copy() const { return new RageSoundReader_SpeedChange(*this); } virtual bool SetProperty( const RString &sProperty, float fValue ); diff --git a/stepmania/src/RageSoundReader_Vorbisfile.cpp b/stepmania/src/RageSoundReader_Vorbisfile.cpp index cf61411f21..a72f60ed15 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.cpp +++ b/stepmania/src/RageSoundReader_Vorbisfile.cpp @@ -142,7 +142,7 @@ int RageSoundReader_Vorbisfile::GetLength_Fast() const return GetLength(); } -int RageSoundReader_Vorbisfile::SetPosition( int iFrame, bool accurate ) +int RageSoundReader_Vorbisfile::SetPosition( int iFrame ) { eof = false; diff --git a/stepmania/src/RageSoundReader_Vorbisfile.h b/stepmania/src/RageSoundReader_Vorbisfile.h index 856d56b081..4502ca2e1f 100644 --- a/stepmania/src/RageSoundReader_Vorbisfile.h +++ b/stepmania/src/RageSoundReader_Vorbisfile.h @@ -16,8 +16,7 @@ public: int GetLength() const; int GetLength_Fast() const; - int SetPosition_Accurate( int iFrame ) { return SetPosition( iFrame, true ); } - int SetPosition_Fast( int iFrame ) { return SetPosition( iFrame, false ); } + int SetPosition( int iFrame ); int Read( char *pBuf, int iFrames ); int GetSampleRate() const; unsigned GetNumChannels() const { return channels; } @@ -29,7 +28,6 @@ public: private: OggVorbis_File *vf; bool eof; - int SetPosition( int iFrame, bool accurate ); bool FillBuf(); RString filename; int read_offset; diff --git a/stepmania/src/RageSoundReader_WAV.h b/stepmania/src/RageSoundReader_WAV.h index 22ad2b6ca2..b163b8d30f 100644 --- a/stepmania/src/RageSoundReader_WAV.h +++ b/stepmania/src/RageSoundReader_WAV.h @@ -14,8 +14,7 @@ public: void Close(); int GetLength() const; int GetLength_Fast() const { return GetLength(); } - int SetPosition_Accurate( int iFrame ) { return SetPosition(iFrame); } - int SetPosition_Fast( int iFrame ) { return SetPosition(iFrame); } + int SetPosition( int iFrame ); int Read( char *pBuf, int iFrames ); int GetSampleRate() const { return m_WavData.m_iSampleRate; } unsigned GetNumChannels() const { return m_WavData.m_iChannels; } @@ -37,8 +36,6 @@ private: WavData m_WavData; WavReader *m_pImpl; - - int SetPosition( int iFrame ); }; #endif diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 4215cc6135..9751f2bdb6 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -2304,8 +2304,8 @@ void ScreenEdit::TransitionEditState( EditState em ) RageSoundParams p; p.m_fSpeed = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; p.m_StartSecond = fStartSeconds; - p.m_bAccurateSync = true; p.StopMode = RageSoundParams::M_CONTINUE; + m_soundMusic.SetProperty( "AccurateSync", true ); m_soundMusic.Play( &p ); break; } diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index f2193c99f9..5f8f6b29fe 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -1323,8 +1323,9 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi fStartSecond = min(fStartSecond, -MinTimeToMusic); + m_pSoundMusic->SetProperty( "AccurateSync", true ); + RageSoundParams p; - p.m_bAccurateSync = true; p.m_fSpeed = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; p.StopMode = RageSoundParams::M_CONTINUE; p.m_StartSecond = fStartSecond; @@ -1482,10 +1483,10 @@ void ScreenGameplay::BeginScreen() NSMAN->StartRequest(1); RageSoundParams p; - p.m_bAccurateSync = true; p.m_fSpeed = 1.0f; //Force 1.0 playback speed p.StopMode = RageSoundParams::M_CONTINUE; p.m_StartSecond = startOffset; + m_pSoundMusic->SetProperty( "AccurateSync", true ); m_pSoundMusic->Play( &p ); UpdateSongPosition(0);