[Scummvm-cvs-logs] SF.net SVN: scummvm:[39112] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Mar 4 07:58:28 CET 2009
Revision: 39112
http://scummvm.svn.sourceforge.net/scummvm/?rev=39112&view=rev
Author: fingolfin
Date: 2009-03-04 06:58:28 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
Added Audio::Timestamp class, based on SCI's sfx_timestamp_t; also provide a unit test for it, based on the old (and very outdated) timetest.cpp. To be used by Audio::Mixer one day...
Modified Paths:
--------------
scummvm/trunk/sound/audiostream.h
scummvm/trunk/sound/module.mk
scummvm/trunk/test/module.mk
Added Paths:
-----------
scummvm/trunk/sound/timestamp.cpp
scummvm/trunk/sound/timestamp.h
scummvm/trunk/test/sound/
scummvm/trunk/test/sound/timestamp.h
Modified: scummvm/trunk/sound/audiostream.h
===================================================================
--- scummvm/trunk/sound/audiostream.h 2009-03-04 06:23:14 UTC (rev 39111)
+++ scummvm/trunk/sound/audiostream.h 2009-03-04 06:58:28 UTC (rev 39112)
@@ -59,6 +59,9 @@
/** Is this a stereo stream? */
virtual bool isStereo() const = 0;
+ /** Sample rate of the stream. */
+ virtual int getRate() const = 0;
+
/**
* End of data reached? If this returns true, it means that at this
* time there is no data available in the stream. However there may be
@@ -78,9 +81,6 @@
*/
virtual bool endOfStream() const { return endOfData(); }
- /** Sample rate of the stream. */
- virtual int getRate() const = 0;
-
/**
* Tries to load a file by trying all available formats.
* In case of an error, the file handle will be closed, but deleting
Modified: scummvm/trunk/sound/module.mk
===================================================================
--- scummvm/trunk/sound/module.mk 2009-03-04 06:23:14 UTC (rev 39111)
+++ scummvm/trunk/sound/module.mk 2009-03-04 06:58:28 UTC (rev 39112)
@@ -18,6 +18,7 @@
musicplugin.o \
null.o \
shorten.o \
+ timestamp.o \
voc.o \
vorbis.o \
wave.o \
Added: scummvm/trunk/sound/timestamp.cpp
===================================================================
--- scummvm/trunk/sound/timestamp.cpp (rev 0)
+++ scummvm/trunk/sound/timestamp.cpp 2009-03-04 06:58:28 UTC (rev 39112)
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "sound/timestamp.h"
+
+namespace Audio {
+
+Timestamp::Timestamp() :
+ _msecs(0), _frameRate(0), _frameOffset(0) {
+}
+
+Timestamp::Timestamp(uint32 m, int frameRate) :
+ _msecs(m), _frameRate(frameRate), _frameOffset(0) {
+}
+
+
+Timestamp Timestamp::addFrames(int frames) const {
+ Timestamp timestamp(*this);
+ timestamp._frameOffset += frames;
+
+ if (timestamp._frameOffset < 0) {
+ int secsub = 1 + (-timestamp._frameOffset / timestamp._frameRate);
+
+ timestamp._frameOffset += timestamp._frameRate * secsub;
+ timestamp._msecs -= secsub * 1000;
+ }
+
+ timestamp._msecs += (timestamp._frameOffset / timestamp._frameRate) * 1000;
+ timestamp._frameOffset %= timestamp._frameRate;
+
+ return timestamp;
+}
+
+int Timestamp::frameDiff(const Timestamp &b) const {
+ assert(_frameRate == b._frameRate);
+
+ int msecdelta = 0;
+ if (_msecs != b._msecs)
+ msecdelta = (long(_msecs) - long(b._msecs)) * _frameRate / 1000;
+
+ return msecdelta + _frameOffset - b._frameOffset;
+}
+
+int Timestamp::msecsDiff(const Timestamp &b) const {
+ return long(msecs()) - long(b.msecs());
+}
+
+uint32 Timestamp::msecs() const {
+ return _msecs + _frameOffset * 1000L / _frameRate;
+}
+
+
+} // End of namespace Audio
Property changes on: scummvm/trunk/sound/timestamp.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: scummvm/trunk/sound/timestamp.h
===================================================================
--- scummvm/trunk/sound/timestamp.h (rev 0)
+++ scummvm/trunk/sound/timestamp.h 2009-03-04 06:58:28 UTC (rev 39112)
@@ -0,0 +1,61 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SOUND_TIMESTAMP_H
+#define SOUND_TIMESTAMP_H
+
+#include "common/scummsys.h"
+
+
+namespace Audio {
+
+class Timestamp {
+protected:
+ uint32 _msecs;
+ int _frameRate;
+ int _frameOffset;
+ /* Total time: msecs + frame_offset/frame_rate */
+
+public:
+ Timestamp();
+ Timestamp(uint32 msecs, int frameRate);
+
+ /** Adds a number of frames to a timestamp. */
+ Timestamp addFrames(int frames) const;
+
+ /** Computes the difference (# of frames) between this timestamp and b. */
+ int frameDiff(const Timestamp &b) const;
+
+ /** Computes the difference (# of milliseconds) between this timestamp and b. */
+ int msecsDiff(const Timestamp &b) const;
+
+ /** Determines the time in milliseconds described by this timestamp. */
+ uint32 msecs() const;
+};
+
+
+} // End of namespace Audio
+
+#endif
Property changes on: scummvm/trunk/sound/timestamp.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: scummvm/trunk/test/module.mk
===================================================================
--- scummvm/trunk/test/module.mk 2009-03-04 06:23:14 UTC (rev 39111)
+++ scummvm/trunk/test/module.mk 2009-03-04 06:58:28 UTC (rev 39112)
@@ -5,8 +5,8 @@
#
######################################################################
-TESTS := test/common/*.h
-TEST_LIBS := common/libcommon.a
+TESTS := test/common/*.h test/sound/*.h
+TEST_LIBS := common/libcommon.a sound/libsound.a
#
TEST_FLAGS := --runner=StdioPrinter
Added: scummvm/trunk/test/sound/timestamp.h
===================================================================
--- scummvm/trunk/test/sound/timestamp.h (rev 0)
+++ scummvm/trunk/test/sound/timestamp.h 2009-03-04 06:58:28 UTC (rev 39112)
@@ -0,0 +1,34 @@
+#include <cxxtest/TestSuite.h>
+
+#include "sound/timestamp.h"
+
+class TimestampTestSuite : public CxxTest::TestSuite
+{
+ public:
+ void test_diff_add(void) {
+ Audio::Timestamp a(10000, 1000);
+ Audio::Timestamp b(10001, 1000);
+ Audio::Timestamp c(10002, 1000);
+
+ TS_ASSERT_EQUALS(a.frameDiff(b), -1);
+ TS_ASSERT_EQUALS(b.frameDiff(a), 1);
+ TS_ASSERT_EQUALS(c.frameDiff(a), 2);
+ TS_ASSERT_EQUALS(b.addFrames(2000).frameDiff(a), 2001);
+ TS_ASSERT_EQUALS(a.frameDiff(b), -1);
+ TS_ASSERT_EQUALS(b.frameDiff(a), 1);
+ TS_ASSERT_EQUALS(c.frameDiff(a), 2);
+ TS_ASSERT_EQUALS(b.addFrames(2000).frameDiff(a.addFrames(-1000)), 3001);
+ TS_ASSERT_EQUALS(a.frameDiff(b), -1);
+ TS_ASSERT_EQUALS(b.frameDiff(a), 1);
+ TS_ASSERT_EQUALS(c.frameDiff(a), 2);
+ }
+
+ void test_more_add_diff(void) {
+ const Audio::Timestamp c(10002, 1000);
+
+ for (int i = -10000; i < 10000; i++) {
+ int v = c.addFrames(i).frameDiff(c);
+ TS_ASSERT_EQUALS(v, i);
+ }
+ }
+};
Property changes on: scummvm/trunk/test/sound/timestamp.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list