Skip to content

Commit

Permalink
Use different math approximations for WDF diodes where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Dec 1, 2023
1 parent 3ba3c54 commit 665a909
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 12 deletions.
7 changes: 7 additions & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ if(ASIOSDK_DIR)
target_compile_definitions(juce_plugin_modules PUBLIC JUCE_ASIO=1)
endif()

if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/math_approx")
message(STATUS "Configuring math_approx")
add_subdirectory(math_approx)
target_link_libraries(juce_plugin_modules PUBLIC math_approx)
target_compile_definitions(juce_plugin_modules PRIVATE BYOD_USE_MATH_APPROX=1)
endif()

if(IOS)
target_link_libraries(juce_plugin_modules PRIVATE juce::juce_product_unlocking)
target_compile_definitions(juce_plugin_modules PUBLIC JUCE_IN_APP_PURCHASES=1)
Expand Down
2 changes: 1 addition & 1 deletion modules/RTNeural
Submodule RTNeural updated 64 files
+1 −0 .gitignore
+4 −3 CMakeLists.txt
+11 −11 README.md
+1 −1 RTNeural/CMakeLists.txt
+8 −7 RTNeural/ModelT.h
+95 −18 RTNeural/conv1d/conv1d.h
+20 −17 RTNeural/conv1d/conv1d.tpp
+67 −13 RTNeural/conv1d/conv1d_eigen.h
+16 −13 RTNeural/conv1d/conv1d_eigen.tpp
+102 −19 RTNeural/conv1d/conv1d_xsimd.h
+19 −16 RTNeural/conv1d/conv1d_xsimd.tpp
+12 −5 RTNeural/model_loader.h
+39 −38 bench/layer_creator.hpp
+24 −0 cmake/CPM.cmake
+37 −0 cmake/Testing.cmake
+1 −1 examples/conv1d_stateless_example/conv1d_stateless_example.cpp
+1 −1 examples/torch/torch_conv1d/torch_conv1d.cpp
+1 −1 examples/torch/torch_gru/torch_gru.cpp
+224 −233 models/conv.json
+1 −0 models/conv1d_torch_group_6_3_3_1_3.json
+1 −0 models/conv1d_torch_group_6_3_4_10_3.json
+1 −0 models/conv1d_torch_group_6_6_1_1_6.json
+1 −0 models/microtcn/bn.json
+1 −0 models/microtcn/conv1.json
+1 −0 models/microtcn/relu.json
+1 −0 models/microtcn/res.json
+ python/conv.png
+1 −1 python/conv.py
+35 −0 python/conv1d_torch_group.py
+99 −0 python/microtcn.py
+1 −0 python/model_utils.py
+500 −0 test_data/conv1d_torch_group_x_python.csv
+3 −0 test_data/conv1d_torch_group_y_python_6_3_3_1_3.csv
+3 −0 test_data/conv1d_torch_group_y_python_6_3_4_10_3.csv
+6 −0 test_data/conv1d_torch_group_y_python_6_6_1_1_6.csv
+100 −100 test_data/conv_y_python.csv
+1,000 −0 test_data/microtcn_x.csv
+32 −0 test_data/microtcn_y.csv
+4 −19 tests/CMakeLists.txt
+55 −0 tests/README.md
+0 −187 tests/conv2d_model.h
+14 −0 tests/functional/CMakeLists.txt
+6 −18 tests/functional/bad_model_test.cpp
+180 −0 tests/functional/conv2d_model_test.cpp
+51 −0 tests/functional/load_csv.hpp
+69 −0 tests/functional/model_test.cpp
+57 −77 tests/functional/sample_rate_rnn_test.cpp
+124 −0 tests/functional/templated_tests.cpp
+0 −0 tests/functional/test_configs.hpp
+77 −0 tests/functional/torch_conv1d_groups_test.cpp
+60 −0 tests/functional/torch_conv1d_test.cpp
+13 −40 tests/functional/torch_gru_test.cpp
+13 −40 tests/functional/torch_lstm_test.cpp
+143 −0 tests/functional/torch_microtcn_test.cpp
+0 −25 tests/load_csv.hpp
+0 −88 tests/model_test.hpp
+0 −137 tests/templated_tests.hpp
+0 −174 tests/tests.cpp
+136 −0 tests/torch_conv1d_group_test.hpp
+0 −107 tests/torch_conv1d_test.hpp
+178 −0 tests/torch_microtcn_test.hpp
+4 −0 tests/unit/CMakeLists.txt
+62 −0 tests/unit/activation_test.cpp
+0 −32 tests/util_tests.hpp
2 changes: 1 addition & 1 deletion modules/chowdsp_wdf
5 changes: 1 addition & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ if (NOT(${JAI_COMPILER} STREQUAL "JAI_COMPILER-NOTFOUND"))
endif()

# AVX/SSE files for accelerated neural nets
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../modules/math_approx")
message(STATUS "Using RTNeural with math_approx")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../modules/math_approx" math_approx)
endif()
make_lib_simd_runtime(rnn_accelerated processors/drive/neural_utils/RNNAccelerated.cpp)
foreach(target IN ITEMS rnn_accelerated_sse_or_arm rnn_accelerated_avx)
target_link_libraries(${target} PRIVATE config_flags juce::juce_recommended_lto_flags warning_flags)
Expand All @@ -187,6 +183,7 @@ foreach(target IN ITEMS rnn_accelerated_sse_or_arm rnn_accelerated_avx)
CXX_VISIBILITY_PRESET hidden
)
if(TARGET math_approx)
message(STATUS "Using math_approx for ${target}")
target_compile_definitions(${target} PRIVATE RTNEURAL_USE_MATH_APPROX=1)
target_link_libraries(${target} PRIVATE math_approx)
endif()
Expand Down
4 changes: 4 additions & 0 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE
#include "jai/SharedJaiContext.h"
#endif

#if BYOD_USE_MATH_APPROX
#include <math_approx/math_approx.hpp>
#endif

// global definitions
using Parameters = std::vector<std::unique_ptr<juce::RangedAudioParameter>>;
using ParamLayout = AudioProcessorValueTreeState::ParameterLayout;
Expand Down
5 changes: 3 additions & 2 deletions src/processors/drive/diode_circuits/DiodeClipperWDF.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <pch.h>
#include "OmegaProvider.h"

template <template <typename, typename, wdft::DiodeQuality> typename DiodeType>
template <template <typename, typename, wdft::DiodeQuality, typename> typename DiodeType>
class DiodeClipperWDF
{
public:
Expand Down Expand Up @@ -96,7 +97,7 @@ class DiodeClipperWDF
Cap C1 { capVal };

wdft::WDFParallelT<wdf_type, Cap, ResVs> P1 { C1, Vs };
DiodeType<wdf_type, decltype (P1), wdft::DiodeQuality::Best> dp { P1, 2.52e-9f };
DiodeType<wdf_type, decltype (P1), wdft::DiodeQuality::Best, OmegaProvider> dp { P1, 2.52e-9f };

SmoothedValue<float, ValueSmoothingTypes::Multiplicative> cutoffSmooth;
SmoothedValue<float, ValueSmoothingTypes::Linear> nDiodesSmooth;
Expand Down
16 changes: 16 additions & 0 deletions src/processors/drive/diode_circuits/OmegaProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <pch.h>

#if BYOD_USE_MATH_APPROX
struct OmegaProvider
{
template <typename T>
static T omega (T x)
{
return math_approx::wright_omega<3, 3> (x);
}
};
#else
using OmegaProvider = chowdsp::Omega::Omega;
#endif
3 changes: 2 additions & 1 deletion src/processors/drive/mouse_drive/MouseDriveWDF.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <pch.h>
#include "../diode_circuits/OmegaProvider.h"

class MouseDriveWDF
{
Expand Down Expand Up @@ -75,7 +76,7 @@ class MouseDriveWDF
wdft::ResistorCapacitorSeriesT<float> R6_C7 { 1.0e3f, 4.7e-6f };
wdft::WDFSeriesT<float, decltype (R), decltype (R6_C7)> Sd { R, R6_C7 };

wdft::DiodePairT<float, decltype (Sd)> diodes { Sd, 5.0e-9f, 25.85e-3f, 2.0f };
wdft::DiodePairT<float, decltype (Sd), wdft::DiodeQuality::Best, OmegaProvider> diodes { Sd, 5.0e-9f, 25.85e-3f, 2.0f };

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MouseDriveWDF)
Expand Down
3 changes: 2 additions & 1 deletion src/processors/drive/mxr_distortion/MXRDistWDF.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <pch.h>
#include "../diode_circuits/OmegaProvider.h"

// This circuit model was originally implemented as part of Sam Schachter's
// Master's Thesis (https://github.com/schachtersam32/WaveDigitalFilters_Sharc/blob/master/MXR_DistPlus.h).
Expand Down Expand Up @@ -89,7 +90,7 @@ class MXRDistWDF
wdft::CapacitorT<float> C5 { 1.0e-9f };
wdft::WDFParallelT<float, decltype (C5), decltype (P4)> P3 { C5, P4 };

wdft::DiodePairT<float, decltype (P3), wdft::DiodeQuality::Best> DP { P3, 2.52e-9f, 25.85e-3f * 1.75f };
wdft::DiodePairT<float, decltype (P3), wdft::DiodeQuality::Best, OmegaProvider> DP { P3, 2.52e-9f, 25.85e-3f * 1.75f };

private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MXRDistWDF)
Expand Down
3 changes: 2 additions & 1 deletion src/processors/drive/tube_screamer/TubeScreamerWDF.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <pch.h>
#include "../diode_circuits/OmegaProvider.h"

class TubeScreamerWDF
{
Expand Down Expand Up @@ -108,7 +109,7 @@ class TubeScreamerWDF
wdft::ResistorCapacitorParallelT<float> R6_P1_par_C4 { R6, 51.0e-12f };
wdft::WDFParallelT<float, decltype (R6_P1_par_C4), decltype (R)> P3 { R6_P1_par_C4, R };

wdft::DiodePairT<float, decltype (P3)> dp { P3, 4.352e-9f, Vt, 1.906f }; // 1N4148
wdft::DiodePairT<float, decltype (P3), wdft::DiodeQuality::Best, OmegaProvider> dp { P3, 4.352e-9f, Vt, 1.906f }; // 1N4148

SmoothedValue<float, ValueSmoothingTypes::Linear> nDiodesSmooth;
SmoothedValue<float, ValueSmoothingTypes::Linear> gainSmooth;
Expand Down
3 changes: 2 additions & 1 deletion src/processors/drive/zen_drive/ZenDriveWDF.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <pch.h>
#include "../diode_circuits/OmegaProvider.h"

class ZenDriveWDF
{
Expand Down Expand Up @@ -111,7 +112,7 @@ class ZenDriveWDF
wdft::ResistorCapacitorParallelT<float> Rv9_C4 { R9, 100.0e-12f };
wdft::WDFParallelT<float, decltype (Rv9_C4), decltype (R)> P3 { Rv9_C4, R };

wdft::DiodePairT<float, decltype (P1)> diodes { P1, 5.241435962608312e-10f, 0.07877217375325735f };
wdft::DiodePairT<float, decltype (P1), wdft::DiodeQuality::Best, OmegaProvider> diodes { P1, 5.241435962608312e-10f, 0.07877217375325735f };

private:
SmoothedValue<float, ValueSmoothingTypes::Linear> voiceSmooth;
Expand Down

0 comments on commit 665a909

Please sign in to comment.