changeset 365:3ba3b6656fff

Actually save the shifted phase inc after applying the block shift
author Mike Pavone <pavone@retrodev.com>
date Wed, 29 May 2013 21:21:14 -0700
parents 62177cc39049
children 836585d389b8
files ym2612.c
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ym2612.c	Wed May 29 00:57:19 2013 -0700
+++ b/ym2612.c	Wed May 29 21:21:14 2013 -0700
@@ -74,7 +74,7 @@
 	1,2,2,2,1,2,2,2,
 };
 
-uint16_t rate_table[64];
+uint16_t rate_table[64*8];
 
 #define MAX_ENVELOPE 0xFFC
 #define YM_DIVIDER 2
@@ -121,15 +121,16 @@
 				uint16_t value;
 				if (rate < 3) {
 					value = 0;
-				} else if (value >= 60) {
+				} else if (rate >= 60) {
 					value = 8;
-				} else if (value < 8) {
+				} else if (rate < 8) {
 					value = rate_table_base[((rate & 6) == 6 ? 16 : 8) + cycle];
-				} else if (value < 48) {
+				} else if (rate < 48) {
 					value = rate_table_base[(rate & 0x3) * 8 + cycle];
 				} else {
 					value = rate_table_base[32 + (rate & 0x3) * 8 + cycle] << (rate >> 2);
 				}
+				rate_table[rate * 8 + cycle] = value;
 			}
 		}
 	}
@@ -408,9 +409,9 @@
 	ym_channel * channel = context->channels + chan_num;
 	uint32_t inc = channel->fnum;
 	if (!channel->block) {
-		inc >> 1;
+		inc >>= 1;
 	} else {
-		inc << (channel->block-1);
+		inc <<= (channel->block-1);
 	}
 	//detune
 	uint32_t detune = detune_table[channel->keycode][operator->detune & 0x3];
@@ -428,6 +429,7 @@
 		//0.5
 		inc >>= 1;
 	}
+	//printf("phase_inc for operator %d: %d, block: %d, fnum: %d, detune: %d, multiple: %d\n", op, inc, channel->block, channel->fnum, detune, operator->multiple);
 	operator->phase_inc = inc;
 }