give each RageSound instance a unique ID
This commit is contained in:
@@ -75,8 +75,8 @@ RageSound::RageSound()
|
|||||||
playing = false;
|
playing = false;
|
||||||
databuf.reserve(internal_buffer_size);
|
databuf.reserve(internal_buffer_size);
|
||||||
|
|
||||||
/* Register ourselves, so we receive Update()s. */
|
/* Register ourself, so we have a unique ID and receive Update()s. */
|
||||||
SOUNDMAN->all_sounds.insert(this);
|
ID = SOUNDMAN->RegisterSound( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound::~RageSound()
|
RageSound::~RageSound()
|
||||||
@@ -88,10 +88,8 @@ RageSound::~RageSound()
|
|||||||
|
|
||||||
Unload();
|
Unload();
|
||||||
|
|
||||||
/* Unregister ourselves. */
|
/* Unregister ourself. */
|
||||||
SOUNDMAN->lock.Lock();
|
SOUNDMAN->UnregisterSound( this );
|
||||||
SOUNDMAN->all_sounds.erase(this);
|
|
||||||
SOUNDMAN->lock.Unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RageSound::RageSound(const RageSound &cpy):
|
RageSound::RageSound(const RageSound &cpy):
|
||||||
@@ -114,8 +112,9 @@ RageSound::RageSound(const RageSound &cpy):
|
|||||||
* copy this down here. */
|
* copy this down here. */
|
||||||
m_sFilePath = cpy.m_sFilePath;
|
m_sFilePath = cpy.m_sFilePath;
|
||||||
|
|
||||||
/* Register ourselves, so we receive Update()s. */
|
/* Register ourselves, so we receive Update()s. We have a different ID than
|
||||||
SOUNDMAN->all_sounds.insert(this);
|
* our parent. */
|
||||||
|
ID = SOUNDMAN->RegisterSound( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSound::Unload()
|
void RageSound::Unload()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public:
|
|||||||
virtual int GetSampleRate() const = 0;
|
virtual int GetSampleRate() const = 0;
|
||||||
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
|
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
|
||||||
virtual float GetVolume() const = 0;
|
virtual float GetVolume() const = 0;
|
||||||
|
virtual int GetID() const = 0;
|
||||||
virtual CString GetLoadedFilePath() const = 0;
|
virtual CString GetLoadedFilePath() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,6 +107,7 @@ public:
|
|||||||
float GetPlaybackRate() const;
|
float GetPlaybackRate() const;
|
||||||
RageTimer GetStartTime() const;
|
RageTimer GetStartTime() const;
|
||||||
float GetVolume() const;
|
float GetVolume() const;
|
||||||
|
int GetID() const { return ID; }
|
||||||
void SetParams( const RageSoundParams &p );
|
void SetParams( const RageSoundParams &p );
|
||||||
const RageSoundParams &GetParams() const { return m_Param; }
|
const RageSoundParams &GetParams() const { return m_Param; }
|
||||||
|
|
||||||
@@ -152,6 +154,9 @@ private:
|
|||||||
int64_t stopped_position;
|
int64_t stopped_position;
|
||||||
bool playing;
|
bool playing;
|
||||||
|
|
||||||
|
/* Unique ID number for this instance of RageSound. */
|
||||||
|
int ID;
|
||||||
|
|
||||||
CString error;
|
CString error;
|
||||||
|
|
||||||
int64_t GetPositionSecondsInternal( bool *approximate=NULL ) const;
|
int64_t GetPositionSecondsInternal( bool *approximate=NULL ) const;
|
||||||
|
|||||||
@@ -88,6 +88,23 @@ void RageSoundManager::Update(float delta)
|
|||||||
driver->Update(delta);
|
driver->Update(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Register the given sound, and return a unique ID. */
|
||||||
|
int RageSoundManager::RegisterSound( RageSound *p )
|
||||||
|
{
|
||||||
|
LockMut(lock);
|
||||||
|
|
||||||
|
all_sounds.insert( p );
|
||||||
|
|
||||||
|
static int iID = 0;
|
||||||
|
return ++iID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageSoundManager::UnregisterSound( RageSound *p )
|
||||||
|
{
|
||||||
|
LockMut(lock);
|
||||||
|
all_sounds.erase( p );
|
||||||
|
}
|
||||||
|
|
||||||
float RageSoundManager::GetPlayLatency() const
|
float RageSoundManager::GetPlayLatency() const
|
||||||
{
|
{
|
||||||
return driver->GetPlayLatency();
|
return driver->GetPlayLatency();
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ public:
|
|||||||
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
|
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
|
||||||
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
|
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
|
||||||
int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */
|
int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */
|
||||||
|
int RegisterSound( RageSound *p ); /* used by RageSound */
|
||||||
|
void UnregisterSound( RageSound *p ); /* used by RageSound */
|
||||||
float GetPlayLatency() const;
|
float GetPlayLatency() const;
|
||||||
int GetDriverSampleRate( int rate ) const;
|
int GetDriverSampleRate( int rate ) const;
|
||||||
const set<RageSound *> &GetPlayingSounds() const { return playing_sounds; }
|
const set<RageSound *> &GetPlayingSounds() const { return playing_sounds; }
|
||||||
|
|||||||
Reference in New Issue
Block a user