summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2014-02-07 00:41:51 -0800
committerMichael Pavone <pavone@retrodev.com>2014-02-07 00:41:51 -0800
commit183c86e98c0ac8d78884509a012e5f99954e0d64 (patch)
tree1b799cecb1cd94f9ac8d398e36df3221e9e3ab73
parent1911beda4d69363892cdc49189ae5ba35b1c1892 (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
-rw-r--r--ym2612.c7
1 files changed, 5 insertions, 2 deletions
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 {