add StartTime, GetPositionSeconds(*approximate)

This commit is contained in:
Glenn Maynard
2004-01-10 10:41:29 +00:00
parent fec182d23b
commit fd6c729f51
2 changed files with 23 additions and 6 deletions
+14 -4
View File
@@ -108,6 +108,7 @@ RageSound::RageSound(const RageSound &cpy)
position = cpy.position;
playing = false;
AccurateSync = cpy.AccurateSync;
StartTime = cpy.StartTime;
fade_length = cpy.fade_length;
speed_input_samples = cpy.speed_input_samples;
speed_output_samples = cpy.speed_output_samples;
@@ -554,11 +555,16 @@ float RageSound::GetLengthSeconds()
return len / 1000.f; /* ms -> secs */
}
/* Get the position in samples, not counting GetOffsetFix, playback rate. */
int RageSound::GetPositionSecondsInternal() const
/* Get the position in frames (ignoring GetOffsetFix). approximate is set to true
* if the returned time is approximated because of underrun, the sound not having started
* (after Play()) or finished (after EOF) yet. */
int RageSound::GetPositionSecondsInternal( bool *approximate ) const
{
LockMut(SOUNDMAN->lock);
if( approximate )
*approximate = false;
/* If we're not playing, just report the static position. */
if( !IsPlaying() )
{
@@ -572,6 +578,8 @@ int RageSound::GetPositionSecondsInternal() const
if(pos_map.empty())
{
LOG->Trace("no data yet; %i", position);
if( approximate )
*approximate = true;
return position - int(samplerate()*SOUNDMAN->GetPlayLatency());
}
@@ -620,12 +628,14 @@ int RageSound::GetPositionSecondsInternal() const
*/
LOG->Trace("Approximate sound time: sample %i, dist %i, closest %i", cur_sample, closest_position_dist, closest_position);
if( approximate )
*approximate = true;
return closest_position;
}
float RageSound::GetPositionSeconds() const
float RageSound::GetPositionSeconds( bool *approximate ) const
{
const float pos = GetPositionSecondsInternal() / float(samplerate());
const float pos = GetPositionSecondsInternal( approximate ) / float(samplerate());
const float fixed_pos = pos + Sample->GetOffsetFix();
return GetPlaybackRate() * fixed_pos;
}
+9 -2
View File
@@ -2,6 +2,7 @@
#define RAGE_SOUND_OBJ_H
#include <deque>
#include "RageTimer.h"
class CircBuf
{
@@ -70,7 +71,7 @@ public:
void Stop();
float GetLengthSeconds();
float GetPositionSeconds() const;
float GetPositionSeconds( bool *approximate=NULL ) const;
int GetSampleRate() const;
bool SetPositionSeconds( float fSeconds = -1);
void SetAccurateSync(bool yes=true) { AccurateSync = yes; }
@@ -80,6 +81,8 @@ public:
float GetPlaybackRate() const { return float(speed_input_samples) / speed_output_samples; }
bool IsPlaying() const { return playing; }
CString GetLoadedFilePath() const { return m_sFilePath; }
void SetStartTime( const RageTimer &tm ) { StartTime = tm; }
RageTimer GetStartTime() const { return StartTime; }
private:
/* If we were copied from another RageSound, this will point to it; otherwise
@@ -130,9 +133,13 @@ private:
int speed_input_samples, speed_output_samples;
bool AccurateSync;
/* Optional driver feature: time to actually start playing sounds. If zero, or if not
* supported, it'll start immediately. */
RageTimer StartTime;
CString error;
int GetPositionSecondsInternal() const;
int GetPositionSecondsInternal( bool *approximate=NULL ) const;
bool SetPositionSamples( int samples = -1 );
int GetData(char *buffer, int size);
void Fail(CString reason);