changeset 1802:1d1198f16279

Fix a couple of minor cases of extra precision in LFO implementation
author Michael Pavone <pavone@retrodev.com>
date Tue, 26 Mar 2019 22:27:23 -0700
parents 2efdace4fb8a
children a851d36e24bb
files ym2612.c
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ym2612.c	Mon Mar 25 23:34:52 2019 -0700
+++ b/ym2612.c	Tue Mar 26 22:27:23 2019 -0700
@@ -519,7 +519,7 @@
 			if (operator->am) {
 				uint16_t base_am = (context->lfo_am_step & 0x80 ? context->lfo_am_step : ~context->lfo_am_step) & 0x7E;
 				if (ams_shift[chan->ams] >= 0) {
-					env += base_am >> ams_shift[chan->ams];
+					env += (base_am >> ams_shift[chan->ams]) & MAX_ENVELOPE;
 				} else {
 					env += base_am << (-ams_shift[chan->ams]);
 				}
@@ -687,6 +687,7 @@
 		inc = context->ch3_supp[index].fnum;
 		if (channel->pms) {
 			inc = inc * 2 + lfo_pm_table[(inc & 0x7F0) * 16 + channel->pms + context->lfo_pm_step];
+			inc &= 0xFFF;
 		}
 		if (!context->ch3_supp[index].block) {
 			inc >>= 1;
@@ -855,7 +856,6 @@
 				operator->rates[PHASE_ATTACK] = value & 0x1F;
 				break;
 			case REG_DECAY_AM:
-				//TODO: AM flag for LFO
 				operator->am = value & 0x80;
 				operator->rates[PHASE_DECAY] = value & 0x1F;
 				break;