merge SetPosition_Accurate and SetPosition_Fast. Use a property

instead.
This commit is contained in:
Glenn Maynard
2006-12-10 08:59:13 +00:00
parent 77d3971fd4
commit 7385c1f4c1
19 changed files with 63 additions and 93 deletions
+2 -9
View File
@@ -48,7 +48,6 @@ RageSoundParams::RageSoundParams():
m_Volume = 1.0f; m_Volume = 1.0f;
m_fPitch = 1.0f; m_fPitch = 1.0f;
m_fSpeed = 1.0f; m_fSpeed = 1.0f;
m_bAccurateSync = false;
StopMode = M_AUTO; StopMode = M_AUTO;
m_bIsCriticalSound = false; m_bIsCriticalSound = false;
} }
@@ -154,8 +153,7 @@ class RageSoundReader_Silence: public RageSoundReader
public: public:
int GetLength() const { return 0; } int GetLength() const { return 0; }
int GetLength_Fast() const { return 0; } int GetLength_Fast() const { return 0; }
int SetPosition_Accurate( int iFrame ) { return 0; } int SetPosition( int iFrame ) { return 0; }
int SetPosition_Fast( int iFrame ) { return 0; }
int Read( char *buf, int iFrames ) { return 0; } int Read( char *buf, int iFrames ) { return 0; }
RageSoundReader *Copy() const { return new RageSoundReader_Silence; } RageSoundReader *Copy() const { return new RageSoundReader_Silence; }
int GetSampleRate() const { return 44100; } int GetSampleRate() const { return 44100; }
@@ -745,12 +743,7 @@ bool RageSound::SetPositionFrames( int iFrames )
int iSeekFrames = max( iFrames, 0 ); int iSeekFrames = max( iFrames, 0 );
int iRet; int iRet = m_pSource->SetPosition( iSeekFrames );
if( m_Param.m_bAccurateSync )
iRet = m_pSource->SetPosition_Accurate( iSeekFrames );
else
iRet = m_pSource->SetPosition_Fast( iSeekFrames );
if( iRet == -1 ) if( iRet == -1 )
{ {
Fail( m_pSource->GetError() ); Fail( m_pSource->GetError() );
-3
View File
@@ -46,9 +46,6 @@ struct RageSoundParams
float m_fPitch; float m_fPitch;
float m_fSpeed; 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 /* Optional driver feature: time to actually start playing sounds. If zero, or if not
* supported, the sound will start immediately. */ * supported, the sound will start immediately. */
RageTimer m_StartTime; RageTimer m_StartTime;
+1 -2
View File
@@ -8,8 +8,7 @@ class RageSoundReader
public: public:
virtual int GetLength() const = 0; /* ms */ virtual int GetLength() const = 0; /* ms */
virtual int GetLength_Fast() const { return GetLength(); } /* ms */ virtual int GetLength_Fast() const { return GetLength(); } /* ms */
virtual int SetPosition_Accurate( int iSample ) = 0; virtual int SetPosition( int iSample ) = 0;
virtual int SetPosition_Fast( int iSample ) { return SetPosition_Accurate(iSample); }
virtual int Read( char *pBuf, int iFrames ) = 0; virtual int Read( char *pBuf, int iFrames ) = 0;
virtual ~RageSoundReader() { } virtual ~RageSoundReader() { }
virtual RageSoundReader *Copy() const = 0; virtual RageSoundReader *Copy() const = 0;
@@ -62,7 +62,6 @@ public:
int RageSoundReader_Split::GetLength() const { return m_pImpl->m_pSource->GetLength(); } 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::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(); } int RageSoundReader_Split::GetSampleRate() const { return m_pImpl->m_pSource->GetSampleRate(); }
unsigned RageSoundReader_Split::GetNumChannels() const { return m_iNumOutputChannels; } unsigned RageSoundReader_Split::GetNumChannels() const { return m_iNumOutputChannels; }
bool RageSoundReader_Split::IsStreamingFromDisk() const { return m_pImpl->m_pSource->IsStreamingFromDisk(); } bool RageSoundReader_Split::IsStreamingFromDisk() const { return m_pImpl->m_pSource->IsStreamingFromDisk(); }
@@ -97,7 +96,7 @@ RageSoundReader_Split::~RageSoundReader_Split()
RageSoundSplitterImpl::Release( m_pImpl ); RageSoundSplitterImpl::Release( m_pImpl );
} }
int RageSoundReader_Split::SetPosition_Accurate( int iFrame ) int RageSoundReader_Split::SetPosition( int iFrame )
{ {
m_iPositionFrame = iFrame; m_iPositionFrame = iFrame;
return iFrame; return iFrame;
@@ -174,7 +173,7 @@ int RageSoundSplitterImpl::ReadBuffer()
if( iMinFrameRequested != m_iBufferPositionFrames ) if( iMinFrameRequested != m_iBufferPositionFrames )
{ {
int iFrame = m_pSource->SetPosition_Accurate( iMinFrameRequested ); int iFrame = m_pSource->SetPosition( iMinFrameRequested );
m_iBufferPositionFrames = iFrame; m_iBufferPositionFrames = iFrame;
m_sBuffer.clear(); m_sBuffer.clear();
} }
+1 -2
View File
@@ -16,8 +16,7 @@ public:
virtual int GetLength() const; virtual int GetLength() const;
virtual int GetLength_Fast() const; virtual int GetLength_Fast() const;
virtual int SetPosition_Accurate( int iFrame ); virtual int SetPosition( int iFrame );
virtual int SetPosition_Fast( int iFrame );
virtual int Read( char *pBuf, int iFrames ); virtual int Read( char *pBuf, int iFrames );
virtual int GetSampleRate() const; virtual int GetSampleRate() const;
virtual unsigned GetNumChannels() const; virtual unsigned GetNumChannels() const;
+1 -2
View File
@@ -15,8 +15,7 @@ public:
virtual int GetLength() const { return m_pSource->GetLength(); } virtual int GetLength() const { return m_pSource->GetLength(); }
virtual int GetLength_Fast() const { return m_pSource->GetLength_Fast(); } 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( int iFrame ) { return m_pSource->SetPosition( iFrame ); }
virtual int SetPosition_Fast( int iFrame ) { return m_pSource->SetPosition_Fast( iFrame ); }
virtual int Read( char *pBuf, int iFrames ) { return m_pSource->Read( pBuf, iFrames ); } virtual int Read( char *pBuf, int iFrames ) { return m_pSource->Read( pBuf, iFrames ); }
virtual int GetSampleRate() const { return m_pSource->GetSampleRate(); } virtual int GetSampleRate() const { return m_pSource->GetSampleRate(); }
virtual unsigned GetNumChannels() const { return m_pSource->GetNumChannels(); } virtual unsigned GetNumChannels() const { return m_pSource->GetNumChannels(); }
+34 -19
View File
@@ -627,6 +627,7 @@ int RageSoundReader_MP3::resync()
RageSoundReader_MP3::RageSoundReader_MP3() RageSoundReader_MP3::RageSoundReader_MP3()
{ {
mad = new madlib_t; mad = new madlib_t;
m_bAccurateSync = false;
mad_stream_init( &mad->Stream ); mad_stream_init( &mad->Stream );
mad_frame_init( &mad->Frame ); mad_frame_init( &mad->Frame );
@@ -710,6 +711,7 @@ RageSoundReader_MP3 *RageSoundReader_MP3::Copy() const
bool b = ret->file.Open( filename ); bool b = ret->file.Open( filename );
ASSERT( b ); ASSERT( b );
ret->m_bAccurateSync = m_bAccurateSync;
ret->mad->filesize = mad->filesize; ret->mad->filesize = mad->filesize;
ret->mad->bitrate = mad->bitrate; ret->mad->bitrate = mad->bitrate;
ret->SampleRate = SampleRate; ret->SampleRate = SampleRate;
@@ -1004,33 +1006,46 @@ int RageSoundReader_MP3::SetPosition_estimate( int iFrame )
return iFrame; return iFrame;
} }
int RageSoundReader_MP3::SetPosition_Accurate( int iFrame ) int RageSoundReader_MP3::SetPosition( int iFrame )
{ {
/* Seek using our own internal (accurate) TOC. */ if( m_bAccurateSync )
int ret = SetPosition_toc( iFrame, false ); {
if( ret <= 0 ) /* Seek using our own internal (accurate) TOC. */
return ret; /* it set the error */ int ret = SetPosition_toc( iFrame, false );
if( ret <= 0 )
return ret; /* it set the error */
/* Align exactly. */ /* Align exactly. */
return SetPosition_hard( iFrame ); 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( sProperty == "AccurateSync" )
if( !iFrame )
{ {
MADLIB_rewind(); m_bAccurateSync = (fValue > 0.001f);
return 0; /* ok */ return true;
} }
/* We can do a fast jump in VBR with Xing with more accuracy than without Xing. */ return RageSoundReader_FileReader::SetProperty( sProperty, fValue );
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::GetNextSourceFrame() const int RageSoundReader_MP3::GetNextSourceFrame() const
+3 -2
View File
@@ -15,12 +15,12 @@ public:
void Close(); void Close();
int GetLength() const { return GetLengthConst(false); } int GetLength() const { return GetLengthConst(false); }
int GetLength_Fast() const { return GetLengthConst(true); } int GetLength_Fast() const { return GetLengthConst(true); }
int SetPosition_Accurate( int iSample ); int SetPosition( int iSample );
int SetPosition_Fast( int iSample );
int Read( char *pBuf, int iFrames ); int Read( char *pBuf, int iFrames );
unsigned GetNumChannels() const { return Channels; } unsigned GetNumChannels() const { return Channels; }
int GetSampleRate() const { return SampleRate; } int GetSampleRate() const { return SampleRate; }
int GetNextSourceFrame() const; int GetNextSourceFrame() const;
bool SetProperty( const RString &sProperty, float fValue );
RageSoundReader_MP3(); RageSoundReader_MP3();
~RageSoundReader_MP3(); ~RageSoundReader_MP3();
@@ -30,6 +30,7 @@ public:
private: private:
int SampleRate; int SampleRate;
int Channels; int Channels;
bool m_bAccurateSync;
RString filename; RString filename;
RageFile file; RageFile file;
+4 -10
View File
@@ -15,7 +15,7 @@ bool RageSoundReader_Preload::PreloadSound( RageSoundReader *&pSound )
if( !pPreload->Open(pSound) ) if( !pPreload->Open(pSound) )
{ {
/* Preload failed. It read some data, so we need to rewind the reader. */ /* Preload failed. It read some data, so we need to rewind the reader. */
pSound->SetPosition_Fast( 0 ); pSound->SetPosition( 0 );
delete pPreload; delete pPreload;
return false; return false;
} }
@@ -70,9 +70,8 @@ bool RageSoundReader_Preload::Open( RageSoundReader *pSource )
SetError(pSource->GetError()); SetError(pSource->GetError());
return false; return false;
} }
if( iCnt == END_OF_FILE )
if( !iCnt ) break;
break; /* eof */
/* Add the buffer. */ /* Add the buffer. */
m_Buffer.Get()->append( buffer, buffer+iCnt*iBytesPerFrame ); m_Buffer.Get()->append( buffer, buffer+iCnt*iBytesPerFrame );
@@ -96,7 +95,7 @@ int RageSoundReader_Preload::GetLength_Fast() const
return GetLength(); return GetLength();
} }
int RageSoundReader_Preload::SetPosition_Accurate( int iFrame ) int RageSoundReader_Preload::SetPosition( int iFrame )
{ {
m_iPosition = iFrame; m_iPosition = iFrame;
m_iPosition = lrintf(m_iPosition / m_fRate); m_iPosition = lrintf(m_iPosition / m_fRate);
@@ -110,11 +109,6 @@ int RageSoundReader_Preload::SetPosition_Accurate( int iFrame )
return iFrame; return iFrame;
} }
int RageSoundReader_Preload::SetPosition_Fast( int iFrame )
{
return SetPosition_Accurate( iFrame );
}
int RageSoundReader_Preload::GetNextSourceFrame() const int RageSoundReader_Preload::GetNextSourceFrame() const
{ {
return lrintf(m_iPosition * m_fRate); return lrintf(m_iPosition * m_fRate);
+1 -2
View File
@@ -15,8 +15,7 @@ public:
bool Open( RageSoundReader *pSource ); bool Open( RageSoundReader *pSource );
int GetLength() const; int GetLength() const;
int GetLength_Fast() const; int GetLength_Fast() const;
int SetPosition_Accurate( int iFrame ); int SetPosition( int iFrame );
int SetPosition_Fast( int iFrame );
int Read( char *pBuffer, int iLength ); int Read( char *pBuffer, int iLength );
int GetSampleRate() const { return m_iSampleRate; } int GetSampleRate() const { return m_iSampleRate; }
unsigned GetNumChannels() const { return m_iChannels; } unsigned GetNumChannels() const { return m_iChannels; }
@@ -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. */ /* 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(); Reset();
iFrame = (int) SCALE( iFrame, 0, (int64_t) m_iSampleRate, 0, (int64_t) m_pSource->GetSampleRate() ); iFrame = (int) SCALE( iFrame, 0, (int64_t) m_iSampleRate, 0, (int64_t) m_pSource->GetSampleRate() );
iFrame = m_pSource->SetPosition_Accurate( iFrame ); iFrame = m_pSource->SetPosition( 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 = (int) SCALE( iFrame, 0, (int64_t) m_pSource->GetSampleRate(), 0, (int64_t) m_iSampleRate ); iFrame = (int) SCALE( iFrame, 0, (int64_t) m_pSource->GetSampleRate(), 0, (int64_t) m_iSampleRate );
return iFrame; return iFrame;
} }
@@ -16,8 +16,7 @@ public:
RageSoundReader_Resample_Good( const RageSoundReader_Resample_Good &cpy ); RageSoundReader_Resample_Good( const RageSoundReader_Resample_Good &cpy );
int GetLength() const; int GetLength() const;
int GetLength_Fast() const; int GetLength_Fast() const;
int SetPosition_Accurate( int iFrame ); int SetPosition( int iFrame );
int SetPosition_Fast( int iFrame );
int Read( char *pBuf, int iFrames ); int Read( char *pBuf, int iFrames );
virtual ~RageSoundReader_Resample_Good(); virtual ~RageSoundReader_Resample_Good();
RageSoundReader_Resample_Good *Copy() const; RageSoundReader_Resample_Good *Copy() const;
+2 -12
View File
@@ -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 /* 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 * 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. */ * 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(); Reset();
int64_t iScaled = (int64_t(iFrame) * GetWindowSizeFrames()) / m_iDeltaFrames; int64_t iScaled = (int64_t(iFrame) * GetWindowSizeFrames()) / m_iDeltaFrames;
iFrame = (int) iScaled; iFrame = (int) iScaled;
return RageSoundReader_Filter::SetPosition_Accurate( iFrame ); return RageSoundReader_Filter::SetPosition( 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 );
} }
bool RageSoundReader_SpeedChange::SetProperty( const RString &sProperty, float fValue ) bool RageSoundReader_SpeedChange::SetProperty( const RString &sProperty, float fValue )
+1 -2
View File
@@ -10,8 +10,7 @@ class RageSoundReader_SpeedChange: public RageSoundReader_Filter
public: public:
RageSoundReader_SpeedChange( RageSoundReader *pSource ); RageSoundReader_SpeedChange( RageSoundReader *pSource );
virtual int SetPosition_Accurate( int iFrame ); virtual int SetPosition( int iFrame );
virtual int SetPosition_Fast( int iFrame );
virtual int Read( char *pBuf, int iFrames ); virtual int Read( char *pBuf, int iFrames );
virtual RageSoundReader_SpeedChange *Copy() const { return new RageSoundReader_SpeedChange(*this); } virtual RageSoundReader_SpeedChange *Copy() const { return new RageSoundReader_SpeedChange(*this); }
virtual bool SetProperty( const RString &sProperty, float fValue ); virtual bool SetProperty( const RString &sProperty, float fValue );
+1 -1
View File
@@ -142,7 +142,7 @@ int RageSoundReader_Vorbisfile::GetLength_Fast() const
return GetLength(); return GetLength();
} }
int RageSoundReader_Vorbisfile::SetPosition( int iFrame, bool accurate ) int RageSoundReader_Vorbisfile::SetPosition( int iFrame )
{ {
eof = false; eof = false;
+1 -3
View File
@@ -16,8 +16,7 @@ public:
int GetLength() const; int GetLength() const;
int GetLength_Fast() const; int GetLength_Fast() const;
int SetPosition_Accurate( int iFrame ) { return SetPosition( iFrame, true ); } int SetPosition( int iFrame );
int SetPosition_Fast( int iFrame ) { return SetPosition( iFrame, false ); }
int Read( char *pBuf, int iFrames ); int Read( char *pBuf, int iFrames );
int GetSampleRate() const; int GetSampleRate() const;
unsigned GetNumChannels() const { return channels; } unsigned GetNumChannels() const { return channels; }
@@ -29,7 +28,6 @@ public:
private: private:
OggVorbis_File *vf; OggVorbis_File *vf;
bool eof; bool eof;
int SetPosition( int iFrame, bool accurate );
bool FillBuf(); bool FillBuf();
RString filename; RString filename;
int read_offset; int read_offset;
+1 -4
View File
@@ -14,8 +14,7 @@ public:
void Close(); void Close();
int GetLength() const; int GetLength() const;
int GetLength_Fast() const { return GetLength(); } int GetLength_Fast() const { return GetLength(); }
int SetPosition_Accurate( int iFrame ) { return SetPosition(iFrame); } int SetPosition( int iFrame );
int SetPosition_Fast( int iFrame ) { return SetPosition(iFrame); }
int Read( char *pBuf, int iFrames ); int Read( char *pBuf, int iFrames );
int GetSampleRate() const { return m_WavData.m_iSampleRate; } int GetSampleRate() const { return m_WavData.m_iSampleRate; }
unsigned GetNumChannels() const { return m_WavData.m_iChannels; } unsigned GetNumChannels() const { return m_WavData.m_iChannels; }
@@ -37,8 +36,6 @@ private:
WavData m_WavData; WavData m_WavData;
WavReader *m_pImpl; WavReader *m_pImpl;
int SetPosition( int iFrame );
}; };
#endif #endif
+1 -1
View File
@@ -2304,8 +2304,8 @@ void ScreenEdit::TransitionEditState( EditState em )
RageSoundParams p; RageSoundParams p;
p.m_fSpeed = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; p.m_fSpeed = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;
p.m_StartSecond = fStartSeconds; p.m_StartSecond = fStartSeconds;
p.m_bAccurateSync = true;
p.StopMode = RageSoundParams::M_CONTINUE; p.StopMode = RageSoundParams::M_CONTINUE;
m_soundMusic.SetProperty( "AccurateSync", true );
m_soundMusic.Play( &p ); m_soundMusic.Play( &p );
break; break;
} }
+3 -2
View File
@@ -1323,8 +1323,9 @@ float ScreenGameplay::StartPlayingSong(float MinTimeToNotes, float MinTimeToMusi
fStartSecond = min(fStartSecond, -MinTimeToMusic); fStartSecond = min(fStartSecond, -MinTimeToMusic);
m_pSoundMusic->SetProperty( "AccurateSync", true );
RageSoundParams p; RageSoundParams p;
p.m_bAccurateSync = true;
p.m_fSpeed = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate; p.m_fSpeed = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;
p.StopMode = RageSoundParams::M_CONTINUE; p.StopMode = RageSoundParams::M_CONTINUE;
p.m_StartSecond = fStartSecond; p.m_StartSecond = fStartSecond;
@@ -1482,10 +1483,10 @@ void ScreenGameplay::BeginScreen()
NSMAN->StartRequest(1); NSMAN->StartRequest(1);
RageSoundParams p; RageSoundParams p;
p.m_bAccurateSync = true;
p.m_fSpeed = 1.0f; //Force 1.0 playback speed p.m_fSpeed = 1.0f; //Force 1.0 playback speed
p.StopMode = RageSoundParams::M_CONTINUE; p.StopMode = RageSoundParams::M_CONTINUE;
p.m_StartSecond = startOffset; p.m_StartSecond = startOffset;
m_pSoundMusic->SetProperty( "AccurateSync", true );
m_pSoundMusic->Play( &p ); m_pSoundMusic->Play( &p );
UpdateSongPosition(0); UpdateSongPosition(0);