diff --git a/deps/NeuralAudio b/deps/NeuralAudio index 162c804..6177d02 160000 --- a/deps/NeuralAudio +++ b/deps/NeuralAudio @@ -1 +1 @@ -Subproject commit 162c80403f95ea0b1a10038887f1ad6265fc20df +Subproject commit 6177d02f4a36c4b13e9a4e1c0f76128156b74138 diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index 1c13c1b..2dc2a8e 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -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 diff --git a/src/nam_plugin.h b/src/nam_plugin.h index 15a03a4..686b495 100644 --- a/src/nam_plugin.h +++ b/src/nam_plugin.h @@ -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; }; }