GetNextStreamFrame, GetStreamToSourceRatio implementations

This commit is contained in:
Glenn Maynard
2006-11-29 08:15:22 +00:00
parent e6d5cbbd77
commit e3b98efd66
4 changed files with 45 additions and 1 deletions
+29
View File
@@ -224,6 +224,35 @@ bool RageSoundReader_Chain::IsStreamingFromDisk() const
return false;
}
int RageSoundReader_Chain::GetNextStreamFrame() const
{
return m_iCurrentFrame;
/* int iPosition = m_apActiveSounds[0].pSound->GetPosition();
for( unsigned i = 1; i < m_apActiveSounds.size(); )
{
if( m_apActiveSounds[i].pSound->GetPosition() != iPosition )
LOG->Warn( "RageSoundReader_Chain: sound positions moving at different rates" );
}
return iPosition;
*/
}
float RageSoundReader_Chain::GetStreamToSourceRatio() const
{
if( m_apActiveSounds.empty() )
return 1.0f;
float iRate = m_apActiveSounds[0].pSound->GetStreamToSourceRatio();
for( unsigned i = 1; i < m_apActiveSounds.size(); )
{
if( m_apActiveSounds[i].pSound->GetStreamToSourceRatio() != iRate )
LOG->Warn( "RageSoundReader_Chain: sound rates changing differently" );
}
return iRate;
}
/* Find the next sound we'll need to start, if any. m_Sounds is sorted by time. */
unsigned RageSoundReader_Chain::GetNextSoundIndex() const
{
+2
View File
@@ -36,6 +36,8 @@ public:
int GetSampleRate() const { return m_iActualSampleRate; }
unsigned GetNumChannels() const { return m_iChannels; }
bool IsStreamingFromDisk() const;
int GetNextStreamFrame() const;
float GetStreamToSourceRatio() const;
private:
int ReadBlock( int16_t *pBuffer, int iFrames );
+11 -1
View File
@@ -4,7 +4,7 @@
#include "global.h"
#include "RageSoundReader_Preload.h"
#define samplesize (2 * m_iChannels) /* 16-bit */
#define samplesize (sizeof(int16_t) * m_iChannels) /* 16-bit */
/* If a sound is smaller than this, we'll load it entirely into memory. */
const unsigned max_prebuf_size = 1024*256;
@@ -39,6 +39,7 @@ bool RageSoundReader_Preload::Open( SoundReader *pSource )
ASSERT( pSource );
m_iSampleRate = pSource->GetSampleRate();
m_iChannels = pSource->GetNumChannels();
m_fRate = pSource->GetStreamToSourceRatio();
/* Check the length, and see if we think it'll fit in the buffer. */
int iLen = pSource->GetLength_Fast();
@@ -55,6 +56,10 @@ bool RageSoundReader_Preload::Open( SoundReader *pSource )
while(1)
{
/* If the rate changes, we won't preload it. */
if( pSource->GetStreamToSourceRatio() != m_fRate )
return false; /* Don't bother trying to preload it. */
char buffer[1024];
int iCnt = pSource->Read(buffer, sizeof(buffer));
@@ -109,6 +114,11 @@ int RageSoundReader_Preload::SetPosition_Fast( int iMS )
return SetPosition_Accurate( iMS );
}
int RageSoundReader_Preload::GetNextStreamFrame() const
{
return m_iPosition / samplesize;
}
int RageSoundReader_Preload::Read( char *pBuffer, unsigned iLen )
{
const unsigned bytes_avail = m_Buffer->size() - m_iPosition;
+3
View File
@@ -21,6 +21,8 @@ public:
int GetSampleRate() const { return m_iSampleRate; }
unsigned GetNumChannels() const { return m_iChannels; }
bool IsStreamingFromDisk() const { return false; }
int GetNextStreamFrame() const;
float GetStreamToSourceRatio() const { return m_fRate; }
/* Return the total number of copies of this sound. (If 1 is returned,
* this is the last copy.) */
@@ -42,6 +44,7 @@ private:
int m_iSampleRate;
unsigned m_iChannels;
float m_fRate;
};
#endif