From 297a95557946555e5cc51279abafc0dc362af5f7 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 6 Jan 2010 15:40:49 +0000 Subject: - Simplify Audio::calculateSampleOffset. - Made Audio::calculateSampleOffset accessable from outside audiostream.cpp. - Adapt KYRA's AUDStream to use Audio::calculateSampleOffset. svn-id: r47082 --- sound/audiostream.cpp | 10 ++-------- sound/audiostream.h | 9 +++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'sound') diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index acd5398bfd..a3a00a4eba 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -109,14 +109,8 @@ inline int32 calculatePlayTime(int rate, int samples) { } uint32 calculateSampleOffset(const Timestamp &where, int rate) { - const uint32 msecs = where.msecs(); - - const Timestamp msecStamp(msecs, rate); - const uint32 seconds = msecs / 1000; - const uint32 millis = msecs % 1000; - const uint32 samples = msecStamp.frameDiff(where) + (millis * rate) / 1000; - - return seconds * rate + samples; + const Timestamp whereRate = where.convertToFramerate(rate); + return whereRate.secs() * rate + whereRate.getNumberOfFrames(); } /** diff --git a/sound/audiostream.h b/sound/audiostream.h index 8fc485bdb3..3889cffbb4 100644 --- a/sound/audiostream.h +++ b/sound/audiostream.h @@ -205,6 +205,15 @@ public: */ AppendableAudioStream *makeAppendableAudioStream(int rate, byte flags); +/** + * Calculates the sample, which the timestamp describes in a + * AudioStream with the given framerate. + * + * @param where point in time + * @param rate rate of the AudioStream + * @return sample index + */ +uint32 calculateSampleOffset(const Timestamp &where, int rate); } // End of namespace Audio -- cgit v1.2.3