changeset 527:7df7f493b3b6

Fix operator 1 self-feedback
author Michael Pavone <pavone@retrodev.com>
date Wed, 12 Feb 2014 22:14:11 -0800
parents 6fe73296938a
children aae9e738c6a4
files ym2612.c ym2612.h
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ym2612.c	Tue Feb 11 23:19:29 2014 -0800
+++ b/ym2612.c	Wed Feb 12 22:14:11 2014 -0800
@@ -374,7 +374,7 @@
 			{
 			case 0://Operator 1
 				if (chan->feedback) {
-					mod = operator->output >> (9-chan->feedback);
+					mod = (chan->op1_old + operator->output) >> (10-chan->feedback);
 				}
 				break;
 			case 1://Operator 3
@@ -431,12 +431,17 @@
 			if (first_key_on) {
 				dfprintf(debug_file, "op %d, base phase: %d, mod: %d, sine: %d, out: %d\n", op, phase, mod, sine_table[(phase+mod) & 0x1FF], pow_table[sine_table[phase & 0x1FF] + env]);
 			}
-			phase += mod;
+			//if ((channel != 0 && channel != 4) || chan->algorithm != 5) {
+				phase += mod;
+			//}
 
 			int16_t output = pow_table[sine_table[phase & 0x1FF] + env];
 			if (phase & 0x200) {
 				output = -output;
 			}
+			if (op % 4 == 0) {
+				chan->op1_old = operator->output;
+			}
 			operator->output = output;
 			//Update the channel output if we've updated all operators
 			if (op % 4 == 3) {
@@ -784,6 +789,7 @@
 			case REG_ALG_FEEDBACK:
 				context->channels[channel].algorithm = value & 0x7;
 				context->channels[channel].feedback = value >> 3 & 0x7;
+				//printf("Algorithm %d, feedback %d for channel %d\n", value & 0x7, value >> 3 & 0x7, channel);
 				break;
 			case REG_LR_AMS_PMS:
 				context->channels[channel].pms = (value & 0x7) * 32;
--- a/ym2612.h	Tue Feb 11 23:19:29 2014 -0800
+++ b/ym2612.h	Wed Feb 12 22:14:11 2014 -0800
@@ -33,6 +33,7 @@
 	FILE *   logfile;
 	uint16_t fnum;
 	int16_t  output;
+	int16_t  op1_old;
 	uint8_t  block_fnum_latch;
 	uint8_t  block;
 	uint8_t  keycode;