GetNextStreamFrame, GetStreamToSourceRatio implementations
This commit is contained in:
@@ -224,6 +224,35 @@ bool RageSoundReader_Chain::IsStreamingFromDisk() const
|
|||||||
return false;
|
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. */
|
/* Find the next sound we'll need to start, if any. m_Sounds is sorted by time. */
|
||||||
unsigned RageSoundReader_Chain::GetNextSoundIndex() const
|
unsigned RageSoundReader_Chain::GetNextSoundIndex() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ public:
|
|||||||
int GetSampleRate() const { return m_iActualSampleRate; }
|
int GetSampleRate() const { return m_iActualSampleRate; }
|
||||||
unsigned GetNumChannels() const { return m_iChannels; }
|
unsigned GetNumChannels() const { return m_iChannels; }
|
||||||
bool IsStreamingFromDisk() const;
|
bool IsStreamingFromDisk() const;
|
||||||
|
int GetNextStreamFrame() const;
|
||||||
|
float GetStreamToSourceRatio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ReadBlock( int16_t *pBuffer, int iFrames );
|
int ReadBlock( int16_t *pBuffer, int iFrames );
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "RageSoundReader_Preload.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. */
|
/* If a sound is smaller than this, we'll load it entirely into memory. */
|
||||||
const unsigned max_prebuf_size = 1024*256;
|
const unsigned max_prebuf_size = 1024*256;
|
||||||
@@ -39,6 +39,7 @@ bool RageSoundReader_Preload::Open( SoundReader *pSource )
|
|||||||
ASSERT( pSource );
|
ASSERT( pSource );
|
||||||
m_iSampleRate = pSource->GetSampleRate();
|
m_iSampleRate = pSource->GetSampleRate();
|
||||||
m_iChannels = pSource->GetNumChannels();
|
m_iChannels = pSource->GetNumChannels();
|
||||||
|
m_fRate = pSource->GetStreamToSourceRatio();
|
||||||
|
|
||||||
/* Check the length, and see if we think it'll fit in the buffer. */
|
/* Check the length, and see if we think it'll fit in the buffer. */
|
||||||
int iLen = pSource->GetLength_Fast();
|
int iLen = pSource->GetLength_Fast();
|
||||||
@@ -55,6 +56,10 @@ bool RageSoundReader_Preload::Open( SoundReader *pSource )
|
|||||||
|
|
||||||
while(1)
|
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];
|
char buffer[1024];
|
||||||
int iCnt = pSource->Read(buffer, sizeof(buffer));
|
int iCnt = pSource->Read(buffer, sizeof(buffer));
|
||||||
|
|
||||||
@@ -109,6 +114,11 @@ int RageSoundReader_Preload::SetPosition_Fast( int iMS )
|
|||||||
return SetPosition_Accurate( iMS );
|
return SetPosition_Accurate( iMS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RageSoundReader_Preload::GetNextStreamFrame() const
|
||||||
|
{
|
||||||
|
return m_iPosition / samplesize;
|
||||||
|
}
|
||||||
|
|
||||||
int RageSoundReader_Preload::Read( char *pBuffer, unsigned iLen )
|
int RageSoundReader_Preload::Read( char *pBuffer, unsigned iLen )
|
||||||
{
|
{
|
||||||
const unsigned bytes_avail = m_Buffer->size() - m_iPosition;
|
const unsigned bytes_avail = m_Buffer->size() - m_iPosition;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public:
|
|||||||
int GetSampleRate() const { return m_iSampleRate; }
|
int GetSampleRate() const { return m_iSampleRate; }
|
||||||
unsigned GetNumChannels() const { return m_iChannels; }
|
unsigned GetNumChannels() const { return m_iChannels; }
|
||||||
bool IsStreamingFromDisk() const { return false; }
|
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,
|
/* Return the total number of copies of this sound. (If 1 is returned,
|
||||||
* this is the last copy.) */
|
* this is the last copy.) */
|
||||||
@@ -42,6 +44,7 @@ private:
|
|||||||
|
|
||||||
int m_iSampleRate;
|
int m_iSampleRate;
|
||||||
unsigned m_iChannels;
|
unsigned m_iChannels;
|
||||||
|
float m_fRate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user