diff --git a/CMakeLists.txt b/CMakeLists.txt index 14ac1bd..436d663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/deps/NeuralAmpModelerCore b/deps/NeuralAmpModelerCore index accaa16..de9cf22 160000 --- a/deps/NeuralAmpModelerCore +++ b/deps/NeuralAmpModelerCore @@ -1 +1 @@ -Subproject commit accaa16ef35bea2e3d257e5f15584f4f644f1438 +Subproject commit de9cf22b0df6dada8f33f35ff98613933b411e96 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ca6c97..a538127 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index a691dbc..b9274b3 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -1,10 +1,10 @@ #include #include #include +#include #include "nam_plugin.h" -#include "activations.h" -#include +#include #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; @@ -243,10 +249,15 @@ namespace NAM { } } + 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 @@ -259,7 +270,7 @@ namespace NAM { // do very basic smoothing outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel); - ports.audio_out[i] *= outputLevel; + ports.audio_out[i] = outputPtrs[0][i] * outputLevel; } } else @@ -268,7 +279,7 @@ namespace NAM { for (unsigned int i = 0; i < n_samples; i++) { - ports.audio_out[i] *= outputLevel; + ports.audio_out[i] = outputPtrs[0][i] * outputLevel; } } } diff --git a/src/nam_plugin.h b/src/nam_plugin.h index e96644d..c1b386c 100644 --- a/src/nam_plugin.h +++ b/src/nam_plugin.h @@ -21,7 +21,8 @@ #include #include -#include "dsp.h" +#include +#include #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 mNAMParams = {};