From b53261743475662dd1c3ac080c84f7c26c5c26aa Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 3 Oct 2003 09:00:02 +0000 Subject: [PATCH] simplify --- stepmania/src/RageSound.cpp | 17 +++++++++-------- stepmania/src/RageSound.h | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index 630eaa1370..7f6626a437 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -555,8 +555,8 @@ float RageSound::GetLengthSeconds() return len / 1000.f; /* ms -> secs */ } -/* Get the position, not counting GetOffsetFix. */ -float RageSound::GetPositionSecondsInternal() const +/* Get the position in samples, not counting GetOffsetFix, playback rate. */ +int RageSound::GetPositionSecondsInternal() const { LockMut(SOUNDMAN->lock); @@ -565,7 +565,7 @@ float RageSound::GetPositionSecondsInternal() const { if(stopped_position != -1) return stopped_position; - return position / float(samplerate()); + return position; } /* If we don't yet have any position data, GetPCM hasn't yet been called at all, @@ -573,7 +573,7 @@ float RageSound::GetPositionSecondsInternal() const if(pos_map.empty()) { LOG->Trace("no data yet; %i", position); - return position / float(samplerate()); + return position; } /* Get our current hardware position. */ @@ -590,7 +590,7 @@ float RageSound::GetPositionSecondsInternal() const /* cur_sample lies in this block; it's an exact match. Figure * out the exact position. */ int diff = pos_map[i].position - pos_map[i].sampleno; - return float(cur_sample + diff) / samplerate(); + return cur_sample + diff; } /* See if the current position is close to the beginning of this block. */ @@ -621,13 +621,14 @@ float RageSound::GetPositionSecondsInternal() const */ LOG->Trace("Approximate sound time: sample %i, dist %i, closest %i", cur_sample, closest_position_dist, closest_position); - return closest_position / float(samplerate()); + return closest_position; } float RageSound::GetPositionSeconds() const { - const float ret = GetPositionSecondsInternal() + Sample->GetOffsetFix(); - return GetPlaybackRate() * ret; + const float pos = GetPositionSecondsInternal() / 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 c6f6036c61..a3f44f5e8a 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -122,7 +122,7 @@ private: * (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 * were at when we stopped without jumping to the last position we buffered. */ - float stopped_position; + int stopped_position; bool playing; /* Number of samples input and output when changing speed. Currently, @@ -132,7 +132,7 @@ private: CString error; - float GetPositionSecondsInternal() const; + int GetPositionSecondsInternal() const; bool SetPositionSamples( int samples = -1 ); int GetData(char *buffer, int size); void Fail(CString reason);