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
+36 -4
View File
@@ -6,6 +6,8 @@
#include "activations.h"
#include <cassert>
#define SMOOTH_EPSILON .0001f
namespace NAM {
Plugin::Plugin()
{
@@ -186,13 +188,28 @@ namespace NAM {
if (dblData.size() != n_samples)
dblData.resize(n_samples);
// convert input level from db
float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
if (fabs(desiredInputLevel - inputLevel) > SMOOTH_EPSILON)
{
for (unsigned int i = 0; i < n_samples; i++)
{
// Convert input level from db and do very basic smoothing
inputLevel = (.99f * inputLevel) + (.01f * powf(10, *(ports.input_level) * 0.05f));
// 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)
{
@@ -205,13 +222,28 @@ namespace NAM {
currentModel->finalize_(n_samples);
}
// convert output level from db
float desiredOutputLevel = powf(10, *(ports.output_level) * 0.05f);
if (fabs(desiredOutputLevel - outputLevel) > SMOOTH_EPSILON)
{
for (unsigned int i = 0; i < n_samples; i++)
{
// Convert output level from db and do very basic smoothing
outputLevel = (.99f * outputLevel) + (.01f * powf(10, *(ports.output_level) * 0.05f));
// 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)
{