From fd6c729f519315bdbeaa7ecb0fdac15480047a26 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 10 Jan 2004 10:41:29 +0000 Subject: [PATCH] add StartTime, GetPositionSeconds(*approximate) --- stepmania/src/RageSound.cpp | 18 ++++++++++++++---- stepmania/src/RageSound.h | 11 +++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 47f0153e7b..60f3402c98 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -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; } diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index a3f44f5e8a..902fb3bbda 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -2,6 +2,7 @@ #define RAGE_SOUND_OBJ_H #include +#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);