Mercurial > repos > blastem
diff ym2612.c @ 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 | b7b7a1cab44a |
children | 7565ec2ac652 |
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 {