[Scummvm-cvs-logs] scummvm master -> 325f60cbd732b5a3d4e932063d764009ef7f8121

lordhoto lordhoto at gmail.com
Thu Jul 18 18:18:04 CEST 2013


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
96c4ebe77f SCUMM: Better Player_Mac::durationToSamples
325f60cbd7 Merge pull request #345 from countingpine/patch-1


Commit: 96c4ebe77fff9f23e085bb80a4907e6f857a96c2
    https://github.com/scummvm/scummvm/commit/96c4ebe77fff9f23e085bb80a4907e6f857a96c2
Author: countingpine (matthew.w.fearnley at gmail.com)
Date: 2013-07-16T08:16:08-07:00

Commit Message:
SCUMM: Better Player_Mac::durationToSamples

Uses the fact that 4*480*480 == 225 << 12, and the identity

(a*b)>>n == (a>>n)*b + ((a%(1<<n))*b)>>n (assuming non-overflowing math),

except the rhs uses smaller intermediate values and does not overflow(*).

Compared to the original code, this uses 1 fewer division and eliminates

the rounding error.



(*) Technical note: In some cases the right hand side of the above

identity still has possibilities of intermediate overflow, but only if

b > (1 << n), or if (b << n) overflows, neither of which are true here.

Changed paths:
    engines/scumm/player_mac.cpp



diff --git a/engines/scumm/player_mac.cpp b/engines/scumm/player_mac.cpp
index c16c85b..a60736d 100644
--- a/engines/scumm/player_mac.cpp
+++ b/engines/scumm/player_mac.cpp
@@ -289,12 +289,16 @@ uint32 Player_Mac::durationToSamples(uint16 duration) {
 	// (duration * 473 * _sampleRate) / (4 * 480 * 480)
 	//
 	// But that's likely to cause integer overflow, so we do it in two
-	// steps and hope that the rounding error won't be noticeable.
+	// steps using bitwise operations to perform
+	// ((duration * 473 * _sampleRate) / 4096) without overflowing,
+	// then divide this by 225
+	// (note that 4 * 480 * 480 == 225 * 4096 == 225 << 12)
 	//
 	// The original code is a bit unclear on if it should be 473 or 437,
 	// but since the comments indicated 473 I'm assuming 437 was a typo.
-	uint32 samples = (duration * _sampleRate) / (4 * 480);
-	samples = (samples * 473) / 480;
+	uint32 samples = (duration * _sampleRate);
+	samples = (samples >> 12) * 473 + (((samples & 4095) * 473) >> 12);
+	samples = samples / 225;
 	return samples;
 }
 


Commit: 325f60cbd732b5a3d4e932063d764009ef7f8121
    https://github.com/scummvm/scummvm/commit/325f60cbd732b5a3d4e932063d764009ef7f8121
Author: Johannes Schickel (lordhoto at gmail.com)
Date: 2013-07-18T09:17:23-07:00

Commit Message:
Merge pull request #345 from countingpine/patch-1

SCUMM: More precise Player_Mac::durationToSamples

Changed paths:
    engines/scumm/player_mac.cpp









More information about the Scummvm-git-logs mailing list