[Scummvm-cvs-logs] CVS: scummvm/backends/midi ym2612.cpp,1.6,1.7

Max Horn fingolfin at users.sourceforge.net
Mon Oct 6 05:34:34 CEST 2003


Update of /cvsroot/scummvm/scummvm/backends/midi
In directory sc8-pr-cvs1:/tmp/cvs-serv22866

Modified Files:
	ym2612.cpp 
Log Message:
some incremental changes (more will follow, this is step-by-step optimzation, watch it happen in pseudo-real-time and color. icecream is sold at the entrance, please stop smoking

Index: ym2612.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/midi/ym2612.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ym2612.cpp	6 Oct 2003 04:41:25 -0000	1.6
+++ ym2612.cpp	6 Oct 2003 12:33:40 -0000	1.7
@@ -315,16 +315,17 @@
 void Operator2612::nextTick(uint16 rate, const int *phasebuf, int *outbuf, int buflen) {
 	if (_state == _s_ready)
 		return;
-	if (_state == _s_attacking && _attackTime <= 0)
+	if (_state == _s_attacking && _attackTime <= 0) {
+		_currentLevel = 0;
 		_state = _s_decaying;
+	}
 
-	int32 increment;
+	int32 levelIncrement;
 	int32 target;
 	State next_state;
-	bool switching;
+	const int32 zero_level = ((int32)0x7f << 15);
 
 	while (buflen) {
-		switching = false;
 		switch (_state) {
 		case _s_ready:
 			return;
@@ -333,23 +334,24 @@
 			next_state = _s_attacking;
 			break;
 		case _s_decaying:
-			increment = _decayRate;
+			levelIncrement = _decayRate;
 			target = _sustainLevel;
 			next_state = _s_sustaining;
 			break;
 		case _s_sustaining:
-			increment = _sustainRate;
-			target = ((int32)0x7f << 15);
+			levelIncrement = _sustainRate;
+			target = zero_level;
 			next_state = _s_ready;
 			break;
 		case _s_releasing:
-			increment = _releaseRate;
-			target = ((int32)0x7f << 15);
+			levelIncrement = _releaseRate;
+			target = zero_level;
 			next_state = _s_ready;
 			break;
 		}
 
-		for (; buflen && !switching; --buflen, ++phasebuf, ++outbuf) {
+		bool switching = false;
+		do {
 			if (next_state == _s_attacking) {
 				// Attack phase
 				++_tickCount;
@@ -369,7 +371,7 @@
 				}
 			} else {
 				// Decay, Sustain and Release phases
-				_currentLevel += increment;
+				_currentLevel += levelIncrement;
 				if (_currentLevel >= target) {
 					_currentLevel = target;
 					_state = next_state;
@@ -379,7 +381,7 @@
 
 			int32 level = _currentLevel + _totalLevel;
 			int32 output = 0;
-			if (level < ((int32)0x7f << 15)) {
+			if (level < zero_level) {
 				_phase &= 0x3ffff;
 				int phaseShift = *phasebuf >> 2; // Àµ¤·¤¤ÊÑÄ´Î̤Ï?  3 ¤¸¤ã¾®¤µ¤¹¤®¤Ç 2 ¤¸¤ãÂ礭¤¤¤è¤¦¤Ê¡£
 				if (_feedbackLevel)
@@ -410,7 +412,10 @@
 
 			_lastOutput = output;
 			*outbuf += output;
-		}
+			 --buflen;
+			 ++phasebuf;
+			 ++outbuf;
+		} while (buflen && !switching);
 	}
 }
 





More information about the Scummvm-git-logs mailing list