gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 2c53030be29d5ac3c144691765e6258560eda12b
parent 6a05beb1789977c2b666cb4b16cf54200b9bdd07
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Tue, 30 Jul 2024 10:22:32 +0200

implement midi timing

Diffstat:
Msource/nord/n2x/n2xLib/n2xdevice.cpp | 13++++++++++++-
Msource/nord/n2x/n2xLib/n2xdevice.h | 1+
Msource/nord/n2x/n2xLib/n2xhardware.cpp | 17+++++++++++++++--
Msource/nord/n2x/n2xLib/n2xhardware.h | 1+
4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/source/nord/n2x/n2xLib/n2xdevice.cpp b/source/nord/n2x/n2xLib/n2xdevice.cpp @@ -70,10 +70,21 @@ namespace n2x void Device::processAudio(const synthLib::TAudioInputs& _inputs, const synthLib::TAudioOutputs& _outputs, size_t _samples) { m_hardware->processAudio(_outputs, static_cast<uint32_t>(_samples), getExtraLatencySamples()); + m_numSamplesProcessed += _samples; } bool Device::sendMidi(const synthLib::SMidiEvent& _ev, std::vector<synthLib::SMidiEvent>& _response) { - return m_hardware->sendMidi(_ev); + if(_ev.sysex.empty()) + { + auto e = _ev; + e.offset += m_numSamplesProcessed + getExtraLatencySamples(); + m_hardware->sendMidi(e); + } + else + { + m_hardware->sendMidi(_ev); + } + return true; } } diff --git a/source/nord/n2x/n2xLib/n2xdevice.h b/source/nord/n2x/n2xLib/n2xdevice.h @@ -32,5 +32,6 @@ namespace n2x std::unique_ptr<Hardware> m_hardware = nullptr; std::vector<uint8_t> m_midiOutBuffer; synthLib::MidiBufferParser m_midiParser; + uint32_t m_numSamplesProcessed = 0; }; } diff --git a/source/nord/n2x/n2xLib/n2xhardware.cpp b/source/nord/n2x/n2xLib/n2xhardware.cpp @@ -51,6 +51,8 @@ namespace n2x void Hardware::processAudio(uint32_t _frames, const uint32_t _latency) { + getMidi().process(_frames); + ensureBufferSize(_frames); dsp56k::TWord* outputs[12]{nullptr}; @@ -120,8 +122,7 @@ namespace n2x bool Hardware::sendMidi(const synthLib::SMidiEvent& _ev) { -// m_midiIn.push_back(_ev); - getMidi().write(_ev); + m_midiIn.push_back(_ev); return true; } @@ -164,6 +165,18 @@ namespace n2x void Hardware::processMidiInput() { + ++m_midiOffsetCounter; + + while(!m_midiIn.empty()) + { + const auto& e = m_midiIn.front(); + + if(e.offset > m_midiOffsetCounter) + break; + + getMidi().write(e); + m_midiIn.pop_front(); + } } void Hardware::onEsaiCallbackB() diff --git a/source/nord/n2x/n2xLib/n2xhardware.h b/source/nord/n2x/n2xLib/n2xhardware.h @@ -76,6 +76,7 @@ namespace n2x dsp56k::RingBuffer<dsp56k::Audio::RxFrame, 4, true> m_dspAtoBbuf; std::unique_ptr<std::thread> m_ucThread; dsp56k::RingBuffer<synthLib::SMidiEvent, 256, true, true> m_midiIn; + uint32_t m_midiOffsetCounter = 0; // DSP slowdown uint32_t m_maxEsaiCallbacks = 0;