From 72dc7b5318eb6abc1486729afb253a21014f79b0 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Sat, 8 Aug 2015 04:03:13 -0500 Subject: [PATCH] Better-sounding noise generator, Halls of Doom in Ultima 5 sounds much better --- src/main/java/jace/hardware/mockingboard/NoiseGenerator.java | 1 + src/main/java/jace/hardware/mockingboard/PSG.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/jace/hardware/mockingboard/NoiseGenerator.java b/src/main/java/jace/hardware/mockingboard/NoiseGenerator.java index 27ec51d..4e88482 100644 --- a/src/main/java/jace/hardware/mockingboard/NoiseGenerator.java +++ b/src/main/java/jace/hardware/mockingboard/NoiseGenerator.java @@ -39,6 +39,7 @@ public class NoiseGenerator extends TimedGenerator { } public static final int bit17 = 0x010000; public void updateRng() { + // noise = (noise >> 1) ^ ((noise & 1) ? 0x14000 : 0); int newBit17 = (rng & 0x04) > 0 == (rng & 0x01) > 0 ? bit17 : 0; rng = newBit17 + (rng >> 1); } diff --git a/src/main/java/jace/hardware/mockingboard/PSG.java b/src/main/java/jace/hardware/mockingboard/PSG.java index ed9d600..67b9a81 100644 --- a/src/main/java/jace/hardware/mockingboard/PSG.java +++ b/src/main/java/jace/hardware/mockingboard/PSG.java @@ -207,6 +207,7 @@ public class PSG { /* Also, note that period = 0 is the same as period = 1. This is mentioned */ /* in the YM2203 data sheets. However, this does NOT apply to the Envelope */ /* period. In that case, period = 0 is half as period = 1. */ + value = value & 0x0ff; switch (r) { case ACoarse: case AFine: @@ -221,7 +222,8 @@ public class PSG { channels.get(2).setPeriod(getReg(Reg.CFine) + (getReg(Reg.CCoarse) << 8)); break; case NoisePeriod: - noiseGenerator.setPeriod(value); + if (value == 0) value = 32; + noiseGenerator.setPeriod(value+16); noiseGenerator.counter = 0; break; case Enable: