22 Commits

Author SHA1 Message Date
Mike Oliphant 34c7628202 Bump version to 0.1.3 2023-10-16 08:17:06 -07:00
Mike Oliphant 8384827981 Removed test value. 2023-10-15 18:12:27 -07:00
Mike Oliphant e3c5b6bd4f Update for normalization->loudness in NAM core. 2023-10-15 18:11:36 -07:00
Mike Oliphant eb46377d71 Update to latest NAM core. Handle model normalization with output gain. 2023-10-15 12:09:52 -07:00
Mike Oliphant b22f02c84e Update NAM core. Switch to new simplified NAM process method. 2023-10-06 11:51:30 -07:00
Mike Oliphant 52810a3f9c Switched to AudioDSPTools for highpass filter implementation 2023-10-02 08:12:33 -07:00
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
Mike Oliphant c990eedf33 Bump version 2023-07-07 07:29:50 -07:00
Mike Oliphant 0255f36ae4 Don't report a worker error if we can't load a model since we're already logging an error. 2023-07-04 16:28:57 -07:00
Mike Oliphant 207fb2281e Fixed some warnings 2023-07-04 14:55:17 -07:00
Mike Oliphant dbf00f0ed3 Formatting 2023-07-04 14:53:39 -07:00
Mike Oliphant 33a0c08327 Set currentModelPath in restore() - even if it is null or empty.
Set it to empty and clear the current model if a model fails to load.
2023-07-04 13:03:46 -07:00
Mike Oliphant cde3df4e84 Update to latest NAM Core 2023-06-23 08:07:43 -07:00
9 changed files with 138 additions and 87 deletions
+3
View File
@@ -8,3 +8,6 @@
path = deps/NeuralAmpModelerCore path = deps/NeuralAmpModelerCore
url = https://github.com/mikeoliphant/NeuralAmpModelerCore url = https://github.com/mikeoliphant/NeuralAmpModelerCore
branch = devel branch = devel
[submodule "deps/AudioDSPTools"]
path = deps/AudioDSPTools
url = https://github.com/sdatkinson/AudioDSPTools
+4 -2
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(NeuralAmpModelerLv2 VERSION 0.1.0) project(NeuralAmpModelerLv2 VERSION 0.1.3)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 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/eigen)
include_directories(SYSTEM deps/lv2/include) include_directories(SYSTEM deps/lv2/include)
include_directories(SYSTEM deps/NeuralAmpModelerCore/NAM) include_directories(SYSTEM deps/NeuralAmpModelerCore)
include_directories(SYSTEM deps/AudioDSPTools)
include_directories(SYSTEM deps/json) include_directories(SYSTEM deps/json)
include_directories(SYSTEM deps/denormal) include_directories(SYSTEM deps/denormal)
add_definitions(-DNAM_SAMPLE_FLOAT) add_definitions(-DNAM_SAMPLE_FLOAT)
add_definitions(-DDSP_SAMPLE_FLOAT)
add_subdirectory(src) 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. 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. 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.
Vendored Submodule
+1
Submodule deps/AudioDSPTools added at 37f73d9ea6
+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.cpp
../deps/NeuralAmpModelerCore/NAM/convnet.h) ../deps/NeuralAmpModelerCore/NAM/convnet.h)
add_library(neural_amp_modeler MODULE ${SOURCES} ${NAM_SOURCES}) set(DSP_SOURCES ../deps/AudioDSPTools/dsp/dsp.h
../deps/AudioDSPTools/dsp/dsp.cpp
../deps/AudioDSPTools/dsp/RecursiveLinearFilter.h
../deps/AudioDSPTools/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(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
source_group(NAM ${CMAKE_CURRENT_SOURCE_DIR} FILES ${NAM_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) option(DISABLE_DENORMALS "Disable floating point denormals" ON)
+2 -1
View File
@@ -27,7 +27,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
return nullptr; return nullptr;
} }
catch(const std::exception& e) catch(const std::exception&)
{ {
return nullptr; return nullptr;
} }
@@ -36,6 +36,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
static void connect_port(LV2_Handle instance, uint32_t port, void* data) static void connect_port(LV2_Handle instance, uint32_t port, void* data)
{ {
auto nam = static_cast<NAM::Plugin*>(instance); auto nam = static_cast<NAM::Plugin*>(instance);
*(reinterpret_cast<void**>(&nam->ports)+port) = data; *(reinterpret_cast<void**>(&nam->ports)+port) = data;
} }
+90 -53
View File
@@ -1,10 +1,10 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <utility> #include <utility>
#include <cassert>
#include "nam_plugin.h" #include "nam_plugin.h"
#include "activations.h" #include <NAM/activations.h>
#include <cassert>
#define SMOOTH_EPSILON .0001f #define SMOOTH_EPSILON .0001f
@@ -20,12 +20,19 @@ namespace NAM {
delete currentModel; 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 // for fetching initial options, can be null
LV2_Options_Option* options = nullptr; LV2_Options_Option* options = nullptr;
for (size_t i = 0; features[i]; ++i) { for (size_t i = 0; features[i]; ++i)
{
if (std::string(features[i]->URI) == std::string(LV2_URID__map)) if (std::string(features[i]->URI) == std::string(LV2_URID__map))
map = static_cast<LV2_URID_Map*>(features[i]->data); map = static_cast<LV2_URID_Map*>(features[i]->data);
else if (std::string(features[i]->URI) == std::string(LV2_WORKER__schedule)) else if (std::string(features[i]->URI) == std::string(LV2_WORKER__schedule))
@@ -85,11 +92,14 @@ namespace NAM {
auto msg = static_cast<const LV2LoadModelMsg*>(data); auto msg = static_cast<const LV2LoadModelMsg*>(data);
auto nam = static_cast<NAM::Plugin*>(instance); auto nam = static_cast<NAM::Plugin*>(instance);
::DSP* model = nullptr;
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, {} };
LV2_Worker_Status result = LV2_WORKER_SUCCESS;
try try
{ {
// load model from path // load model from path
const size_t pathlen = strlen(msg->path); const size_t pathlen = strlen(msg->path);
::DSP* model;
if (pathlen == 0 || pathlen >= MAX_FILE_NAME) if (pathlen == 0 || pathlen >= MAX_FILE_NAME)
{ {
@@ -103,40 +113,42 @@ namespace NAM {
model = get_dsp(msg->path).release(); model = get_dsp(msg->path).release();
// Enable model loudness normalization
model->SetNormalize(true);
// Pre-run model to ensure all needed buffers are allocated in advance // Pre-run model to ensure all needed buffers are allocated in advance
if (const int32_t numSamples = nam->maxBufferSize) if (const int32_t numSamples = nam->maxBufferSize)
{ {
float* buffer = new float[numSamples]; float* buffer = new float[numSamples];
memset(buffer, 0, numSamples * sizeof(float));
std::unordered_map<std::string, double> params = {}; model->process(buffer, buffer, numSamples);
model->process(&buffer, &buffer, 1, numSamples, 1.0, 1.0, params);
model->finalize_(numSamples); model->finalize_(numSamples);
delete[] buffer; delete[] buffer;
} }
} }
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, model }; response.model = model;
memcpy(response.path, msg->path, pathlen); memcpy(response.path, msg->path, pathlen);
}
catch (const std::exception&)
{
response.path[0] = '\0';
lv2_log_error(&nam->logger, "Unable to load model from: '%s'\n", msg->path);
//result = LV2_WORKER_ERR_UNKNOWN;
}
respond(handle, sizeof(response), &response); respond(handle, sizeof(response), &response);
return LV2_WORKER_SUCCESS; return result;
}
catch (std::exception& e)
{
lv2_log_error(&nam->logger, "Unable to load model from: '%s'\n", msg->path);
}
break;
} }
case kWorkTypeFree: case kWorkTypeFree:
{ {
auto msg = static_cast<const LV2FreeModelMsg*>(data); auto msg = static_cast<const LV2FreeModelMsg*>(data);
delete msg->model; delete msg->model;
return LV2_WORKER_SUCCESS; return LV2_WORKER_SUCCESS;
} }
@@ -211,55 +223,77 @@ namespace NAM {
} }
} }
float level;
// convert input level from db // convert input level from db
float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f); float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
if (fabs(desiredInputLevel - inputLevel) > SMOOTH_EPSILON) if (fabs(desiredInputLevel - inputLevel) > SMOOTH_EPSILON)
{ {
level = inputLevel;
for (unsigned int i = 0; i < n_samples; i++) for (unsigned int i = 0; i < n_samples; i++)
{ {
// do very basic smoothing // 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 else
{ {
inputLevel = desiredInputLevel; level = inputLevel = desiredInputLevel;
for (unsigned int i = 0; i < n_samples; i++) 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;
float modelLoudnessAdjustmentDB = 0;
if (currentModel != nullptr) if (currentModel != nullptr)
{ {
currentModel->process(&ports.audio_out, &ports.audio_out, 1, n_samples, 1.0, 1.0, mNAMParams); currentModel->process(ports.audio_out, ports.audio_out, n_samples);
currentModel->finalize_(n_samples); currentModel->finalize_(n_samples);
// Apply a high pass filter at 5Hz to eliminate any DC offset
outputPtrs = mHighPass.Process(outputPtrs, 1, n_samples);
if (currentModel->HasLoudness())
{
// Normalize model to -18dB
modelLoudnessAdjustmentDB = -18 - currentModel->GetLoudness();
}
} }
// convert output level from db // Convert output level from db
float desiredOutputLevel = powf(10, *(ports.output_level) * 0.05f); float desiredOutputLevel = powf(10, (*(ports.output_level) + modelLoudnessAdjustmentDB) * 0.05f);
if (fabs(desiredOutputLevel - outputLevel) > SMOOTH_EPSILON) if (fabs(desiredOutputLevel - outputLevel) > SMOOTH_EPSILON)
{ {
level = outputLevel;
for (unsigned int i = 0; i < n_samples; i++) for (unsigned int i = 0; i < n_samples; i++)
{ {
// do very basic smoothing // 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 else
{ {
outputLevel = desiredOutputLevel; level = outputLevel = desiredOutputLevel;
for (unsigned int i = 0; i < n_samples; i++) for (unsigned int i = 0; i < n_samples; i++)
{ {
ports.audio_out[i] *= outputLevel; ports.audio_out[i] = outputPtrs[0][i] * level;
} }
} }
} }
@@ -293,7 +327,8 @@ namespace NAM {
lv2_log_trace(&nam->logger, "Saving state\n"); lv2_log_trace(&nam->logger, "Saving state\n");
if (!nam->currentModel) { if (!nam->currentModel)
{
return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;
} }
@@ -331,8 +366,6 @@ namespace NAM {
LV2_State_Status Plugin::restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, LV2_State_Status Plugin::restore(LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle,
uint32_t flags, const LV2_Feature* const* features) uint32_t flags, const LV2_Feature* const* features)
{ {
//if (!haveLog) return LV2_STATE_SUCCESS;
auto nam = static_cast<NAM::Plugin*>(instance); auto nam = static_cast<NAM::Plugin*>(instance);
// Get model_Path from state // Get model_Path from state
@@ -343,16 +376,17 @@ namespace NAM {
lv2_log_trace(&nam->logger, "Restoring model '%s'\n", (const char*)value); lv2_log_trace(&nam->logger, "Restoring model '%s'\n", (const char*)value);
if (!value) { NAM::LV2LoadModelMsg msg = { NAM::kWorkTypeLoad, {} };
lv2_log_error(&nam->logger, "Missing model_Path\n");
return LV2_STATE_ERR_NO_PROPERTY;
}
if (type != nam->uris.atom_Path) { LV2_State_Status result = LV2_STATE_SUCCESS;
lv2_log_error(&nam->logger, "Non-path model_Path\n");
return LV2_STATE_ERR_BAD_TYPE;
}
// Check if a path is set
if (!value || (type != nam->uris.atom_Path))
{
msg.path[0] = '\0';
}
else
{
LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath); LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath);
if (map_path == nullptr) if (map_path == nullptr)
@@ -367,22 +401,16 @@ namespace NAM {
size_t pathLen = strlen(path); size_t pathLen = strlen(path);
LV2_State_Status result = LV2_STATE_SUCCESS; if (pathLen >= MAX_FILE_NAME)
if (pathLen < MAX_FILE_NAME)
{
// Schedule model to be loaded by the provided worker
NAM::LV2LoadModelMsg msg = { NAM::kWorkTypeLoad, {} };
memcpy(msg.path, path, pathLen);
nam->schedule->schedule_work(nam->schedule->handle, sizeof(msg), &msg);
}
else
{ {
lv2_log_error(&nam->logger, "Model path is too long (max %u chars)\n", MAX_FILE_NAME); lv2_log_error(&nam->logger, "Model path is too long (max %u chars)\n", MAX_FILE_NAME);
result = LV2_STATE_ERR_UNKNOWN; result = LV2_STATE_ERR_UNKNOWN;
} }
else
{
memcpy(msg.path, path, pathLen);
}
LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath); LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath);
@@ -396,6 +424,15 @@ namespace NAM {
free(path); free(path);
#endif #endif
} }
}
if (result == LV2_STATE_SUCCESS)
{
// Schedule model to be loaded by the provided worker
nam->schedule->schedule_work(nam->schedule->handle, sizeof(msg), &msg);
nam->currentModelPath = msg.path;
}
return result; return result;
} }
@@ -410,7 +447,7 @@ namespace NAM {
lv2_atom_forge_key(&atom_forge, uris.patch_property); lv2_atom_forge_key(&atom_forge, uris.patch_property);
lv2_atom_forge_urid(&atom_forge, uris.model_Path); lv2_atom_forge_urid(&atom_forge, uris.model_Path);
lv2_atom_forge_key(&atom_forge, uris.patch_value); lv2_atom_forge_key(&atom_forge, uris.patch_value);
lv2_atom_forge_path(&atom_forge, currentModelPath.c_str(), currentModelPath.length() + 1); lv2_atom_forge_path(&atom_forge, currentModelPath.c_str(), (uint32_t)currentModelPath.length() + 1);
lv2_atom_forge_pop(&atom_forge, &frame); lv2_atom_forge_pop(&atom_forge, &frame);
} }
+5 -4
View File
@@ -21,7 +21,8 @@
#include <lv2/state/state.h> #include <lv2/state/state.h>
#include <lv2/units/units.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 PlUGIN_URI "http://github.com/mikeoliphant/neural-amp-modeler-lv2"
#define MODEL_URI PlUGIN_URI "#model" #define MODEL_URI PlUGIN_URI "#model"
@@ -64,14 +65,15 @@ namespace NAM {
Ports ports = {}; Ports ports = {};
double sampleRate;
LV2_URID_Map* map = nullptr; LV2_URID_Map* map = nullptr;
LV2_Log_Logger logger = {}; LV2_Log_Logger logger = {};
LV2_Worker_Schedule* schedule = nullptr; LV2_Worker_Schedule* schedule = nullptr;
::DSP* currentModel = nullptr; ::DSP* currentModel = nullptr;
std::string currentModelPath; std::string currentModelPath;
recursive_linear_filter::HighPass mHighPass;
std::unordered_map<std::string, double> mNAMParams = {};
Plugin(); Plugin();
~Plugin(); ~Plugin();
@@ -114,7 +116,6 @@ namespace NAM {
LV2_Atom_Forge atom_forge = {}; LV2_Atom_Forge atom_forge = {};
LV2_Atom_Forge_Frame sequence_frame; LV2_Atom_Forge_Frame sequence_frame;
float m_rate;
float inputLevel = 0; float inputLevel = 0;
float outputLevel = 0; float outputLevel = 0;
int32_t maxBufferSize = 0; int32_t maxBufferSize = 0;