commit 83fa931886f2fd0ab15e38d4bd5c5a9b23716717
parent 220c8b65ebf48c750624e667c285ec922ed6134a
Author: Steven Atkinson <steven@atkinson.mn>
Date: Sun, 28 Jul 2024 17:55:29 -0700
Fix bug reporting latency (#489)
Diffstat:
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp
@@ -366,6 +366,7 @@ void NeuralAmpModeler::OnReset()
// If there is a model or IR loaded, they need to be checked for resampling.
_ResetModelAndIR(sampleRate, GetBlockSize());
mToneStack->Reset(sampleRate, maxBlockSize);
+ _UpdateLatency();
}
void NeuralAmpModeler::OnIdle()
@@ -533,7 +534,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
mModel = nullptr;
mNAMPath.Set("");
mShouldRemoveModel = false;
- SetLatency(0);
+ _UpdateLatency();
}
if (mShouldRemoveIR)
{
@@ -548,7 +549,7 @@ void NeuralAmpModeler::_ApplyDSPStaging()
mModel = std::move(mStagedModel);
mStagedModel = nullptr;
mNewModelLoadedInDSP = true;
- SetLatency(mModel->GetLatency());
+ _UpdateLatency();
}
if (mStagedIR != nullptr)
{
@@ -881,6 +882,17 @@ int NeuralAmpModeler::_UnserializeStateLegacy_0_7_9(const IByteChunk& chunk, int
return pos;
}
+void NeuralAmpModeler::_UpdateLatency()
+{
+ int latency = 0;
+ if (mModel)
+ {
+ latency += mModel->GetLatency();
+ }
+ // Other things that add latency here...
+ SetLatency(latency);
+}
+
void NeuralAmpModeler::_UpdateMeters(sample** inputPointer, sample** outputPointer, const size_t nFrames,
const size_t nChansIn, const size_t nChansOut)
{
diff --git a/NeuralAmpModeler/NeuralAmpModeler.h b/NeuralAmpModeler/NeuralAmpModeler.h
@@ -126,7 +126,7 @@ public:
// We can afford to be careful
throw std::runtime_error("More frames were provided than the max expected!");
- if (GetExpectedSampleRate() == GetEncapsulatedSampleRate())
+ if (!NeedToResample())
{
mEncapsulated->process(input, output, num_frames);
mEncapsulated->finalize_(num_frames);
@@ -156,7 +156,7 @@ public:
mFinalized = true;
};
- int GetLatency() const { return mResampler.GetLatency(); };
+ int GetLatency() const { return NeedToResample() ? mResampler.GetLatency() : 0; };
void Reset(const double sampleRate, const int maxBlockSize)
{
@@ -182,6 +182,7 @@ public:
double GetEncapsulatedSampleRate() const { return GetNAMSampleRate(mEncapsulated); };
private:
+ bool NeedToResample() const { return GetExpectedSampleRate() != GetEncapsulatedSampleRate(); };
// The encapsulated NAM
std::unique_ptr<nam::DSP> mEncapsulated;
// The processing for NAM is a little weird--there's a call to .finalize_() that's expected.
@@ -271,6 +272,9 @@ private:
int _UnserializeStateLegacy_0_7_9(const iplug::IByteChunk& chunk, int startPos);
// And other legacy unsrializations if/as needed...
+ // Make sure that the latency is reported correctly.
+ void _UpdateLatency();
+
// Update level meters
// Called within ProcessBlock().
// Assume _ProcessInput() and _ProcessOutput() were run immediately before.