changeset 513:24ebabd89162

Properly clamp envelope value to zero when it overflows during the attack phase. This fixes a number of instruments that sounded rather wrong as well as the missing melody line from Mushroom Hill Zone in Sonic and Knuckles
author Michael Pavone <pavone@retrodev.com>
date Fri, 07 Feb 2014 00:41:51 -0800
parents 6800d30437c9
children f66c78cbdcaa
files ym2612.c
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ym2612.c	Fri Feb 07 00:21:56 2014 -0800
+++ b/ym2612.c	Fri Feb 07 00:41:51 2014 -0800
@@ -315,10 +315,13 @@
 					if (first_key_on) {
 						dfprintf(debug_file, "Changing op %d envelope %d by %d(%d * %d) in attack phase\n", op, operator->envelope, (~operator->envelope * envelope_inc) >> 4, ~operator->envelope, envelope_inc);
 					}
+					uint16_t old_env = operator->envelope;
 					operator->envelope += (~operator->envelope * envelope_inc) >> 4;
-					operator->envelope &= MAX_ENVELOPE;
+					if (operator->envelope > old_env) {
+						//Handle overflow
+						operator->envelope = 0;
+					}
 					if (!operator->envelope) {
-						operator->envelope = 0;
 						operator->env_phase = PHASE_DECAY;
 					}
 				} else {