commit d23e2fd62be2e44db7076c4867334390d3796070
parent 75e278005edc3dd892bd549207836fe950c69e57
Author: Steven Atkinson <steven@atkinson.mn>
Date: Sun, 15 Oct 2023 14:05:09 -0700
Update NeuralAmpModelerCore (#377)
* Update NeuralAmpModelerCore, NeuralAmpModeler.cpp, NeuralAmpModeler.h
Up to date with the latest changes on the core, including simplifying
the process call and briging normalization into the plugin.
* Formatting
Diffstat:
2 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/NeuralAmpModeler/NeuralAmpModeler.cpp b/NeuralAmpModeler/NeuralAmpModeler.cpp
@@ -1,5 +1,5 @@
#include <algorithm> // std::clamp
-#include <cmath>
+#include <cmath> // pow
#include <filesystem>
#include <iostream>
#include <utility>
@@ -143,7 +143,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
contentArea.GetFromBottom((2.0f * fileHeight)).GetFromTop(fileHeight).GetMidHPadded(fileWidth).GetVShifted(-1);
const auto modelIconArea = modelArea.GetFromLeft(30).GetTranslated(-40, 10);
const auto irArea = modelArea.GetVShifted(irYOffset);
- const auto irSwitchArea = irArea.GetFromLeft(30).GetHShifted(-40).GetScaledAboutCentre(0.6);
+ const auto irSwitchArea = irArea.GetFromLeft(30.0f).GetHShifted(-40.0f).GetScaledAboutCentre(0.6f);
// Areas for meters
const auto inputMeterArea = contentArea.GetFromLeft(30).GetHShifted(-20).GetMidVPadded(100).GetVShifted(-25);
@@ -293,13 +293,15 @@ void NeuralAmpModeler::ProcessBlock(iplug::sample** inputs, iplug::sample** outp
if (mModel != nullptr)
{
- mModel->SetNormalize(GetParam(kOutNorm)->Value());
- // TODO remove input / output gains from here.
- const double inputGain = 1.0;
- const double outputGain = 1.0;
- const int nChans = (int)numChannelsInternal;
- mModel->process(triggerOutput, mOutputPointers, nChans, nFrames, inputGain, outputGain, mNAMParams);
+ // TODO multi-channel processing; Issue
+ // <ake sure it's multi-threaded or else this won't perform well!
+ mModel->process(triggerOutput[0], mOutputPointers[0], nFrames);
mModel->finalize_(nFrames);
+ // Normalize loudness
+ if (GetParam(kOutNorm)->Value())
+ {
+ _NormalizeModelOutput(mOutputPointers, numChannelsInternal, numFrames);
+ }
}
else
{
@@ -592,6 +594,24 @@ void NeuralAmpModeler::_FallbackDSP(iplug::sample** inputs, iplug::sample** outp
mOutputArray[c][s] = mInputArray[c][s];
}
+void NeuralAmpModeler::_NormalizeModelOutput(iplug::sample** buffer, const size_t numChannels, const size_t numFrames)
+{
+ if (!mModel)
+ return;
+ if (!mModel->HasLoudness())
+ return;
+ const double loudness = mModel->GetLoudness();
+ const double targetLoudness = -18.0;
+ const double gain = pow(10.0, (targetLoudness - loudness) / 20.0);
+ for (size_t c = 0; c < numChannels; c++)
+ {
+ for (size_t f = 0; f < numFrames; f++)
+ {
+ buffer[c][f] *= gain;
+ }
+ }
+}
+
void NeuralAmpModeler::_ResampleModelAndIR()
{
const auto sampleRate = GetSampleRate();
diff --git a/NeuralAmpModeler/NeuralAmpModeler.h b/NeuralAmpModeler/NeuralAmpModeler.h
@@ -104,6 +104,8 @@ private:
// Sizes based on mInputArray
size_t _GetBufferNumChannels() const;
size_t _GetBufferNumFrames() const;
+ // Apply the normalization for the model output (if possible)
+ void _NormalizeModelOutput(iplug::sample** buffer, const size_t numChannels, const size_t numFrames);
// Loads a NAM model and stores it to mStagedNAM
// Returns an empty string on success, or an error message on failure.
std::string _StageModel(const WDL_String& dspFile);