Skip to content

Commit

Permalink
Add CMake option for denormal disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeoliphant committed Jun 19, 2023
1 parent 4d9b5be commit 0aad7c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ add_library(neural_amp_modeler MODULE ${SOURCES} ${NAM_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
source_group(NAM ${CMAKE_CURRENT_SOURCE_DIR} FILES ${NAM_SOURCES})

option(DISABLE_DENORMALS "Disable floating point denormals" ON)

if(DISABLE_DENORMALS)
add_definitions(-DDISABLE_DENORMALS)
endif(DISABLE_DENORMALS)

target_compile_features(neural_amp_modeler PUBLIC cxx_std_17)

set_target_properties(neural_amp_modeler
Expand Down
6 changes: 4 additions & 2 deletions src/nam_lv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ static void activate(LV2_Handle) {}

static void run(LV2_Handle instance, uint32_t n_samples)
{
// Disable floating point denormals
#ifdef DISABLE_DENORMALS // Disable floating point denormals
std::fenv_t fe_state;
std::feholdexcept(&fe_state);
disable_denormals();
#endif

static_cast<NAM::Plugin*>(instance)->process(n_samples);

// restore previous floating point state
#ifdef DISABLE_DENORMALS // restore previous floating point state
std::feupdateenv(&fe_state);
#endif
}

static void deactivate(LV2_Handle) {}
Expand Down

0 comments on commit 0aad7c3

Please sign in to comment.