From 41a45ace933add36aa663f04711ccbd321af1ce8 Mon Sep 17 00:00:00 2001 From: Mike Oliphant Date: Wed, 31 May 2023 09:26:12 -0700 Subject: [PATCH] Float interface with NAM core. Workaround for Reaper crash. Use "nam" for model path fle type --- CMakeLists.txt | 5 +++-- deps/NeuralAmpModelerCore | 2 +- resources/neural_amp_modeler.ttl.in | 4 ++-- src/CMakeLists.txt | 1 - src/nam_lv2.cpp | 1 - src/nam_plugin.cpp | 28 +++++++++++++++------------- src/nam_plugin.h | 2 -- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eee2cec..742c413 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,14 +11,13 @@ set(CMAKE_CXX_EXTENSIONS OFF) if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") include_directories(SYSTEM /usr/local/include) elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + link_libraries(stdc++fs) elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN) else() message(FATAL_ERROR "Unrecognized Platform!") endif() -link_libraries(stdc++fs) - set(NAM_LV2_ID http://github.com/mikeoliphant/neural-amp-modeler-lv2) include_directories(SYSTEM deps/eigen) @@ -27,6 +26,8 @@ include_directories(SYSTEM deps/NeuralAmpModelerCore/NAM) include_directories(SYSTEM deps/json) include_directories(SYSTEM deps/denormal) +add_definitions(-DNAM_SAMPLE_FLOAT) + add_subdirectory(src) diff --git a/deps/NeuralAmpModelerCore b/deps/NeuralAmpModelerCore index c31dc55..d72e8dc 160000 --- a/deps/NeuralAmpModelerCore +++ b/deps/NeuralAmpModelerCore @@ -1 +1 @@ -Subproject commit c31dc557df6a12002e880e9c5b1a0a5b0cc216ca +Subproject commit d72e8dc9bbf7331ad8998cc5fc02c8960cc13b93 diff --git a/resources/neural_amp_modeler.ttl.in b/resources/neural_amp_modeler.ttl.in index 998977d..c43b9ea 100644 --- a/resources/neural_amp_modeler.ttl.in +++ b/resources/neural_amp_modeler.ttl.in @@ -15,7 +15,7 @@ <@NAM_LV2_ID@#model> a lv2:Parameter; - mod:fileTypes "nammodel"; + mod:fileTypes "nam"; rdfs:label "Neural Model"; rdfs:range atom:Path. @@ -99,5 +99,5 @@ A large collection of .nam files is available at https://tonehunt.org/ units:unit units:db; ]; state:state [ - <@NAM_LV2_ID@#model> ; + <@NAM_LV2_ID@#model>; ]. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11f781d..8f7ac77 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,6 @@ set_target_properties(neural_amp_modeler PREFIX "" ) - # Platform if (CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/src/nam_lv2.cpp b/src/nam_lv2.cpp index 0e6973d..2468801 100644 --- a/src/nam_lv2.cpp +++ b/src/nam_lv2.cpp @@ -70,7 +70,6 @@ static const void* extension_data(const char* uri) return &state; } - if (!strcmp(uri, LV2_WORKER__interface)) return &worker; diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index 9cd91e1..fba6c43 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -13,7 +13,9 @@ namespace NAM { { // Turn on fast tanh approximation activations::Activation::enable_fast_tanh(); - currentModelPath.reserve(MAX_FILE_NAME+1); // prevent allocations on the audio thread. + + // prevent allocations on the audio thread + currentModelPath.reserve(MAX_FILE_NAME+1); } bool Plugin::initialize(double rate, const LV2_Feature* const* features) noexcept @@ -94,6 +96,7 @@ namespace NAM { // Enable model loudness normalization nam->stagedModel->SetNormalize(true); } + LV2WorkType response = kWorkTypeSwitch; respond(handle, sizeof(response), &response); @@ -121,7 +124,7 @@ namespace NAM { std::swap(nam->currentModel, nam->stagedModel); nam->currentModelPath = nam->stagedModelPath; - assert(nam->currentModelPath.capacity() == MAX_FILE_NAME+1); + assert(nam->currentModelPath.capacity() >= MAX_FILE_NAME + 1); nam->stateChanged = true; nam->deleteModel = std::move(nam->stagedModel); @@ -143,6 +146,7 @@ namespace NAM { void Plugin::process(uint32_t n_samples) noexcept { + return; lv2_atom_forge_set_buffer(&atom_forge,(uint8_t*)ports.notify,ports.notify->atom.size); lv2_atom_forge_sequence_head(&atom_forge,&sequence_frame,uris.units_frame); @@ -185,9 +189,6 @@ namespace NAM { } } - if (dblData.size() != n_samples) - dblData.resize(n_samples); - // convert input level from db float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f); @@ -198,7 +199,7 @@ namespace NAM { // do very basic smoothing inputLevel = (.99f * inputLevel) + (.01f * desiredInputLevel); - dblData[i] = ports.audio_in[i] * inputLevel; + ports.audio_out[i] = ports.audio_in[i] * inputLevel; } } else @@ -207,7 +208,7 @@ namespace NAM { for (unsigned int i = 0; i < n_samples; i++) { - dblData[i] = ports.audio_in[i] * inputLevel; + ports.audio_out[i] = ports.audio_in[i] * inputLevel; } } @@ -216,9 +217,7 @@ namespace NAM { } else { - double* data = dblData.data(); - - currentModel->process(&data, &data, 1, n_samples, 1.0, 1.0, mNAMParams); + currentModel->process(&ports.audio_out, &ports.audio_out, 1, n_samples, 1.0, 1.0, mNAMParams); currentModel->finalize_(n_samples); } @@ -232,7 +231,7 @@ namespace NAM { // do very basic smoothing outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel); - ports.audio_out[i] = (float)(dblData[i] * outputLevel); + ports.audio_out[i] *= outputLevel; } } else @@ -241,7 +240,7 @@ namespace NAM { for (unsigned int i = 0; i < n_samples; i++) { - ports.audio_out[i] = (float)(dblData[i] * outputLevel); + ports.audio_out[i] *= outputLevel; } } @@ -260,7 +259,8 @@ namespace NAM { { auto nam = static_cast(instance); - lv2_log_trace(&nam->logger, "Saving state\n"); + // Commented out because Reaper seems to crash 80% of the time if we log here + //lv2_log_trace(&nam->logger, "Saving state\n"); if (!nam->currentModel) { return LV2_STATE_SUCCESS; @@ -300,6 +300,8 @@ namespace NAM { 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) { + return LV2_STATE_SUCCESS; + auto nam = static_cast(instance); // Get model_Path from state diff --git a/src/nam_plugin.h b/src/nam_plugin.h index 6ee3a7c..038c843 100644 --- a/src/nam_plugin.h +++ b/src/nam_plugin.h @@ -104,8 +104,6 @@ namespace NAM { LV2_Atom_Forge atom_forge = {}; LV2_Atom_Forge_Frame sequence_frame; - std::vector dblData; - float m_rate; float inputLevel = 0; float outputLevel = 0;