Skip to content

Commit d23e2fd

Browse files
authored
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
1 parent 75e2780 commit d23e2fd

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

NeuralAmpModeler/NeuralAmpModeler.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <algorithm> // std::clamp
2-
#include <cmath>
2+
#include <cmath> // pow
33
#include <filesystem>
44
#include <iostream>
55
#include <utility>
@@ -143,7 +143,7 @@ NeuralAmpModeler::NeuralAmpModeler(const InstanceInfo& info)
143143
contentArea.GetFromBottom((2.0f * fileHeight)).GetFromTop(fileHeight).GetMidHPadded(fileWidth).GetVShifted(-1);
144144
const auto modelIconArea = modelArea.GetFromLeft(30).GetTranslated(-40, 10);
145145
const auto irArea = modelArea.GetVShifted(irYOffset);
146-
const auto irSwitchArea = irArea.GetFromLeft(30).GetHShifted(-40).GetScaledAboutCentre(0.6);
146+
const auto irSwitchArea = irArea.GetFromLeft(30.0f).GetHShifted(-40.0f).GetScaledAboutCentre(0.6f);
147147

148148
// Areas for meters
149149
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
293293

294294
if (mModel != nullptr)
295295
{
296-
mModel->SetNormalize(GetParam(kOutNorm)->Value());
297-
// TODO remove input / output gains from here.
298-
const double inputGain = 1.0;
299-
const double outputGain = 1.0;
300-
const int nChans = (int)numChannelsInternal;
301-
mModel->process(triggerOutput, mOutputPointers, nChans, nFrames, inputGain, outputGain, mNAMParams);
296+
// TODO multi-channel processing; Issue
297+
// <ake sure it's multi-threaded or else this won't perform well!
298+
mModel->process(triggerOutput[0], mOutputPointers[0], nFrames);
302299
mModel->finalize_(nFrames);
300+
// Normalize loudness
301+
if (GetParam(kOutNorm)->Value())
302+
{
303+
_NormalizeModelOutput(mOutputPointers, numChannelsInternal, numFrames);
304+
}
303305
}
304306
else
305307
{
@@ -592,6 +594,24 @@ void NeuralAmpModeler::_FallbackDSP(iplug::sample** inputs, iplug::sample** outp
592594
mOutputArray[c][s] = mInputArray[c][s];
593595
}
594596

597+
void NeuralAmpModeler::_NormalizeModelOutput(iplug::sample** buffer, const size_t numChannels, const size_t numFrames)
598+
{
599+
if (!mModel)
600+
return;
601+
if (!mModel->HasLoudness())
602+
return;
603+
const double loudness = mModel->GetLoudness();
604+
const double targetLoudness = -18.0;
605+
const double gain = pow(10.0, (targetLoudness - loudness) / 20.0);
606+
for (size_t c = 0; c < numChannels; c++)
607+
{
608+
for (size_t f = 0; f < numFrames; f++)
609+
{
610+
buffer[c][f] *= gain;
611+
}
612+
}
613+
}
614+
595615
void NeuralAmpModeler::_ResampleModelAndIR()
596616
{
597617
const auto sampleRate = GetSampleRate();

NeuralAmpModeler/NeuralAmpModeler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class NeuralAmpModeler final : public iplug::Plugin
104104
// Sizes based on mInputArray
105105
size_t _GetBufferNumChannels() const;
106106
size_t _GetBufferNumFrames() const;
107+
// Apply the normalization for the model output (if possible)
108+
void _NormalizeModelOutput(iplug::sample** buffer, const size_t numChannels, const size_t numFrames);
107109
// Loads a NAM model and stores it to mStagedNAM
108110
// Returns an empty string on success, or an error message on failure.
109111
std::string _StageModel(const WDL_String& dspFile);

0 commit comments

Comments
 (0)