add DeleteSoundWhenFinished, PlayCopyOfSound
This commit is contained in:
@@ -200,30 +200,37 @@ int RageSoundManager::GetDriverSampleRate( int rate ) const
|
|||||||
return driver->GetSampleRate( rate );
|
return driver->GetSampleRate( rate );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The return value of PlaySound and PlayCopyOfSound is only valid in the main
|
||||||
|
* thread, until the next call to Update(). After that, it may be deleted. */
|
||||||
RageSound *RageSoundManager::PlaySound( RageSound &snd, const RageSoundParams *params )
|
RageSound *RageSoundManager::PlaySound( RageSound &snd, const RageSoundParams *params )
|
||||||
{
|
{
|
||||||
RageSound *sound_to_play;
|
if( snd.IsPlaying() )
|
||||||
if(!snd.IsPlaying())
|
return PlayCopyOfSound( snd, params );
|
||||||
sound_to_play = &snd;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sound_to_play = new RageSound(snd);
|
|
||||||
|
|
||||||
/* We're responsible for freeing it. */
|
|
||||||
g_SoundManMutex.Lock(); /* lock for access to owned_sounds */
|
|
||||||
owned_sounds.insert(sound_to_play);
|
|
||||||
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
|
|
||||||
}
|
|
||||||
|
|
||||||
if( params )
|
if( params )
|
||||||
sound_to_play->SetParams( *params );
|
snd.SetParams( *params );
|
||||||
|
|
||||||
// Move to the start position.
|
// Move to the start position.
|
||||||
sound_to_play->SetPositionSeconds( sound_to_play->GetParams().m_StartSecond );
|
snd.SetPositionSeconds( snd.GetParams().m_StartSecond );
|
||||||
|
|
||||||
sound_to_play->StartPlaying();
|
snd.StartPlaying();
|
||||||
|
return &snd;
|
||||||
|
}
|
||||||
|
|
||||||
return sound_to_play;
|
RageSound *RageSoundManager::PlayCopyOfSound( RageSound &snd, const RageSoundParams *params )
|
||||||
|
{
|
||||||
|
RageSound *pSound = new RageSound(snd);
|
||||||
|
DeleteSoundWhenFinished( pSound );
|
||||||
|
|
||||||
|
if( params )
|
||||||
|
pSound->SetParams( *params );
|
||||||
|
|
||||||
|
// Move to the start position.
|
||||||
|
pSound->SetPositionSeconds( pSound->GetParams().m_StartSecond );
|
||||||
|
|
||||||
|
pSound->StartPlaying();
|
||||||
|
|
||||||
|
return pSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundManager::DeleteSound( RageSound *p )
|
void RageSoundManager::DeleteSound( RageSound *p )
|
||||||
@@ -231,10 +238,14 @@ void RageSoundManager::DeleteSound( RageSound *p )
|
|||||||
/* Stop playing the sound. */
|
/* Stop playing the sound. */
|
||||||
p->StopPlaying();
|
p->StopPlaying();
|
||||||
|
|
||||||
/* Add it to owned_sounds. It'll be deleted the next time we come around
|
/* We might be in a thread, so don't delete it here. */
|
||||||
* to Update(). */
|
DeleteSoundWhenFinished( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageSoundManager::DeleteSoundWhenFinished( RageSound *pSound )
|
||||||
|
{
|
||||||
g_SoundManMutex.Lock(); /* lock for access to owned_sounds */
|
g_SoundManMutex.Lock(); /* lock for access to owned_sounds */
|
||||||
owned_sounds.insert( p );
|
owned_sounds.insert( pSound );
|
||||||
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
|
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,9 +262,7 @@ void RageSoundManager::PlayOnce( CString sPath )
|
|||||||
/* We're responsible for freeing it. Add it to owned_sounds *after* we start
|
/* We're responsible for freeing it. Add it to owned_sounds *after* we start
|
||||||
* playing, so RageSoundManager::Update doesn't free it before we actually start
|
* playing, so RageSoundManager::Update doesn't free it before we actually start
|
||||||
* it. */
|
* it. */
|
||||||
g_SoundManMutex.Lock(); /* lock for access to owned_sounds */
|
DeleteSoundWhenFinished( snd );
|
||||||
owned_sounds.insert(snd);
|
|
||||||
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSoundManager::SetPrefs(float MixVol)
|
void RageSoundManager::SetPrefs(float MixVol)
|
||||||
|
|||||||
@@ -60,10 +60,12 @@ public:
|
|||||||
/* When deleting a sound from any thread except the one calling Update(), this
|
/* When deleting a sound from any thread except the one calling Update(), this
|
||||||
* must be used to prevent race conditions. */
|
* must be used to prevent race conditions. */
|
||||||
void DeleteSound( RageSound *p );
|
void DeleteSound( RageSound *p );
|
||||||
|
void DeleteSoundWhenFinished( RageSound *pSound );
|
||||||
|
|
||||||
void PlayOnce( CString sPath );
|
void PlayOnce( CString sPath );
|
||||||
|
|
||||||
RageSound *PlaySound( RageSound &snd, const RageSoundParams *params );
|
RageSound *PlaySound( RageSound &snd, const RageSoundParams *params = NULL );
|
||||||
|
RageSound *PlayCopyOfSound( RageSound &snd, const RageSoundParams *params = NULL );
|
||||||
|
|
||||||
static void AttenuateBuf( int16_t *buf, int samples, float vol );
|
static void AttenuateBuf( int16_t *buf, int samples, float vol );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user