SoundReader -> RageSoundReader
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
#ifndef RAGE_SOUND_READER_H
|
#ifndef RAGE_SOUND_READER_H
|
||||||
#define RAGE_SOUND_READER_H
|
#define RAGE_SOUND_READER_H
|
||||||
|
|
||||||
#define SoundReader RageSoundReader
|
|
||||||
class RageSoundReader
|
class RageSoundReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -12,8 +11,8 @@ public:
|
|||||||
virtual int SetPosition_Accurate( int ms ) = 0;
|
virtual int SetPosition_Accurate( int ms ) = 0;
|
||||||
virtual int SetPosition_Fast( int ms ) { return SetPosition_Accurate(ms); }
|
virtual int SetPosition_Fast( int ms ) { return SetPosition_Accurate(ms); }
|
||||||
virtual int Read(char *buf, unsigned len) = 0;
|
virtual int Read(char *buf, unsigned len) = 0;
|
||||||
virtual ~SoundReader() { }
|
virtual ~RageSoundReader() { }
|
||||||
virtual SoundReader *Copy() const = 0;
|
virtual RageSoundReader *Copy() const = 0;
|
||||||
virtual int GetSampleRate() const = 0;
|
virtual int GetSampleRate() const = 0;
|
||||||
virtual unsigned GetNumChannels() const { return 2; } /* 1 or 2 */
|
virtual unsigned GetNumChannels() const { return 2; } /* 1 or 2 */
|
||||||
virtual bool IsStreamingFromDisk() const = 0;
|
virtual bool IsStreamingFromDisk() const = 0;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ RageSoundReader_Chain::~RageSoundReader_Chain()
|
|||||||
while( !m_apActiveSounds.empty() )
|
while( !m_apActiveSounds.empty() )
|
||||||
ReleaseSound( 0 );
|
ReleaseSound( 0 );
|
||||||
|
|
||||||
map<RString, SoundReader *>::iterator it;
|
map<RString, RageSoundReader *>::iterator it;
|
||||||
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
@@ -49,12 +49,12 @@ bool RageSoundReader_Chain::AddSound( RString sPath, float fOffsetSecs, float fP
|
|||||||
{
|
{
|
||||||
sPath.MakeLower();
|
sPath.MakeLower();
|
||||||
|
|
||||||
map<RString, SoundReader *>::const_iterator it;
|
map<RString, RageSoundReader *>::const_iterator it;
|
||||||
it = m_apLoadedSounds.find( sPath );
|
it = m_apLoadedSounds.find( sPath );
|
||||||
if( it == m_apLoadedSounds.end() )
|
if( it == m_apLoadedSounds.end() )
|
||||||
{
|
{
|
||||||
RString error;
|
RString error;
|
||||||
SoundReader *pReader = SoundReader_FileReader::OpenFile( sPath, error );
|
RageSoundReader *pReader = SoundReader_FileReader::OpenFile( sPath, error );
|
||||||
if( pReader == NULL )
|
if( pReader == NULL )
|
||||||
{
|
{
|
||||||
LOG->Warn( "RageSoundReader_Chain: error opening sound \"%s\": %s",
|
LOG->Warn( "RageSoundReader_Chain: error opening sound \"%s\": %s",
|
||||||
@@ -80,7 +80,7 @@ int RageSoundReader_Chain::GetSampleRateInternal() const
|
|||||||
if( m_apLoadedSounds.empty() )
|
if( m_apLoadedSounds.empty() )
|
||||||
return m_iPreferredSampleRate;
|
return m_iPreferredSampleRate;
|
||||||
|
|
||||||
map<RString, SoundReader *>::const_iterator it;
|
map<RString, RageSoundReader *>::const_iterator it;
|
||||||
int iRate = -1;
|
int iRate = -1;
|
||||||
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
||||||
{
|
{
|
||||||
@@ -99,7 +99,7 @@ void RageSoundReader_Chain::Finish()
|
|||||||
{
|
{
|
||||||
sound &sound = m_Sounds[i];
|
sound &sound = m_Sounds[i];
|
||||||
|
|
||||||
map<RString, SoundReader *>::iterator it = m_apLoadedSounds.find( sound.sPath );
|
map<RString, RageSoundReader *>::iterator it = m_apLoadedSounds.find( sound.sPath );
|
||||||
if( it == m_apLoadedSounds.end() )
|
if( it == m_apLoadedSounds.end() )
|
||||||
{
|
{
|
||||||
m_Sounds.erase( m_Sounds.begin()+i );
|
m_Sounds.erase( m_Sounds.begin()+i );
|
||||||
@@ -111,7 +111,7 @@ void RageSoundReader_Chain::Finish()
|
|||||||
|
|
||||||
/* Figure out how many channels we have. */
|
/* Figure out how many channels we have. */
|
||||||
m_iChannels = 1;
|
m_iChannels = 1;
|
||||||
map<RString, SoundReader *>::iterator it;
|
map<RString, RageSoundReader *>::iterator it;
|
||||||
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
||||||
m_iChannels = max( m_iChannels, it->second->GetNumChannels() );
|
m_iChannels = max( m_iChannels, it->second->GetNumChannels() );
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ void RageSoundReader_Chain::Finish()
|
|||||||
{
|
{
|
||||||
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
||||||
{
|
{
|
||||||
SoundReader *&pSound = it->second;
|
RageSoundReader *&pSound = it->second;
|
||||||
|
|
||||||
RageSoundReader_Resample_Good *pResample = new RageSoundReader_Resample_Good( pSound, m_iPreferredSampleRate );
|
RageSoundReader_Resample_Good *pResample = new RageSoundReader_Resample_Good( pSound, m_iPreferredSampleRate );
|
||||||
pSound = pResample;
|
pSound = pResample;
|
||||||
@@ -143,7 +143,7 @@ void RageSoundReader_Chain::Finish()
|
|||||||
/* Attempt to preload all sounds. */
|
/* Attempt to preload all sounds. */
|
||||||
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
||||||
{
|
{
|
||||||
SoundReader *&pSound = it->second;
|
RageSoundReader *&pSound = it->second;
|
||||||
RageSoundReader_Preload::PreloadSound( pSound );
|
RageSoundReader_Preload::PreloadSound( pSound );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +169,9 @@ int RageSoundReader_Chain::SetPosition_Accurate( int ms )
|
|||||||
if( sound.iOffsetMS > ms )
|
if( sound.iOffsetMS > ms )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Find the SoundReader. */
|
/* Find the RageSoundReader. */
|
||||||
int n = ActivateSound( sound );
|
int n = ActivateSound( sound );
|
||||||
SoundReader *pSound = m_apActiveSounds[n].pSound;
|
RageSoundReader *pSound = m_apActiveSounds[n].pSound;
|
||||||
|
|
||||||
int iOffsetMS = ms - sound.iOffsetMS;
|
int iOffsetMS = ms - sound.iOffsetMS;
|
||||||
if( pSound->SetPosition_Accurate(iOffsetMS) == 0 )
|
if( pSound->SetPosition_Accurate(iOffsetMS) == 0 )
|
||||||
@@ -194,7 +194,7 @@ int RageSoundReader_Chain::SetPosition_Accurate( int ms )
|
|||||||
|
|
||||||
unsigned RageSoundReader_Chain::ActivateSound( const sound &s )
|
unsigned RageSoundReader_Chain::ActivateSound( const sound &s )
|
||||||
{
|
{
|
||||||
SoundReader *pSound = m_apLoadedSounds[s.sPath];
|
RageSoundReader *pSound = m_apLoadedSounds[s.sPath];
|
||||||
|
|
||||||
ActiveSound add;
|
ActiveSound add;
|
||||||
add.fPan = s.fPan;
|
add.fPan = s.fPan;
|
||||||
@@ -207,7 +207,7 @@ unsigned RageSoundReader_Chain::ActivateSound( const sound &s )
|
|||||||
void RageSoundReader_Chain::ReleaseSound( unsigned n )
|
void RageSoundReader_Chain::ReleaseSound( unsigned n )
|
||||||
{
|
{
|
||||||
ASSERT_M( n < m_apActiveSounds.size(), ssprintf("%u, %u", n, unsigned(m_apActiveSounds.size())) );
|
ASSERT_M( n < m_apActiveSounds.size(), ssprintf("%u, %u", n, unsigned(m_apActiveSounds.size())) );
|
||||||
SoundReader *pSound = m_apActiveSounds[n].pSound;
|
RageSoundReader *pSound = m_apActiveSounds[n].pSound;
|
||||||
|
|
||||||
delete pSound;
|
delete pSound;
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ void RageSoundReader_Chain::ReleaseSound( unsigned n )
|
|||||||
|
|
||||||
bool RageSoundReader_Chain::IsStreamingFromDisk() const
|
bool RageSoundReader_Chain::IsStreamingFromDisk() const
|
||||||
{
|
{
|
||||||
map<RString, SoundReader *>::const_iterator it;
|
map<RString, RageSoundReader *>::const_iterator it;
|
||||||
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
for( it = m_apLoadedSounds.begin(); it != m_apLoadedSounds.end(); ++it )
|
||||||
if( it->second->IsStreamingFromDisk() )
|
if( it->second->IsStreamingFromDisk() )
|
||||||
return true;
|
return true;
|
||||||
@@ -311,7 +311,7 @@ int RageSoundReader_Chain::ReadBlock( int16_t *pBuffer, int iFrames )
|
|||||||
for( unsigned i = 0; i < m_apActiveSounds.size(); )
|
for( unsigned i = 0; i < m_apActiveSounds.size(); )
|
||||||
{
|
{
|
||||||
ActiveSound &s = m_apActiveSounds[i];
|
ActiveSound &s = m_apActiveSounds[i];
|
||||||
SoundReader *pSound = s.pSound;
|
RageSoundReader *pSound = s.pSound;
|
||||||
int iSamples = min( iFramesToRead * pSound->GetNumChannels(), ARRAYLEN(Buffer) );
|
int iSamples = min( iFramesToRead * pSound->GetNumChannels(), ARRAYLEN(Buffer) );
|
||||||
int iBytesRead = pSound->Read( (char *) Buffer, iSamples*sizeof(int16_t) );
|
int iBytesRead = pSound->Read( (char *) Buffer, iSamples*sizeof(int16_t) );
|
||||||
if( iBytesRead == -1 || iBytesRead == 0 )
|
if( iBytesRead == -1 || iBytesRead == 0 )
|
||||||
@@ -390,7 +390,7 @@ int RageSoundReader_Chain::GetLength() const
|
|||||||
for( unsigned i = 0; i < m_Sounds.size(); ++i )
|
for( unsigned i = 0; i < m_Sounds.size(); ++i )
|
||||||
{
|
{
|
||||||
const sound &sound = m_Sounds[i];
|
const sound &sound = m_Sounds[i];
|
||||||
const SoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second;
|
const RageSoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second;
|
||||||
int iThisLength = pSound->GetLength();
|
int iThisLength = pSound->GetLength();
|
||||||
if( iThisLength )
|
if( iThisLength )
|
||||||
iLength = max( iLength, iThisLength + sound.iOffsetMS );
|
iLength = max( iLength, iThisLength + sound.iOffsetMS );
|
||||||
@@ -404,7 +404,7 @@ int RageSoundReader_Chain::GetLength_Fast() const
|
|||||||
for( unsigned i = 0; i < m_Sounds.size(); ++i )
|
for( unsigned i = 0; i < m_Sounds.size(); ++i )
|
||||||
{
|
{
|
||||||
const sound &sound = m_Sounds[i];
|
const sound &sound = m_Sounds[i];
|
||||||
const SoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second;
|
const RageSoundReader *pSound = m_apLoadedSounds.find( sound.sPath )->second;
|
||||||
int iThisLength = pSound->GetLength_Fast();
|
int iThisLength = pSound->GetLength_Fast();
|
||||||
if( iThisLength )
|
if( iThisLength )
|
||||||
iLength = max( iLength, iThisLength + sound.iOffsetMS );
|
iLength = max( iLength, iThisLength + sound.iOffsetMS );
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
class RageSoundReader_Chain: public SoundReader
|
class RageSoundReader_Chain: public RageSoundReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RageSoundReader_Chain();
|
RageSoundReader_Chain();
|
||||||
@@ -48,7 +48,7 @@ private:
|
|||||||
int m_iActualSampleRate;
|
int m_iActualSampleRate;
|
||||||
unsigned m_iChannels;
|
unsigned m_iChannels;
|
||||||
|
|
||||||
map<RString, SoundReader *> m_apLoadedSounds;
|
map<RString, RageSoundReader *> m_apLoadedSounds;
|
||||||
|
|
||||||
struct sound
|
struct sound
|
||||||
{
|
{
|
||||||
@@ -66,7 +66,7 @@ private:
|
|||||||
unsigned m_iNextSound;
|
unsigned m_iNextSound;
|
||||||
struct ActiveSound
|
struct ActiveSound
|
||||||
{
|
{
|
||||||
SoundReader *pSound;
|
RageSoundReader *pSound;
|
||||||
float fPan;
|
float fPan;
|
||||||
bool operator< ( const ActiveSound &rhs ) const { return pSound < rhs.pSound; }
|
bool operator< ( const ActiveSound &rhs ) const { return pSound < rhs.pSound; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ SoundReader_FileReader *SoundReader_FileReader::TryOpenFile( RString filename, R
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundReader *SoundReader_FileReader::OpenFile( RString filename, RString &error )
|
RageSoundReader *SoundReader_FileReader::OpenFile( RString filename, RString &error )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RageFile TestOpen;
|
RageFile TestOpen;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "RageSoundReader.h"
|
#include "RageSoundReader.h"
|
||||||
|
|
||||||
class SoundReader_FileReader: public SoundReader
|
class SoundReader_FileReader: public RageSoundReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
virtual bool IsStreamingFromDisk() const { return true; }
|
virtual bool IsStreamingFromDisk() const { return true; }
|
||||||
virtual float GetStreamToSourceRatio() const { return 1.0f; }
|
virtual float GetStreamToSourceRatio() const { return 1.0f; }
|
||||||
|
|
||||||
static SoundReader *OpenFile( RString filename, RString &error );
|
static RageSoundReader *OpenFile( RString filename, RString &error );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static SoundReader_FileReader *TryOpenFile( RString filename, RString &error, RString format, bool &bKeepTrying );
|
static SoundReader_FileReader *TryOpenFile( RString filename, RString &error, RString format, bool &bKeepTrying );
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
/* 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;
|
||||||
|
|
||||||
bool RageSoundReader_Preload::PreloadSound( SoundReader *&pSound )
|
bool RageSoundReader_Preload::PreloadSound( RageSoundReader *&pSound )
|
||||||
{
|
{
|
||||||
RageSoundReader_Preload *pPreload = new RageSoundReader_Preload;
|
RageSoundReader_Preload *pPreload = new RageSoundReader_Preload;
|
||||||
if( !pPreload->Open(pSound) )
|
if( !pPreload->Open(pSound) )
|
||||||
@@ -34,7 +34,7 @@ int RageSoundReader_Preload::GetTotalSamples() const
|
|||||||
return m_Buffer->size() / samplesize;
|
return m_Buffer->size() / samplesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RageSoundReader_Preload::Open( SoundReader *pSource )
|
bool RageSoundReader_Preload::Open( RageSoundReader *pSource )
|
||||||
{
|
{
|
||||||
ASSERT( pSource );
|
ASSERT( pSource );
|
||||||
m_iSampleRate = pSource->GetSampleRate();
|
m_iSampleRate = pSource->GetSampleRate();
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
#include "RageSoundReader.h"
|
#include "RageSoundReader.h"
|
||||||
#include "RageUtil_AutoPtr.h"
|
#include "RageUtil_AutoPtr.h"
|
||||||
|
|
||||||
class RageSoundReader_Preload: public SoundReader
|
class RageSoundReader_Preload: public RageSoundReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RageSoundReader_Preload();
|
RageSoundReader_Preload();
|
||||||
/* Return true if the sound has been preloaded, in which case source will
|
/* Return true if the sound has been preloaded, in which case source will
|
||||||
* be deleted. Otherwise, return false. */
|
* be deleted. Otherwise, return false. */
|
||||||
bool Open( SoundReader *pSource );
|
bool Open( RageSoundReader *pSource );
|
||||||
int GetLength() const;
|
int GetLength() const;
|
||||||
int GetLength_Fast() const;
|
int GetLength_Fast() const;
|
||||||
int SetPosition_Accurate( int iMS );
|
int SetPosition_Accurate( int iMS );
|
||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
~RageSoundReader_Preload() { }
|
~RageSoundReader_Preload() { }
|
||||||
|
|
||||||
/* Attempt to preload a sound. pSound must be rewound. */
|
/* Attempt to preload a sound. pSound must be rewound. */
|
||||||
static bool PreloadSound( SoundReader *&pSound );
|
static bool PreloadSound( RageSoundReader *&pSound );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AutoPtrCopyOnWrite<RString> m_Buffer;
|
AutoPtrCopyOnWrite<RString> m_Buffer;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ private:
|
|||||||
|
|
||||||
vector<RageSoundResampler_Polyphase *> m_apResamplers; /* one per channel */
|
vector<RageSoundResampler_Polyphase *> m_apResamplers; /* one per channel */
|
||||||
|
|
||||||
SoundReader *m_pSource;
|
RageSoundReader *m_pSource;
|
||||||
int m_iSampleRate;
|
int m_iSampleRate;
|
||||||
int m_iDownFactor;
|
int m_iDownFactor;
|
||||||
float m_fRate;
|
float m_fRate;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
static const int WINDOW_SIZE_MS = 30;
|
static const int WINDOW_SIZE_MS = 30;
|
||||||
|
|
||||||
RageSoundReader_SpeedChange::RageSoundReader_SpeedChange( SoundReader *pSource ):
|
RageSoundReader_SpeedChange::RageSoundReader_SpeedChange( RageSoundReader *pSource ):
|
||||||
RageSoundReader_Filter( pSource )
|
RageSoundReader_Filter( pSource )
|
||||||
{
|
{
|
||||||
m_Channels.resize( pSource->GetNumChannels() );
|
m_Channels.resize( pSource->GetNumChannels() );
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
class RageSoundReader_SpeedChange: public RageSoundReader_Filter
|
class RageSoundReader_SpeedChange: public RageSoundReader_Filter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RageSoundReader_SpeedChange( SoundReader *pSource );
|
RageSoundReader_SpeedChange( RageSoundReader *pSource );
|
||||||
|
|
||||||
virtual int SetPosition_Accurate( int ms );
|
virtual int SetPosition_Accurate( int ms );
|
||||||
virtual int SetPosition_Fast( int ms );
|
virtual int SetPosition_Fast( int ms );
|
||||||
|
|||||||
Reference in New Issue
Block a user