From eeaeeecf24cea63cbebf2d7d712ab8fd44045748 Mon Sep 17 00:00:00 2001 From: Mike Oliphant Date: Tue, 11 Nov 2025 07:23:47 -0800 Subject: [PATCH] Start new models bypassed. Prevent silentSamples from overflowing. --- src/nam_plugin.cpp | 17 ++++++++++++++--- src/nam_plugin.h | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index 2dc2a8e..df825fb 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -187,8 +187,17 @@ namespace NAM { nam->currentModelPath = msg->path; assert(nam->currentModelPath.capacity() >= MAX_FILE_NAME + 1); - nam->silentSamples = 0; - nam->smartBypassed = false; + if (nam->currentModel != nullptr) + { + int receptiveFieldSize = nam->currentModel->GetReceptiveFieldSize(); + + if (receptiveFieldSize > -1) + { + // A newly loaded model is prewarmed to have a silent sample history + nam->silentSamples = receptiveFieldSize; + nam->smartBypassed = true; + } + } // send reply nam->schedule->schedule_work(nam->schedule->handle, sizeof(reply), &reply); @@ -268,8 +277,10 @@ namespace NAM { } } - if (silentSamples > (uint32_t)receptiveFieldSamples) + if (silentSamples >= (uint32_t)receptiveFieldSamples) { + silentSamples = (uint32_t)receptiveFieldSamples; // Prevent silentSamples growing and eventually overflowing uint32 + if (smartBypassed) { for (unsigned int i = 0; i < n_samples; i++) diff --git a/src/nam_plugin.h b/src/nam_plugin.h index 686b495..b47ab9e 100644 --- a/src/nam_plugin.h +++ b/src/nam_plugin.h @@ -80,6 +80,7 @@ namespace NAM { bool initialize(double rate, const LV2_Feature* const* features) noexcept; void set_max_buffer_size(int size) noexcept; + void activate() noexcept; void process(uint32_t n_samples) noexcept; void write_current_path(); @@ -122,6 +123,6 @@ namespace NAM { int32_t maxBufferSize = 512; float bypassThresholdLinear = 0; uint32_t silentSamples = 0; - bool smartBypassed = false; + bool smartBypassed = true; }; }