Smart bypass on silence

This commit is contained in:
Mike Oliphant
2025-11-10 10:45:29 -08:00
parent b5b934d4e7
commit 42d9d8b4c3
3 changed files with 49 additions and 1 deletions
+45
View File
@@ -7,12 +7,18 @@
#define SMOOTH_EPSILON .0001f
#ifndef BYPASS_DB_THRESHOLD
#define BYPASS_DB_THRESHOLD -100
#endif
namespace NAM {
Plugin::Plugin()
{
// prevent allocations on the audio thread
currentModelPath.reserve(MAX_FILE_NAME + 1);
bypassThresholdLinear = powf(10, BYPASS_DB_THRESHOLD * 0.05f);
// NeuralAudio::NeuralModel::SetLSTMLoadMode(
//#ifdef LSTM_PREFER_NAM
// NeuralAudio::PreferNAMCore
@@ -181,6 +187,9 @@ namespace NAM {
nam->currentModelPath = msg->path;
assert(nam->currentModelPath.capacity() >= MAX_FILE_NAME + 1);
nam->silentSamples = 0;
nam->smartBypassed = false;
// send reply
nam->schedule->schedule_work(nam->schedule->handle, sizeof(reply), &reply);
@@ -241,6 +250,42 @@ namespace NAM {
if (currentModel != nullptr)
{
modelInputAdjustmentDB = currentModel->GetRecommendedInputDBAdjustment();
#ifdef SMART_BYPASS_ENABLED
int receptiveFieldSamples = currentModel->GetReceptiveFieldSize();
if (receptiveFieldSamples > -1)
{
for (unsigned int i = 0; i < n_samples; i++)
{
if (abs(ports.audio_in[i]) <= bypassThresholdLinear)
{
silentSamples++;
}
else
{
silentSamples = 0;
}
}
if (silentSamples > (uint32_t)receptiveFieldSamples)
{
if (smartBypassed)
{
for (unsigned int i = 0; i < n_samples; i++)
{
ports.audio_out[i] = ports.audio_in[i];
}
return;
}
smartBypassed = true; // If we aren't already, we'll be bypassed on the next process call
}
else
smartBypassed = false;
}
#endif
}
// convert input level from db
+3
View File
@@ -120,5 +120,8 @@ namespace NAM {
float inputLevel = 0;
float outputLevel = 0;
int32_t maxBufferSize = 512;
float bypassThresholdLinear = 0;
uint32_t silentSamples = 0;
bool smartBypassed = false;
};
}