don't use -1 as a sentinel position value; -1 is a valid frame number
improve GetPosition edge cases
This commit is contained in:
@@ -71,7 +71,7 @@ RageSound::RageSound()
|
|||||||
original = this;
|
original = this;
|
||||||
Sample = NULL;
|
Sample = NULL;
|
||||||
position = 0;
|
position = 0;
|
||||||
stopped_position = -1;
|
stopped_position = 0;
|
||||||
playing = false;
|
playing = false;
|
||||||
databuf.reserve(internal_buffer_size);
|
databuf.reserve(internal_buffer_size);
|
||||||
|
|
||||||
@@ -103,6 +103,7 @@ RageSound::RageSound(const RageSound &cpy):
|
|||||||
original = cpy.original;
|
original = cpy.original;
|
||||||
m_Param = cpy.m_Param;
|
m_Param = cpy.m_Param;
|
||||||
position = cpy.position;
|
position = cpy.position;
|
||||||
|
stopped_position = cpy.stopped_position;
|
||||||
playing = false;
|
playing = false;
|
||||||
|
|
||||||
databuf.reserve(internal_buffer_size);
|
databuf.reserve(internal_buffer_size);
|
||||||
@@ -150,7 +151,7 @@ bool RageSound::Load(CString sSoundFilePath, int precache)
|
|||||||
Unload();
|
Unload();
|
||||||
|
|
||||||
m_sFilePath = sSoundFilePath;
|
m_sFilePath = sSoundFilePath;
|
||||||
position = 0;
|
position = stopped_position = 0;
|
||||||
|
|
||||||
CString error;
|
CString error;
|
||||||
Sample = SoundReader_FileReader::OpenFile( m_sFilePath, error );
|
Sample = SoundReader_FileReader::OpenFile( m_sFilePath, error );
|
||||||
@@ -570,8 +571,6 @@ void RageSound::StartPlaying()
|
|||||||
if( m_Param.m_Volume == -1 )
|
if( m_Param.m_Volume == -1 )
|
||||||
m_Param.m_Volume = SOUNDMAN->GetMixVolume();
|
m_Param.m_Volume = SOUNDMAN->GetMixVolume();
|
||||||
|
|
||||||
stopped_position = -1;
|
|
||||||
|
|
||||||
ASSERT(!playing);
|
ASSERT(!playing);
|
||||||
|
|
||||||
/* If StartTime is in the past, then we probably set a start time but took too
|
/* If StartTime is in the past, then we probably set a start time but took too
|
||||||
@@ -591,7 +590,7 @@ void RageSound::StopPlaying()
|
|||||||
if(!playing)
|
if(!playing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
stopped_position = GetPositionSecondsInternal();
|
stopped_position = (int) GetPositionSecondsInternal();
|
||||||
|
|
||||||
/* Tell the sound manager to stop mixing this sound. */
|
/* Tell the sound manager to stop mixing this sound. */
|
||||||
SOUNDMAN->StopMixing(this);
|
SOUNDMAN->StopMixing(this);
|
||||||
@@ -712,11 +711,7 @@ int64_t RageSound::GetPositionSecondsInternal( bool *approximate ) const
|
|||||||
|
|
||||||
/* If we're not playing, just report the static position. */
|
/* If we're not playing, just report the static position. */
|
||||||
if( !IsPlaying() )
|
if( !IsPlaying() )
|
||||||
{
|
return stopped_position;
|
||||||
if(stopped_position != -1)
|
|
||||||
return stopped_position;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we don't yet have any position data, GetPCM hasn't yet been called at all,
|
/* If we don't yet have any position data, GetPCM hasn't yet been called at all,
|
||||||
* so guess what we think the real time is. */
|
* so guess what we think the real time is. */
|
||||||
@@ -725,7 +720,7 @@ int64_t RageSound::GetPositionSecondsInternal( bool *approximate ) const
|
|||||||
LOG->Trace("no data yet; %i", position);
|
LOG->Trace("no data yet; %i", position);
|
||||||
if( approximate )
|
if( approximate )
|
||||||
*approximate = true;
|
*approximate = true;
|
||||||
return position - int(samplerate()*SOUNDMAN->GetPlayLatency());
|
return stopped_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get our current hardware position. */
|
/* Get our current hardware position. */
|
||||||
@@ -767,9 +762,6 @@ float RageSound::GetPositionSeconds( bool *approximate, RageTimer *Timestamp ) c
|
|||||||
|
|
||||||
bool RageSound::SetPositionSeconds( float fSeconds )
|
bool RageSound::SetPositionSeconds( float fSeconds )
|
||||||
{
|
{
|
||||||
if( fSeconds == -1 )
|
|
||||||
fSeconds = m_Param.m_StartSecond;
|
|
||||||
|
|
||||||
return SetPositionFrames( int(fSeconds * samplerate()) );
|
return SetPositionFrames( int(fSeconds * samplerate()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,7 +792,7 @@ bool RageSound::SetPositionFrames( int frames )
|
|||||||
if( position == scaled_frames )
|
if( position == scaled_frames )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
position = scaled_frames;
|
stopped_position = position = scaled_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The position we're going to seek the input stream to. We have
|
/* The position we're going to seek the input stream to. We have
|
||||||
|
|||||||
@@ -152,8 +152,10 @@ private:
|
|||||||
/* Hack: When we stop a playing sound, we can't ask the driver the position
|
/* Hack: When we stop a playing sound, we can't ask the driver the position
|
||||||
* (we're not playing); and we can't seek back to the current playing position
|
* (we're not playing); and we can't seek back to the current playing position
|
||||||
* when we stop (too slow), but we want to be able to report the position we
|
* when we stop (too slow), but we want to be able to report the position we
|
||||||
* were at when we stopped without jumping to the last position we buffered. */
|
* were at when we stopped without jumping to the last position we buffered.
|
||||||
int64_t stopped_position;
|
* Keep track of the position after a seek or stop, so we can return a sane
|
||||||
|
* position when stopped, and when playing but pos_map hasn't yet been filled. */
|
||||||
|
int stopped_position;
|
||||||
bool playing;
|
bool playing;
|
||||||
|
|
||||||
/* Unique ID number for this instance of RageSound. */
|
/* Unique ID number for this instance of RageSound. */
|
||||||
|
|||||||
Reference in New Issue
Block a user