10 Commits

Author SHA1 Message Date
Mike Oliphant 1deb8cb5bc Bump version to 0.1.2 2023-09-13 07:52:52 -07:00
Mike Oliphant c3888eccae Update NAM core 2023-09-13 07:51:22 -07:00
Mike Oliphant 2d126db631 Update NAM Core. 2023-09-06 17:32:00 -07:00
Mike Oliphant bae8b0a627 Update README.md 2023-08-23 07:43:25 -07:00
Mike Oliphant 46a73d83fa Initialize model pre-run buffer to zero. Update to latest devel NAM Core with pre-warm instead of anti-pop. 2023-08-18 13:20:27 -07:00
Mike Oliphant 88c8441f0b Merge pull request #47 from moddevices/optimize-audio-level-loop
Optimize audio level loop code
2023-08-16 12:13:29 -07:00
falkTX 6f1a423b5a Optimize audio level loop code
Signed-off-by: falkTX <falktx@falktx.com>
2023-08-16 18:39:50 +02:00
Mike Oliphant fbf05b4472 Do 5Hz high pass filter to clean up any DC offset created by the model 2023-07-28 09:20:52 -07:00
Mike Oliphant ee0c83a10e Update NeuralAmpModelerCore 2023-07-27 15:32:38 -07:00
Mike Oliphant d4482b3b14 Catch exceptions by reference 2023-07-12 09:50:27 -07:00
7 changed files with 49 additions and 19 deletions
+4 -2
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(NeuralAmpModelerLv2 VERSION 0.1.1)
project(NeuralAmpModelerLv2 VERSION 0.1.2)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
@@ -22,11 +22,13 @@ set(NAM_LV2_ID http://github.com/mikeoliphant/neural-amp-modeler-lv2)
include_directories(SYSTEM deps/eigen)
include_directories(SYSTEM deps/lv2/include)
include_directories(SYSTEM deps/NeuralAmpModelerCore/NAM)
include_directories(SYSTEM deps/NeuralAmpModelerCore)
include_directories(SYSTEM deps/NeuralAmpModelerCore)
include_directories(SYSTEM deps/json)
include_directories(SYSTEM deps/denormal)
add_definitions(-DNAM_SAMPLE_FLOAT)
add_definitions(-DDSP_SAMPLE_FLOAT)
add_subdirectory(src)
+1 -1
View File
@@ -2,7 +2,7 @@
Bare-bones implementation of [Neural Amp Modeler](https://github.com/sdatkinson/neural-amp-modeler) (NAM) models in an LV2 plugin.
**There is no user interface**. Setting the model to use requires that your LV2 host supports atom:Path parameters. Reaper does not. Carla and Ardour do. If your favorite LV2 host does not support atom:Path, let them know you want it. **A Reaper feature request for this is [here](https://forum.cockos.com/showthread.php?p=2505988)**.
**There is no user interface**. Setting the model to use requires that your LV2 host supports atom:Path parameters. Reaper does as of v6.82. Carla and Ardour do. If your favorite LV2 host does not support atom:Path, let them know you want it.
To get the intended behavior, **you must run your audio host at the same sample rate the model was trained at** (usually 48kHz) - no resampling is done by the plugin.
+7 -1
View File
@@ -17,10 +17,16 @@ set(NAM_SOURCES ../deps/NeuralAmpModelerCore/NAM/activations.h
../deps/NeuralAmpModelerCore/NAM/convnet.cpp
../deps/NeuralAmpModelerCore/NAM/convnet.h)
add_library(neural_amp_modeler MODULE ${SOURCES} ${NAM_SOURCES})
set(DSP_SOURCES ../deps/NeuralAmpModelerCore/dsp/dsp.h
../deps/NeuralAmpModelerCore/dsp/dsp.cpp
../deps/NeuralAmpModelerCore/dsp/RecursiveLinearFilter.h
../deps/NeuralAmpModelerCore/dsp/RecursiveLinearFilter.cpp)
add_library(neural_amp_modeler MODULE ${SOURCES} ${NAM_SOURCES} ${DSP_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
source_group(NAM ${CMAKE_CURRENT_SOURCE_DIR} FILES ${NAM_SOURCES})
source_group(dsp ${CMAKE_CURRENT_SOURCE_DIR} FILES ${DSP_SOURCES})
option(DISABLE_DENORMALS "Disable floating point denormals" ON)
+1 -1
View File
@@ -27,7 +27,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
return nullptr;
}
catch(const std::exception)
catch(const std::exception&)
{
return nullptr;
}
+30 -12
View File
@@ -1,10 +1,10 @@
#include <algorithm>
#include <cmath>
#include <utility>
#include <cassert>
#include "nam_plugin.h"
#include "activations.h"
#include <cassert>
#include <NAM/activations.h>
#define SMOOTH_EPSILON .0001f
@@ -20,8 +20,14 @@ namespace NAM {
delete currentModel;
}
bool Plugin::initialize(double rate, const LV2_Feature* const* features) noexcept
bool Plugin::initialize(double sampleRate, const LV2_Feature* const* features) noexcept
{
this->sampleRate = sampleRate;
const double highPassCutoffFreq = 5.0;
const recursive_linear_filter::HighPassParams highPassParams(sampleRate, highPassCutoffFreq);
mHighPass.SetParams(highPassParams);
// for fetching initial options, can be null
LV2_Options_Option* options = nullptr;
@@ -114,6 +120,7 @@ namespace NAM {
if (const int32_t numSamples = nam->maxBufferSize)
{
float* buffer = new float[numSamples];
memset(buffer, 0, numSamples * sizeof(float));
std::unordered_map<std::string, double> params = {};
model->process(&buffer, &buffer, 1, numSamples, 1.0, 1.0, params);
@@ -127,7 +134,7 @@ namespace NAM {
memcpy(response.path, msg->path, pathlen);
}
catch (std::exception)
catch (const std::exception&)
{
response.path[0] = '\0';
@@ -220,33 +227,42 @@ namespace NAM {
}
}
float level;
// convert input level from db
float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
if (fabs(desiredInputLevel - inputLevel) > SMOOTH_EPSILON)
{
level = inputLevel;
for (unsigned int i = 0; i < n_samples; i++)
{
// do very basic smoothing
inputLevel = (.99f * inputLevel) + (.01f * desiredInputLevel);
level = (.99f * level) + (.01f * desiredInputLevel);
ports.audio_out[i] = ports.audio_in[i] * inputLevel;
ports.audio_out[i] = ports.audio_in[i] * level;
}
inputLevel = level;
}
else
{
inputLevel = desiredInputLevel;
level = inputLevel = desiredInputLevel;
for (unsigned int i = 0; i < n_samples; i++)
{
ports.audio_out[i] = ports.audio_in[i] * inputLevel;
ports.audio_out[i] = ports.audio_in[i] * level;
}
}
float** outputPtrs = &ports.audio_out;
if (currentModel != nullptr)
{
currentModel->process(&ports.audio_out, &ports.audio_out, 1, n_samples, 1.0, 1.0, mNAMParams);
currentModel->finalize_(n_samples);
// Apply a high pass filter at 5Hz to eliminate any DC offset
outputPtrs = mHighPass.Process(outputPtrs, 1, n_samples);
}
// convert output level from db
@@ -254,21 +270,23 @@ namespace NAM {
if (fabs(desiredOutputLevel - outputLevel) > SMOOTH_EPSILON)
{
level = outputLevel;
for (unsigned int i = 0; i < n_samples; i++)
{
// do very basic smoothing
outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel);
level = (.99f * level) + (.01f * desiredOutputLevel);
ports.audio_out[i] *= outputLevel;
ports.audio_out[i] = outputPtrs[0][i] * outputLevel;
}
outputLevel = level;
}
else
{
outputLevel = desiredOutputLevel;
level = outputLevel = desiredOutputLevel;
for (unsigned int i = 0; i < n_samples; i++)
{
ports.audio_out[i] *= outputLevel;
ports.audio_out[i] = outputPtrs[0][i] * level;
}
}
}
+5 -1
View File
@@ -21,7 +21,8 @@
#include <lv2/state/state.h>
#include <lv2/units/units.h>
#include "dsp.h"
#include <NAM/dsp.h>
#include <dsp/RecursiveLinearFilter.h>
#define PlUGIN_URI "http://github.com/mikeoliphant/neural-amp-modeler-lv2"
#define MODEL_URI PlUGIN_URI "#model"
@@ -64,12 +65,15 @@ namespace NAM {
Ports ports = {};
double sampleRate;
LV2_URID_Map* map = nullptr;
LV2_Log_Logger logger = {};
LV2_Worker_Schedule* schedule = nullptr;
::DSP* currentModel = nullptr;
std::string currentModelPath;
recursive_linear_filter::HighPass mHighPass;
std::unordered_map<std::string, double> mNAMParams = {};