Skip to content

Commit e270f8e

Browse files
committed
Update libOPNMIDI: Fixed bank switching logic
1 parent d98f3c1 commit e270f8e

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

OPNMIDI-Player/src/main/cpp/src/opnmidi_opn2.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,22 @@ void OPN2::setPan(size_t c, uint8_t value)
557557

558558
void OPN2::silenceAll() // Silence all OPL channels.
559559
{
560+
size_t chip;
561+
uint8_t port;
562+
uint32_t cc;
563+
560564
for(size_t c = 0; c < m_numChannels; ++c)
561565
{
566+
getOpnChannel(c, chip, port, cc);
567+
562568
noteOff(c);
563569
touchNote(c, 0);
570+
571+
for(uint8_t op = 0; op < 4; op++)
572+
{
573+
writeRegI(chip, port, 0x30 + (0x10 * 1) + (op * 4) + cc, 0x7F);
574+
writeRegI(chip, port, 0x30 + (0x10 * 5) + (op * 4) + cc, 0xFF);
575+
}
564576
}
565577
}
566578

@@ -629,7 +641,7 @@ void OPN2::clearChips()
629641

630642
void OPN2::reset(int emulator, unsigned long PCM_RATE, OPNFamily family, void *audioTickHandler)
631643
{
632-
bool rebuild_needed = m_curState.cmp(emulator, m_numChips);
644+
bool rebuild_needed = m_curState.cmp(emulator, m_numChips, family);
633645

634646
if(rebuild_needed)
635647
clearChips();
@@ -646,10 +658,10 @@ void OPN2::reset(int emulator, unsigned long PCM_RATE, OPNFamily family, void *a
646658
const struct OpnTimbre defaultInsCache =
647659
{
648660
{
649-
{0, 0, 0, 0, 0, 0, 0},
650-
{0, 0, 0, 0, 0, 0, 0},
651-
{0, 0, 0, 0, 0, 0, 0},
652-
{0, 0, 0, 0, 0, 0, 0}
661+
{0, 0x7F, 0, 0, 0, 0xFF, 0},
662+
{0, 0x7F, 0, 0, 0, 0xFF, 0},
663+
{0, 0x7F, 0, 0, 0, 0xFF, 0},
664+
{0, 0x7F, 0, 0, 0, 0xFF, 0}
653665
}, 0, 0, 0
654666
};
655667

OPNMIDI-Player/src/main/cpp/src/opnmidi_opn2.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class OPN2
7474
int emulator;
7575
uint32_t numChips;
7676
unsigned long pcm_rate;
77+
OPNFamily familyType;
7778

7879
State()
7980
{
@@ -85,6 +86,7 @@ class OPN2
8586
emulator = -2;
8687
numChips = 0;
8788
pcm_rate = 0;
89+
familyType = OPNChip_OPN2;
8890
}
8991

9092
bool cmp_rate(unsigned long rate)
@@ -97,14 +99,15 @@ class OPN2
9799
return ret;
98100
}
99101

100-
bool cmp(int emu, uint32_t chips)
102+
bool cmp(int emu, uint32_t chips, OPNFamily family)
101103
{
102-
bool ret = emu != emulator || chips != numChips;
104+
bool ret = emu != emulator || chips != numChips || family != familyType;
103105

104106
if(ret)
105107
{
106108
emulator = emu;
107109
numChips = chips;
110+
familyType = family;
108111
}
109112

110113
return ret;

0 commit comments

Comments
 (0)