From 9b478615e7f0cd73c360fd289b05db52b5f730f1 Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Wed, 16 May 2018 01:31:18 +0200 Subject: storing adldata and adlinsdata in unified structures --- src/adlmidi_opl3.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index 66254b6..d7dec78 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -130,11 +130,11 @@ static const unsigned short Channels[23] = */ -const adlinsdata &OPL3::GetAdlMetaIns(size_t n) +adlinsdata2 OPL3::GetAdlMetaIns(size_t n) { return (n & DynamicMetaInstrumentTag) ? dynamic_metainstruments[n & ~DynamicMetaInstrumentTag] - : adlins[n]; + : adlinsdata2(adlins[n]); } size_t OPL3::GetAdlMetaNumber(size_t midiins) @@ -144,13 +144,6 @@ size_t OPL3::GetAdlMetaNumber(size_t midiins) : banks[AdlBank][midiins]; } -const adldata &OPL3::GetAdlIns(size_t insno) -{ - return (insno & DynamicInstrumentTag) - ? dynamic_instruments[insno & ~DynamicInstrumentTag] - : adl[insno]; -} - void OPL3::setEmbeddedBank(unsigned int bank) { AdlBank = bank; @@ -282,10 +275,9 @@ void OPL3::Touch_Real(unsigned c, unsigned volume, uint8_t brightness) volume = 63; size_t card = c / 23, cc = c % 23; - size_t i = ins[c]; + const adldata &adli = ins[c]; uint16_t o1 = Operators[cc * 2 + 0]; uint16_t o2 = Operators[cc * 2 + 1]; - const adldata &adli = GetAdlIns(i); uint8_t x = adli.modulator_40, y = adli.carrier_40; uint16_t mode = 1; // 2-op AM @@ -295,22 +287,22 @@ void OPL3::Touch_Real(unsigned c, unsigned volume, uint8_t brightness) } else if(four_op_category[c] == 1 || four_op_category[c] == 2) { - size_t i0, i1; + const adldata *i0, *i1; if(four_op_category[c] == 1) { - i0 = i; - i1 = ins[c + 3]; + i0 = &adli; + i1 = &ins[c + 3]; mode = 2; // 4-op xx-xx ops 1&2 } else { - i0 = ins[c - 3]; - i1 = i; + i0 = &ins[c - 3]; + i1 = &adli; mode = 6; // 4-op xx-xx ops 3&4 } - mode += (GetAdlIns(i0).feedconn & 1) + (GetAdlIns(i1).feedconn & 1) * 2; + mode += (i0->feedconn & 1) + (i1->feedconn & 1) * 2; } static const bool do_ops[10][2] = @@ -377,14 +369,13 @@ void OPL3::Touch(unsigned c, unsigned volume) // Volume maxes at 127*127*127 } }*/ -void OPL3::Patch(uint16_t c, size_t i) +void OPL3::Patch(uint16_t c, const adldata &adli) { uint16_t card = c / 23, cc = c % 23; static const uint8_t data[4] = {0x20, 0x60, 0x80, 0xE0}; - ins[c] = i; + ins[c] = adli; uint16_t o1 = Operators[cc * 2 + 0]; uint16_t o2 = Operators[cc * 2 + 1]; - const adldata &adli = GetAdlIns(i); unsigned x = adli.modulator_E862, y = adli.carrier_E862; for(unsigned a = 0; a < 4; ++a, x >>= 8, y >>= 8) @@ -400,7 +391,7 @@ void OPL3::Pan(unsigned c, unsigned value) unsigned card = c / 23, cc = c % 23; if(Channels[cc] != 0xFFF) - Poke(card, 0xC0 + Channels[cc], GetAdlIns(ins[c]).feedconn | value); + Poke(card, 0xC0 + Channels[cc], ins[c].feedconn | value); } void OPL3::Silence() // Silence all OPL channels. @@ -527,7 +518,7 @@ void OPL3::Reset(int emulator, unsigned long PCM_RATE) #endif NumChannels = NumCards * 23; - ins.resize(NumChannels, 189); + ins.resize(NumChannels, adl[adlDefaultNumber]); pit.resize(NumChannels, 0); regBD.resize(NumCards, 0); four_op_category.resize(NumChannels, 0); -- cgit v1.2.3 From bb4797ee68c0f12018196d3ee8caddcdcad9fe38 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sat, 19 May 2018 22:33:37 +0300 Subject: Works and fixes - Fixed an incorrect calculation of 4-op channels and choosing 4-op channels for 2-op only banks - Resolved trouble with automatically chosen flags because of internal confusion --- src/adlmidi_opl3.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index d7dec78..279a7d5 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -151,6 +151,7 @@ void OPL3::setEmbeddedBank(unsigned int bank) dynamic_percussion_offset = 128; dynamic_melodic_banks.clear(); dynamic_percussion_banks.clear(); + dynamic_metainstruments.clear(); } -- cgit v1.2.3 From 56c0cd7f2439898080df2e0a8129b72d2d85ca70 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Thu, 31 May 2018 02:05:58 +0300 Subject: Small polishing of volume model and CMF/RSXX tempo - Removed "Logarithmic volumes" flag as volume models concept successfuly serves this task. "Logarithmic volumes" flag is useless when we have volume models. - Fixed "too fast" tempo while playing CMF and EA-MUS (aka RSXX) files --- src/adlmidi_opl3.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index 279a7d5..143c911 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -165,8 +165,6 @@ OPL3::OPL3() : HighTremoloMode(false), HighVibratoMode(false), AdlPercussionMode(false), - LogarithmicVolumes(false), - //CartoonersVolumes(false), m_musicMode(MODE_MIDI), m_volumeScale(VOLUME_Generic) {} @@ -476,9 +474,8 @@ void OPL3::ChangeVolumeRangesModel(ADLMIDI_VolumeModels volumeModel) m_volumeScale = OPL3::VOLUME_Generic; break; - case ADLMIDI_VolumeModel_CMF: - LogarithmicVolumes = true; - m_volumeScale = OPL3::VOLUME_CMF; + case ADLMIDI_VolumeModel_NativeOPL3: + m_volumeScale = OPL3::VOLUME_NATIVE; break; case ADLMIDI_VolumeModel_DMX: -- cgit v1.2.3 From c4ed5cf15e64a84129865a58b5063ef0e73f0bcf Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Wed, 16 May 2018 14:27:04 +0200 Subject: bank storage inside dynamic map --- src/adlmidi_opl3.cpp | 55 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index 143c911..f82302c 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -129,45 +129,54 @@ static const unsigned short Channels[23] = Ports: ??? */ - -adlinsdata2 OPL3::GetAdlMetaIns(size_t n) +void OPL3::setEmbeddedBank(unsigned int bank) { - return (n & DynamicMetaInstrumentTag) ? - dynamic_metainstruments[n & ~DynamicMetaInstrumentTag] - : adlinsdata2(adlins[n]); -} + AdlBank = bank; + //Embedded banks are supports 128:128 GM set only + dynamic_banks.clear(); -size_t OPL3::GetAdlMetaNumber(size_t midiins) -{ - return (AdlBank == ~0u) ? - (midiins | DynamicMetaInstrumentTag) - : banks[AdlBank][midiins]; + if(bank >= maxAdlBanks()) + return; + + Bank *bank_pair[2] = + { + &dynamic_banks[0], + &dynamic_banks[PercussionTag] + }; + + for(unsigned i = 0; i < 256; ++i) + { + size_t meta = banks[bank][i]; + adlinsdata2 &ins = bank_pair[i / 128]->ins[i % 128]; + ins = adlinsdata2(adlins[meta]); + } } -void OPL3::setEmbeddedBank(unsigned int bank) +static adlinsdata2 makeEmptyInstrument() { - AdlBank = bank; - //Embedded banks are supports 128:128 GM set only - dynamic_percussion_offset = 128; - dynamic_melodic_banks.clear(); - dynamic_percussion_banks.clear(); - dynamic_metainstruments.clear(); + adlinsdata2 ins; + memset(&ins, 0, sizeof(adlinsdata2)); + ins.flags = adlinsdata::Flag_NoSound; + return ins; } +const adlinsdata2 OPL3::emptyInstrument = makeEmptyInstrument(); OPL3::OPL3() : - dynamic_percussion_offset(128), - DynamicInstrumentTag(0x8000u), - DynamicMetaInstrumentTag(0x4000000u), NumCards(1), - AdlBank(0), NumFourOps(0), HighTremoloMode(false), HighVibratoMode(false), AdlPercussionMode(false), m_musicMode(MODE_MIDI), m_volumeScale(VOLUME_Generic) -{} +{ +#ifdef DISABLE_EMBEDDED_BANKS + AdlBank = ~0u; +#else + setEmbeddedBank(0); +#endif +} void OPL3::Poke(size_t card, uint32_t index, uint32_t value) { -- cgit v1.2.3 From 82e57cf34fe4b5cd01ed6499eb0db6edc67b5da3 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sat, 2 Jun 2018 00:46:50 +0300 Subject: Warning fixes --- src/adlmidi_opl3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index f82302c..26883a1 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -135,7 +135,7 @@ void OPL3::setEmbeddedBank(unsigned int bank) //Embedded banks are supports 128:128 GM set only dynamic_banks.clear(); - if(bank >= maxAdlBanks()) + if(bank >= static_cast(maxAdlBanks())) return; Bank *bank_pair[2] = -- cgit v1.2.3 From 461bc4c3c4a89852bcd70c793f55cda3eba2ff4c Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sat, 2 Jun 2018 01:25:49 +0300 Subject: Remove duplicated "Poke" function call It's no sense to have uint32-argument poke function as all emulators are using uint16 and uint8 data only --- src/adlmidi_opl3.cpp | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index 26883a1..b4db049 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -178,33 +178,7 @@ OPL3::OPL3() : #endif } -void OPL3::Poke(size_t card, uint32_t index, uint32_t value) -{ - #ifdef ADLMIDI_HW_OPL - (void)card; - unsigned o = index >> 8; - unsigned port = OPLBase + o * 2; - - #ifdef __DJGPP__ - outportb(port, index); - for(unsigned c = 0; c < 6; ++c) inportb(port); - outportb(port + 1, value); - for(unsigned c = 0; c < 35; ++c) inportb(port); - #endif//__DJGPP__ - - #ifdef __WATCOMC__ - outp(port, index); - for(uint16_t c = 0; c < 6; ++c) inp(port); - outp(port + 1, value); - for(uint16_t c = 0; c < 35; ++c) inp(port); - #endif//__WATCOMC__ - - #else//ADLMIDI_HW_OPL - cardsOP2[card]->writeReg(static_cast(index), static_cast(value)); - #endif//ADLMIDI_HW_OPL -} - -void OPL3::PokeN(size_t card, uint16_t index, uint8_t value) +void OPL3::Poke(size_t card, uint16_t index, uint8_t value) { #ifdef ADLMIDI_HW_OPL (void)card; @@ -569,7 +543,7 @@ void OPL3::Reset(int emulator, unsigned long PCM_RATE) for(unsigned a = 0; a < 18; ++a) Poke(i, 0xB0 + Channels[a], 0x00); for(unsigned a = 0; a < sizeof(data) / sizeof(*data); a += 2) - PokeN(i, data[a], static_cast(data[a + 1])); + Poke(i, data[a], static_cast(data[a + 1])); Poke(i, 0x0BD, regBD[i] = (HighTremoloMode * 0x80 + HighVibratoMode * 0x40 + AdlPercussionMode * 0x20)); -- cgit v1.2.3 From a6a6f7f7d93678853c3189529639c3d8dc1ee5e5 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sat, 16 Jun 2018 19:40:40 +0300 Subject: Small warning fix on DJGPP --- src/adlmidi_opl3.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/adlmidi_opl3.cpp') diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index b4db049..16a481d 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -489,6 +489,7 @@ void OPL3::Reset(int emulator, unsigned long PCM_RATE) #ifndef ADLMIDI_HW_OPL ClearChips(); #endif + (void)emulator; (void)PCM_RATE; ins.clear(); pit.clear(); -- cgit v1.2.3