From 183c86e98c0ac8d78884509a012e5f99954e0d64 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Fri, 7 Feb 2014 00:41:51 -0800 Subject: 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 --- ym2612.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ym2612.c') diff --git a/ym2612.c b/ym2612.c index e56e7e7..978dc95 100644 --- a/ym2612.c +++ b/ym2612.c @@ -315,10 +315,13 @@ void ym_run(ym2612_context * context, uint32_t to_cycle) 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) { + if (operator->envelope > old_env) { + //Handle overflow operator->envelope = 0; + } + if (!operator->envelope) { operator->env_phase = PHASE_DECAY; } } else { -- cgit v1.2.3