mirror of
https://github.com/mikeoliphant/neural-amp-modeler-lv2.git
synced 2026-05-06 19:50:11 +02:00
Float interface with NAM core. Workaround for Reaper crash. Use "nam" for model path fle type
This commit is contained in:
+3
-2
@@ -11,14 +11,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||||
include_directories(SYSTEM /usr/local/include)
|
include_directories(SYSTEM /usr/local/include)
|
||||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
link_libraries(stdc++fs)
|
||||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
|
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unrecognized Platform!")
|
message(FATAL_ERROR "Unrecognized Platform!")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
link_libraries(stdc++fs)
|
|
||||||
|
|
||||||
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/eigen)
|
||||||
@@ -27,6 +26,8 @@ include_directories(SYSTEM deps/NeuralAmpModelerCore/NAM)
|
|||||||
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_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
Submodule deps/NeuralAmpModelerCore updated: c31dc557df...d72e8dc9bb
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<@NAM_LV2_ID@#model>
|
<@NAM_LV2_ID@#model>
|
||||||
a lv2:Parameter;
|
a lv2:Parameter;
|
||||||
mod:fileTypes "nammodel";
|
mod:fileTypes "nam";
|
||||||
rdfs:label "Neural Model";
|
rdfs:label "Neural Model";
|
||||||
rdfs:range atom:Path.
|
rdfs:range atom:Path.
|
||||||
|
|
||||||
@@ -99,5 +99,5 @@ A large collection of .nam files is available at https://tonehunt.org/
|
|||||||
units:unit units:db;
|
units:unit units:db;
|
||||||
];
|
];
|
||||||
state:state [
|
state:state [
|
||||||
<@NAM_LV2_ID@#model> <click.wav> ;
|
<@NAM_LV2_ID@#model>;
|
||||||
].
|
].
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ set_target_properties(neural_amp_modeler
|
|||||||
PREFIX ""
|
PREFIX ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Platform
|
# Platform
|
||||||
|
|
||||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ static const void* extension_data(const char* uri)
|
|||||||
return &state;
|
return &state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!strcmp(uri, LV2_WORKER__interface))
|
if (!strcmp(uri, LV2_WORKER__interface))
|
||||||
return &worker;
|
return &worker;
|
||||||
|
|
||||||
|
|||||||
+15
-13
@@ -13,7 +13,9 @@ namespace NAM {
|
|||||||
{
|
{
|
||||||
// Turn on fast tanh approximation
|
// Turn on fast tanh approximation
|
||||||
activations::Activation::enable_fast_tanh();
|
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
|
bool Plugin::initialize(double rate, const LV2_Feature* const* features) noexcept
|
||||||
@@ -94,6 +96,7 @@ namespace NAM {
|
|||||||
// Enable model loudness normalization
|
// Enable model loudness normalization
|
||||||
nam->stagedModel->SetNormalize(true);
|
nam->stagedModel->SetNormalize(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
LV2WorkType response = kWorkTypeSwitch;
|
LV2WorkType response = kWorkTypeSwitch;
|
||||||
respond(handle, sizeof(response), &response);
|
respond(handle, sizeof(response), &response);
|
||||||
|
|
||||||
@@ -121,7 +124,7 @@ namespace NAM {
|
|||||||
|
|
||||||
std::swap(nam->currentModel, nam->stagedModel);
|
std::swap(nam->currentModel, nam->stagedModel);
|
||||||
nam->currentModelPath = nam->stagedModelPath;
|
nam->currentModelPath = nam->stagedModelPath;
|
||||||
assert(nam->currentModelPath.capacity() == MAX_FILE_NAME+1);
|
assert(nam->currentModelPath.capacity() >= MAX_FILE_NAME + 1);
|
||||||
nam->stateChanged = true;
|
nam->stateChanged = true;
|
||||||
|
|
||||||
nam->deleteModel = std::move(nam->stagedModel);
|
nam->deleteModel = std::move(nam->stagedModel);
|
||||||
@@ -143,6 +146,7 @@ namespace NAM {
|
|||||||
|
|
||||||
void Plugin::process(uint32_t n_samples) noexcept
|
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_set_buffer(&atom_forge,(uint8_t*)ports.notify,ports.notify->atom.size);
|
||||||
lv2_atom_forge_sequence_head(&atom_forge,&sequence_frame,uris.units_frame);
|
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
|
// convert input level from db
|
||||||
float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
|
float desiredInputLevel = powf(10, *(ports.input_level) * 0.05f);
|
||||||
|
|
||||||
@@ -198,7 +199,7 @@ namespace NAM {
|
|||||||
// do very basic smoothing
|
// do very basic smoothing
|
||||||
inputLevel = (.99f * inputLevel) + (.01f * desiredInputLevel);
|
inputLevel = (.99f * inputLevel) + (.01f * desiredInputLevel);
|
||||||
|
|
||||||
dblData[i] = ports.audio_in[i] * inputLevel;
|
ports.audio_out[i] = ports.audio_in[i] * inputLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -207,7 +208,7 @@ namespace NAM {
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < n_samples; i++)
|
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
|
else
|
||||||
{
|
{
|
||||||
double* data = dblData.data();
|
currentModel->process(&ports.audio_out, &ports.audio_out, 1, n_samples, 1.0, 1.0, mNAMParams);
|
||||||
|
|
||||||
currentModel->process(&data, &data, 1, n_samples, 1.0, 1.0, mNAMParams);
|
|
||||||
currentModel->finalize_(n_samples);
|
currentModel->finalize_(n_samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +231,7 @@ namespace NAM {
|
|||||||
// do very basic smoothing
|
// do very basic smoothing
|
||||||
outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel);
|
outputLevel = (.99f * outputLevel) + (.01f * desiredOutputLevel);
|
||||||
|
|
||||||
ports.audio_out[i] = (float)(dblData[i] * outputLevel);
|
ports.audio_out[i] *= outputLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -241,7 +240,7 @@ namespace NAM {
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < n_samples; i++)
|
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<NAM::Plugin*>(instance);
|
auto nam = static_cast<NAM::Plugin*>(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) {
|
if (!nam->currentModel) {
|
||||||
return LV2_STATE_SUCCESS;
|
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,
|
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)
|
||||||
{
|
{
|
||||||
|
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
|
||||||
|
|||||||
@@ -104,8 +104,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;
|
||||||
|
|
||||||
std::vector<double> dblData;
|
|
||||||
|
|
||||||
float m_rate;
|
float m_rate;
|
||||||
float inputLevel = 0;
|
float inputLevel = 0;
|
||||||
float outputLevel = 0;
|
float outputLevel = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user