diff options
author | Michael Pavone <pavone@retrodev.com> | 2014-02-07 00:41:51 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2014-02-07 00:41:51 -0800 |
commit | 183c86e98c0ac8d78884509a012e5f99954e0d64 (patch) | |
tree | 1b799cecb1cd94f9ac8d398e36df3221e9e3ab73 /ym2612.c | |
parent | 1911beda4d69363892cdc49189ae5ba35b1c1892 (diff) |
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
Diffstat (limited to 'ym2612.c')
-rw-r--r-- | ym2612.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 { |