only do smoothing if we need to, and keep db conversion out of the sampe loop

This commit is contained in:
Mike Oliphant
2023-05-11 11:52:06 -07:00
parent d8193de9eb
commit 207777ec3f
+42 -10
View File
@@ -6,6 +6,8 @@
#include "activations.h" #include "activations.h"
#include <cassert> #include <cassert>
#define SMOOTH_EPSILON .0001f
namespace NAM { namespace NAM {
Plugin::Plugin() Plugin::Plugin()
{ {
@@ -186,12 +188,27 @@ namespace NAM {
if (dblData.size() != n_samples) if (dblData.size() != n_samples)
dblData.resize(n_samples); dblData.resize(n_samples);
for (unsigned int i = 0; i < n_samples; i++) // convert input level from db
{ float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
// Convert input level from db and do very basic smoothing
inputLevel = (.99f * inputLevel) + (.01f * powf(10, *(ports.input_level) * 0.05f));
dblData[i] = ports.audio_in[i] * inputLevel; if (fabs(desiredInputLevel - inputLevel) > SMOOTH_EPSILON)
{
for (unsigned int i = 0; i < n_samples; i++)
{
// do very basic smoothing
inputLevel = (.99f * inputLevel) + (.01f * desiredInputLevel);
dblData[i] = ports.audio_in[i] * inputLevel;
}
}
else
{
inputLevel = desiredInputLevel;
for (unsigned int i = 0; i < n_samples; i++)
{
dblData[i] = ports.audio_in[i] * inputLevel;
}
} }
if (currentModel == nullptr) if (currentModel == nullptr)
@@ -205,12 +222,27 @@ namespace NAM {
currentModel->finalize_(n_samples); currentModel->finalize_(n_samples);
} }
for (unsigned int i = 0; i < n_samples; i++) // convert output level from db
{ float desiredOutputLevel = powf(10, *(ports.output_level) * 0.05f);
// Convert output level from db and do very basic smoothing
outputLevel = (.99f * outputLevel) + (.01f * powf(10, *(ports.output_level) * 0.05f));
ports.audio_out[i] = (float)(dblData[i] * outputLevel); if (fabs(desiredOutputLevel - outputLevel) > SMOOTH_EPSILON)
{
for (unsigned int i = 0; i < n_samples; i++)
{
// do very basic smoothing
outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel);
ports.audio_out[i] = (float)(dblData[i] * outputLevel);
}
}
else
{
outputLevel = desiredOutputLevel;
for (unsigned int i = 0; i < n_samples; i++)
{
ports.audio_out[i] = (float)(dblData[i] * outputLevel);
}
} }
if (stateChanged) if (stateChanged)