Skip to content

Commit

Permalink
Rework Normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
olilarkin committed Oct 17, 2023
1 parent 77eb924 commit 467de16
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions NeuralAmpModeler/NeuralAmpModeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,31 @@ void NeuralAmpModeler::ProcessBlock(iplug::sample** inputs, iplug::sample** outp
mModel->process(newInputs[0], newOutputs[0], newNFrames);
mModel->finalize_(newNFrames);
});

auto outputGain = GetParam(kOutputLevel)->DBToAmp();

// Apply loudness normalization and output level gain
if (mModel->HasLoudness())
{
const auto loudness = mModel->GetLoudness();
const auto targetLoudness = -18.0;
const auto loudnessGain = pow(10.0, (targetLoudness - loudness) / 20.0);
outputGain *= loudnessGain;
}

for (auto s=0; s<nFrames; s++)
{
outputs[0][s] = outputs[0][s] * outputGain;
outputs[1][s] = outputs[0][s];
}
}
else
else // no model, pass through
{
for (auto s=0; s<nFrames; s++)
{
outputs[0][s] = inputs[0][s];
}
}

const auto outputGain = GetParam(kOutputLevel)->DBToAmp();

for (auto s=0; s<nFrames; s++)
{
outputs[0][s] = outputs[0][s] * outputGain;
outputs[1][s] = outputs[0][s];
}

mInputSender.ProcessBlock(inputs, nFrames, kCtrlTagInputMeter, 1);
mOutputSender.ProcessBlock(outputs, nFrames, kCtrlTagOutputMeter, 1);
Expand Down

0 comments on commit 467de16

Please sign in to comment.