Adjustments to audio parsing

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-15 12:37:04 +01:00
parent 431126f893
commit 0dcc19dd37
2 changed files with 10 additions and 6 deletions

View File

@@ -56,6 +56,9 @@ class Opl2Emulator {
int channelIdx = reg - 0xB0;
Opl2Channel channel = channels[channelIdx];
// Track the previous key state to prevent constant phase resetting
bool wasKeyOn = channel.keyOn;
// Extract the bits using bitwise masks
channel.keyOn = (data & 0x20) != 0; // Bit 5
channel.block = (data & 0x1C) >> 2; // Bits 2-4
@@ -65,8 +68,8 @@ class Opl2Emulator {
channel.fNum = (channel.fNum & 0xFF) | fNumHigh;
channel.updateFrequency();
// When a new note is struck, we reset the phase counter to 0
if (channel.keyOn) {
// ONLY reset the phase if the note was just struck
if (!wasKeyOn && channel.keyOn) {
channel.phase = 0.0;
}
}