diff options
author | Vitaly Novichkov <admin@wohlnet.ru> | 2018-09-26 03:54:31 +0300 |
---|---|---|
committer | Vitaly Novichkov <admin@wohlnet.ru> | 2018-09-26 03:54:31 +0300 |
commit | 6a4d5ea439bb5bafb5747d6a7f4d9bb628bfa648 (patch) | |
tree | 61b37158b3d7bdb6db0b0fd48b3fa80a3d3564ee | |
parent | c478795f8ff5690c21ef6fbcb4e184e37a57a464 (diff) | |
parent | 98caeed048a59ae639fe02858e98f35984585aca (diff) | |
download | libADLMIDI-6a4d5ea439bb5bafb5747d6a7f4d9bb628bfa648.tar.gz libADLMIDI-6a4d5ea439bb5bafb5747d6a7f4d9bb628bfa648.tar.bz2 libADLMIDI-6a4d5ea439bb5bafb5747d6a7f4d9bb628bfa648.zip |
Merge branch 'master' into stable
-rw-r--r-- | src/adlmidi_load.cpp | 2 | ||||
-rw-r--r-- | src/adlmidi_midiplay.cpp | 29 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 4 | ||||
-rw-r--r-- | src/adlmidi_sequencer.cpp | 2 |
4 files changed, 28 insertions, 9 deletions
diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp index 915b587..e86f23e 100644 --- a/src/adlmidi_load.cpp +++ b/src/adlmidi_load.cpp @@ -203,7 +203,7 @@ bool MIDIplay::LoadMIDI_post() adlins.adl[0] = adl; adlins.adl[1] = adl; adlins.ms_sound_kon = 1000; - adlins.ms_sound_koff = 0; + adlins.ms_sound_koff = 500; adlins.tone = 0; adlins.flags = 0; adlins.voice2_fine_tune = 0.0; diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 42b5b01..276a33d 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<int64_t>(-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; @@ -584,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); } @@ -1161,7 +1166,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); } } } @@ -1331,14 +1336,24 @@ 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 -= 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 : -koff_ms; + 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 -= 4000; + s -= 4000000; int64_t kon_ms = j->kon_time_until_neglible_us / 1000; s -= (j->sustained == AdlChannel::LocationData::Sustain_None) ? @@ -1356,7 +1371,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 diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index c5b70ee..43986c5 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -880,6 +880,9 @@ public: //! Time left until sounding will be muted after key off int64_t koff_time_until_neglible_us; + //! Recently passed instrument, improves a goodness of released but busy channel when matching + MIDIchannel::NoteInfo::Phys recent_ins; + enum { users_max = 128 }; LocationData *users_first, *users_free_cells; LocationData users_cells[users_max]; @@ -898,6 +901,7 @@ public: AdlChannel(): koff_time_until_neglible_us(0) { users_clear(); + std::memset(&recent_ins, 0, sizeof(MIDIchannel::NoteInfo::Phys)); } AdlChannel(const AdlChannel &oth): koff_time_until_neglible_us(oth.koff_time_until_neglible_us) diff --git a/src/adlmidi_sequencer.cpp b/src/adlmidi_sequencer.cpp index 3c18cad..66b9b9a 100644 --- a/src/adlmidi_sequencer.cpp +++ b/src/adlmidi_sequencer.cpp @@ -137,7 +137,7 @@ double MIDIplay::Tick(double s, double granularity) s *= m_sequencer.getTempoMultiplier(); for(uint16_t c = 0; c < m_synth.m_numChannels; ++c) - m_chipChannels[c].addAge(static_cast<int64_t>(s * 1000.0)); + m_chipChannels[c].addAge(static_cast<int64_t>(s * 1e6)); updateVibrato(s); updateArpeggio(s); |