From 60171b220a3d0d195fee73b284c4cae7fddf0f58 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Wed, 26 Sep 2018 02:24:37 +0300 Subject: Fixed the too fast killing of releasing notes #181 --- src/adlmidi_midiplay.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 42b5b01..9276d0e 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -104,7 +104,11 @@ void MIDIplay::AdlChannel::addAge(int64_t us) { const int64_t neg = 1000 * static_cast(-0x1FFFFFFFll); if(users_empty()) + { koff_time_until_neglible_us = std::max(koff_time_until_neglible_us - us, neg); + if(koff_time_until_neglible_us < 0) + koff_time_until_neglible_us = 0; + } else { koff_time_until_neglible_us = 0; @@ -1161,7 +1165,7 @@ void MIDIplay::noteUpdate(size_t midCh, } else { - m_chipChannels[c].koff_time_until_neglible_us = 1000 * ains.ms_sound_koff; + m_chipChannels[c].koff_time_until_neglible_us = 1000 * int64_t(ains.ms_sound_koff); } } } @@ -1338,7 +1342,7 @@ int64_t MIDIplay::calculateChipChannelGoodness(size_t c, const MIDIchannel::Note //if(c == MidCh) s += 4; for(AdlChannel::LocationData *j = m_chipChannels[c].users_first; j; j = j->next) { - s -= 4000; + s -= 4000000; int64_t kon_ms = j->kon_time_until_neglible_us / 1000; s -= (j->sustained == AdlChannel::LocationData::Sustain_None) ? @@ -1356,7 +1360,7 @@ int64_t MIDIplay::calculateChipChannelGoodness(size_t c, const MIDIchannel::Note // Arpeggio candidate = even better if(j->vibdelay_us < 70000 || j->kon_time_until_neglible_us > 20000000) - s += 0; + s += 10; } // Percussion is inferior to melody -- cgit v1.2.3 From 63dfa67e16887c550b29ee5a1e97c895a9878441 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Wed, 26 Sep 2018 02:58:19 +0300 Subject: Pay attention to releasing notes #181 --- src/adlmidi_midiplay.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 9276d0e..105d54a 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -588,6 +588,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity) int32_t c = adlchannel[ccount]; if(c < 0) continue; + m_chipChannels[c].recent_ins = voices[ccount]; m_chipChannels[c].addAge(0); } @@ -1335,12 +1336,22 @@ void MIDIplay::setErrorString(const std::string &err) int64_t MIDIplay::calculateChipChannelGoodness(size_t c, const MIDIchannel::NoteInfo::Phys &ins) const { - int64_t koff_ms = m_chipChannels[c].koff_time_until_neglible_us / 1000; - int64_t s = (m_synth.m_musicMode != OPL3::MODE_CMF) ? -koff_ms : 0; + const AdlChannel &chan = m_chipChannels[c]; + int64_t koff_ms = chan.koff_time_until_neglible_us / 1000; + int64_t s = -koff_ms; + + // Rate channel with a releasing note + if(s < 0 && chan.users_empty()) + { + s = -10000; + // If it's same instrument, better chance to get it when no free channels + if(chan.recent_ins == ins) + s = (m_synth.m_musicMode == OPL3::MODE_CMF) ? 0 : -5000; + return s; + } // Same midi-instrument = some stability - //if(c == MidCh) s += 4; - for(AdlChannel::LocationData *j = m_chipChannels[c].users_first; j; j = j->next) + for(AdlChannel::LocationData *j = chan.users_first; j; j = j->next) { s -= 4000000; -- cgit v1.2.3 From 98caeed048a59ae639fe02858e98f35984585aca Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Wed, 26 Sep 2018 03:15:28 +0300 Subject: Add the competition between channels with releasing notes #181 --- src/adlmidi_midiplay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 105d54a..276a33d 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -1343,10 +1343,10 @@ int64_t MIDIplay::calculateChipChannelGoodness(size_t c, const MIDIchannel::Note // Rate channel with a releasing note if(s < 0 && chan.users_empty()) { - s = -10000; + s -= 40000; // If it's same instrument, better chance to get it when no free channels if(chan.recent_ins == ins) - s = (m_synth.m_musicMode == OPL3::MODE_CMF) ? 0 : -5000; + s = (m_synth.m_musicMode == OPL3::MODE_CMF) ? 0 : -koff_ms; return s; } -- cgit v1.2.3 From c971992278519b29768be349dd3962bbd93dbb22 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sun, 30 Sep 2018 04:57:56 +0300 Subject: Lock settings for CMF and IMF playing to don't destroy them For now, all settings are in safe, except of custom bank that getting be dropped away by CMF file that does passing of own custom instruments. --- src/adlmidi_midiplay.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 276a33d..585e855 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -141,7 +141,7 @@ MIDIplay::MIDIplay(unsigned long sampleRate): m_setup.maxdelay = 512.0 / (double)m_setup.PCM_RATE; m_setup.bankId = 0; - m_setup.numFourOps = 7; + m_setup.numFourOps = -1; m_setup.numChips = 2; m_setup.deepTremoloMode = -1; m_setup.deepVibratoMode = -1; @@ -198,9 +198,13 @@ void MIDIplay::applySetup() m_synth.m_volumeScale = (OPL3::VolumesScale)m_synth.m_insBankSetup.volumeModel; m_synth.m_numChips = m_setup.numChips; - m_synth.m_numFourOps = m_setup.numFourOps; m_cmfPercussionMode = false; + if(m_setup.numFourOps >= 0) + m_synth.m_numFourOps = m_setup.numFourOps; + else + adlCalculateFourOpChannels(this, true); + m_synth.reset(m_setup.emulator, m_setup.PCM_RATE, this); m_chipChannels.clear(); m_chipChannels.resize(m_synth.m_numChannels); -- cgit v1.2.3 From 10c6c335697cd7e570d06089c61c1fae8acb29e1 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sun, 30 Sep 2018 18:53:32 +0300 Subject: Remove useless condition --- src/adlmidi_midiplay.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 585e855..673ec30 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -1474,8 +1474,6 @@ void MIDIplay::killOrEvacuate(size_t from_channel, { uint16_t cs = static_cast(c); - if(c > std::numeric_limits::max()) - break; if(c == from_channel) continue; if(m_synth.m_channelCategory[c] != m_synth.m_channelCategory[from_channel]) -- cgit v1.2.3 From 77e8b86be524edf42a7070e2b7a1f6f67d7cfaa8 Mon Sep 17 00:00:00 2001 From: Vitaly Novichkov Date: Sun, 30 Sep 2018 18:58:13 +0300 Subject: Move "MaxChips" constant macro into adlmidi_private.hpp --- src/adlmidi_midiplay.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/adlmidi_midiplay.cpp') diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 673ec30..1e1da07 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -1465,6 +1465,8 @@ void MIDIplay::killOrEvacuate(size_t from_channel, AdlChannel::LocationData *j, MIDIplay::MIDIchannel::activenoteiterator i) { + uint32_t maxChannels = ADL_MAX_CHIPS * 18; + // Before killing the note, check if it can be // evacuated to another channel as an arpeggio // instrument. This helps if e.g. all channels @@ -1474,6 +1476,8 @@ void MIDIplay::killOrEvacuate(size_t from_channel, { uint16_t cs = static_cast(c); + if(c >= maxChannels) + break; if(c == from_channel) continue; if(m_synth.m_channelCategory[c] != m_synth.m_channelCategory[from_channel]) -- cgit v1.2.3