mirror of
https://github.com/mikeoliphant/neural-amp-modeler-lv2.git
synced 2026-05-09 20:29:12 +02:00
Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 94a48c2862 | |||
| 09166f198b | |||
| ad593b4038 | |||
| 32f18a242a | |||
| d48e4a4080 | |||
| 5ed03b558c | |||
| b9e6cf65ca | |||
| a7d19ecfab | |||
| be05479671 | |||
| 38456dae4a | |||
| d2cc00186f | |||
| ec34afb608 | |||
| 7326960e2a | |||
| 000925228f | |||
| ecf21c6c62 | |||
| 276dafd832 | |||
| 29b52ae3e9 | |||
| b06904b56b | |||
| 19d3abb12d | |||
| 567719af61 | |||
| eb5bd17f70 | |||
| 57f79945de | |||
| 4643e66e08 | |||
| 0649b4a822 | |||
| 61bbce1e2a | |||
| 1dc54bc5f9 | |||
| 40bae2bd87 | |||
| 1ff6dab119 | |||
| baff908f93 | |||
| 72fd4a1e3d | |||
| 1626e74d0e | |||
| d1794e1bbd | |||
| b8c6333955 | |||
| 02256b4349 | |||
| f07c40c16f | |||
| 5605b03acc | |||
| 43fb036706 | |||
| b40df0945c | |||
| 24f03afd69 | |||
| db3603e134 | |||
| 97cff04114 | |||
| 067b3236ea | |||
| 191ae3786e | |||
| 2b5a4c9912 | |||
| 23200eb566 | |||
| 3434ba0b7d | |||
| 3e9ffee4e7 | |||
| 3cff8ca37a | |||
| fcec78fa0f | |||
| 34be69df6d | |||
| 34c7628202 | |||
| 8384827981 | |||
| e3c5b6bd4f | |||
| eb46377d71 | |||
| b22f02c84e | |||
| 52810a3f9c | |||
| 1deb8cb5bc | |||
| c3888eccae | |||
| 2d126db631 | |||
| bae8b0a627 | |||
| 46a73d83fa | |||
| 88c8441f0b | |||
| 6f1a423b5a | |||
| fbf05b4472 | |||
| ee0c83a10e | |||
| d4482b3b14 |
@@ -24,6 +24,18 @@ jobs:
|
|||||||
cmake --build . --config $BUILD_TYPE -j4
|
cmake --build . --config $BUILD_TYPE -j4
|
||||||
cpack
|
cpack
|
||||||
|
|
||||||
|
- name: Upload binary
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: neural_amp_modeler.lv2-linux-amd64
|
||||||
|
path: ${{github.workspace}}/build/neural_amp_modeler.lv2
|
||||||
|
|
||||||
|
# - name: Upload deb
|
||||||
|
# uses: actions/upload-artifact@v4
|
||||||
|
# with:
|
||||||
|
# name: neural_amp_modeler.lv2-linux-deb-amd64
|
||||||
|
# path: ${{github.workspace}}/build/*.deb
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
name: Build Windows
|
name: Build Windows
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
@@ -35,5 +47,11 @@ jobs:
|
|||||||
- name: Build Plugin
|
- name: Build Plugin
|
||||||
working-directory: ${{github.workspace}}/build
|
working-directory: ${{github.workspace}}/build
|
||||||
run: |
|
run: |
|
||||||
cmake.exe -G "Visual Studio 17 2022" -A x64 ..
|
cmake.exe -G "Visual Studio 17 2022" -A x64 -T ClangCL ..
|
||||||
cmake --build . --config=release -j4
|
cmake --build . --config=release -j4
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: neural_amp_modeler.lv2-win
|
||||||
|
path: ${{github.workspace}}/build/neural_amp_modeler.lv2
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
BUILD_TYPE: Release
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create_release:
|
||||||
|
name: Create release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
upload_url: ${{steps.create_release.outputs.upload_url}}
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
tag_name: ${{github.ref}}
|
||||||
|
release_name: Release ${{github.ref}}
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
name: Build Windows
|
||||||
|
needs: create_release
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3.3.0
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Build Plugin
|
||||||
|
working-directory: ${{github.workspace}}/build
|
||||||
|
run: |
|
||||||
|
cmake.exe -G "Visual Studio 17 2022" -A x64 -T ClangCL ..
|
||||||
|
cmake --build . --config=release -j4
|
||||||
|
|
||||||
|
- name: Add LV2 Archive
|
||||||
|
run: Compress-Archive -Path ${{github.workspace}}\build\neural_amp_modeler.lv2 -Destination neural_amp_modeler.lv2.zip
|
||||||
|
|
||||||
|
- name: Upload Plugin Asset
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ needs.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ./neural_amp_modeler.lv2.zip
|
||||||
|
asset_name: neural_amp_modeler.lv2.zip
|
||||||
|
asset_content_type: application/zip
|
||||||
+3
-7
@@ -1,10 +1,6 @@
|
|||||||
[submodule "lv2"]
|
[submodule "lv2"]
|
||||||
path = deps/lv2
|
path = deps/lv2
|
||||||
url = https://github.com/lv2/lv2
|
url = https://github.com/lv2/lv2
|
||||||
[submodule "eigen"]
|
[submodule "deps/NeuralAudio"]
|
||||||
path = deps/eigen
|
path = deps/NeuralAudio
|
||||||
url = https://gitlab.com/libeigen/eigen
|
url = https://github.com/mikeoliphant/NeuralAudio
|
||||||
[submodule "NeuralAmpModelerCore"]
|
|
||||||
path = deps/NeuralAmpModelerCore
|
|
||||||
url = https://github.com/mikeoliphant/NeuralAmpModelerCore
|
|
||||||
branch = devel
|
|
||||||
|
|||||||
+2
-10
@@ -1,10 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
project(NeuralAmpModelerLv2 VERSION 0.1.1)
|
project(NeuralAmpModelerLv2 VERSION 0.1.5)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
|
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
@@ -20,14 +20,6 @@ endif()
|
|||||||
|
|
||||||
set(NAM_LV2_ID http://github.com/mikeoliphant/neural-amp-modeler-lv2)
|
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/json)
|
|
||||||
include_directories(SYSTEM deps/denormal)
|
|
||||||
|
|
||||||
add_definitions(-DNAM_SAMPLE_FLOAT)
|
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -1,9 +1,11 @@
|
|||||||
This repository uses code from a number of sources:
|
This repository uses code from a number of sources:
|
||||||
|
|
||||||
https://github.com/sdatkinson/NeuralAmpModelerPlugin
|
https://github.com/sdatkinson/NeuralAmpModelerCore
|
||||||
|
|
||||||
https://gitlab.com/libeigen/eigen
|
https://gitlab.com/libeigen/eigen
|
||||||
|
|
||||||
|
https://github.com/jatinchowdhury18/RTNeural
|
||||||
|
|
||||||
https://github.com/lv2/lv2
|
https://github.com/lv2/lv2
|
||||||
|
|
||||||
In addition, the CMake structure and LV2 plugin structure are based on code from https://github.com/Dougal-s/Aether.
|
In addition, the CMake structure and LV2 plugin structure are based on code from https://github.com/Dougal-s/Aether.
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
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.
|
||||||
|
If you are looking for a GUI version, @brummer10 [has one here](https://github.com/brummer10/neural-amp-modeler-ui) that works for Linux and Windows. You may also be interested in the the version shipped with the [MOD Desktop App](https://github.com/moddevices/mod-desktop-app), or my digital pedalboard app [Stompbox](https://github.com/mikeoliphant/StompboxUI).
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
@@ -44,3 +45,6 @@ Note - you'll have to change the Visual Studio version if you are using a differ
|
|||||||
|
|
||||||
After building, the plugin will be in **build/neural_amp_modeler.lv2**.
|
After building, the plugin will be in **build/neural_amp_modeler.lv2**.
|
||||||
|
|
||||||
|
### Optimization
|
||||||
|
|
||||||
|
If you have a relatively modern x64 processor, you can pass "**‑DUSE_NATIVE_ARCH=ON**" on your cmake command line to enable certain processor-specific optimizations.
|
||||||
|
|||||||
Vendored
-1
Submodule deps/NeuralAmpModelerCore deleted from 637dc60c9a
+1
Submodule deps/NeuralAudio added at 2f6f136dc3
Vendored
-1
Submodule deps/eigen deleted from 7bf2968fed
Vendored
-22875
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
Submodule deps/lv2 updated: dbdbe3e518...e9d9432874
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<@NAM_LV2_ID@#model>
|
<@NAM_LV2_ID@#model>
|
||||||
a lv2:Parameter;
|
a lv2:Parameter;
|
||||||
mod:fileTypes "nam,nammodel";
|
mod:fileTypes "nam,nammodel,json";
|
||||||
rdfs:label "Neural Model";
|
rdfs:label "Neural Model";
|
||||||
rdfs:range atom:Path.
|
rdfs:range atom:Path.
|
||||||
|
|
||||||
@@ -39,11 +39,13 @@
|
|||||||
opts:supportedOption <http://lv2plug.in/ns/ext/buf-size#maxBlockLength>;
|
opts:supportedOption <http://lv2plug.in/ns/ext/buf-size#maxBlockLength>;
|
||||||
|
|
||||||
rdfs:comment """
|
rdfs:comment """
|
||||||
An LV2 implementation of Neural Amp Modeler.
|
LV2 plugin for neural network machine learning guitar amplifier simulation models
|
||||||
|
|
||||||
NAM accepts Neural Amp Modeler .nam files.
|
Models supported:
|
||||||
|
Neural Amp Modeler (NAM): https://github.com/sdatkinson/neural-amp-modeler
|
||||||
|
RTNeural keras/Aida-x models: https://github.com/jatinchowdhury18/RTNeural
|
||||||
|
|
||||||
A large collection of .nam files is available at https://tonehunt.org/
|
A large collection of models is available at https://tonehunt.org
|
||||||
""";
|
""";
|
||||||
|
|
||||||
patch:writable <@NAM_LV2_ID@#model>;
|
patch:writable <@NAM_LV2_ID@#model>;
|
||||||
|
|||||||
+19
-17
@@ -1,26 +1,21 @@
|
|||||||
|
add_subdirectory(../deps/NeuralAudio NeuralAudio)
|
||||||
|
|
||||||
|
include_directories(SYSTEM ../deps/NeuralAudio)
|
||||||
|
include_directories(SYSTEM ../deps/lv2/include)
|
||||||
|
include_directories(SYSTEM ../deps/denormal)
|
||||||
|
|
||||||
set(SOURCES nam_lv2.cpp
|
set(SOURCES nam_lv2.cpp
|
||||||
nam_plugin.cpp
|
nam_plugin.cpp
|
||||||
nam_plugin.h)
|
nam_plugin.h)
|
||||||
|
|
||||||
set(NAM_SOURCES ../deps/NeuralAmpModelerCore/NAM/activations.h
|
set(NA_SOURCES ../deps/NeuralAudio/NeuralAudio/NeuralModel.h)
|
||||||
../deps/NeuralAmpModelerCore/NAM/activations.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/version.h
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/lstm.h
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/lstm.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/dsp.h
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/dsp.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/get_dsp.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/util.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/util.h
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/wavenet.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/wavenet.h
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/convnet.cpp
|
|
||||||
../deps/NeuralAmpModelerCore/NAM/convnet.h)
|
|
||||||
|
|
||||||
add_library(neural_amp_modeler MODULE ${SOURCES} ${NAM_SOURCES})
|
add_library(neural_amp_modeler SHARED ${SOURCES} ${NA_SOURCES})
|
||||||
|
|
||||||
|
target_link_libraries(neural_amp_modeler PRIVATE NeuralAudio)
|
||||||
|
|
||||||
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 ${NA_SOURCES})
|
||||||
|
|
||||||
option(DISABLE_DENORMALS "Disable floating point denormals" ON)
|
option(DISABLE_DENORMALS "Disable floating point denormals" ON)
|
||||||
|
|
||||||
@@ -28,7 +23,14 @@ if(DISABLE_DENORMALS)
|
|||||||
add_definitions(-DDISABLE_DENORMALS)
|
add_definitions(-DDISABLE_DENORMALS)
|
||||||
endif (DISABLE_DENORMALS)
|
endif (DISABLE_DENORMALS)
|
||||||
|
|
||||||
target_compile_features(neural_amp_modeler PUBLIC cxx_std_17)
|
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64)|(AMD64)|(x86_64)")
|
||||||
|
option(USE_NATIVE_ARCH "Enable architecture-specific optimizations" OFF)
|
||||||
|
|
||||||
|
if (USE_NATIVE_ARCH)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64-v3")
|
||||||
|
message("Enabling -march=x86-64-v3")
|
||||||
|
endif (USE_NATIVE_ARCH)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set_target_properties(neural_amp_modeler
|
set_target_properties(neural_amp_modeler
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
|
|||||||
+1
-4
@@ -27,7 +27,7 @@ static LV2_Handle instantiate(const LV2_Descriptor*, double rate, const char*, c
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
catch(const std::exception)
|
catch(const std::exception&)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -95,9 +95,6 @@ static const LV2_Descriptor descriptor =
|
|||||||
LV2_SYMBOL_EXPORT const LV2_Descriptor* lv2_descriptor(uint32_t index)
|
LV2_SYMBOL_EXPORT const LV2_Descriptor* lv2_descriptor(uint32_t index)
|
||||||
{
|
{
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
// Turn on fast tanh approximation
|
|
||||||
activations::Activation::enable_fast_tanh();
|
|
||||||
|
|
||||||
return &descriptor;
|
return &descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+77
-47
@@ -1,10 +1,9 @@
|
|||||||
#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 <cassert>
|
|
||||||
|
|
||||||
#define SMOOTH_EPSILON .0001f
|
#define SMOOTH_EPSILON .0001f
|
||||||
|
|
||||||
@@ -20,8 +19,10 @@ 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;
|
||||||
|
|
||||||
// for fetching initial options, can be null
|
// for fetching initial options, can be null
|
||||||
LV2_Options_Option* options = nullptr;
|
LV2_Options_Option* options = nullptr;
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ 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;
|
NeuralAudio::NeuralModel* model = nullptr;
|
||||||
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, {} };
|
LV2SwitchModelMsg response = { kWorkTypeSwitch, {}, {} };
|
||||||
LV2_Worker_Status result = LV2_WORKER_SUCCESS;
|
LV2_Worker_Status result = LV2_WORKER_SUCCESS;
|
||||||
|
|
||||||
@@ -105,29 +106,26 @@ namespace NAM {
|
|||||||
{
|
{
|
||||||
lv2_log_trace(&nam->logger, "Staging model change: `%s`\n", msg->path);
|
lv2_log_trace(&nam->logger, "Staging model change: `%s`\n", msg->path);
|
||||||
|
|
||||||
model = get_dsp(msg->path).release();
|
model = NeuralAudio::NeuralModel::CreateFromFile(msg->path);
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.model = model;
|
response.model = model;
|
||||||
|
|
||||||
memcpy(response.path, msg->path, pathlen);
|
memcpy(response.path, msg->path, pathlen);
|
||||||
}
|
}
|
||||||
catch (std::exception)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
response.path[0] = '\0';
|
response.path[0] = '\0';
|
||||||
|
|
||||||
@@ -220,57 +218,89 @@ namespace NAM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert input level from db
|
float level;
|
||||||
float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
|
|
||||||
|
|
||||||
if (fabs(desiredInputLevel - inputLevel) > SMOOTH_EPSILON)
|
float modelInputAdjustmentDB = 0;
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < n_samples; i++)
|
|
||||||
{
|
|
||||||
// do very basic smoothing
|
|
||||||
inputLevel = (.99f * inputLevel) + (.01f * desiredInputLevel);
|
|
||||||
|
|
||||||
ports.audio_out[i] = ports.audio_in[i] * inputLevel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
inputLevel = desiredInputLevel;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n_samples; i++)
|
|
||||||
{
|
|
||||||
ports.audio_out[i] = ports.audio_in[i] * inputLevel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentModel != nullptr)
|
if (currentModel != nullptr)
|
||||||
{
|
{
|
||||||
currentModel->process(&ports.audio_out, &ports.audio_out, 1, n_samples, 1.0, 1.0, mNAMParams);
|
modelInputAdjustmentDB = currentModel->GetRecommendedInputDBAdjustment();
|
||||||
currentModel->finalize_(n_samples);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert output level from db
|
// convert input level from db
|
||||||
float desiredOutputLevel = powf(10, *(ports.output_level) * 0.05f);
|
float desiredInputLevel = powf(10, (*(ports.input_level) + modelInputAdjustmentDB) * 0.05f);
|
||||||
|
|
||||||
if (fabs(desiredOutputLevel - outputLevel) > 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
|
||||||
outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel);
|
level = (.99f * level) + (.01f * desiredInputLevel);
|
||||||
|
|
||||||
ports.audio_out[i] *= outputLevel;
|
ports.audio_out[i] = ports.audio_in[i] * level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputLevel = level;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outputLevel = desiredOutputLevel;
|
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] *= outputLevel;
|
ports.audio_out[i] = ports.audio_in[i] * level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float modelLoudnessAdjustmentDB = 0;
|
||||||
|
|
||||||
|
if (currentModel != nullptr)
|
||||||
|
{
|
||||||
|
currentModel->Process(ports.audio_out, ports.audio_out, n_samples);
|
||||||
|
|
||||||
|
modelLoudnessAdjustmentDB = currentModel->GetRecommendedOutputDBAdjustment();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert output level from db
|
||||||
|
float desiredOutputLevel = powf(10, (*(ports.output_level) + modelLoudnessAdjustmentDB) * 0.05f);
|
||||||
|
|
||||||
|
if (fabs(desiredOutputLevel - outputLevel) > SMOOTH_EPSILON)
|
||||||
|
{
|
||||||
|
level = outputLevel;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < n_samples; i++)
|
||||||
|
{
|
||||||
|
// do very basic smoothing
|
||||||
|
level = (.99f * level) + (.01f * desiredOutputLevel);
|
||||||
|
|
||||||
|
ports.audio_out[i] = ports.audio_out[i] * outputLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
outputLevel = level;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = outputLevel = desiredOutputLevel;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < n_samples; i++)
|
||||||
|
{
|
||||||
|
ports.audio_out[i] = ports.audio_out[i] * level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//float dcBlockCoefficient = 1 - (220.0 / sampleRate);
|
||||||
|
|
||||||
|
//for (unsigned int i = 0; i < n_samples; i++)
|
||||||
|
//{
|
||||||
|
// float dcInput = ports.audio_out[i];
|
||||||
|
|
||||||
|
// // dc blocker
|
||||||
|
// ports.audio_out[i] = ports.audio_out[i] - prevDCInput + dcBlockCoefficient * prevDCOutput;
|
||||||
|
|
||||||
|
// prevDCInput = dcInput;
|
||||||
|
// prevDCOutput = ports.audio_out[i];
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Plugin::options_get(LV2_Handle, LV2_Options_Option*)
|
uint32_t Plugin::options_get(LV2_Handle, LV2_Options_Option*)
|
||||||
|
|||||||
+8
-6
@@ -21,7 +21,7 @@
|
|||||||
#include <lv2/state/state.h>
|
#include <lv2/state/state.h>
|
||||||
#include <lv2/units/units.h>
|
#include <lv2/units/units.h>
|
||||||
|
|
||||||
#include "dsp.h"
|
#include <NeuralAudio/NeuralModel.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"
|
||||||
@@ -43,12 +43,12 @@ namespace NAM {
|
|||||||
struct LV2SwitchModelMsg {
|
struct LV2SwitchModelMsg {
|
||||||
LV2WorkType type;
|
LV2WorkType type;
|
||||||
char path[MAX_FILE_NAME];
|
char path[MAX_FILE_NAME];
|
||||||
::DSP* model;
|
NeuralAudio::NeuralModel* model;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LV2FreeModelMsg {
|
struct LV2FreeModelMsg {
|
||||||
LV2WorkType type;
|
LV2WorkType type;
|
||||||
::DSP* model;
|
NeuralAudio::NeuralModel* model;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Plugin {
|
class Plugin {
|
||||||
@@ -64,14 +64,16 @@ 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;
|
NeuralAudio::NeuralModel* currentModel = nullptr;
|
||||||
std::string currentModelPath;
|
std::string currentModelPath;
|
||||||
|
float prevDCInput = 0;
|
||||||
std::unordered_map<std::string, double> mNAMParams = {};
|
float prevDCOutput = 0;
|
||||||
|
|
||||||
Plugin();
|
Plugin();
|
||||||
~Plugin();
|
~Plugin();
|
||||||
|
|||||||
Reference in New Issue
Block a user