mirror of
https://github.com/mikeoliphant/neural-amp-modeler-lv2.git
synced 2026-05-06 19:50:11 +02:00
Smart bypass on silence
This commit is contained in:
Vendored
+1
-1
Submodule deps/NeuralAudio updated: 162c80403f...6177d02f4a
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user