[Scummvm-cvs-logs] SF.net SVN: scummvm: [27763] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Jun 28 22:09:58 CEST 2007


Revision: 27763
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27763&view=rev
Author:   fingolfin
Date:     2007-06-28 13:09:58 -0700 (Thu, 28 Jun 2007)

Log Message:
-----------
Changed GOB to use common/frac.h

Modified Paths:
--------------
    scummvm/trunk/common/frac.h
    scummvm/trunk/engines/gob/sound.cpp
    scummvm/trunk/engines/gob/sound.h

Modified: scummvm/trunk/common/frac.h
===================================================================
--- scummvm/trunk/common/frac.h	2007-06-28 19:48:41 UTC (rev 27762)
+++ scummvm/trunk/common/frac.h	2007-06-28 20:09:58 UTC (rev 27763)
@@ -46,6 +46,7 @@
  */
 typedef int32 frac_t;
 
-inline frac_t  intToFrac(int16 value) { return value << FRAC_BITS; }
+inline frac_t intToFrac(int16 value) { return value << FRAC_BITS; }
+inline int16 fracToInt(frac_t value) { return value >> FRAC_BITS; }
 
 #endif

Modified: scummvm/trunk/engines/gob/sound.cpp
===================================================================
--- scummvm/trunk/engines/gob/sound.cpp	2007-06-28 19:48:41 UTC (rev 27762)
+++ scummvm/trunk/engines/gob/sound.cpp	2007-06-28 20:09:58 UTC (rev 27763)
@@ -35,8 +35,6 @@
 
 namespace Gob {
 
-#define FRAC_BITS 16
-
 void SoundDesc::set(SoundType type, SoundSource src,
 		byte *data, uint32 dSize) {
 
@@ -174,9 +172,7 @@
 	_repCount = 0;
 
 	_offset = 0;
-	_offsetFrac = 0;
 	_offsetInc = 0;
-	_offsetIncFrac = 0;
 
 	_cur = 0;
 	_last = 0;
@@ -324,12 +320,8 @@
 	_playingSound = 1;
 
 	_offset = 0;
-	_offsetFrac = 0;
+	_offsetInc = (_freq << FRAC_BITS) / _rate;
 
-	uint32 incr = (_freq << FRAC_BITS) / _rate;
-	_offsetInc = incr >> FRAC_BITS;
-	_offsetIncFrac = incr & ((1UL << FRAC_BITS) - 1);
-
 	_last = _cur;
 	_cur = _data[0];
 
@@ -381,7 +373,6 @@
 		nextCompositionPos();
 	else if ((_repCount == -1) || (--_repCount > 0)) {
 		_offset = 0;
-		_offsetFrac = 0;
 		_end = false;
 		_playingSound = 1;
 	} else {
@@ -393,30 +384,26 @@
 int Snd::readBuffer(int16 *buffer, const int numSamples) {
 	Common::StackLock slock(_mutex);
 
-	int16 val;
-	uint32 tmp, oldOffset;
-
 	for (int i = 0; i < numSamples; i++) {
 		if (!_data)
 			return i;
-		if (_end || (_offset >= _length))
+		if (_end || (fracToInt(_offset) >= (int)_length))
 			checkEndSample();
 		if (_end)
 			return i;
 
 		// Linear interpolation. See sound/rate.cpp
 
-		val = (_last + (((_cur - _last) * _offsetFrac +
-					(1UL << (FRAC_BITS - 1))) >> FRAC_BITS)) << 8;
-		*buffer++ = (((int32) val) * _fadeVol) >> 16;
+		int32 val = (_last + (((_cur - _last) * (_offset & FRAC_LO_MASK) +
+					FRAC_HALF) >> FRAC_BITS)) << 8;
+		*buffer++ = (val * _fadeVol) >> 16;
 		
-		oldOffset = _offset;
+		int16 oldOffset = fracToInt(_offset);
 
-		tmp = _offsetFrac + _offsetIncFrac;
-		_offset += _offsetInc + (tmp >> FRAC_BITS);
-		_offsetFrac = tmp & ((1UL << FRAC_BITS) - 1);
+		_offset += _offsetInc;
 
-		if (oldOffset < _offset) {
+		// Was there an integral change?
+		if (oldOffset < fracToInt(_offset)) {
 			_last = _cur;
 			_cur = _data[oldOffset];
 		}

Modified: scummvm/trunk/engines/gob/sound.h
===================================================================
--- scummvm/trunk/engines/gob/sound.h	2007-06-28 19:48:41 UTC (rev 27762)
+++ scummvm/trunk/engines/gob/sound.h	2007-06-28 20:09:58 UTC (rev 27763)
@@ -27,6 +27,7 @@
 #define GOB_SOUND_H
 
 #include "common/mutex.h"
+#include "common/frac.h"
 #include "sound/audiostream.h"
 #include "sound/mixer.h"
 
@@ -174,10 +175,8 @@
 	int32 _freq;
 	int32 _repCount;
 
-	uint32 _offset;
-	uint32 _offsetFrac;
-	uint32 _offsetInc;
-	uint32 _offsetIncFrac;
+	frac_t _offset;
+	frac_t _offsetInc;
 
 	int16 _cur;
 	int16 _last;


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