Working on clean pausing support. (This will break the ALSA and DSound hardware builds until they're updated, soon.)

This commit is contained in:
Glenn Maynard
2005-03-10 22:49:28 +00:00
parent 93947f375a
commit ef68b4acdd
7 changed files with 54 additions and 0 deletions
+6
View File
@@ -643,6 +643,12 @@ void RageSound::Stop()
StopPlaying();
}
bool RageSound::Pause( bool bPause )
{
ASSERT( Sample );
return SOUNDMAN->Pause( this, bPause );
}
float RageSound::GetLengthSeconds()
{
+4
View File
@@ -108,6 +108,10 @@ public:
RageSound *Play( const RageSoundParams *params=NULL );
void Stop();
/* Cleanly pause or unpause the sound. If the sound wasn't already playing,
* return true and do nothing. */
bool Pause( bool bPause );
float GetLengthSeconds();
float GetPositionSeconds( bool *approximate=NULL, RageTimer *Timestamp=NULL ) const;
int GetSampleRate() const;
+8
View File
@@ -81,6 +81,14 @@ void RageSoundManager::StopMixing( RageSoundBase *snd )
driver->StopMixing(snd);
}
bool RageSoundManager::Pause( RageSoundBase *snd, bool bPause )
{
if( driver == NULL )
return false;
else
return driver->PauseMixing( snd, bPause );
}
int64_t RageSoundManager::GetPosition( const RageSoundBase *snd ) const
{
if( driver == NULL )
+1
View File
@@ -32,6 +32,7 @@ public:
void Update(float delta);
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
bool Pause( RageSoundBase *snd, bool bPause ); /* used by RageSound */
int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */
void RegisterSound( RageSound *p ); /* used by RageSound */
void UnregisterSound( RageSound *p ); /* used by RageSound */
@@ -21,6 +21,13 @@ public:
* snd was not actually being played, though it may print a warning. */
virtual void StopMixing( RageSoundBase *snd ) = 0;
/* Pause or unpause the given sound. If the sound was stopped (not paused),
* return false and do nothing; otherwise return true and pause or unpause
* the sound. Unlike StopMixing, pausing and unpause a sound will not lose
* any buffered sound (but will not release any resources associated with
* playing the sound, either). */
virtual bool PauseMixing( RageSoundBase *snd, bool bStop ) = 0;
/* Get the current position of a given buffer, in the same units and time base
* as passed to RageSound::GetPCM. */
virtual int64_t GetPosition( const RageSoundBase *snd ) const = 0;
@@ -26,6 +26,7 @@ RageSound_Generic_Software::sound::sound()
snd = NULL;
state = STOPPED;
available = true;
paused = false;
}
void RageSound_Generic_Software::sound::Allocate( int frames )
@@ -82,6 +83,9 @@ void RageSound_Generic_Software::Mix( int16_t *buf, int frames, int64_t frameno,
continue;
/* STOPPING or PLAYING. Read sound data. */
if( sounds[i].paused )
continue;
int got_frames = 0;
int frames_left = frames;
@@ -397,6 +401,27 @@ void RageSound_Generic_Software::StopMixing( RageSoundBase *snd )
}
bool RageSound_Generic_Software::PauseMixing( RageSoundBase *snd, bool bStop )
{
LockMut( m_Mutex );
/* Find the sound. */
unsigned i;
for( i = 0; i < ARRAYSIZE(sounds); ++i )
if( !sounds[i].available && sounds[i].snd == snd )
break;
if( i == ARRAYSIZE(sounds) )
{
LOG->Trace( "not pausing a sound because it's not playing" );
return false;
}
sounds[i].paused = bStop;
return true;
}
void RageSound_Generic_Software::StartDecodeThread()
{
ASSERT( !m_DecodeThread.IsCreated() );
@@ -14,6 +14,7 @@ public:
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
bool PauseMixing( RageSoundBase *snd, bool bStop );
RageSound_Generic_Software();
virtual ~RageSound_Generic_Software();
@@ -107,6 +108,8 @@ private:
/* If true, this sound is in STOPPED and available for use. */
bool available;
bool paused;
enum
{
STOPPED, /* idle */