diff options
-rw-r--r-- | src/adlmidi_midiplay.cpp | 66 | ||||
-rw-r--r-- | src/adlmidi_private.cpp | 2 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 7 |
3 files changed, 49 insertions, 26 deletions
diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 6dad2a9..f52d936 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -680,8 +680,10 @@ bool MIDIplay::buildTrackData() MIDIplay::MIDIplay(unsigned long sampleRate): cmf_percussion_mode(false), - m_arpeggioCounter(0), - m_audioTickCounter(0) + m_arpeggioCounter(0) +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) + , m_audioTickCounter(0) +#endif #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER , fullSongTimeLength(0.0), postSongWaitDelay(1.0), @@ -825,6 +827,9 @@ double MIDIplay::Tick(double s, double granularity) UpdateVibrato(s); UpdateArpeggio(s); +#if !defined(ADLMIDI_AUDIO_TICK_HANDLER) + UpdateGlide(s); +#endif if(CurrentPositionNew.wait < 0.0)//Avoid negative delay value! return 0.0; @@ -839,6 +844,9 @@ void MIDIplay::TickIteratos(double s) ch[c].AddAge(static_cast<int64_t>(s * 1000.0)); UpdateVibrato(s); UpdateArpeggio(s); +#if !defined(ADLMIDI_AUDIO_TICK_HANDLER) + UpdateGlide(s); +#endif } #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER @@ -1454,6 +1462,7 @@ void MIDIplay::realTime_panic() KillSustainingNotes(-1, -1); } +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) void MIDIplay::AudioTick(uint32_t chipId, uint32_t rate) { if(chipId != 0) // do first chip ticks only @@ -1467,32 +1476,10 @@ void MIDIplay::AudioTick(uint32_t chipId, uint32_t rate) if(tickNumber % portamentoInterval == 0) { double portamentoDelta = timeDelta * portamentoInterval; - - for(unsigned channel = 0; channel < 16; ++channel) - { - MIDIchannel &midiChan = Ch[channel]; - for(MIDIchannel::activenoteiterator it = midiChan.activenotes_begin(); - it; ++it) - { - double finalTone = it->noteTone; - double previousTone = it->currentTone; - - bool directionUp = previousTone < finalTone; - double toneIncr = portamentoDelta * (directionUp ? +it->glideRate : -it->glideRate); - - double currentTone = previousTone + toneIncr; - bool glideFinished = !(directionUp ? (currentTone < finalTone) : (currentTone > finalTone)); - currentTone = glideFinished ? finalTone : currentTone; - - if(currentTone != previousTone) - { - it->currentTone = currentTone; - NoteUpdate(channel, it, Upd_Pitch); - } - } - } + UpdateGlide(portamentoDelta); } } +#endif void MIDIplay::NoteUpdate(uint16_t MidCh, MIDIplay::MIDIchannel::activenoteiterator i, @@ -2601,6 +2588,33 @@ retry_arpeggio: } } +void MIDIplay::UpdateGlide(double amount) +{ + for(unsigned channel = 0; channel < 16; ++channel) + { + MIDIchannel &midiChan = Ch[channel]; + for(MIDIchannel::activenoteiterator it = midiChan.activenotes_begin(); + it; ++it) + { + double finalTone = it->noteTone; + double previousTone = it->currentTone; + + bool directionUp = previousTone < finalTone; + double toneIncr = amount * (directionUp ? +it->glideRate : -it->glideRate); + + double currentTone = previousTone + toneIncr; + bool glideFinished = !(directionUp ? (currentTone < finalTone) : (currentTone > finalTone)); + currentTone = glideFinished ? finalTone : currentTone; + + if(currentTone != previousTone) + { + it->currentTone = currentTone; + NoteUpdate(channel, it, Upd_Pitch); + } + } + } +} + #ifndef ADLMIDI_DISABLE_CPP_EXTRAS diff --git a/src/adlmidi_private.cpp b/src/adlmidi_private.cpp index 1ee7c4a..3bc73a4 100644 --- a/src/adlmidi_private.cpp +++ b/src/adlmidi_private.cpp @@ -27,10 +27,12 @@ std::string ADLMIDI_ErrorString; // Generator callback on audio rate ticks +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate) { reinterpret_cast<MIDIplay *>(instance)->AudioTick(chipId, rate); } +#endif int adlRefreshNumCards(ADL_MIDIPlayer *device) { diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 93817cd..7aad63b 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -996,8 +996,10 @@ private: //! Counter of arpeggio processing size_t m_arpeggioCounter; +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) //! Audio tick counter uint32_t m_audioTickCounter; +#endif #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER std::vector<std::vector<uint8_t> > TrackData; @@ -1196,8 +1198,10 @@ public: void realTime_panic(); +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) // Audio rate tick handler void AudioTick(uint32_t chipId, uint32_t rate); +#endif private: enum @@ -1243,6 +1247,7 @@ private: void UpdateVibrato(double amount); void UpdateArpeggio(double /*amount*/); + void UpdateGlide(double amount); public: uint64_t ChooseDevice(const std::string &name); @@ -1267,7 +1272,9 @@ struct FourChars }; */ +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) extern void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate); +#endif extern int adlRefreshNumCards(ADL_MIDIPlayer *device); |