GetNextStreamFrame implementations

This commit is contained in:
Glenn Maynard
2006-11-29 07:40:19 +00:00
parent b2bbf941fc
commit 0f9e6c9153
6 changed files with 48 additions and 0 deletions
+8
View File
@@ -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 )
+1
View File
@@ -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();
@@ -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;
@@ -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;
+29
View File
@@ -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 );
+1
View File
@@ -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 */