commit ed1b3b002bbcd9ac6124e3299fc440cb5cfcae21
parent 21d92d0783790baefe6f446ef63784841896bb79
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Thu, 7 Apr 2022 23:23:26 +0200
include resampler latency in total latency calculation
Diffstat:
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/source/synthLib/plugin.cpp b/source/synthLib/plugin.cpp
@@ -278,12 +278,12 @@ namespace synthLib
uint32_t Plugin::getLatencyMidiToOutput() const
{
std::lock_guard lock(m_lock);
- return m_blockSize * g_extraLatencyBlocks + m_deviceLatencyMidiToOutput;
+ return m_blockSize * g_extraLatencyBlocks + m_deviceLatencyMidiToOutput + m_resampler.getOutputLatency();
}
uint32_t Plugin::getLatencyInputToOutput() const
{
std::lock_guard lock(m_lock);
- return m_blockSize * g_extraLatencyBlocks + m_deviceLatencyInputToOutput;
+ return m_blockSize * g_extraLatencyBlocks + m_deviceLatencyInputToOutput + m_resampler.getOutputLatency() + m_resampler.getInputLatency();
}
}
diff --git a/source/synthLib/resamplerInOut.cpp b/source/synthLib/resamplerInOut.cpp
@@ -1,5 +1,7 @@
#include "resamplerInOut.h"
+#include <array>
+
#include "../dsp56300/source/dsp56kEmu/fastmath.h"
#include "../dsp56300/source/dsp56kEmu/logging.h"
@@ -39,6 +41,27 @@ namespace synthLib
m_scaledInputSize = 8;
m_scaledInput.resize(m_scaledInputSize);
+
+ m_inputLatency = 0;
+ m_outputLatency = 0;
+
+ // prewarm to calculate latency
+ std::array<std::vector<float>, g_channelCount> data;
+
+ std::array<const float*, g_channelCount> ins{};
+ std::array<float*, g_channelCount> outs{};
+
+ for(size_t i=0; i<data.size(); ++i)
+ {
+ data[i].resize(512, 0);
+ ins[i] = &data[i][0];
+ outs[i] = &data[i][0];
+ }
+
+ TMidiVec midiIn, midiOut;
+ process(&ins[0], &outs[0], TMidiVec(), midiOut, static_cast<uint32_t>(data[0].size()), [&](const float**, float**, size_t, const TMidiVec&, TMidiVec&)
+ {
+ });
}
void ResamplerInOut::scaleMidiEvents(TMidiVec& _dst, const TMidiVec& _src, float _scale)
diff --git a/source/virusLib/device.cpp b/source/virusLib/device.cpp
@@ -60,12 +60,8 @@ namespace virusLib
uint32_t Device::getInternalLatencyMidiToOutput() const
{
- /*
- * hard to believe but this is what I figured out by measuring with a customized init patch
- *
- * Note that this is an average value, midi latency drifts in a range of roughly +/- 61 samples
- */
- return 384 + 28;
+ // Note that this is an average value, midi latency drifts in a range of roughly +/- 61 samples
+ return 324;
}
uint32_t Device::getInternalLatencyInputToOutput() const