├── Utils ├── ModelTest │ ├── CMakeLists.txt │ └── ModelTest.cpp ├── Models │ ├── README.md │ ├── BossWN-nano.nam │ ├── BossLSTM-2x8.nam │ └── BossLSTM-1x16.nam └── CMakeLists.txt ├── CMakeLists.txt ├── .gitmodules ├── NeuralAudioCAPI ├── CMakeLists.txt ├── NeuralAudioCApi.h └── NeuralAudioCApi.cpp ├── NeuralAudio ├── RTNeuralLoader.h ├── TemplateHelper.h ├── Activation.h ├── NAMModel.h ├── NeuralModel.h ├── RTNeuralLoader.cpp ├── CMakeLists.txt ├── LSTMDynamic.h ├── LSTM.h ├── NeuralModel.cpp ├── InternalModel.h ├── WaveNetDynamic.h ├── RTNeuralModel.h └── WaveNet.h ├── CREDITS.md ├── NeuralAudioCSharp ├── NeuralAudioTest │ ├── Program.cs │ └── NeuralAudioTest.csproj ├── NeuralAudio │ ├── NeuralAudio.csproj │ ├── NativeApi.cs │ └── NeuralModel.cs └── NeuralAudioCSharp.sln ├── LICENSE ├── deps └── RTNeural-NAM │ ├── LICENSE │ └── wavenet │ ├── arena.hpp │ ├── wavenet_model.hpp │ ├── wavenet_layer.hpp │ └── wavenet_layer_array.hpp ├── .github └── workflows │ └── build.yml ├── .gitignore └── README.md /Utils/ModelTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | create_util(ModelTest) 3 | -------------------------------------------------------------------------------- /Utils/Models/README.md: -------------------------------------------------------------------------------- 1 | Licensing note: 2 | 3 | The "tw40_blues_deluxe_deerinkstudios.json" model was created by Deer Ink Studios and is under the CC BY-NC-ND 4.0 license. 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(NeuralAudio VERSION 0.0.1) 4 | 5 | add_subdirectory(NeuralAudio) 6 | add_subdirectory(NeuralAudioCAPI) 7 | 8 | option(BUILD_UTILS "Build NeuralAudio utils" OFF) 9 | if(BUILD_UTILS) 10 | message(STATUS "Building NeuralAudio Utils") 11 | add_subdirectory(Utils) 12 | endif() 13 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/NeuralAmpModelerCore"] 2 | path = deps/NeuralAmpModelerCore 3 | url = https://github.com/mikeoliphant/NeuralAmpModelerCore 4 | [submodule "deps/RTNeural"] 5 | path = deps/RTNeural 6 | url = https://github.com/mikeoliphant/RTNeural 7 | [submodule "deps/math_approx"] 8 | path = deps/math_approx 9 | url = https://github.com/Chowdhury-DSP/math_approx 10 | -------------------------------------------------------------------------------- /NeuralAudioCAPI/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD 20) 2 | 3 | set(SOURCES NeuralAudioCApi.h NeuralAudioCApi.cpp) 4 | 5 | add_library(NeuralAudioCAPI SHARED ${SOURCES}) 6 | 7 | include_directories(NeuralAudioCAPI ../NeuralAudio) 8 | 9 | target_link_libraries(NeuralAudioCAPI PRIVATE NeuralAudio) 10 | 11 | source_group(NeuralAudioCAPI ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 12 | -------------------------------------------------------------------------------- /NeuralAudio/RTNeuralLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NeuralModel.h" 4 | 5 | namespace NeuralAudio 6 | { 7 | extern void EnsureRTNeuralModelDefsAreLoaded(); 8 | extern NeuralModel* RTNeuralLoadNAMWaveNet(const nlohmann::json& modelJson); 9 | extern NeuralModel* RTNeuralLoadNAMLSTM(const nlohmann::json& modelJson); 10 | extern NeuralModel* RTNeuralLoadKeras(const nlohmann::json& modelJson); 11 | } -------------------------------------------------------------------------------- /Utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | function(create_util util_name) 2 | message(STATUS "Configuring util: ${util_name}") 3 | add_executable(${util_name} ${util_name}.cpp) 4 | target_include_directories(${util_name} PUBLIC ${CMAKE_SOURCE_DIR}) 5 | target_link_libraries(${util_name} PUBLIC NeuralAudio) 6 | target_compile_features(${util_name} PRIVATE cxx_std_17) 7 | endfunction() 8 | 9 | add_subdirectory(ModelTest) 10 | 11 | file(COPY Models DESTINATION ./) 12 | -------------------------------------------------------------------------------- /CREDITS.md: -------------------------------------------------------------------------------- 1 | [GitHub contributers](https://github.com/mikeoliphant/NeuralAudio/graphs/contributors) 2 | 3 | Depending on how it is compiled, this repository uses code from a number of sources. Please see the individual repositories for license information. 4 | 5 | https://github.com/sdatkinson/NeuralAmpModelerCore 6 | 7 | https://github.com/jatinchowdhury18/RTNeural 8 | 9 | https://github.com/jatinchowdhury18/RTNeural-NAM 10 | 11 | https://gitlab.com/libeigen/eigen 12 | 13 | https://github.com/nlohmann/json 14 | -------------------------------------------------------------------------------- /NeuralAudioCSharp/NeuralAudioTest/Program.cs: -------------------------------------------------------------------------------- 1 | namespace NeuralAudioTest 2 | { 3 | using NeuralAudio; 4 | 5 | internal class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | NeuralModel.SetWaveNetModelLoadMode(NeuralModel.EModelLoadMode.Internal); 10 | 11 | NeuralModel model = NeuralModel.FromFile("BossWN-standard.nam"); 12 | 13 | var input = new float[1024]; 14 | var output = new float[1024]; 15 | 16 | model.Process(input, output, 1024); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NeuralAudioCSharp/NeuralAudio/NeuralAudio.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | True 8 | 9 | 10 | 11 | 12 | PreserveNewest 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NeuralAudio/TemplateHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace NeuralAudio 6 | { 7 | template 8 | void ForEachIndex(std::index_sequence, F&& f) 9 | { 10 | int dummy[] = { 0, /* Handles empty Is. following cast handle evil operator comma */ 11 | (static_cast(f(std::integral_constant())), 0)... }; 12 | static_cast(dummy); // avoid warning for unused variable 13 | } 14 | 15 | template 16 | void ForEachIndex(F&& f) 17 | { 18 | ForEachIndex(std::make_index_sequence(), std::forward(f)); 19 | } 20 | } -------------------------------------------------------------------------------- /NeuralAudioCSharp/NeuralAudioTest/NeuralAudioTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | PreserveNewest 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Mike Oliphant 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NeuralAudioCAPI/NeuralAudioCApi.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #ifdef _MSC_VER 10 | #define NA_EXTERN extern __declspec(dllexport) 11 | #else 12 | #define NA_EXTERN extern 13 | #endif 14 | 15 | struct NeuralModel; 16 | 17 | 18 | NA_EXTERN NeuralModel* CreateModelFromFile(const wchar_t* modelPath); 19 | 20 | NA_EXTERN void DeleteModel(NeuralModel* model); 21 | 22 | NA_EXTERN void SetLSTMLoadMode(int loadMode); 23 | 24 | NA_EXTERN void SetWaveNetLoadMode(int loadMode); 25 | 26 | NA_EXTERN void SetAudioInputLevelDBu(float audioDBu); 27 | 28 | NA_EXTERN void SetDefaultMaxAudioBufferSize(int maxSize); 29 | 30 | NA_EXTERN int GetLoadMode(NeuralModel* model); 31 | 32 | NA_EXTERN bool IsStatic(NeuralModel* model); 33 | 34 | NA_EXTERN void SetMaxAudioBufferSize(NeuralModel* model, int maxSize); 35 | 36 | NA_EXTERN float GetRecommendedInputDBAdjustment(NeuralModel* model); 37 | 38 | NA_EXTERN float GetRecommendedOutputDBAdjustment(NeuralModel* model); 39 | 40 | NA_EXTERN float GetSampleRate(NeuralModel* model); 41 | 42 | NA_EXTERN void Process(NeuralModel* model, float* input, float* output, size_t numSamples); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif -------------------------------------------------------------------------------- /deps/RTNeural-NAM/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2024, jatinchowdhury18 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /NeuralAudioCSharp/NeuralAudioCSharp.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.13.35806.99 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeuralAudioTest", "NeuralAudioTest\NeuralAudioTest.csproj", "{9BC1E0F6-360A-0836-DD8E-C5B24C9DFBF0}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeuralAudio", "NeuralAudio\NeuralAudio.csproj", "{861DAACF-7A17-46AC-9416-3FE206F1449A}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9BC1E0F6-360A-0836-DD8E-C5B24C9DFBF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9BC1E0F6-360A-0836-DD8E-C5B24C9DFBF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9BC1E0F6-360A-0836-DD8E-C5B24C9DFBF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {9BC1E0F6-360A-0836-DD8E-C5B24C9DFBF0}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {861DAACF-7A17-46AC-9416-3FE206F1449A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {861DAACF-7A17-46AC-9416-3FE206F1449A}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {861DAACF-7A17-46AC-9416-3FE206F1449A}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {861DAACF-7A17-46AC-9416-3FE206F1449A}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DE4D2541-2A2F-4F6E-852E-80980B5B2862} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | [workflow_dispatch, push, pull_request] 5 | 6 | env: 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | name: Build Windows 12 | runs-on: windows-latest 13 | steps: 14 | - uses: actions/checkout@v3.3.0 15 | with: 16 | submodules: recursive 17 | 18 | - name: Build 19 | working-directory: ${{github.workspace}}/build 20 | run: | 21 | cmake -G "Visual Studio 17 2022" -A x64 -DBUILD_UTILS=ON -DBUILD_NAMCORE=ON -DBUILD_STATIC_RTNEURAL=ON -T ClangCL .. 22 | cmake --build . --config=release -j4 23 | 24 | - name: Run ModelTest 25 | working-directory: ${{github.workspace}}/build/Utils/ModelTest/Release 26 | run: | 27 | ./ModelTest.exe 28 | ./ModelTest.exe ..\..\Models\tw40_blues_deluxe_deerinkstudios.json 29 | 30 | - name: Upload binary 31 | uses: actions/upload-artifact@v4 32 | with: 33 | name: ModelTest-Windows 34 | path: ${{github.workspace}}/build/Utils 35 | 36 | build-linux-x64: 37 | name: Build Linux x64 38 | runs-on: ubuntu-24.04 39 | steps: 40 | - uses: actions/checkout@v3.3.0 41 | with: 42 | submodules: recursive 43 | 44 | - name: Build 45 | working-directory: ${{github.workspace}}/build 46 | env: 47 | CXX: g++-13 48 | run: | 49 | cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_UTILS=ON -DBUILD_NAMCORE=ON -DBUILD_STATIC_RTNEURAL=ON 50 | cmake --build . --config $BUILD_TYPE -j4 51 | 52 | - name: Run ModelTest 53 | working-directory: ${{github.workspace}}/build/Utils/ModelTest 54 | run: | 55 | ./ModelTest 56 | ./ModelTest ../Models/tw40_blues_deluxe_deerinkstudios.json 57 | 58 | - name: Upload ModelTest 59 | uses: actions/upload-artifact@v4 60 | with: 61 | name: ModelTest-Linux-x64 62 | path: ${{github.workspace}}/build/Utils 63 | -------------------------------------------------------------------------------- /NeuralAudioCAPI/NeuralAudioCApi.cpp: -------------------------------------------------------------------------------- 1 | #include "NeuralAudioCApi.h" 2 | #include "NeuralModel.h" 3 | 4 | struct NeuralModel 5 | { 6 | NeuralAudio::NeuralModel* model; 7 | }; 8 | 9 | NeuralModel* CreateModelFromFile(const wchar_t* modelPath) 10 | { 11 | NeuralModel* model = new NeuralModel(); 12 | 13 | model->model = NeuralAudio::NeuralModel::CreateFromFile(modelPath); 14 | 15 | return model; 16 | } 17 | 18 | void DeleteModel(NeuralModel* model) 19 | { 20 | delete model->model; 21 | delete model; 22 | } 23 | 24 | void SetLSTMLoadMode(int loadMode) 25 | { 26 | NeuralAudio::NeuralModel::SetLSTMLoadMode((NeuralAudio::EModelLoadMode)loadMode); 27 | } 28 | 29 | void SetWaveNetLoadMode(int loadMode) 30 | { 31 | NeuralAudio::NeuralModel::SetWaveNetLoadMode((NeuralAudio::EModelLoadMode)loadMode); 32 | } 33 | 34 | void SetAudioInputLevelDBu(float audioDBu) 35 | { 36 | NeuralAudio::NeuralModel::SetAudioInputLevelDBu(audioDBu); 37 | } 38 | 39 | void SetDefaultMaxAudioBufferSize(int maxSize) 40 | { 41 | NeuralAudio::NeuralModel::SetDefaultMaxAudioBufferSize(maxSize); 42 | } 43 | 44 | int GetLoadMode(NeuralModel* model) 45 | { 46 | return model->model->GetLoadMode(); 47 | } 48 | 49 | bool IsStatic(NeuralModel* model) 50 | { 51 | return model->model->IsStatic(); 52 | } 53 | 54 | void SetMaxAudioBufferSize(NeuralModel* model, int maxSize) 55 | { 56 | model->model->SetMaxAudioBufferSize(maxSize); 57 | } 58 | 59 | float GetRecommendedInputDBAdjustment(NeuralModel* model) 60 | { 61 | return model->model->GetRecommendedInputDBAdjustment(); 62 | } 63 | 64 | float GetRecommendedOutputDBAdjustment(NeuralModel* model) 65 | { 66 | return model->model->GetRecommendedOutputDBAdjustment(); 67 | } 68 | 69 | float GetSampleRate(NeuralModel* model) 70 | { 71 | return model->model->GetSampleRate(); 72 | } 73 | 74 | void Process(NeuralModel* model, float* input, float* output, size_t numSamples) 75 | { 76 | model->model->Process(input, output, numSamples); 77 | } 78 | 79 | 80 | -------------------------------------------------------------------------------- /NeuralAudioCSharp/NeuralAudio/NativeApi.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualBasic; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace NeuralAudio 6 | { 7 | static class NativeApi 8 | { 9 | public const string NEURAL_AUDIO_LIB_NAME = "NeuralAudioCAPI"; 10 | 11 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 12 | public static extern IntPtr CreateModelFromFile([MarshalAs(UnmanagedType.LPWStr)]string modelPath); 13 | 14 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 15 | public static extern void DeleteModel(IntPtr model); 16 | 17 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 18 | public static extern void SetLSTMLoadMode(int loadMode); 19 | 20 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 21 | public static extern void SetWaveNetLoadMode(int loadMode); 22 | 23 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 24 | public static extern void SetAudioInputLevelDBu(float audioDBu); 25 | 26 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 27 | public static extern void SetDefaultMaxAudioBufferSize(int maxSize); 28 | 29 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 30 | public static extern int GetLoadMode(IntPtr model); 31 | 32 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 33 | public static extern bool IsStatic(IntPtr model); 34 | 35 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 36 | public static extern void SetMaxAudioBufferSize(IntPtr model, int maxSize); 37 | 38 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 39 | public static extern float GetRecommendedInputDBAdjustment(IntPtr model); 40 | 41 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 42 | public static extern float GetRecommendedOutputDBAdjustment(IntPtr model); 43 | 44 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 45 | public static extern float GetSampleRate(IntPtr model); 46 | 47 | [DllImport(NEURAL_AUDIO_LIB_NAME)] 48 | public static extern unsafe void Process(IntPtr model, float* input, float* output, uint numSamples); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /NeuralAudio/Activation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace NeuralAudio 8 | { 9 | #ifndef LSTM_MATH 10 | #define LSTM_MATH FastMath 11 | #endif 12 | 13 | #ifndef WAVENET_MATH 14 | #define WAVENET_MATH FastMath 15 | #endif 16 | 17 | struct StdMath 18 | { 19 | template 20 | static auto Tanh(Matrix& x) 21 | { 22 | float* data = x.data(); 23 | size_t size = x.rows() * x.cols(); 24 | 25 | for (size_t pos = 0; pos < size; pos++) 26 | { 27 | data[pos] = Tanh(data[pos]); 28 | } 29 | 30 | return x; 31 | } 32 | 33 | static inline float Tanh(const float x) 34 | { 35 | return std::tanh(x); 36 | } 37 | 38 | static inline float Sigmoid(float x) 39 | { 40 | return 1.0f / (1.0f + std::exp(-x)); 41 | } 42 | }; 43 | 44 | struct FastMath 45 | { 46 | template 47 | static auto Tanh(Matrix& x) 48 | { 49 | float* data = x.data(); 50 | size_t size = x.rows() * x.cols(); 51 | 52 | for (size_t pos = 0; pos < size; pos++) 53 | { 54 | data[pos] = Tanh(data[pos]); 55 | } 56 | 57 | return x; 58 | } 59 | 60 | static inline float Tanh(const float x) 61 | { 62 | //return std::tanh(x); 63 | 64 | //return math_approx::tanh<5>(x); 65 | 66 | const float ax = fabsf(x); 67 | 68 | const float x2 = x * x; 69 | 70 | return (x * (2.45550750702956f + 2.45550750702956f * ax + (0.893229853513558f + 0.821226666969744f * ax) * x2) 71 | / (2.44506634652299f + (2.44506634652299f + x2) * fabsf(x + 0.814642734961073f * x * ax))); 72 | } 73 | 74 | static inline float Sigmoid(float x) 75 | { 76 | //return math_approx::sigmoid_exp<5>(x); 77 | 78 | //return 1.0f / (1.0f + std::exp(-x)); 79 | return 0.5f * (Tanh(x * 0.5f) + 1); 80 | } 81 | }; 82 | 83 | struct EigenMath 84 | { 85 | template 86 | static auto Tanh(const Matrix& x) 87 | { 88 | return x.array().tanh(); 89 | } 90 | 91 | static inline float Tanh(const float x) 92 | { 93 | return Eigen::numext::tanh(x); 94 | } 95 | 96 | static inline float Sigmoid(float x) 97 | { 98 | return 0.5f * (Tanh(x * 0.5f) + 1); 99 | } 100 | }; 101 | } -------------------------------------------------------------------------------- /NeuralAudioCSharp/NeuralAudio/NeuralModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | namespace NeuralAudio 5 | { 6 | public class NeuralModel 7 | { 8 | public enum EModelLoadMode 9 | { 10 | Internal, 11 | RTNeural, 12 | NAMCore 13 | }; 14 | 15 | IntPtr nativeModel; 16 | 17 | public static void SetLSTMModelLoadMode(EModelLoadMode mode) 18 | { 19 | NativeApi.SetLSTMLoadMode((int)mode); 20 | } 21 | 22 | public static void SetWaveNetModelLoadMode(EModelLoadMode mode) 23 | { 24 | NativeApi.SetWaveNetLoadMode((int)mode); 25 | } 26 | 27 | public static void SetDefaultMaxAudioBufferSize(int bufferSize) 28 | { 29 | NativeApi.SetDefaultMaxAudioBufferSize(bufferSize); 30 | } 31 | 32 | public bool IsStatic { get { return NativeApi.IsStatic(nativeModel); } } 33 | public EModelLoadMode LoadMode { get { return (EModelLoadMode)NativeApi.GetLoadMode(nativeModel); } } 34 | public float SampleRate { get { return NativeApi.GetSampleRate(nativeModel); } } 35 | public float RecommendedInputDBAdjustment { get { return NativeApi.GetRecommendedInputDBAdjustment(nativeModel); } } 36 | public float RecommendedOutputDBAdjustment { get { return NativeApi.GetRecommendedOutputDBAdjustment(nativeModel); } } 37 | 38 | public static NeuralModel FromFile(string modelPath) 39 | { 40 | NeuralModel model = new NeuralModel(); 41 | 42 | IntPtr nativeModel = NativeApi.CreateModelFromFile(modelPath); 43 | 44 | model.nativeModel = nativeModel; 45 | 46 | return model; 47 | } 48 | 49 | public void SetMaxAudioBufferSize(int bufferSize) 50 | { 51 | NativeApi.SetMaxAudioBufferSize(nativeModel, bufferSize); 52 | } 53 | 54 | public unsafe void Process(ReadOnlySpan input, Span output, uint numSamples) 55 | { 56 | fixed (float* inputPtr = input) 57 | { 58 | fixed (float* outputPtr = output) 59 | { 60 | NativeApi.Process(nativeModel, inputPtr, outputPtr, numSamples); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /NeuralAudio/NAMModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NeuralModel.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace NeuralAudio 10 | { 11 | class NAMModel : public NeuralModel 12 | { 13 | public: 14 | NAMModel() 15 | { 16 | nam::activations::Activation::enable_fast_tanh(); 17 | } 18 | 19 | ~NAMModel() 20 | { 21 | if (namModel) 22 | namModel.reset(); 23 | } 24 | 25 | EModelLoadMode GetLoadMode() 26 | { 27 | return EModelLoadMode::NAMCore; 28 | } 29 | 30 | bool LoadFromJson(const nlohmann::json& modelJson) 31 | { 32 | if (namModel) 33 | namModel.reset(); 34 | 35 | ReadNAMConfig(modelJson); 36 | 37 | std::string arch = modelJson.at("architecture"); 38 | 39 | nlohmann::json config = modelJson.at("config"); 40 | 41 | std::vector weights = modelJson.at("weights"); 42 | 43 | if (arch == "WaveNet") 44 | { 45 | std::vector layer_array_params; 46 | 47 | for (size_t i = 0; i < config.at("layers").size(); i++) 48 | { 49 | nlohmann::json layerConfig = config.at("layers").at(i); 50 | 51 | layer_array_params.push_back( 52 | nam::wavenet::LayerArrayParams(layerConfig.at("input_size"), layerConfig.at("condition_size"), layerConfig.at("head_size"), 53 | layerConfig.at("channels"), layerConfig.at("kernel_size"), layerConfig.at("dilations"), 54 | layerConfig.at("activation"), layerConfig.at("gated"), layerConfig.at("head_bias"))); 55 | } 56 | 57 | const bool with_head = !config.at("head").is_null(); 58 | const float head_scale = config.at("head_scale"); 59 | 60 | namModel = std::make_unique(layer_array_params, head_scale, with_head, weights, sampleRate); 61 | } 62 | else if (arch == "LSTM") 63 | { 64 | const int num_layers = config.at("num_layers"); 65 | const int input_size = config.at("input_size"); 66 | const int hidden_size = config.at("hidden_size"); 67 | 68 | namModel = std::make_unique(num_layers, input_size, hidden_size, weights, sampleRate); 69 | } 70 | 71 | return true; 72 | } 73 | 74 | void Process(float* input, float* output, size_t numSamples) 75 | { 76 | namModel->process(input, output, (int)numSamples); 77 | } 78 | 79 | void Prewarm() 80 | { 81 | namModel->prewarm(); 82 | } 83 | 84 | private: 85 | std::unique_ptr namModel = nullptr; 86 | }; 87 | } -------------------------------------------------------------------------------- /NeuralAudio/NeuralModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "json.hpp" 6 | 7 | namespace NeuralAudio 8 | { 9 | enum EModelLoadMode 10 | { 11 | Internal, 12 | RTNeural, 13 | NAMCore 14 | }; 15 | 16 | class NeuralModel 17 | { 18 | public: 19 | static NeuralModel* CreateFromFile(std::filesystem::path modelPath); 20 | static NeuralModel* CreateFromStream(std::basic_istream& stream, std::filesystem::path extension); 21 | 22 | virtual ~NeuralModel() 23 | { 24 | } 25 | 26 | static bool SetLSTMLoadMode(EModelLoadMode val) 27 | { 28 | if (!SupportsLSTMLoadMode(val)) 29 | return false; 30 | 31 | lstmLoadMode = val; 32 | 33 | return true; 34 | } 35 | 36 | static bool SetWaveNetLoadMode(EModelLoadMode val) 37 | { 38 | if (!SupportsWaveNetLoadMode(val)) 39 | return false; 40 | 41 | wavenetLoadMode = val; 42 | 43 | return true; 44 | } 45 | 46 | static bool SupportsWaveNetLoadMode(EModelLoadMode mode); 47 | static bool SupportsLSTMLoadMode(EModelLoadMode mode); 48 | 49 | static void SetAudioInputLevelDBu(float audioDBu) 50 | { 51 | audioInputLevelDBu = audioDBu; 52 | } 53 | 54 | static void SetDefaultMaxAudioBufferSize(int maxSize) 55 | { 56 | defaultMaxAudioBufferSize = maxSize; 57 | } 58 | 59 | virtual EModelLoadMode GetLoadMode() 60 | { 61 | return EModelLoadMode::Internal; 62 | } 63 | 64 | virtual bool IsStatic() 65 | { 66 | return false; 67 | } 68 | 69 | virtual void SetMaxAudioBufferSize(int maxSize) 70 | { 71 | (void)maxSize; 72 | } 73 | 74 | virtual float GetRecommendedInputDBAdjustment() 75 | { 76 | return audioInputLevelDBu - modelInputLevelDBu; 77 | } 78 | 79 | virtual float GetRecommendedOutputDBAdjustment() 80 | { 81 | return -18 - modelLoudnessDB; 82 | } 83 | 84 | virtual float GetSampleRate() 85 | { 86 | return sampleRate; 87 | } 88 | 89 | virtual int GetReceptiveFieldSize() 90 | { 91 | return -1; // No fixed receptive field size (ie: for LSTM) 92 | } 93 | 94 | virtual void Process(float* input, float* output, size_t numSamples) 95 | { 96 | (void)input; 97 | (void)output; 98 | (void)numSamples; 99 | } 100 | 101 | virtual void Prewarm() 102 | { 103 | } 104 | 105 | protected: 106 | void ReadNAMConfig(const nlohmann::json& modelJson); 107 | void ReadKerasConfig(const nlohmann::json& modelJson); 108 | 109 | float modelInputLevelDBu = 12; 110 | float modelOutputLevelDBu = 12; 111 | float modelLoudnessDB = -18; 112 | float sampleRate = 48000; 113 | 114 | inline static float audioInputLevelDBu = 12; 115 | inline static EModelLoadMode lstmLoadMode = EModelLoadMode::Internal; 116 | inline static EModelLoadMode wavenetLoadMode = EModelLoadMode::Internal; 117 | inline static int defaultMaxAudioBufferSize = 128; 118 | 119 | void Prewarm(size_t numSamples, size_t blockSize) 120 | { 121 | std::vector input; 122 | input.resize(blockSize); 123 | std::fill(input.begin(), input.end(), 0.0f); 124 | 125 | std::vector output; 126 | output.resize(blockSize); 127 | 128 | for (size_t block = 0; block < (numSamples / blockSize); block++) 129 | { 130 | Process(input.data(), output.data(), blockSize); 131 | } 132 | } 133 | }; 134 | } -------------------------------------------------------------------------------- /NeuralAudio/RTNeuralLoader.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "RTNeuralModel.h" 3 | 4 | namespace NeuralAudio 5 | { 6 | #ifdef BUILD_STATIC_RTNEURAL 7 | std::list rtNeuralLSTMModelDefs; 8 | std::list rtNeuralWaveNetModelDefs; 9 | 10 | void EnsureRTNeuralModelDefsAreLoaded() 11 | { 12 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<1, 8>); 13 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<1, 12>); 14 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<1, 16>); 15 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<1, 24>); 16 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<2, 8>); 17 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<2, 12>); 18 | rtNeuralLSTMModelDefs.push_back(new RTNeuralLSTMDefinitionT<2, 16>); 19 | 20 | rtNeuralWaveNetModelDefs.push_back(new RTNeuralWaveNetDefinitionT<16, 8>); // Standard 21 | rtNeuralWaveNetModelDefs.push_back(new RTNeuralWaveNetDefinitionT<12, 6>); // Lite 22 | rtNeuralWaveNetModelDefs.push_back(new RTNeuralWaveNetDefinitionT<8, 4>); // Feather 23 | rtNeuralWaveNetModelDefs.push_back(new RTNeuralWaveNetDefinitionT<4, 2>); // Nano 24 | } 25 | 26 | RTNeuralLSTMDefinitionBase* FindRTNeuralLSTMDefinition(size_t numLayers, size_t hiddenSize) 27 | { 28 | for (auto const& model : rtNeuralLSTMModelDefs) 29 | { 30 | if ((numLayers == model->GetNumLayers()) && (hiddenSize == model->GetHiddenSize())) 31 | return model; 32 | } 33 | 34 | return nullptr; 35 | } 36 | 37 | RTNeuralWaveNetDefinitionBase* FindRTNeuralWaveNetDefinition(size_t numChannels, size_t headSize) 38 | { 39 | for (auto const& model : rtNeuralWaveNetModelDefs) 40 | { 41 | if ((numChannels == model->GetNumChannels()) && (headSize == model->GetHeadSize())) 42 | return model; 43 | } 44 | 45 | return nullptr; 46 | } 47 | 48 | NeuralModel* RTNeuralLoadNAMWaveNet(const nlohmann::json& modelJson) 49 | { 50 | nlohmann::json config = modelJson.at("config"); 51 | 52 | nlohmann::json firstLayerConfig = config.at("layers").at(0); 53 | nlohmann::json secondLayerConfig = config.at("layers").at(1); 54 | 55 | auto modelDef = FindRTNeuralWaveNetDefinition(firstLayerConfig.at("channels"), firstLayerConfig.at("head_size")); 56 | 57 | if (modelDef != nullptr) 58 | { 59 | auto model = modelDef->CreateModel(); 60 | 61 | model->LoadFromNAMJson(modelJson); 62 | 63 | return model; 64 | } 65 | 66 | return nullptr; 67 | } 68 | 69 | NeuralModel* RTNeuralLoadNAMLSTM(const nlohmann::json& modelJson) 70 | { 71 | nlohmann::json config = modelJson.at("config"); 72 | 73 | auto modelDef = FindRTNeuralLSTMDefinition(config.at("num_layers"), config.at("hidden_size")); 74 | 75 | if (modelDef != nullptr) 76 | { 77 | RTNeuralModel* model = modelDef->CreateModel(); 78 | model->LoadFromNAMJson(modelJson); 79 | 80 | if (model != nullptr) 81 | return model; 82 | 83 | // If we didn't have a static model that matched, use RTNeural's dynamic model 84 | RTNeuralModelDyn* dynModel = new RTNeuralModelDyn; 85 | dynModel->LoadFromNAMJson(modelJson); 86 | 87 | return dynModel; 88 | } 89 | 90 | return nullptr; 91 | } 92 | 93 | NeuralModel* RTNeuralLoadKeras(const nlohmann::json& modelJson) 94 | { 95 | const auto layers = modelJson.at("layers"); 96 | const size_t numLayers = layers.size() - 1; 97 | const std::string modelType = layers.at(0).at("type"); 98 | const int hiddenSize = layers.at(0).at("shape").back(); 99 | 100 | auto modelDef = FindRTNeuralLSTMDefinition(numLayers, hiddenSize); 101 | 102 | if (modelDef != nullptr) 103 | { 104 | RTNeuralModel* model = modelDef->CreateModel(); 105 | 106 | model->LoadFromKerasJson(modelJson); 107 | 108 | return model; 109 | } 110 | 111 | return nullptr; 112 | } 113 | #endif 114 | } 115 | 116 | -------------------------------------------------------------------------------- /NeuralAudio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD 20) 2 | 3 | add_definitions(-DNAM_SAMPLE_FLOAT) 4 | add_definitions(-DDSP_SAMPLE_FLOAT) 5 | 6 | option(BUILD_STATIC_RTNEURAL "Build Static RTNeural" OFF) 7 | if(BUILD_STATIC_RTNEURAL) 8 | message(STATUS "Building static RTNeural models") 9 | add_definitions(-DBUILD_STATIC_RTNEURAL) 10 | else() 11 | message(STATUS "NOT Building static RTNeural models") 12 | endif() 13 | 14 | option(BUILD_NAMCORE "Build NAM Core" OFF) 15 | if(BUILD_NAMCORE) 16 | message(STATUS "Building NAM Core implementation") 17 | add_definitions(-DBUILD_NAMCORE) 18 | else() 19 | message(STATUS "NOT Building NAM Core implementation") 20 | endif() 21 | 22 | option(BUILD_INTERNAL_STATIC_WAVENET "Build Internal static WaveNet models" ON) 23 | if(BUILD_INTERNAL_STATIC_WAVENET) 24 | message(STATUS "Building Internal static WaveNet models") 25 | add_definitions(-DBUILD_INTERNAL_STATIC_WAVENET) 26 | else() 27 | message(STATUS "NOT Building Internal static WaveNet models") 28 | endif() 29 | 30 | option(BUILD_INTERNAL_STATIC_LSTM "Build Internal static LSTM models" ON) 31 | if(BUILD_INTERNAL_STATIC_LSTM) 32 | message(STATUS "Building Internal static LSTM models") 33 | add_definitions(-DBUILD_INTERNAL_STATIC_LSTM) 34 | else() 35 | message(STATUS "NOT Building Internal static LSTM models") 36 | endif() 37 | 38 | set(LSTM_MATH "FastMath" CACHE STRING "LSTM math functions") 39 | add_definitions(-DLSTM_MATH=${LSTM_MATH}) 40 | message(STATUS "LSTM math is: ${LSTM_MATH}") 41 | 42 | set(WAVENET_MATH "FastMath" CACHE STRING "WaveNet math functions") 43 | add_definitions(-DWAVENET_MATH=${WAVENET_MATH}) 44 | message(STATUS "WaveNet math is: ${WAVENET_MATH}") 45 | 46 | set(WAVENET_FRAMES "64" CACHE STRING "WaveNet frame size") 47 | 48 | add_definitions(-DWAVENET_MAX_NUM_FRAMES=${WAVENET_FRAMES}) 49 | 50 | message(STATUS "WaveNet frame size is: ${WAVENET_FRAMES}") 51 | 52 | if (MSVC) 53 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") 54 | endif() 55 | 56 | set(SOURCES 57 | NeuralModel.h 58 | NeuralModel.cpp 59 | NAMModel.h 60 | RTNeuralModel.h 61 | RTNeuralLoader.cpp 62 | RTNeuralLoader.h 63 | Activation.h 64 | WaveNet.h 65 | WaveNetDynamic.h 66 | LSTM.h 67 | LSTMDynamic.h 68 | InternalModel.h 69 | TemplateHelper.h) 70 | 71 | if(BUILD_NAMCORE) 72 | set(NAM_SOURCES ../deps/NeuralAmpModelerCore/NAM/activations.h 73 | ../deps/NeuralAmpModelerCore/NAM/activations.cpp 74 | ../deps/NeuralAmpModelerCore/NAM/lstm.h 75 | ../deps/NeuralAmpModelerCore/NAM/lstm.cpp 76 | ../deps/NeuralAmpModelerCore/NAM/dsp.h 77 | ../deps/NeuralAmpModelerCore/NAM/dsp.cpp 78 | ../deps/NeuralAmpModelerCore/NAM/wavenet.cpp 79 | ../deps/NeuralAmpModelerCore/NAM/wavenet.h) 80 | endif() 81 | 82 | if(BUILD_STATIC_RTNEURAL) 83 | set(RTNEURAL_WN_SOURCES ../deps/RTNeural-NAM/wavenet/wavenet_layer.hpp 84 | ../deps/RTNeural-NAM/wavenet/wavenet_layer_array.hpp 85 | ../deps/RTNeural-NAM/wavenet/wavenet_model.hpp 86 | ../deps/RTNeural-NAM/wavenet/arena.hpp) 87 | endif() 88 | 89 | add_library(NeuralAudio STATIC ${SOURCES} ${NAM_SOURCES} ${RTNEURAL_WN_SOURCES}) 90 | 91 | target_include_directories(NeuralAudio PUBLIC ..) 92 | target_include_directories(NeuralAudio SYSTEM PRIVATE ../deps/NeuralAmpModelerCore) 93 | target_include_directories(NeuralAudio SYSTEM PRIVATE ../deps/RTNeural) 94 | target_include_directories(NeuralAudio SYSTEM PRIVATE ../deps/math_approx) 95 | target_include_directories(NeuralAudio SYSTEM PRIVATE ../deps/RTNeural-NAM/wavenet) 96 | target_include_directories(NeuralAudio SYSTEM PRIVATE ../deps/RTNeural/modules/Eigen) 97 | target_include_directories(NeuralAudio SYSTEM PRIVATE ../deps/RTNeural/modules/json) 98 | 99 | set_property(TARGET NeuralAudio PROPERTY POSITION_INDEPENDENT_CODE ON) 100 | 101 | add_subdirectory(../deps/RTNeural RTNeural) 102 | add_subdirectory(../deps/math_approx math_approx) 103 | target_link_libraries(NeuralAudio LINK_PUBLIC RTNeural math_approx) 104 | 105 | source_group(NeuralAudio ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 106 | source_group(NAM ${CMAKE_CURRENT_SOURCE_DIR} FILES ${NAM_SOURCES}) 107 | source_group(RTNeural-NAM ${CMAKE_CURRENT_SOURCE_DIR} FILES ${RTNEURAL_WN_SOURCES}) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | 84 | # Visual Studio profiler 85 | *.psess 86 | *.vsp 87 | *.vspx 88 | *.sap 89 | 90 | # TFS 2012 Local Workspace 91 | $tf/ 92 | 93 | # Guidance Automation Toolkit 94 | *.gpState 95 | 96 | # ReSharper is a .NET coding add-in 97 | _ReSharper*/ 98 | *.[Rr]e[Ss]harper 99 | *.DotSettings.user 100 | 101 | # JustCode is a .NET coding add-in 102 | .JustCode 103 | 104 | # TeamCity is a build add-in 105 | _TeamCity* 106 | 107 | # DotCover is a Code Coverage Tool 108 | *.dotCover 109 | 110 | # NCrunch 111 | _NCrunch_* 112 | .*crunch*.local.xml 113 | nCrunchTemp_* 114 | 115 | # MightyMoose 116 | *.mm.* 117 | AutoTest.Net/ 118 | 119 | # Web workbench (sass) 120 | .sass-cache/ 121 | 122 | # Installshield output folder 123 | [Ee]xpress/ 124 | 125 | # DocProject is a documentation generator add-in 126 | DocProject/buildhelp/ 127 | DocProject/Help/*.HxT 128 | DocProject/Help/*.HxC 129 | DocProject/Help/*.hhc 130 | DocProject/Help/*.hhk 131 | DocProject/Help/*.hhp 132 | DocProject/Help/Html2 133 | DocProject/Help/html 134 | 135 | # Click-Once directory 136 | publish/ 137 | 138 | # Publish Web Output 139 | *.[Pp]ublish.xml 140 | *.azurePubxml 141 | # TODO: Comment the next line if you want to checkin your web deploy settings 142 | # but database connection strings (with potential passwords) will be unencrypted 143 | *.pubxml 144 | *.publishproj 145 | 146 | # NuGet Packages 147 | *.nupkg 148 | # The packages folder can be ignored because of Package Restore 149 | **/packages/* 150 | # except build/, which is used as an MSBuild target. 151 | !**/packages/build/ 152 | # Uncomment if necessary however generally it will be regenerated when needed 153 | #!**/packages/repositories.config 154 | # NuGet v3's project.json files produces more ignoreable files 155 | *.nuget.props 156 | *.nuget.targets 157 | 158 | # Microsoft Azure Build Output 159 | csx/ 160 | *.build.csdef 161 | 162 | # Microsoft Azure Emulator 163 | ecf/ 164 | rcf/ 165 | 166 | # Microsoft Azure ApplicationInsights config file 167 | ApplicationInsights.config 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | ~$* 182 | *~ 183 | *.dbmdl 184 | *.dbproj.schemaview 185 | *.pfx 186 | *.publishsettings 187 | node_modules/ 188 | orleans.codegen.cs 189 | 190 | # RIA/Silverlight projects 191 | Generated_Code/ 192 | 193 | # Backup & report files from converting an old project file 194 | # to a newer Visual Studio version. Backup files are not needed, 195 | # because we have git ;-) 196 | _UpgradeReport_Files/ 197 | Backup*/ 198 | UpgradeLog*.XML 199 | UpgradeLog*.htm 200 | 201 | # SQL Server files 202 | *.mdf 203 | *.ldf 204 | 205 | # Business Intelligence projects 206 | *.rdl.data 207 | *.bim.layout 208 | *.bim_*.settings 209 | 210 | # Microsoft Fakes 211 | FakesAssemblies/ 212 | 213 | # GhostDoc plugin setting file 214 | *.GhostDoc.xml 215 | 216 | # Node.js Tools for Visual Studio 217 | .ntvs_analysis.dat 218 | 219 | # Visual Studio 6 build log 220 | *.plg 221 | 222 | # Visual Studio 6 workspace options file 223 | *.opt 224 | 225 | # Visual Studio LightSwitch build output 226 | **/*.HTMLClient/GeneratedArtifacts 227 | **/*.DesktopClient/GeneratedArtifacts 228 | **/*.DesktopClient/ModelManifest.xml 229 | **/*.Server/GeneratedArtifacts 230 | **/*.Server/ModelManifest.xml 231 | _Pvt_Extensions 232 | 233 | # Paket dependency manager 234 | .paket/paket.exe 235 | 236 | # FAKE - F# Make 237 | .fake/ 238 | -------------------------------------------------------------------------------- /NeuralAudio/LSTMDynamic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Activation.h" 6 | #include "LSTM.h" 7 | 8 | namespace NeuralAudio 9 | { 10 | class LSTMLayer 11 | { 12 | private: 13 | size_t inputSize; 14 | size_t hiddenSize; 15 | size_t inputHiddenSize; 16 | size_t gateSize; 17 | Eigen::MatrixXf inputHiddenWeights; 18 | Eigen::VectorXf bias; 19 | Eigen::VectorXf state; 20 | Eigen::VectorXf gates; 21 | Eigen::VectorXf cellState; 22 | 23 | size_t iOffset; 24 | size_t fOffset; 25 | size_t gOffset; 26 | size_t oOffset; 27 | size_t hOffset; 28 | 29 | public: 30 | LSTMLayer(size_t inputSize, size_t hiddenSize) : 31 | inputSize(inputSize), 32 | hiddenSize(hiddenSize), 33 | inputHiddenSize(inputSize + hiddenSize), 34 | gateSize(4 * hiddenSize), 35 | inputHiddenWeights(gateSize, inputHiddenSize), 36 | bias(gateSize), 37 | state(inputHiddenSize), 38 | gates(gateSize), 39 | cellState(hiddenSize), 40 | iOffset(0), 41 | fOffset(hiddenSize), 42 | gOffset(2 * hiddenSize), 43 | oOffset(3 * hiddenSize), 44 | hOffset(inputSize) 45 | { 46 | } 47 | 48 | auto GetHiddenState() const { return state(Eigen::placeholders::lastN(hiddenSize)); }; 49 | 50 | void SetNAMWeights(std::vector::iterator& weights) 51 | { 52 | for (size_t i = 0; i < gateSize; i++) 53 | for (size_t j = 0; j < inputHiddenSize; j++) 54 | inputHiddenWeights(i, j) = *(weights++); 55 | 56 | for (size_t i = 0; i < gateSize; i++) 57 | bias[i] = *(weights++); 58 | 59 | for (size_t i = 0; i < hiddenSize; i++) 60 | state[i + inputSize] = *(weights++); 61 | 62 | for (size_t i = 0; i < hiddenSize; i++) 63 | cellState[i] = *(weights++); 64 | } 65 | 66 | void SetWeights(LSTMLayerDef& def) 67 | { 68 | std::vector::iterator it = def.InputWeights.begin(); 69 | 70 | for (size_t j = 0; j < inputSize; j++) 71 | for (size_t i = 0; i < gateSize; i++) 72 | { 73 | inputHiddenWeights(i, j) = *(it++); 74 | } 75 | 76 | assert(std::distance(def.InputWeights.begin(), it) == (long)def.InputWeights.size()); 77 | 78 | it = def.HiddenWeights.begin(); 79 | 80 | for (size_t j = 0; j < hiddenSize; j++) 81 | for (size_t i = 0; i < gateSize; i++) 82 | { 83 | inputHiddenWeights(i, j + inputSize) = *(it++); 84 | } 85 | 86 | assert(std::distance(def.HiddenWeights.begin(), it) == (long)def.HiddenWeights.size()); 87 | 88 | for (size_t i = 0; i < gateSize; i++) 89 | bias[i] = def.BiasWeights[i]; 90 | 91 | state.setZero(); 92 | cellState.setZero(); 93 | } 94 | 95 | inline void Process(const float* input) 96 | { 97 | for (size_t i = 0; i < inputSize; i++) 98 | state(i) = input[i]; 99 | 100 | gates = (inputHiddenWeights * state) + bias; 101 | 102 | for (size_t i = 0; i < hiddenSize; i++) 103 | cellState[i] = (LSTM_MATH::Sigmoid(gates[i + fOffset]) * cellState[i]) + (LSTM_MATH::Sigmoid(gates[i + iOffset]) * 104 | LSTM_MATH::Tanh(gates[i + gOffset])); 105 | 106 | for (size_t i = 0; i < hiddenSize; i++) 107 | state[i + hOffset] = LSTM_MATH::Sigmoid(gates[i + oOffset]) * LSTM_MATH::Tanh(cellState[i]); 108 | } 109 | }; 110 | 111 | class LSTMModel 112 | { 113 | private: 114 | size_t numLayers; 115 | size_t lastLayer; 116 | size_t hiddenSize; 117 | std::vector layers; 118 | Eigen::VectorXf headWeights; 119 | float headBias; 120 | 121 | public: 122 | LSTMModel(size_t numLayers, size_t hiddenSize) : 123 | numLayers(numLayers), 124 | lastLayer(numLayers - 1), 125 | hiddenSize(hiddenSize), 126 | headWeights(hiddenSize) 127 | { 128 | layers.push_back(LSTMLayer(1, hiddenSize)); 129 | 130 | for (size_t i = 0; i < numLayers - 1; i++) 131 | { 132 | layers.push_back(LSTMLayer(hiddenSize, hiddenSize)); 133 | } 134 | } 135 | 136 | void SetNAMWeights(std::vector weights) 137 | { 138 | std::vector::iterator it = weights.begin(); 139 | 140 | for (auto& layer : layers) 141 | { 142 | layer.SetNAMWeights(it); 143 | } 144 | 145 | for (int i = 0; i < hiddenSize; i++) 146 | headWeights[i] = *(it++); 147 | 148 | headBias = *(it++); 149 | 150 | assert(std::distance(weights.begin(), it) == (long)weights.size()); 151 | } 152 | 153 | void SetWeights(LSTMDef& def) 154 | { 155 | for (size_t i = 0; i < hiddenSize; i++) 156 | headWeights[i] = def.HeadWeights[i]; 157 | 158 | headBias = def.HeadBias; 159 | 160 | for (size_t i = 0; i < numLayers; i++) 161 | { 162 | layers[i].SetWeights(def.Layers[i]); 163 | } 164 | } 165 | 166 | void Process(const float* input, float* output, const size_t numSamples) 167 | { 168 | for (size_t i = 0; i < numSamples; i++) 169 | { 170 | layers[0].Process(input + i); 171 | 172 | for (size_t layer = 1; layer < numLayers; layer++) 173 | { 174 | layers[layer].Process(layers[layer - 1].GetHiddenState().data()); 175 | } 176 | 177 | output[i] = headWeights.dot(layers[lastLayer].GetHiddenState()) + headBias; 178 | } 179 | } 180 | }; 181 | } -------------------------------------------------------------------------------- /deps/RTNeural-NAM/wavenet/arena.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace wavenet 10 | { 11 | /** 12 | * Returns the next pointer with a given byte alignment, 13 | * or the base pointer if it is already aligned. 14 | */ 15 | template 16 | Type* snap_pointer_to_alignment (Type* base_pointer, 17 | Integer_Type alignment_bytes) noexcept 18 | { 19 | return (Type*) ((((size_t) base_pointer) + (alignment_bytes - 1)) & ~(alignment_bytes - 1)); 20 | } 21 | 22 | static constexpr int default_byte_alignment = 16; 23 | 24 | /** 25 | * A simple memory arena. By default the arena will be 26 | * backed with a vector of bytes, but the underlying 27 | * memory resource can be changed via the template argument. 28 | */ 29 | template > 30 | class Memory_Arena 31 | { 32 | public: 33 | Memory_Arena() = default; 34 | 35 | /** Constructs the arena with an initial allocated size. */ 36 | explicit Memory_Arena (size_t size_in_bytes) { resize (size_in_bytes); } 37 | 38 | Memory_Arena (const Memory_Arena&) = delete; 39 | Memory_Arena& operator= (const Memory_Arena&) = delete; 40 | 41 | Memory_Arena (Memory_Arena&&) noexcept = default; 42 | Memory_Arena& operator= (Memory_Arena&&) noexcept = default; 43 | 44 | /** Re-allocates the internal buffer with a given number of bytes */ 45 | void resize (size_t new_size_bytes) 46 | { 47 | clear(); 48 | raw_data.resize (new_size_bytes, std::byte {}); 49 | } 50 | 51 | /** 52 | * Moves the allocator "stack pointer" back to zero, 53 | * effectively "reclaiming" all allocated memory. 54 | */ 55 | void clear() noexcept 56 | { 57 | #if DEBUG 58 | std::fill (raw_data.begin(), raw_data.begin() + bytes_used, std::byte { 0xDD }); 59 | #endif 60 | bytes_used = 0; 61 | } 62 | 63 | /** Returns the number of bytes currently being used */ 64 | [[nodiscard]] size_t get_bytes_used() const noexcept { return bytes_used; } 65 | 66 | /** 67 | * Allocates a given number of bytes. 68 | * The returned memory will be un-initialized, so be sure to clear it manually 69 | * if needed. 70 | */ 71 | void* allocate_bytes (size_t num_bytes, size_t alignment = 1) 72 | { 73 | auto* pointer = snap_pointer_to_alignment (raw_data.data() + bytes_used, alignment); 74 | const auto bytes_increment = static_cast (std::distance (raw_data.data() + bytes_used, pointer + num_bytes)); 75 | 76 | if (bytes_used + bytes_increment > raw_data.size()) 77 | { 78 | assert (false); 79 | return nullptr; 80 | } 81 | 82 | bytes_used += bytes_increment; 83 | return pointer; 84 | } 85 | 86 | /** 87 | * Allocates space for some number of objects of type T 88 | * The returned memory will be un-initialized, so be sure to clear it manually 89 | * if needed. 90 | */ 91 | template 92 | T* allocate (IntType num_Ts, size_t alignment = alignof (T)) 93 | { 94 | return static_cast (allocate_bytes ((size_t) num_Ts * sizeof (T), alignment)); 95 | } 96 | 97 | /** 98 | * Returns a span of type T, and size count. 99 | * The returned memory will be un-initialized, so be sure to clear it manually 100 | * if needed. 101 | */ 102 | template 103 | auto make_span (IntType count, size_t alignment = default_byte_alignment) 104 | { 105 | return std::span { allocate (count, alignment), 106 | static_cast (count) }; 107 | } 108 | 109 | /** Returns a pointer to the internal buffer with a given offset in bytes */ 110 | template 111 | T* data (IntType offset_bytes) noexcept 112 | { 113 | return reinterpret_cast (raw_data.data() + offset_bytes); 114 | } 115 | 116 | /** 117 | * Creates a "frame" for the allocator. 118 | * Once the frame goes out of scope, the allocator will be reset 119 | * to whatever it's state was at the beginning of the frame. 120 | */ 121 | struct Frame 122 | { 123 | Frame() = default; 124 | explicit Frame (Memory_Arena& allocator) 125 | : alloc (&allocator), bytes_used_at_start (alloc->bytes_used) {} 126 | 127 | ~Frame() { alloc->bytes_used = bytes_used_at_start; } 128 | 129 | Memory_Arena* alloc = nullptr; 130 | size_t bytes_used_at_start = 0; 131 | }; 132 | 133 | /** Creates a frame for this allocator */ 134 | auto create_frame() { return Frame { *this }; } 135 | 136 | void reset_to_frame (const Frame& frame) 137 | { 138 | assert (frame.alloc == this); 139 | bytes_used = frame.bytes_used_at_start; 140 | } 141 | 142 | private: 143 | MemoryResourceType raw_data {}; 144 | size_t bytes_used = 0; 145 | }; 146 | } // namespace wavenet 147 | -------------------------------------------------------------------------------- /NeuralAudio/LSTM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Activation.h" 5 | #include "TemplateHelper.h" 6 | 7 | namespace NeuralAudio 8 | { 9 | struct LSTMLayerDef 10 | { 11 | std::vector InputWeights; 12 | std::vector HiddenWeights; 13 | std::vector BiasWeights; 14 | }; 15 | 16 | struct LSTMDef 17 | { 18 | std::vector Layers; 19 | std::vector HeadWeights; 20 | float HeadBias; 21 | }; 22 | 23 | template 24 | class LSTMLayerT 25 | { 26 | private: 27 | Eigen::Matrix inputHiddenWeights; 28 | Eigen::Vector bias; 29 | Eigen::Vector state; 30 | Eigen::Vector gates; 31 | Eigen::Vector cellState; 32 | 33 | constexpr static long iOffset = 0; 34 | constexpr static long fOffset = HiddenSize; 35 | constexpr static long gOffset = 2 * HiddenSize; 36 | constexpr static long oOffset = 3 * HiddenSize; 37 | constexpr static long hOffset = InputSize; 38 | 39 | public: 40 | auto GetHiddenState() const { return state(Eigen::placeholders::lastN(HiddenSize)); }; 41 | 42 | void SetNAMWeights(std::vector::iterator& weights) 43 | { 44 | for (int i = 0; i < inputHiddenWeights.rows(); i++) 45 | for (int j = 0; j < inputHiddenWeights.cols(); j++) 46 | inputHiddenWeights(i, j) = *(weights++); 47 | 48 | for (int i = 0; i < bias.size(); i++) 49 | bias[i] = *(weights++); 50 | 51 | for (int i = 0; i < HiddenSize; i++) 52 | state[i + InputSize] = *(weights++); 53 | 54 | for (int i = 0; i < HiddenSize; i++) 55 | cellState[i] = *(weights++); 56 | } 57 | 58 | void SetWeights(LSTMLayerDef& def) 59 | { 60 | std::vector::iterator it = def.InputWeights.begin(); 61 | 62 | for (int j = 0; j < InputSize; j++) 63 | for (int i = 0; i < inputHiddenWeights.rows(); i++) 64 | { 65 | inputHiddenWeights(i, j) = *(it++); 66 | } 67 | 68 | assert(std::distance(def.InputWeights.begin(), it) == (long)def.InputWeights.size()); 69 | 70 | it = def.HiddenWeights.begin(); 71 | 72 | for (int j = 0; j < HiddenSize; j++) 73 | for (int i = 0; i < inputHiddenWeights.rows(); i++) 74 | { 75 | inputHiddenWeights(i, j + InputSize) = *(it++); 76 | } 77 | 78 | assert(std::distance(def.HiddenWeights.begin(), it) == (long)def.HiddenWeights.size()); 79 | 80 | for (int i = 0; i < bias.rows(); i++) 81 | bias[i] = def.BiasWeights[i]; 82 | 83 | state.setZero(); 84 | cellState.setZero(); 85 | } 86 | 87 | inline void Process(const float* input) 88 | { 89 | for (int i = 0; i < InputSize; i++) 90 | state(i) = input[i]; 91 | 92 | gates = (inputHiddenWeights * state) + bias; 93 | 94 | for (auto i = 0; i < HiddenSize; i++) 95 | cellState[i] = (LSTM_MATH::Sigmoid(gates[i + fOffset]) * cellState[i]) + 96 | (LSTM_MATH::Sigmoid(gates[i + iOffset]) * LSTM_MATH::Tanh(gates[i + gOffset])); 97 | 98 | for (int i = 0; i < HiddenSize; i++) 99 | state[i + hOffset] = LSTM_MATH::Sigmoid(gates[i + oOffset]) * LSTM_MATH::Tanh(cellState[i]); 100 | } 101 | }; 102 | 103 | template 104 | class LSTMModelT 105 | { 106 | private: 107 | LSTMLayerT<1, HiddenSize> firstLayer; 108 | std::vector> remainingLayers; 109 | Eigen::Vector headWeights; 110 | float headBias; 111 | 112 | public: 113 | LSTMModelT() 114 | { 115 | if constexpr (NumLayers > 1) 116 | { 117 | remainingLayers.resize(NumLayers - 1); 118 | 119 | ForEachIndex([&](auto layerIndex) 120 | { 121 | (void)layerIndex; 122 | 123 | LSTMLayerT layer; 124 | 125 | remainingLayers.push_back(layer); 126 | }); 127 | } 128 | } 129 | 130 | void SetNAMWeights(std::vector weights) 131 | { 132 | std::vector::iterator it = weights.begin(); 133 | 134 | firstLayer.SetNAMWeights(it); 135 | 136 | ForEachIndex([&](auto layerIndex) 137 | { 138 | remainingLayers[layerIndex].SetNAMWeights(it); 139 | }); 140 | 141 | for (int i = 0; i < HiddenSize; i++) 142 | headWeights[i] = *(it++); 143 | 144 | headBias = *(it++); 145 | 146 | assert(std::distance(weights.begin(), it) == (long)weights.size()); 147 | } 148 | 149 | void SetWeights(LSTMDef& def) 150 | { 151 | for (int i = 0; i < HiddenSize; i++) 152 | headWeights[i] = def.HeadWeights[i]; 153 | 154 | headBias = def.HeadBias; 155 | 156 | firstLayer.SetWeights(def.Layers[0]); 157 | 158 | ForEachIndex([&](auto layerIndex) 159 | { 160 | remainingLayers[layerIndex].SetWeights(def.Layers[layerIndex + 1]); 161 | }); 162 | } 163 | 164 | void Process(const float* input, float* output, const size_t numSamples) 165 | { 166 | for (size_t i = 0; i < numSamples; i++) 167 | { 168 | firstLayer.Process(input + i); 169 | 170 | ForEachIndex([&](auto layerIndex) 171 | { 172 | if constexpr (layerIndex == 0) 173 | { 174 | remainingLayers[layerIndex].Process(firstLayer.GetHiddenState().data()); 175 | } 176 | else 177 | { 178 | remainingLayers[layerIndex].Process(remainingLayers[layerIndex - 1].GetHiddenState().data()); 179 | } 180 | }); 181 | 182 | if constexpr (NumLayers == 1) 183 | { 184 | output[i] = headWeights.dot(firstLayer.GetHiddenState()) + headBias; 185 | } 186 | else 187 | { 188 | output[i] = headWeights.dot(remainingLayers[NumLayers - 2].GetHiddenState()) + headBias; 189 | } 190 | } 191 | } 192 | }; 193 | } -------------------------------------------------------------------------------- /deps/RTNeural-NAM/wavenet/wavenet_model.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "arena.hpp" 4 | #include "wavenet_layer_array.hpp" 5 | 6 | namespace wavenet 7 | { 8 | template 11 | struct Wavenet_Model 12 | { 13 | std::tuple layer_arrays; 14 | 15 | static constexpr auto head_layer_n_channels = std::tuple_element_t<0, std::tuple>::n_channels; 16 | 17 | #if RTNEURAL_USE_EIGEN 18 | Eigen::Matrix head_input {}; 19 | #elif RTNEURAL_USE_XSIMD 20 | xsimd::batch head_input[RTNeural::ceil_div (head_layer_n_channels, (int) xsimd::batch::size)]; 21 | #endif 22 | T head_scale = (T) 0; 23 | 24 | Memory_Arena<> arena {}; 25 | 26 | Wavenet_Model() = default; 27 | 28 | void prepare (int block_size) 29 | { 30 | #if RTNEURAL_USE_EIGEN 31 | size_t arena_bytes_needed = sizeof (Eigen::Matrix) * block_size; 32 | #elif RTNEURAL_USE_XSIMD 33 | size_t arena_bytes_needed = sizeof (xsimd::batch[RTNeural::ceil_div (head_layer_n_channels, (int) xsimd::batch::size)]) * block_size 34 | + sizeof (xsimd::batch) * block_size; 35 | #endif 36 | RTNeural::modelt_detail::forEachInTuple ( 37 | [&arena_bytes_needed, block_size] (auto& layer_array, auto) 38 | { 39 | arena_bytes_needed += layer_array.get_arena_bytes_needed (block_size); 40 | }, 41 | layer_arrays); 42 | 43 | arena.resize (arena_bytes_needed + 256); 44 | // prewarm(); 45 | } 46 | 47 | void prewarm() 48 | { 49 | RTNeural::modelt_detail::forEachInTuple ( 50 | [] (auto& layer, size_t) 51 | { 52 | layer.reset(); 53 | }, 54 | layer_arrays); 55 | for (int i = 0; i < 1 << 14; ++i) 56 | forward (0.0f); 57 | } 58 | 59 | void load_weights (const nlohmann::json& model_json) 60 | { 61 | std::vector model_weights = model_json.at ("weights"); 62 | auto weights_iterator = model_weights.begin(); 63 | RTNeural::modelt_detail::forEachInTuple ( 64 | [&weights_iterator] (auto& layer, size_t) 65 | { 66 | layer.load_weights (weights_iterator); 67 | }, 68 | layer_arrays); 69 | 70 | head_scale = *weights_iterator++; 71 | 72 | // Make sure we use the all of the weights exactly 73 | assert (std::distance (model_weights.begin(), weights_iterator) == model_weights.size()); 74 | } 75 | 76 | T forward (T input) noexcept 77 | { 78 | #if RTNEURAL_USE_EIGEN 79 | const auto v_ins = Eigen::Matrix::Constant (input); 80 | #elif RTNEURAL_USE_XSIMD 81 | xsimd::batch v_ins[1]; 82 | v_ins[0] = RTNeural::set_value (v_ins[0], 0, input); 83 | #endif 84 | 85 | RTNeural::modelt_detail::forEachInTuple ( 86 | [this, v_ins] (auto& layer_array, auto index_t) 87 | { 88 | static constexpr size_t index = index_t; 89 | if constexpr (index == 0) 90 | { 91 | #if RTNEURAL_USE_EIGEN 92 | head_input.setZero(); 93 | std::get<0> (layer_arrays).forward (v_ins, v_ins, head_input); 94 | #elif RTNEURAL_USE_XSIMD 95 | std::fill (std::begin (head_input), std::end (head_input), xsimd::batch {}); 96 | std::get<0> (layer_arrays).forward (v_ins, v_ins, head_input); 97 | #endif 98 | } 99 | else 100 | { 101 | std::get (layer_arrays).forward (std::get (layer_arrays).layer_outputs, v_ins, std::get (layer_arrays).head_outputs); 102 | } 103 | }, 104 | layer_arrays); 105 | 106 | #if RTNEURAL_USE_EIGEN 107 | return std::get - 1> (layer_arrays).head_outputs[0] * head_scale; 108 | #elif RTNEURAL_USE_XSIMD 109 | return std::get - 1> (layer_arrays).head_outputs[0].get (0) * head_scale; 110 | #endif 111 | } 112 | 113 | void forward (const T* input, T* output, int N) noexcept 114 | { 115 | #if RTNEURAL_USE_EIGEN 116 | const auto* v_ins = reinterpret_cast*> (input); 117 | #elif RTNEURAL_USE_XSIMD 118 | auto* v_ins = arena.allocate[1]> (N, RTNEURAL_DEFAULT_ALIGNMENT); 119 | for (int n = 0; n < N; ++n) 120 | v_ins[n][0] = RTNeural::set_value (v_ins[n][0], 0, input[n]); 121 | #endif 122 | 123 | RTNeural::modelt_detail::forEachInTuple ( 124 | [this, v_ins, N, output] (auto& layer_array, auto index_t) 125 | { 126 | static constexpr size_t index = index_t; 127 | if constexpr (index == 0) 128 | { 129 | #if RTNEURAL_USE_EIGEN 130 | auto* head_inputs = arena.allocate> (N, RTNEURAL_DEFAULT_ALIGNMENT); 131 | for (int n = 0; n < N; ++n) 132 | head_inputs[n].setZero(); 133 | std::get<0> (layer_arrays).forward (v_ins, v_ins, head_inputs, N, arena); 134 | #elif RTNEURAL_USE_XSIMD 135 | auto* head_inputs = arena.allocate[RTNeural::ceil_div (head_layer_n_channels, (int) xsimd::batch::size)]> (N, RTNEURAL_DEFAULT_ALIGNMENT); 136 | for (int n = 0; n < N; ++n) 137 | std::fill (std::begin (head_inputs[n]), std::end (head_inputs[n]), xsimd::batch {}); 138 | std::get<0> (layer_arrays).forward (v_ins, v_ins, head_inputs, N, arena); 139 | #endif 140 | } 141 | else 142 | { 143 | auto& prev_layer_array = std::get (layer_arrays); 144 | std::get (layer_arrays).forward (prev_layer_array.layer_outputs_arr, v_ins, prev_layer_array.head_outputs_arr, N, arena); 145 | } 146 | }, 147 | layer_arrays); 148 | 149 | auto& last_layer_array = std::get - 1> (layer_arrays); 150 | for (int n = 0; n < N; ++n) 151 | { 152 | #if RTNEURAL_USE_EIGEN 153 | output[n] = last_layer_array.head_outputs_arr[n][0] * head_scale; 154 | #elif RTNEURAL_USE_XSIMD 155 | output[n] = last_layer_array.head_outputs_arr[n][0].get (0) * head_scale; 156 | #endif 157 | } 158 | 159 | arena.clear(); 160 | } 161 | }; 162 | } // namespace wavenet 163 | -------------------------------------------------------------------------------- /deps/RTNeural-NAM/wavenet/wavenet_layer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace wavenet 6 | { 7 | template > 14 | // TODO: gated? 15 | struct Wavenet_Layer 16 | { 17 | RTNeural::Conv1DT conv; 18 | RTNeural::DenseT input_mixin; 19 | RTNeural::DenseT _1x1; 20 | Activation activation; 21 | 22 | #if RTNEURAL_USE_EIGEN 23 | Eigen::Matrix outs; 24 | #elif RTNEURAL_USE_XSIMD 25 | xsimd::batch outs[RTNeural::ceil_div (channels, (int) xsimd::batch::size)]; 26 | #endif 27 | 28 | void reset() 29 | { 30 | conv.reset(); 31 | } 32 | 33 | void load_weights (std::vector::iterator& weights) 34 | { 35 | conv.reset(); 36 | 37 | std::vector>> conv_weights (channels, std::vector> (channels, std::vector (kernel_size))); 38 | for (int i = 0; i < channels; ++i) 39 | for (int j = 0; j < channels; ++j) 40 | for (int k = 0; k < kernel_size; k++) 41 | conv_weights[i][j][k] = *(weights++); 42 | RTNeural::torch_helpers::detail::reverseKernels (conv_weights); 43 | conv.setWeights (conv_weights); 44 | 45 | std::vector conv_bias (channels); 46 | for (int i = 0; i < channels; ++i) 47 | conv_bias[i] = *(weights++); 48 | conv.setBias (conv_bias); 49 | 50 | std::vector> input_mixin_weights (channels, std::vector (condition_size)); 51 | for (int i = 0; i < channels; i++) 52 | for (int j = 0; j < condition_size; j++) 53 | input_mixin_weights[i][j] = *(weights++); 54 | input_mixin.setWeights (input_mixin_weights); 55 | 56 | std::vector> _1x1_weights (channels, std::vector (channels)); 57 | for (int i = 0; i < channels; i++) 58 | for (int j = 0; j < channels; j++) 59 | _1x1_weights[i][j] = *(weights++); 60 | _1x1.setWeights (_1x1_weights); 61 | 62 | std::vector _1x1_bias (channels); 63 | for (int i = 0; i < channels; i++) 64 | _1x1_bias[i] = *(weights++); 65 | _1x1.setBias (_1x1_bias.data()); 66 | } 67 | 68 | #if RTNEURAL_USE_EIGEN 69 | void forward (const Eigen::Matrix& ins, 70 | const Eigen::Matrix& condition, 71 | Eigen::Matrix& head_io) 72 | #elif RTNEURAL_USE_XSIMD 73 | void forward (const xsimd::batch (&ins)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)], 74 | const xsimd::batch (&condition)[RTNeural::ceil_div (condition_size, (int) xsimd::batch::size)], 75 | xsimd::batch (&head_io)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)]) 76 | #endif 77 | { 78 | conv.forward (ins); 79 | input_mixin.forward (condition); 80 | 81 | #if RTNEURAL_USE_EIGEN 82 | outs = conv.outs + input_mixin.outs; 83 | #elif RTNEURAL_USE_XSIMD 84 | for (int i = 0; i < std::size (outs); ++i) 85 | outs[i] = conv.outs[i] + input_mixin.outs[i]; 86 | #endif 87 | 88 | activation.forward (outs); 89 | 90 | #if RTNEURAL_USE_EIGEN 91 | head_io.noalias() += activation.outs; 92 | #elif RTNEURAL_USE_XSIMD 93 | for (int i = 0; i < std::size (head_io); ++i) 94 | head_io[i] += activation.outs[i]; 95 | #endif 96 | 97 | _1x1.forward (activation.outs); 98 | 99 | #if RTNEURAL_USE_EIGEN 100 | outs = ins + _1x1.outs; 101 | #elif RTNEURAL_USE_XSIMD 102 | for (int i = 0; i < std::size (outs); ++i) 103 | outs[i] = ins[i] + _1x1.outs[i]; 104 | #endif 105 | } 106 | 107 | #if RTNEURAL_USE_EIGEN 108 | void forward (const Eigen::Matrix* ins, 109 | const Eigen::Matrix* condition, 110 | Eigen::Matrix* head_io, 111 | Eigen::Matrix* layer_outputs, 112 | int N, 113 | Memory_Arena<>& arena) 114 | #elif RTNEURAL_USE_XSIMD 115 | void forward (const xsimd::batch (*ins)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)], 116 | const xsimd::batch (*condition)[RTNeural::ceil_div (condition_size, (int) xsimd::batch::size)], 117 | xsimd::batch (*head_io)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)], 118 | xsimd::batch (*layer_outputs)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)], 119 | int N, 120 | Memory_Arena<>& arena) 121 | #endif 122 | { 123 | const auto _ = arena.create_frame(); 124 | #if RTNEURAL_USE_EIGEN 125 | auto* temp_outs = arena.allocate> (N, RTNEURAL_DEFAULT_ALIGNMENT); 126 | #elif RTNEURAL_USE_XSIMD 127 | auto* temp_outs = arena.allocate[RTNeural::ceil_div (channels, (int) xsimd::batch::size)]> (N, RTNEURAL_DEFAULT_ALIGNMENT); 128 | #endif 129 | 130 | for (int n = 0; n < N; ++n) 131 | { 132 | conv.forward (ins[n]); 133 | #if RTNEURAL_USE_EIGEN 134 | temp_outs[n].noalias() = conv.outs; 135 | #elif RTNEURAL_USE_XSIMD 136 | for (int i = 0; i < std::size (conv.outs); ++i) 137 | temp_outs[n][i] = conv.outs[i]; 138 | #endif 139 | } 140 | 141 | for (int n = 0; n < N; ++n) 142 | { 143 | input_mixin.forward (condition[n]); 144 | #if RTNEURAL_USE_EIGEN 145 | temp_outs[n].noalias() += input_mixin.outs; 146 | #elif RTNEURAL_USE_XSIMD 147 | for (int i = 0; i < std::size (input_mixin.outs); ++i) 148 | temp_outs[n][i] += input_mixin.outs[i]; 149 | #endif 150 | } 151 | 152 | for (int n = 0; n < N; ++n) 153 | { 154 | activation.forward (temp_outs[n]); 155 | #if RTNEURAL_USE_EIGEN 156 | temp_outs[n].noalias() = activation.outs; 157 | head_io[n].noalias() += activation.outs; 158 | #elif RTNEURAL_USE_XSIMD 159 | for (int i = 0; i < std::size (activation.outs); ++i) 160 | temp_outs[n][i] = activation.outs[i]; 161 | for (int i = 0; i < std::size (activation.outs); ++i) 162 | head_io[n][i] += activation.outs[i]; 163 | #endif 164 | } 165 | 166 | for (int n = 0; n < N; ++n) 167 | { 168 | _1x1.forward (temp_outs[n]); 169 | #if RTNEURAL_USE_EIGEN 170 | layer_outputs[n].noalias() = ins[n] + _1x1.outs; 171 | #elif RTNEURAL_USE_XSIMD 172 | for (int i = 0; i < std::size (_1x1.outs); ++i) 173 | layer_outputs[n][i] = ins[n][i] + _1x1.outs[i]; 174 | #endif 175 | } 176 | } 177 | }; 178 | } // namespace wavenet 179 | -------------------------------------------------------------------------------- /deps/RTNeural-NAM/wavenet/wavenet_layer_array.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "wavenet_layer.hpp" 4 | 5 | namespace wavenet 6 | { 7 | template 8 | using Dilations = std::integer_sequence; 9 | 10 | template > 20 | struct Layer_Array 21 | { 22 | template 23 | struct Layers_Helper 24 | { 25 | }; 26 | 27 | template 28 | struct Layers_Helper> 29 | { 30 | using type = std::tuple...>; 31 | }; 32 | 33 | using Layers = typename Layers_Helper::type; 34 | 35 | static constexpr auto n_channels = channels; 36 | 37 | RTNeural::DenseT rechannel; // no bias! 38 | Layers layers; 39 | static constexpr auto num_layers = std::tuple_size_v; 40 | RTNeural::DenseT head_rechannel; 41 | 42 | using Last_Layer_Type = std::remove_reference_t - 1> (layers))>; 43 | decltype (Last_Layer_Type::outs)& layer_outputs { std::get - 1> (layers).outs }; 44 | 45 | #if RTNEURAL_USE_EIGEN 46 | Eigen::Matrix head_outputs {}; 47 | Eigen::Matrix* layer_outputs_arr; 48 | Eigen::Matrix* head_outputs_arr; 49 | #elif RTNEURAL_USE_XSIMD 50 | decltype (RTNeural::DenseT::outs)& head_outputs { head_rechannel.outs }; 51 | using Layer_Out = xsimd::batch[RTNeural::ceil_div (channels, (int) xsimd::batch::size)]; 52 | Layer_Out* layer_outputs_arr; 53 | using Head_Out = xsimd::batch[RTNeural::ceil_div (head_size, (int) xsimd::batch::size)]; 54 | Head_Out* head_outputs_arr; 55 | #endif 56 | 57 | void reset() 58 | { 59 | RTNeural::modelt_detail::forEachInTuple ([] (auto& layer, size_t) 60 | { layer.reset(); }, 61 | layers); 62 | } 63 | 64 | static size_t get_arena_bytes_needed (int N) 65 | { 66 | #if RTNEURAL_USE_EIGEN 67 | return 2 * sizeof (Eigen::Matrix) * N + sizeof (Eigen::Matrix) * N; 68 | #elif RTNEURAL_USE_XSIMD 69 | return 2 * sizeof (Layer_Out) * N + sizeof (Head_Out) * N; 70 | #endif 71 | } 72 | 73 | void load_weights (std::vector::iterator& weights) 74 | { 75 | std::vector> rechannel_weights (channels, std::vector (in_size)); 76 | for (int i = 0; i < channels; i++) 77 | for (int j = 0; j < in_size; j++) 78 | rechannel_weights[i][j] = *(weights++); 79 | rechannel.setWeights (rechannel_weights); 80 | 81 | RTNeural::modelt_detail::forEachInTuple ([&weights] (auto& layer, size_t) 82 | { layer.load_weights (weights); }, 83 | layers); 84 | 85 | std::vector> head_rechannel_weights (head_size, std::vector (channels)); 86 | for (int i = 0; i < head_size; i++) 87 | for (int j = 0; j < channels; j++) 88 | head_rechannel_weights[i][j] = *(weights++); 89 | head_rechannel.setWeights (head_rechannel_weights); 90 | 91 | if constexpr (has_head_bias) 92 | { 93 | std::vector head_rechannel_bias (head_size); 94 | for (int i = 0; i < head_size; i++) 95 | head_rechannel_bias[i] = *(weights++); 96 | head_rechannel.setBias (head_rechannel_bias.data()); 97 | } 98 | } 99 | 100 | #if RTNEURAL_USE_EIGEN 101 | void forward (const Eigen::Matrix& ins, 102 | const Eigen::Matrix& condition, 103 | Eigen::Matrix& head_io) 104 | #elif RTNEURAL_USE_XSIMD 105 | void forward (const xsimd::batch (&ins)[RTNeural::ceil_div (in_size, (int) xsimd::batch::size)], 106 | const xsimd::batch (&condition)[RTNeural::ceil_div (condition_size, (int) xsimd::batch::size)], 107 | xsimd::batch (&head_io)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)]) 108 | #endif 109 | { 110 | rechannel.forward (ins); 111 | 112 | RTNeural::modelt_detail::forEachInTuple ( 113 | [&] (auto& layer, auto index_t) 114 | { 115 | static constexpr size_t index = index_t; 116 | if constexpr (index == 0) 117 | layer.forward (rechannel.outs, condition, head_io); 118 | else 119 | layer.forward (std::get (layers).outs, condition, head_io); 120 | }, 121 | layers); 122 | 123 | head_rechannel.forward (head_io); 124 | #if RTNEURAL_USE_EIGEN 125 | head_outputs = head_rechannel.outs; 126 | #endif 127 | } 128 | 129 | #if RTNEURAL_USE_EIGEN 130 | void forward (const Eigen::Matrix* ins, 131 | const Eigen::Matrix* condition, 132 | Eigen::Matrix* head_io, 133 | int N, 134 | Memory_Arena<>& arena) 135 | #elif RTNEURAL_USE_XSIMD 136 | void forward (const xsimd::batch (*ins)[RTNeural::ceil_div (in_size, (int) xsimd::batch::size)], 137 | const xsimd::batch (*condition)[RTNeural::ceil_div (condition_size, (int) xsimd::batch::size)], 138 | xsimd::batch (*head_io)[RTNeural::ceil_div (channels, (int) xsimd::batch::size)], 139 | int N, 140 | Memory_Arena<>& arena) 141 | #endif 142 | { 143 | #if RTNEURAL_USE_EIGEN 144 | layer_outputs_arr = arena.allocate> (N, RTNEURAL_DEFAULT_ALIGNMENT); 145 | head_outputs_arr = arena.allocate> (N, RTNEURAL_DEFAULT_ALIGNMENT); 146 | #elif RTNEURAL_USE_XSIMD 147 | layer_outputs_arr = arena.allocate (N, RTNEURAL_DEFAULT_ALIGNMENT); 148 | head_outputs_arr = arena.allocate (N, RTNEURAL_DEFAULT_ALIGNMENT); 149 | #endif 150 | 151 | for (int n = 0; n < N; ++n) 152 | { 153 | rechannel.forward (ins[n]); 154 | #if RTNEURAL_USE_EIGEN 155 | layer_outputs_arr[n] = rechannel.outs; 156 | #elif RTNEURAL_USE_XSIMD 157 | std::copy (std::begin (rechannel.outs), std::end (rechannel.outs), std::begin (layer_outputs_arr[n])); 158 | #endif 159 | } 160 | 161 | RTNeural::modelt_detail::forEachInTuple ( 162 | [&] (auto& layer, auto) 163 | { 164 | layer.forward (layer_outputs_arr, condition, head_io, layer_outputs_arr, N, arena); 165 | }, 166 | layers); 167 | 168 | for (int n = 0; n < N; ++n) 169 | { 170 | head_rechannel.forward (head_io[n]); 171 | #if RTNEURAL_USE_EIGEN 172 | head_outputs_arr[n] = head_rechannel.outs; 173 | #elif RTNEURAL_USE_XSIMD 174 | std::copy (std::begin (head_rechannel.outs), std::end (head_rechannel.outs), std::begin (head_outputs_arr[n])); 175 | #endif 176 | } 177 | } 178 | }; 179 | } // namespace wavenet 180 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NeuralAudio 2 | 3 | NeuralAudio is a C++ library designed to make it easy to use neural network machine learning models (ie: guitar amplifier captures/profiles) in real-time audio applications. 4 | 5 | # Supported Models 6 | 7 | NeuralAudio currently supports the following model types: 8 | 9 | - [Neural Amp Modeler](https://github.com/sdatkinson/neural-amp-modeler) (NAM) WaveNet and LSTM models 10 | - [RTNeural](https://github.com/jatinchowdhury18/RTNeural) keras models (LSTM, GRU) 11 | 12 | # Underlying Libraries and Performance 13 | 14 | By default, NeuralAudio uses its own implementation of WaveNet and LSTM network models. This implementation has been designed to produce **exactly** the same output as the [NAM Core library](https://github.com/sdatkinson/NeuralAmpModelerCore), but with increased performance and reduced memory usage. 15 | 16 | For completeness, and to facilitate accuracy and performance benchmarking, it can also load models using the [NAM Core implementation](https://github.com/sdatkinson/NeuralAmpModelerCore) and [RTNeural](https://github.com/jatinchowdhury18/RTNeural). 17 | 18 | The internal NeuralAudio implmentation currently outperforms the other implementations on all tested platforms (Windows x64, Linux x64/Arm64). It also uses significantly less memory than the NAM Core WaveNet implementation (which, for example, uses about 10x as much memory for a "standard" WaveNet model). 19 | 20 | For WaveNet, the internal implmeentation supports optimized static models of the offical NAM network architectures: "Standard", "Lite", "Feather", "Nano". 21 | 22 | For LSTM, the internal implementation supports optimized static models architectures for 1x8, 1x12, 1x16, 1x24, 2x8, 2x12, and 2x16 models. 23 | 24 | All NAM files with WaveNet and LSTM architectures not supported internally will fall back on a less performant dynamic implementation (although still faster than NAM Core). 25 | 26 | All keras models not supported internally will fall back to the RTNeural implmentation. 27 | 28 | # API overview 29 | 30 | To load a model: 31 | ``` 32 | NeuralModel* model = NeuralAudio::NeuralModel::CreateFromFile(""); 33 | ``` 34 | 35 | To process a model: 36 | 37 | ``` 38 | model->Process(pointerToFloatInputData, pointerToFloatOutputData, int numSamples); 39 | ``` 40 | 41 | ## Setting maximum buffer size 42 | 43 | Some models need to allocate memory based on the size of the audio buffers being used. You need to make sure that processing does not exceed the specified maximum buffer size. 44 | 45 | The default maximum size is 128 samples. To change it, do: 46 | 47 | ``` 48 | NeuralAudio::NeuralModel::SetDefaultMaxAudioBufferSize(maxSize); 49 | ``` 50 | 51 | if you want to change the maximum buffer size of an already created model, do: 52 | 53 | ``` 54 | model->SetMaxAudioBufferSize(int maxSize); 55 | ``` 56 | 57 | ***Note: this is not real-time safe, and should not be done on a real-time audio thread.*** 58 | 59 | ## Input/Output calibration 60 | 61 | Use ```model->GetRecommendedInputDBAdjustment()``` and ```model->GetRecommendedOutputDBAdjustment()``` to obtain the ideal input and output volume level adjustments in dB. 62 | 63 | To set a known audio input level (ie: from an audio interface), use ```model->SetAudioInputLevelDBu(float audioDBu)```. This is set at 12DBu by default. 64 | 65 | ## Model load behavior 66 | 67 | By default, models are loaded using the internal NeuralAudio implementation. If you would like to force the use of the NAM Core or RTNeural implementations, you can use: 68 | 69 | ``` 70 | NeuralAudio::NeuralModel::SetWaveNetLoadMode(loadMode) 71 | ``` 72 | 73 | and 74 | 75 | ``` 76 | NeuralAudio::NeuralModel::SetLSTMLoadMode(loadMode) 77 | ``` 78 | 79 | where "loadMode" is one of: 80 | 81 | ``` 82 | NeuralAudio::EModelLoadMode::Internal 83 | NeuralAudio::EModelLoadMode::NAMCore 84 | NeuralAudio::EModelLoadMode::RTNeural 85 | ``` 86 | 87 | You can check which implementation was actually used to load the model with ```model->GetLoadMode()```. 88 | 89 | **NOTE:** Because of compile time and executable size considerations, only the internal and dynamic RTNeural implementations are built by default. If you want to use RTNeural, it is recommended that you add ```-DBUILD_STATIC_RTNEURAL=ON``` to your cmake commandline. This will create static model implmentations for the same sets of WaveNet and LSTM models as the internal implmentation, and results in increased performance. If you want to use NAM Core, add ```DBUILD_NAMCORE=ON``` to your cmake commandline. 90 | 91 | ## Getting the model receptive field size 92 | 93 | WaveNet models have a fixed receptive field size (ie: size of the input that the output depends on). 94 | 95 | To get this value, do: 96 | 97 | ``` 98 | int receptiveFieldSamples = model->GetReceptiveFieldSize(); 99 | ``` 100 | 101 | Note that this can return -1, which means that the receptive field size is unknown, or not fixed (ie: LSTM models technically have an infinite tail because of their internal feedback loop). 102 | 103 | This method is only supported for "internal" models. If you are using NAM Core or RTNeural it will always return -1. 104 | 105 | # Building 106 | 107 | First clone the repository: 108 | ```bash 109 | git clone --recurse-submodules https://github.com/mikeoliphant/NeuralAudio 110 | cd NeuralAudio/build 111 | ``` 112 | 113 | Then compile the plugin using: 114 | 115 | **Linux/MacOS** 116 | ```bash 117 | cmake .. -DCMAKE_BUILD_TYPE="Release" 118 | make -j4 119 | ``` 120 | 121 | **Windows** 122 | ```bash 123 | cmake.exe -G "Visual Studio 17 2022" -A x64 .. 124 | cmake --build . --config=release -j4 125 | ``` 126 | 127 | Note - you'll have to change the Visual Studio version if you are using a different one. 128 | 129 | ## CMake Options 130 | 131 | ```-DBUILD_NAMCORE=ON|OFF```: Support loading models using the NAM Core implemenations. 132 | 133 | ```-DBUILD_STATIC_RTNEURAL=ON|OFF```: Build static RTNeural model architectures (slower compile, larger size - only use if you plan on forcing RTNeural model loading). 134 | 135 | ```-DBUILD_INTERNAL_STATIC_WAVENET=ON|OFF```: Build internal static WaveNet model architectures (faster internal WaveNet, but slower compile, larger size). 136 | 137 | ```-DBUILD_INTERNAL_STATIC_LSTM=ON|OFF```: Build internal static LSTM model architectures (faster internal LSTM, but slower compile, larger size). 138 | 139 | ```-DWAVENET_FRAMES=XXX```: Sample buffer size for the internal WaveNet implementation. Defaults to **64**. If you know you are going to be using a fixed sample buffer smaller or larger than this, use that instead. Note that the model will still be able to process any buffer size - it is just optimized for this size. 140 | 141 | ```-DWAVENET_MATH=XXX``` 142 | ```-DLSTM_MATH=XXX```: Which math approximations (tanh and sigmoid) to use for WaveNet and LSTM models. Options are: 143 | 144 | - ```FastMath``` (the default): Use the same approximations as NAM Core. 145 | - ```EigenMath```: Use Eigen's builtin tanh approximation. Somewhat slower, but more accurate. 146 | - ```StdMath```: Use standard math functions. No approxmation used - much slower. 147 | 148 | ```-DBUILD_UTILS=ON|OFF```: Build performance/accuracy testing tools (located in the "Utils" folder). 149 | 150 | # Software/Hardware Using NeuralAudio 151 | 152 | The following applications and devices are using the NeuralAudio library for model processing: 153 | 154 | - [neural-amp-modeler-lv2](https://github.com/mikeoliphant/neural-amp-modeler-lv2): LV2 plugin for using neural network machine learning amp models. 155 | - [stompbox](https://github.com/mikeoliphant/stompbox): Guitar amplification and effects pedalboard simulation. 156 | - [NeuralRack](https://github.com/brummer10/NeuralRack): Neural Model and Impulse Response File loader for Linux/Windows. 157 | - [Darkglass Anagram](https://www.darkglass.com/creation/anagram): Bass guitar effects unit. 158 | -------------------------------------------------------------------------------- /Utils/ModelTest/ModelTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace NeuralAudio; 6 | 7 | static std::string LoadModes[] = { "Internal", "RTNeural", "NAMCore" }; 8 | 9 | NeuralModel* LoadModel(std::filesystem::path modelPath, EModelLoadMode loadMode) 10 | { 11 | NeuralModel::SetWaveNetLoadMode(loadMode); 12 | NeuralModel::SetLSTMLoadMode(loadMode); 13 | 14 | try 15 | { 16 | auto model = NeuralAudio::NeuralModel::CreateFromFile(modelPath); 17 | 18 | if (model == nullptr) 19 | { 20 | std::cout << "Unable to load model from: " << modelPath << std::endl; 21 | 22 | return nullptr; 23 | } 24 | 25 | if (model->GetLoadMode() != loadMode) 26 | { 27 | delete model; 28 | 29 | return nullptr; 30 | } 31 | 32 | if (model->GetLoadMode() != NeuralAudio::EModelLoadMode::NAMCore) 33 | { 34 | if (!model->IsStatic()) 35 | { 36 | std::cout << "**Warning: " << LoadModes[model->GetLoadMode()] << " model is not using a static architecture" << std::endl; 37 | } 38 | } 39 | 40 | return model; 41 | } 42 | catch (...) 43 | { 44 | std::cout << "Error loading model" << std::endl; 45 | } 46 | 47 | return nullptr; 48 | } 49 | 50 | static std::tuple BenchModel(NeuralModel* model, int blockSize, int numBlocks) 51 | { 52 | std::vector inData; 53 | inData.resize(blockSize); 54 | 55 | std::vector outData; 56 | outData.resize(blockSize); 57 | 58 | auto start = std::chrono::high_resolution_clock::now(); 59 | 60 | double maxBlock = 0; 61 | 62 | for (int block = 0; block < numBlocks; block++) 63 | { 64 | auto blockStart = std::chrono::high_resolution_clock::now(); 65 | 66 | model->Process(inData.data(), outData.data(), blockSize); 67 | 68 | auto blockEnd = std::chrono::high_resolution_clock::now(); 69 | 70 | maxBlock = std::max(maxBlock, std::chrono::duration_cast> (blockEnd - blockStart).count()); 71 | } 72 | 73 | auto end = std::chrono::high_resolution_clock::now(); 74 | 75 | double tot = std::chrono::duration_cast> (end - start).count(); 76 | 77 | return std::tie(tot, maxBlock); 78 | } 79 | 80 | static double ComputeError(NeuralModel* model1, NeuralModel* model2, int blockSize, int numBlocks) 81 | { 82 | std::vector inData; 83 | inData.resize(blockSize); 84 | 85 | std::vector outData; 86 | outData.resize(blockSize); 87 | 88 | std::vector outData2; 89 | outData2.resize(blockSize); 90 | 91 | model1->Prewarm(); 92 | model2->Prewarm(); 93 | 94 | double totErr = 0; 95 | 96 | long pos = 0; 97 | 98 | for (int block = 0; block < numBlocks; block++) 99 | { 100 | for (int i = 0; i < blockSize; i++) 101 | { 102 | inData[i] = (float)sin(pos++ * 0.01); 103 | } 104 | 105 | model1->Process(inData.data(), outData.data(), blockSize); 106 | model2->Process(inData.data(), outData2.data(), blockSize); 107 | 108 | for (int i = 0; i < blockSize; i++) 109 | { 110 | double diff = outData[i] - outData2[i]; 111 | 112 | totErr += (diff * diff); 113 | } 114 | } 115 | 116 | return sqrt(totErr / (double)(blockSize * numBlocks)); 117 | } 118 | 119 | void RunNAMTests(std::filesystem::path modelPath, int blockSize) 120 | { 121 | std::cout << "Model: " << modelPath << std::endl; 122 | std::cout << std::endl; 123 | 124 | int dataSize = 4096 * 64; 125 | 126 | int numBlocks = dataSize / blockSize; 127 | 128 | NeuralModel::SetDefaultMaxAudioBufferSize(blockSize); 129 | 130 | NeuralModel* rtNeuralModel = LoadModel(modelPath, EModelLoadMode::RTNeural); 131 | NeuralModel* namCoreModel = LoadModel(modelPath, EModelLoadMode::NAMCore); 132 | NeuralModel* internalModel = LoadModel(modelPath, EModelLoadMode::Internal); 133 | 134 | double rms; 135 | 136 | if (namCoreModel != nullptr) 137 | { 138 | } 139 | 140 | std::tuple internal; 141 | std::tuple rtNeural; 142 | std::tuple namCore; 143 | 144 | internal = BenchModel(internalModel, blockSize, numBlocks); 145 | 146 | std::cout << "Internal: " << std::get<0>(internal) << " (" << std::get<1>(internal) << ")" << std::endl; 147 | 148 | if (namCoreModel != nullptr) 149 | { 150 | std::cout << std::endl; 151 | 152 | namCore = BenchModel(namCoreModel, blockSize, numBlocks); 153 | 154 | rms = ComputeError(namCoreModel, internalModel, blockSize, numBlocks); 155 | 156 | std::cout << "NAM Core: " << std::get<0>(namCore) << " (" << std::get<1>(namCore) << ")" << std::endl; 157 | std::cout << "NAM vs Internal RMS err: " << rms << std::endl; 158 | std::cout << "Internal is: " << (std::get<0>(namCore) / std::get<0>(internal)) << "x NAM (" << (std::get<1>(namCore) / std::get<1>(internal)) << "x worst case)" << std::endl; 159 | } 160 | 161 | if (rtNeuralModel != nullptr) 162 | { 163 | std::cout << std::endl; 164 | 165 | rtNeural = BenchModel(rtNeuralModel, blockSize, numBlocks); 166 | 167 | std::cout << "RTNeural: " << std::get<0>(rtNeural) << " (" << std::get<1>(rtNeural) << ")" << std::endl; 168 | rms = ComputeError(namCoreModel, rtNeuralModel, blockSize, numBlocks); 169 | std::cout << "NAM vs RTNeural RMS err: " << rms << std::endl; 170 | 171 | if (namCoreModel != nullptr) 172 | { 173 | std::cout << "RTNeural is: " << (std::get<0>(namCore) / std::get<0>(rtNeural)) << "x NAM (" << (std::get<1>(namCore) / std::get<1>(rtNeural)) << "x worst case)" << std::endl; 174 | } 175 | } 176 | 177 | std::cout << std::endl; 178 | } 179 | 180 | void RunKerasTests(std::filesystem::path modelPath, int blockSize) 181 | { 182 | std::cout << "Model: " << modelPath << std::endl; 183 | 184 | int dataSize = 4096 * 64; 185 | 186 | int numBlocks = dataSize / blockSize; 187 | 188 | NeuralAudio::NeuralModel::SetDefaultMaxAudioBufferSize(blockSize); 189 | 190 | auto internalModel = LoadModel(modelPath, EModelLoadMode::Internal); 191 | auto rtNeuralModel = LoadModel(modelPath, EModelLoadMode::RTNeural); 192 | 193 | double rms = ComputeError(rtNeuralModel, internalModel, blockSize, numBlocks); 194 | std::cout << "Internal vs RTNeural RMS err: " << rms << std::endl; 195 | std::cout << std::endl; 196 | 197 | auto internal = BenchModel(internalModel, blockSize, numBlocks); 198 | auto rt = BenchModel(rtNeuralModel, blockSize, numBlocks); 199 | 200 | std::cout << "RTNeural: " << std::get<0>(rt) << " (" << std::get<1>(rt) << ")" << std::endl; 201 | std::cout << "Internal: " << std::get<0>(internal) << " (" << std::get<1>(internal) << ")" << std::endl; 202 | std::cout << "Internal is: " << (std::get<0>(rt) / std::get<0>(internal)) << "x RTNeural" << std::endl; 203 | 204 | std::cout << std::endl; 205 | } 206 | 207 | int RunDefaultTests(int blockSize) 208 | { 209 | std::filesystem::path modelPath = std::filesystem::current_path(); 210 | 211 | while (modelPath.filename() != "Utils") 212 | { 213 | modelPath = modelPath.parent_path(); 214 | 215 | if (modelPath == modelPath.root_path()) 216 | { 217 | std::cout << "Unable to find Models: " << std::filesystem::current_path() << std::endl; 218 | std::cout << "ModelTest must be run from within the Utils subdirectory" << std::endl; 219 | 220 | return -1; 221 | } 222 | } 223 | 224 | modelPath = modelPath / "Models"; 225 | 226 | std::cout << "Loading models from: " << modelPath << std::endl << std::endl; 227 | 228 | std::cout << "WaveNet (Standard) Test" << std::endl; 229 | RunNAMTests(modelPath / "BossWN-standard.nam", blockSize); 230 | 231 | std::cout << std::endl; 232 | 233 | std::cout << "LSTM (1x16) Test" << std::endl; 234 | RunNAMTests(modelPath / "BossLSTM-1x16.nam", blockSize); 235 | 236 | return 0; 237 | } 238 | 239 | int main(int argc, char* argv[]) 240 | { 241 | std::cout << std::endl; 242 | 243 | int blockSize = 64; 244 | 245 | std::filesystem::path modelPath; 246 | 247 | for (int arg = 1; arg < argc; arg++) 248 | { 249 | char* end; 250 | 251 | long val = strtol(argv[arg], &end, 10); 252 | 253 | if (val != 0) 254 | { 255 | blockSize = (int)val; 256 | } 257 | else 258 | { 259 | modelPath.assign(argv[arg]); 260 | } 261 | } 262 | 263 | std::cout << "Block size: " << blockSize << std::endl; 264 | 265 | if (!modelPath.empty()) 266 | { 267 | if (modelPath.extension() == ".nam") 268 | { 269 | RunNAMTests(modelPath, blockSize); 270 | } 271 | else 272 | { 273 | RunKerasTests(modelPath, blockSize); 274 | } 275 | } 276 | else 277 | { 278 | if (RunDefaultTests(blockSize) < 0) 279 | return -1; 280 | } 281 | 282 | return 0; 283 | } 284 | -------------------------------------------------------------------------------- /NeuralAudio/NeuralModel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NeuralModel.h" 3 | #ifdef BUILD_NAMCORE 4 | #include "NAMModel.h" 5 | #endif 6 | #ifdef BUILD_STATIC_RTNEURAL 7 | #include "RTNeuralLoader.h" 8 | #endif 9 | #include "RTNeuralModel.h" 10 | #include "InternalModel.h" 11 | 12 | namespace NeuralAudio 13 | { 14 | static bool modelDefsAreLoaded; 15 | 16 | static std::list internalWavenetModelDefs; 17 | static std::list internalLSTMModelDefs; 18 | 19 | static void EnsureModelDefsAreLoaded() 20 | { 21 | if (!modelDefsAreLoaded) 22 | { 23 | #ifdef BUILD_INTERNAL_STATIC_WAVENET 24 | internalWavenetModelDefs.push_back(new InternalWaveNetDefinitionT<16, 8>); // Standard 25 | internalWavenetModelDefs.push_back(new InternalWaveNetDefinitionT<12, 6>); // Lite 26 | internalWavenetModelDefs.push_back(new InternalWaveNetDefinitionT<8, 4>); // Feather 27 | internalWavenetModelDefs.push_back(new InternalWaveNetDefinitionT<4, 2>); // Nano 28 | #endif 29 | 30 | #ifdef BUILD_INTERNAL_STATIC_LSTM 31 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<1, 8>); 32 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<1, 12>); 33 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<1, 16>); 34 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<1, 24>); 35 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<2, 8>); 36 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<2, 12>); 37 | internalLSTMModelDefs.push_back(new InternalLSTMDefinitionT<2, 16>); 38 | #endif 39 | 40 | #ifdef BUILD_STATIC_RTNEURAL 41 | EnsureRTNeuralModelDefsAreLoaded(); 42 | #endif 43 | 44 | modelDefsAreLoaded = true; 45 | } 46 | } 47 | 48 | static InternalWaveNetDefinitionBase* FindInternalWaveNetDefinition(size_t numChannels, size_t headSize) 49 | { 50 | for (auto const& model : internalWavenetModelDefs) 51 | { 52 | if ((numChannels == model->GetNumChannels()) && (headSize == model->GetHeadSize())) 53 | return model; 54 | } 55 | 56 | return nullptr; 57 | } 58 | 59 | static InternalLSTMDefinitionBase* FindInternalLSTMDefinition(size_t numLayers, size_t hiddenSize) 60 | { 61 | for (auto const& model : internalLSTMModelDefs) 62 | { 63 | if ((numLayers == model->GetNumLayers()) && (hiddenSize == model->GetHiddenSize())) 64 | return model; 65 | } 66 | 67 | return nullptr; 68 | } 69 | 70 | static std::vector stdDilations = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }; 71 | static std::vector liteDilations = { 1, 2, 4, 8, 16, 32, 64 }; 72 | static std::vector liteDilations2 = { 128, 256, 512, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }; 73 | 74 | static bool CheckDilations(const nlohmann::json dilationJson, std::vector& checkDilations) 75 | { 76 | if (dilationJson.size() != checkDilations.size()) 77 | return false; 78 | 79 | for (size_t i = 0; i < dilationJson.size(); i++) 80 | { 81 | if (dilationJson[i] != checkDilations[i]) 82 | return false; 83 | } 84 | 85 | return true; 86 | } 87 | 88 | bool NeuralModel::SupportsWaveNetLoadMode(EModelLoadMode mode) 89 | { 90 | if (mode == EModelLoadMode::NAMCore) 91 | #ifdef BUILD_NAMCORE 92 | return true; 93 | #else 94 | return false; 95 | #endif 96 | 97 | if (mode == EModelLoadMode::RTNeural) 98 | #ifdef BUILD_STATIC_RTNEURAL 99 | return true; 100 | #else 101 | return false; 102 | #endif 103 | 104 | return true; 105 | } 106 | 107 | bool NeuralModel::SupportsLSTMLoadMode(EModelLoadMode mode) 108 | { 109 | if (mode == EModelLoadMode::NAMCore) 110 | #ifdef BUILD_NAMCORE 111 | return true; 112 | #else 113 | return false; 114 | #endif 115 | 116 | return true; 117 | } 118 | 119 | NeuralModel* NeuralModel::CreateFromFile(std::filesystem::path modelPath) 120 | { 121 | if (!std::filesystem::exists(modelPath)) 122 | return nullptr; 123 | 124 | std::ifstream jsonStream(modelPath, std::ifstream::binary); 125 | 126 | return CreateFromStream(jsonStream, modelPath.extension()); 127 | } 128 | 129 | NeuralModel* NeuralModel::CreateFromStream(std::basic_istream& jsonStream, std::filesystem::path extension) 130 | { 131 | EnsureModelDefsAreLoaded(); 132 | 133 | nlohmann::json modelJson; 134 | jsonStream >> modelJson; 135 | 136 | NeuralModel* newModel = nullptr; 137 | 138 | if (extension == ".nam") 139 | { 140 | std::string arch = modelJson.at("architecture"); 141 | 142 | #ifdef BUILD_NAMCORE 143 | if (wavenetLoadMode == EModelLoadMode::NAMCore) 144 | { 145 | NAMModel* model = new NAMModel; 146 | 147 | model->LoadFromJson(modelJson); 148 | 149 | newModel = model; 150 | } 151 | #endif 152 | 153 | if (newModel == nullptr) 154 | { 155 | if (arch == "WaveNet") 156 | { 157 | nlohmann::json config = modelJson.at("config"); 158 | 159 | if (config.at("layers").size() == 2) 160 | { 161 | nlohmann::json firstLayerConfig = config.at("layers").at(0); 162 | nlohmann::json secondLayerConfig = config.at("layers").at(1); 163 | 164 | if (!firstLayerConfig.at("gated") && !secondLayerConfig.at("gated") && !firstLayerConfig.at("head_bias") && secondLayerConfig.at("head_bias")) 165 | { 166 | bool isOfficialArchitecture = false; 167 | 168 | if (firstLayerConfig.at("channels") == 16) 169 | { 170 | if (CheckDilations(firstLayerConfig.at("dilations"), stdDilations) && CheckDilations(secondLayerConfig.at("dilations"), stdDilations)) 171 | { 172 | isOfficialArchitecture = true; 173 | } 174 | } 175 | else 176 | { 177 | if (CheckDilations(firstLayerConfig.at("dilations"), liteDilations) && CheckDilations(secondLayerConfig.at("dilations"), liteDilations2)) 178 | { 179 | isOfficialArchitecture = true; 180 | } 181 | } 182 | 183 | if (isOfficialArchitecture) 184 | { 185 | if (wavenetLoadMode == EModelLoadMode::RTNeural) 186 | { 187 | #ifdef BUILD_STATIC_RTNEURAL 188 | newModel = RTNeuralLoadNAMWaveNet(modelJson); 189 | #endif 190 | } 191 | 192 | if (newModel == nullptr) 193 | { 194 | auto modelDef = FindInternalWaveNetDefinition(firstLayerConfig.at("channels"), firstLayerConfig.at("head_size")); 195 | 196 | if (modelDef != nullptr) 197 | { 198 | auto model = modelDef->CreateModel(); 199 | 200 | model->LoadFromNAMJson(modelJson); 201 | 202 | newModel = model; 203 | } 204 | } 205 | } 206 | } 207 | } 208 | 209 | if (newModel == nullptr) 210 | { 211 | // Use a dynamic model if we had no static definition 212 | InternalWaveNetModelDyn* model = new InternalWaveNetModelDyn; 213 | 214 | if (model->LoadFromNAMJson(modelJson)) 215 | { 216 | newModel = model; 217 | } 218 | } 219 | } 220 | else if (arch == "LSTM") 221 | { 222 | nlohmann::json config = modelJson.at("config"); 223 | 224 | #ifdef BUILD_STATIC_RTNEURAL 225 | if (lstmLoadMode == EModelLoadMode::RTNeural) 226 | { 227 | newModel = RTNeuralLoadNAMLSTM(modelJson); 228 | } 229 | #endif 230 | 231 | if (newModel == nullptr) 232 | { 233 | auto modelDef = FindInternalLSTMDefinition(config.at("num_layers"), config.at("hidden_size")); 234 | 235 | if (modelDef != nullptr) 236 | { 237 | auto model = modelDef->CreateModel(); 238 | model->LoadFromNAMJson(modelJson); 239 | 240 | newModel = model; 241 | } 242 | 243 | // Use a dynamic model if we had no static definition 244 | if (newModel == nullptr) 245 | { 246 | InternalLSTMModelDyn* model = new InternalLSTMModelDyn; 247 | 248 | if (model->LoadFromNAMJson(modelJson)) 249 | { 250 | newModel = model; 251 | } 252 | } 253 | } 254 | } 255 | } 256 | } 257 | else if ((extension == ".json") || (extension == ".aidax")) 258 | { 259 | const auto layers = modelJson.at("layers"); 260 | const size_t numLayers = layers.size() - 1; 261 | const std::string modelType = layers.at(0).at("type"); 262 | const int hiddenSize = layers.at(0).at("shape").back(); 263 | 264 | if (modelType == "lstm") 265 | { 266 | #ifdef BUILD_STATIC_RTNEURAL 267 | if (lstmLoadMode == EModelLoadMode::RTNeural) 268 | { 269 | newModel = RTNeuralLoadKeras(modelJson); 270 | } 271 | #endif 272 | 273 | if (newModel == nullptr && lstmLoadMode == EModelLoadMode::Internal) 274 | { 275 | if (numLayers == 1) 276 | { 277 | auto modelDef = FindInternalLSTMDefinition(numLayers, hiddenSize); 278 | 279 | if (modelDef != nullptr) 280 | { 281 | auto model = modelDef->CreateModel(); 282 | 283 | if (model->LoadFromKerasJson(modelJson)) 284 | { 285 | newModel = model; 286 | } 287 | } 288 | } 289 | 290 | if (newModel == nullptr) 291 | { 292 | // Use a dynamic model if we had no static definition 293 | InternalLSTMModelDyn* model = new InternalLSTMModelDyn; 294 | 295 | if (model->LoadFromKerasJson(modelJson)) 296 | { 297 | newModel = model; 298 | } 299 | } 300 | } 301 | } 302 | 303 | if (newModel == nullptr) 304 | { 305 | // Use a dynamic model for other model types 306 | RTNeuralModelDyn* model = new RTNeuralModelDyn; 307 | model->LoadFromKerasJson(modelJson); 308 | 309 | newModel = model; 310 | } 311 | } 312 | 313 | if (newModel != nullptr) 314 | { 315 | newModel->Prewarm(); 316 | } 317 | 318 | return newModel; 319 | } 320 | 321 | void NeuralModel::ReadNAMConfig(const nlohmann::json& modelJson) 322 | { 323 | if (modelJson.contains("sample_rate") && modelJson.at("sample_rate").is_number()) 324 | { 325 | sampleRate = modelJson.at("sample_rate"); 326 | } 327 | 328 | if (modelJson.contains("metadata")) 329 | { 330 | nlohmann::json metaData = modelJson.at("metadata"); 331 | 332 | if (metaData.contains("loudness") && metaData.at("loudness").is_number_float()) 333 | { 334 | modelLoudnessDB = (float)metaData.at("loudness"); 335 | } 336 | 337 | if (metaData.contains("input_level_dbu") && metaData.at("input_level_dbu").is_number_float()) 338 | { 339 | modelInputLevelDBu = metaData.at("input_level_dbu"); 340 | } 341 | 342 | if (metaData.contains("output_level_dbu") && metaData.at("output_level_dbu").is_number_float()) 343 | { 344 | modelOutputLevelDBu = metaData.at("output_level_dbu"); 345 | } 346 | } 347 | } 348 | 349 | void NeuralModel::ReadKerasConfig(const nlohmann::json& modelJson) 350 | { 351 | if (modelJson.contains("samplerate") && modelJson.at("samplerate").is_number()) 352 | { 353 | sampleRate = modelJson.at("samplerate"); 354 | } 355 | 356 | if (modelJson.contains("in_gain") && modelJson.at("in_gain").is_number_float()) 357 | { 358 | modelInputLevelDBu = modelJson.at("in_gain"); 359 | } 360 | 361 | if (modelJson.contains("out_gain") && modelJson.at("out_gain").is_number_float()) 362 | { 363 | modelLoudnessDB = -18 - (float)modelJson.at("out_gain"); 364 | } 365 | } 366 | } -------------------------------------------------------------------------------- /NeuralAudio/InternalModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NeuralModel.h" 4 | #include "WaveNet.h" 5 | #include "WaveNetDynamic.h" 6 | #include "LSTM.h" 7 | #include "LSTMDynamic.h" 8 | 9 | namespace NeuralAudio 10 | { 11 | using IStdDilations = NeuralAudio::Dilations<1, 2, 4, 8, 16, 32, 64, 128, 256, 512>; 12 | using ILiteDilations1 = NeuralAudio::Dilations<1, 2, 4, 8, 16, 32, 64>; 13 | using ILiteDilations2 = NeuralAudio::Dilations<128, 256, 512, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512>; 14 | 15 | class InternalModel : public NeuralModel 16 | { 17 | public: 18 | bool LoadFromKerasJson(const nlohmann::json& modelJson) 19 | { 20 | ReadKerasConfig(modelJson); 21 | 22 | return CreateModelFromKerasJson(modelJson); 23 | 24 | return true; 25 | } 26 | 27 | virtual bool CreateModelFromKerasJson(const nlohmann::json& modelJson) 28 | { 29 | (void)modelJson; 30 | 31 | return false; 32 | } 33 | 34 | virtual bool LoadFromNAMJson(const nlohmann::json& modelJson) 35 | { 36 | ReadNAMConfig(modelJson); 37 | 38 | return CreateModelFromNAMJson(modelJson); 39 | } 40 | 41 | virtual bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 42 | { 43 | (void)modelJson; 44 | 45 | return false; 46 | } 47 | }; 48 | 49 | 50 | template 51 | class InternalWaveNetModelT : public InternalModel 52 | { 53 | using ModelType = typename std::conditional, 56 | NeuralAudio::WaveNetLayerArrayT>, 57 | NeuralAudio::WaveNetModelT< 58 | NeuralAudio::WaveNetLayerArrayT<1, 1, headSize, numChannels, 3, ILiteDilations1, false>, 59 | NeuralAudio::WaveNetLayerArrayT> 60 | >::type; 61 | 62 | public: 63 | InternalWaveNetModelT() 64 | : model(nullptr) 65 | { 66 | } 67 | 68 | ~InternalWaveNetModelT() 69 | { 70 | if (model != nullptr) 71 | { 72 | delete model; 73 | model = nullptr; 74 | } 75 | } 76 | 77 | bool IsStatic() 78 | { 79 | return true; 80 | } 81 | 82 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 83 | { 84 | if (model != nullptr) 85 | { 86 | delete model; 87 | model = nullptr; 88 | } 89 | 90 | model = new ModelType; 91 | 92 | nlohmann::json config = modelJson.at("config"); 93 | 94 | model->SetWeights(modelJson.at("weights")); 95 | 96 | SetMaxAudioBufferSize(defaultMaxAudioBufferSize); 97 | 98 | return true; 99 | } 100 | 101 | void SetMaxAudioBufferSize(int maxSize) 102 | { 103 | (void)maxSize; 104 | } 105 | 106 | int GetReceptiveFieldSize() 107 | { 108 | return model->ReceptiveFieldSize; 109 | } 110 | 111 | void Process(float* input, float* output, size_t numSamples) 112 | { 113 | size_t offset = 0; 114 | 115 | while (numSamples > 0) 116 | { 117 | size_t toProcess = std::min(numSamples, model->GetMaxFrames()); 118 | 119 | model->Process(input + offset, output + offset, toProcess); 120 | 121 | offset += toProcess; 122 | numSamples -= toProcess; 123 | } 124 | } 125 | 126 | void Prewarm() 127 | { 128 | model->Prewarm(); 129 | } 130 | 131 | private: 132 | ModelType* model = nullptr; 133 | }; 134 | 135 | 136 | class InternalWaveNetDefinitionBase 137 | { 138 | public: 139 | virtual InternalModel* CreateModel() 140 | { 141 | return nullptr; 142 | } 143 | 144 | virtual size_t GetNumChannels() 145 | { 146 | return 0; 147 | } 148 | 149 | virtual size_t GetHeadSize() 150 | { 151 | return 0; 152 | } 153 | }; 154 | 155 | template 156 | class InternalWaveNetDefinitionT : public InternalWaveNetDefinitionBase 157 | { 158 | public: 159 | InternalModel* CreateModel() 160 | { 161 | return new InternalWaveNetModelT; 162 | } 163 | 164 | virtual size_t GetNumChannels() 165 | { 166 | return numChannels; 167 | } 168 | 169 | virtual size_t GetHeadSize() 170 | { 171 | return headSize; 172 | } 173 | }; 174 | 175 | class InternalWaveNetModelDyn : public InternalModel 176 | { 177 | public: 178 | InternalWaveNetModelDyn() 179 | { 180 | } 181 | 182 | ~InternalWaveNetModelDyn() 183 | { 184 | if (model != nullptr) 185 | { 186 | delete model; 187 | model = nullptr; 188 | } 189 | } 190 | 191 | EModelLoadMode GetLoadMode() 192 | { 193 | return EModelLoadMode::Internal; 194 | } 195 | 196 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 197 | { 198 | nlohmann::json config = modelJson.at("config"); 199 | 200 | std::vector layerArrays; 201 | 202 | for (size_t i = 0; i < config.at("layers").size(); i++) 203 | { 204 | nlohmann::json layerConfig = config.at("layers").at(i); 205 | 206 | layerArrays.push_back(WaveNetLayerArray(layerConfig.at("input_size"), layerConfig.at("condition_size"), layerConfig.at("head_size"), 207 | layerConfig.at("channels"), layerConfig.at("kernel_size"), layerConfig.at("head_bias"), layerConfig.at("dilations"))); 208 | } 209 | 210 | model = new WaveNetModel(layerArrays); 211 | 212 | model->SetWeights(modelJson.at("weights")); 213 | 214 | SetMaxAudioBufferSize(defaultMaxAudioBufferSize); 215 | 216 | return true; 217 | } 218 | 219 | void SetMaxAudioBufferSize(int maxSize) 220 | { 221 | model->SetMaxFrames(maxSize); 222 | } 223 | 224 | void Process(float* input, float* output, size_t numSamples) 225 | { 226 | size_t offset = 0; 227 | 228 | while (numSamples > 0) 229 | { 230 | size_t toProcess = std::min(numSamples, model->GetMaxFrames()); 231 | 232 | model->Process(input + offset, output + offset, toProcess); 233 | 234 | offset += toProcess; 235 | numSamples -= toProcess; 236 | } 237 | } 238 | 239 | void Prewarm() 240 | { 241 | model->Prewarm(); 242 | } 243 | 244 | private: 245 | WaveNetModel* model = nullptr; 246 | }; 247 | 248 | 249 | template 250 | class InternalLSTMModelT : public InternalModel 251 | { 252 | public: 253 | InternalLSTMModelT() 254 | : model(nullptr) 255 | { 256 | } 257 | 258 | ~InternalLSTMModelT() 259 | { 260 | if (model != nullptr) 261 | { 262 | delete model; 263 | model = nullptr; 264 | } 265 | } 266 | 267 | bool IsStatic() 268 | { 269 | return true; 270 | } 271 | 272 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 273 | { 274 | if (model != nullptr) 275 | { 276 | delete model; 277 | model = nullptr; 278 | } 279 | 280 | model = new LSTMModelT; 281 | 282 | nlohmann::json config = modelJson.at("config"); 283 | 284 | model->SetNAMWeights(modelJson.at("weights")); 285 | 286 | SetMaxAudioBufferSize(defaultMaxAudioBufferSize); 287 | 288 | return true; 289 | } 290 | 291 | std::vector FlattenWeights(const nlohmann::json& weights) 292 | { 293 | std::vector vec; 294 | 295 | for (size_t i = 0; i < weights.size(); i++) 296 | { 297 | if (weights[i].is_array()) 298 | { 299 | auto subVec = FlattenWeights(weights[i]); 300 | vec.insert(vec.end(), subVec.begin(), subVec.end()); 301 | } 302 | else 303 | { 304 | vec.push_back(weights[i]); 305 | } 306 | } 307 | 308 | return vec; 309 | } 310 | 311 | bool CreateModelFromKerasJson(const nlohmann::json& modelJson) 312 | { 313 | if (model != nullptr) 314 | { 315 | delete model; 316 | model = nullptr; 317 | } 318 | 319 | model = new LSTMModelT; 320 | 321 | const auto layers = modelJson.at("layers"); 322 | const size_t numLayers = layers.size(); 323 | 324 | if (numLayers < 2) 325 | return false; 326 | 327 | auto lastLayer = layers[numLayers - 1]; 328 | 329 | if (lastLayer.at("type") != "dense") 330 | return false; 331 | 332 | LSTMDef lstmDef; 333 | 334 | lstmDef.HeadWeights = FlattenWeights(lastLayer.at("weights").at(0)); 335 | lstmDef.HeadBias = lastLayer.at("weights").at(1).at(0); 336 | 337 | for (size_t i = 0; i < (numLayers - 1); i++) 338 | { 339 | auto layer = layers[i]; 340 | 341 | if (layer.at("type") != "lstm") 342 | return false; 343 | 344 | LSTMLayerDef layerDef; 345 | 346 | layerDef.InputWeights = FlattenWeights(layer.at("weights").at(0)); 347 | layerDef.HiddenWeights = FlattenWeights(layer.at("weights").at(1)); 348 | layerDef.BiasWeights = FlattenWeights(layer.at("weights").at(2)); 349 | 350 | lstmDef.Layers.push_back(layerDef); 351 | } 352 | 353 | model->SetWeights(lstmDef); 354 | 355 | return true; 356 | } 357 | 358 | void SetMaxAudioBufferSize(int maxSize) 359 | { 360 | (void)maxSize; 361 | } 362 | 363 | void Process(float* input, float* output, size_t numSamples) 364 | { 365 | model->Process(input, output, numSamples); 366 | } 367 | 368 | void Prewarm() 369 | { 370 | NeuralModel::Prewarm(2048, 64); 371 | } 372 | 373 | private: 374 | LSTMModelT* model = nullptr; 375 | }; 376 | 377 | 378 | class InternalLSTMDefinitionBase 379 | { 380 | public: 381 | virtual InternalModel* CreateModel() 382 | { 383 | return nullptr; 384 | } 385 | 386 | virtual size_t GetNumLayers() 387 | { 388 | return 0; 389 | } 390 | 391 | virtual size_t GetHiddenSize() 392 | { 393 | return 0; 394 | } 395 | }; 396 | 397 | template 398 | class InternalLSTMDefinitionT : public InternalLSTMDefinitionBase 399 | { 400 | public: 401 | InternalModel* CreateModel() 402 | { 403 | return new InternalLSTMModelT; 404 | } 405 | 406 | virtual size_t GetNumLayers() 407 | { 408 | return NumLayers; 409 | } 410 | 411 | virtual size_t GetHiddenSize() 412 | { 413 | return HiddenSize; 414 | } 415 | }; 416 | 417 | class InternalLSTMModelDyn : public InternalModel 418 | { 419 | public: 420 | InternalLSTMModelDyn() 421 | : model(nullptr) 422 | { 423 | } 424 | 425 | ~InternalLSTMModelDyn() 426 | { 427 | if (model != nullptr) 428 | { 429 | delete model; 430 | model = nullptr; 431 | } 432 | } 433 | 434 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 435 | { 436 | if (model != nullptr) 437 | { 438 | delete model; 439 | model = nullptr; 440 | } 441 | 442 | nlohmann::json config = modelJson.at("config"); 443 | 444 | model = new LSTMModel(config.at("num_layers"), config.at("hidden_size")); 445 | 446 | model->SetNAMWeights(modelJson.at("weights")); 447 | 448 | SetMaxAudioBufferSize(defaultMaxAudioBufferSize); 449 | 450 | return true; 451 | } 452 | 453 | std::vector FlattenWeights(const nlohmann::json& weights) 454 | { 455 | std::vector vec; 456 | 457 | for (size_t i = 0; i < weights.size(); i++) 458 | { 459 | if (weights[i].is_array()) 460 | { 461 | auto subVec = FlattenWeights(weights[i]); 462 | vec.insert(vec.end(), subVec.begin(), subVec.end()); 463 | } 464 | else 465 | { 466 | vec.push_back(weights[i]); 467 | } 468 | } 469 | 470 | return vec; 471 | } 472 | 473 | bool CreateModelFromKerasJson(const nlohmann::json& modelJson) 474 | { 475 | if (model != nullptr) 476 | { 477 | delete model; 478 | model = nullptr; 479 | } 480 | 481 | const auto layers = modelJson.at("layers"); 482 | const size_t numLayers = layers.size(); 483 | const size_t hiddenSize = layers.at(0).at("shape").back(); 484 | 485 | if (numLayers < 2) 486 | return false; 487 | 488 | auto lastLayer = layers[numLayers - 1]; 489 | 490 | if (lastLayer.at("type") != "dense") 491 | return false; 492 | 493 | model = new LSTMModel(numLayers - 1, hiddenSize); 494 | 495 | LSTMDef lstmDef; 496 | 497 | lstmDef.HeadWeights = FlattenWeights(lastLayer.at("weights").at(0)); 498 | lstmDef.HeadBias = lastLayer.at("weights").at(1).at(0); 499 | 500 | for (size_t i = 0; i < (numLayers - 1); i++) 501 | { 502 | auto layer = layers[i]; 503 | 504 | if (layer.at("type") != "lstm") 505 | return false; 506 | 507 | LSTMLayerDef layerDef; 508 | 509 | layerDef.InputWeights = FlattenWeights(layer.at("weights").at(0)); 510 | layerDef.HiddenWeights = FlattenWeights(layer.at("weights").at(1)); 511 | layerDef.BiasWeights = FlattenWeights(layer.at("weights").at(2)); 512 | 513 | lstmDef.Layers.push_back(layerDef); 514 | } 515 | 516 | model->SetWeights(lstmDef); 517 | 518 | return true; 519 | } 520 | 521 | void SetMaxAudioBufferSize(int maxSize) 522 | { 523 | (void)maxSize; 524 | } 525 | 526 | void Process(float* input, float* output, size_t numSamples) 527 | { 528 | model->Process(input, output, numSamples); 529 | } 530 | 531 | void Prewarm() 532 | { 533 | NeuralModel::Prewarm(2048, 64); 534 | } 535 | 536 | private: 537 | LSTMModel* model = nullptr; 538 | }; 539 | } 540 | 541 | 542 | -------------------------------------------------------------------------------- /NeuralAudio/WaveNetDynamic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Based on WaveNet model structure from https://github.com/sdatkinson/NeuralAmpModelerCore 4 | // with some template ideas from https://github.com/jatinchowdhury18/RTNeural-NAM 5 | 6 | #include 7 | #include 8 | #include "NeuralModel.h" 9 | #include "Activation.h" 10 | 11 | #ifndef WAVENET_MAX_NUM_FRAMES 12 | #define WAVENET_MAX_NUM_FRAMES 64 13 | #endif 14 | 15 | namespace NeuralAudio 16 | { 17 | class Conv1D 18 | { 19 | private: 20 | size_t inChannels; 21 | size_t outChannels; 22 | size_t kernelSize; 23 | bool doBias; 24 | size_t dilation; 25 | std::vector weights; 26 | Eigen::VectorXf bias; 27 | 28 | public: 29 | Conv1D(size_t inChannels, size_t outChannels, size_t kernelSize, bool doBias, size_t dilation) : 30 | inChannels(inChannels), 31 | outChannels(outChannels), 32 | kernelSize(kernelSize), 33 | doBias(doBias), 34 | dilation(dilation) 35 | { 36 | for (size_t k = 0; k < kernelSize; k++) 37 | { 38 | auto kernelWeights = Eigen::MatrixXf(outChannels, inChannels); 39 | weights.push_back(kernelWeights); 40 | } 41 | 42 | if (doBias) 43 | { 44 | bias.resize(outChannels); 45 | } 46 | } 47 | 48 | void SetWeights(std::vector::iterator& inWeights) 49 | { 50 | weights.resize(kernelSize); 51 | 52 | for (size_t i = 0; i < outChannels; i++) 53 | for (size_t j = 0; j < inChannels; j++) 54 | for (size_t k = 0; k < kernelSize; k++) 55 | weights[k](i, j) = *(inWeights++); 56 | 57 | if (doBias) 58 | { 59 | for (size_t i = 0; i < outChannels; i++) 60 | bias(i) = *(inWeights++); 61 | } 62 | } 63 | 64 | inline void Process(const Eigen::Ref& input, Eigen::Ref output, const size_t iStart, const size_t nCols) const 65 | { 66 | for (size_t k = 0; k < kernelSize; k++) 67 | { 68 | size_t offset = dilation * (k + 1 - kernelSize); 69 | 70 | auto& inBlock = input.middleCols(iStart + offset, nCols); 71 | 72 | if (k == 0) 73 | output.noalias() = weights[k] * inBlock; 74 | else 75 | output.noalias() += weights[k] * inBlock; 76 | } 77 | 78 | if (doBias) 79 | output.colwise() += bias; 80 | } 81 | }; 82 | 83 | class DenseLayer 84 | { 85 | private: 86 | size_t inSize; 87 | size_t outSize; 88 | bool doBias; 89 | Eigen::MatrixXf weights; 90 | Eigen::VectorXf bias; 91 | 92 | public: 93 | DenseLayer(size_t inSize, size_t outSize, bool doBias) : 94 | inSize(inSize), 95 | outSize(outSize), 96 | doBias(doBias), 97 | weights(outSize, inSize) 98 | { 99 | if (doBias) 100 | { 101 | bias.resize(outSize); 102 | } 103 | } 104 | 105 | void SetWeights(std::vector::iterator& inWeights) 106 | { 107 | for (auto i = 0; i < outSize; i++) 108 | for (auto j = 0; j < inSize; j++) 109 | weights(i, j) = *(inWeights++); 110 | 111 | if (doBias) 112 | { 113 | for (auto i = 0; i < outSize; i++) 114 | bias(i) = *(inWeights++); 115 | } 116 | } 117 | 118 | void Process(const Eigen::Ref& input, Eigen::Ref output) const 119 | { 120 | if (doBias) 121 | { 122 | output.noalias() = (weights * input).colwise() + bias; 123 | } 124 | else 125 | { 126 | output.noalias() = weights * input; 127 | } 128 | } 129 | 130 | void ProcessAcc(const Eigen::Ref& input, Eigen::Ref output) const 131 | { 132 | if (doBias) 133 | { 134 | output.noalias() += (weights * input).colwise() + bias; 135 | } 136 | else 137 | { 138 | output.noalias() += weights * input; 139 | } 140 | } 141 | }; 142 | 143 | class WaveNetLayer 144 | { 145 | private: 146 | size_t conditionSize; 147 | size_t channels; 148 | size_t kernelSize; 149 | size_t dilation; 150 | Conv1D conv1D; 151 | DenseLayer inputMixin; 152 | DenseLayer oneByOne; 153 | Eigen::MatrixXf state; 154 | Eigen::MatrixXf layerBuffer; 155 | 156 | public: 157 | size_t ReceptiveFieldSize; 158 | size_t BufferSize; 159 | size_t bufferStart; 160 | 161 | WaveNetLayer(size_t conditionSize, size_t channels, size_t kernelSize, size_t dilation) : 162 | conditionSize(conditionSize), 163 | channels(channels), 164 | kernelSize(kernelSize), 165 | dilation(dilation), 166 | conv1D(channels, channels, kernelSize, true, dilation), 167 | inputMixin(conditionSize, channels, false), 168 | oneByOne(channels, channels, true), 169 | state(channels, WAVENET_MAX_NUM_FRAMES), 170 | ReceptiveFieldSize((kernelSize - 1) * dilation), 171 | BufferSize((ReceptiveFieldSize * 2) + WAVENET_MAX_NUM_FRAMES) 172 | { 173 | state.setZero(); 174 | } 175 | 176 | Eigen::MatrixXf& GetLayerBuffer() 177 | { 178 | return layerBuffer; 179 | } 180 | 181 | void AllocBuffer(size_t allocNum) 182 | { 183 | size_t size = BufferSize; 184 | 185 | layerBuffer.resize(channels, size); 186 | layerBuffer.setZero(); 187 | 188 | bufferStart = ReceptiveFieldSize; 189 | } 190 | 191 | void SetWeights(std::vector::iterator& weights) 192 | { 193 | conv1D.SetWeights(weights); 194 | inputMixin.SetWeights(weights); 195 | oneByOne.SetWeights(weights); 196 | } 197 | 198 | void SetMaxFrames(const size_t maxFrames) 199 | { 200 | (void)maxFrames; 201 | } 202 | 203 | void AdvanceFrames(const size_t numFrames) 204 | { 205 | if (ReceptiveFieldSize <= WAVENET_MAX_NUM_FRAMES) 206 | { 207 | layerBuffer.middleCols(0, ReceptiveFieldSize).noalias() = layerBuffer.middleCols(numFrames, ReceptiveFieldSize); 208 | } 209 | else 210 | { 211 | layerBuffer.middleCols(bufferStart - ReceptiveFieldSize, numFrames).noalias() = layerBuffer.middleCols(bufferStart, numFrames); 212 | 213 | bufferStart += numFrames; 214 | 215 | if (bufferStart > (BufferSize - WAVENET_MAX_NUM_FRAMES)) 216 | bufferStart -= ReceptiveFieldSize; 217 | } 218 | } 219 | 220 | void CopyBuffer() 221 | { 222 | for (size_t offset = 1; offset < ReceptiveFieldSize + 1; offset++) 223 | { 224 | layerBuffer.col(bufferStart - offset).noalias() = layerBuffer.col(bufferStart); 225 | } 226 | } 227 | 228 | void Process(const Eigen::Ref& condition, Eigen::Ref headInput, Eigen::Ref output, const size_t outputStart, const size_t numFrames) 229 | { 230 | auto block = state.leftCols(numFrames); 231 | 232 | conv1D.Process(layerBuffer, block, bufferStart, numFrames); 233 | 234 | inputMixin.ProcessAcc(condition, block); 235 | 236 | //block = block.array().tanh(); 237 | 238 | float* data = block.data(); 239 | auto size = block.rows() * block.cols(); 240 | 241 | for (auto pos = 0; pos < size; pos++) 242 | { 243 | data[pos] = WAVENET_MATH::Tanh(data[pos]); 244 | } 245 | 246 | headInput.noalias() += block.topRows(channels); 247 | 248 | oneByOne.Process(block.topRows(channels), output.middleCols(outputStart, numFrames)); 249 | 250 | output.middleCols(outputStart, numFrames).noalias() += layerBuffer.middleCols(bufferStart, numFrames); 251 | } 252 | }; 253 | 254 | class WaveNetLayerArray 255 | { 256 | private: 257 | size_t inputSize; 258 | size_t conditionSize; 259 | size_t headSize; 260 | size_t channels; 261 | size_t kernelSize; 262 | std::vector layers; 263 | DenseLayer rechannel; 264 | DenseLayer headRechannel; 265 | size_t lastLayer; 266 | Eigen::MatrixXf arrayOutputs; 267 | Eigen::MatrixXf headOutputs; 268 | 269 | 270 | public: 271 | WaveNetLayerArray(size_t inputSize, size_t conditionSize, size_t headSize, size_t channels, size_t kernelSize, bool hasHeadBias, std::vector dilations) : 272 | inputSize(inputSize), 273 | conditionSize(conditionSize), 274 | headSize(headSize), 275 | channels(channels), 276 | kernelSize(kernelSize), 277 | rechannel(inputSize, channels, false), 278 | headRechannel(channels, headSize, hasHeadBias), 279 | arrayOutputs(channels, WAVENET_MAX_NUM_FRAMES), 280 | headOutputs(headSize, WAVENET_MAX_NUM_FRAMES) 281 | { 282 | for (auto dilation : dilations) 283 | { 284 | layers.push_back(WaveNetLayer(conditionSize, channels, kernelSize, dilation)); 285 | } 286 | 287 | lastLayer = layers.size() - 1; 288 | } 289 | 290 | Eigen::MatrixXf& GetArrayOutputs() 291 | { 292 | return arrayOutputs; 293 | } 294 | 295 | Eigen::MatrixXf& GetHeadOutputs() 296 | { 297 | return headOutputs; 298 | } 299 | 300 | size_t GetNumChannels() 301 | { 302 | return channels; 303 | } 304 | 305 | size_t AllocBuffers(size_t allocNum) 306 | { 307 | for (auto& layer : layers) 308 | { 309 | layer.AllocBuffer(allocNum++); 310 | } 311 | 312 | return allocNum; 313 | } 314 | 315 | void SetMaxFrames(const size_t maxFrames) 316 | { 317 | for (auto& layer : layers) 318 | { 319 | layer.SetMaxFrames(maxFrames); 320 | } 321 | } 322 | 323 | void SetWeights(std::vector::iterator& weights) 324 | { 325 | rechannel.SetWeights(weights); 326 | 327 | for (auto& layer : layers) 328 | { 329 | layer.SetWeights(weights); 330 | } 331 | 332 | headRechannel.SetWeights(weights); 333 | } 334 | 335 | void Prewarm(const Eigen::MatrixXf& layerInputs, const Eigen::MatrixXf& condition, Eigen::Ref const& headInputs) 336 | { 337 | rechannel.Process(layerInputs, layers[0].GetLayerBuffer().middleCols(layers[0].bufferStart, 1)); 338 | 339 | for (size_t layerIndex = 0; layerIndex < layers.size(); layerIndex++) 340 | { 341 | layers[layerIndex].CopyBuffer(); 342 | 343 | if (layerIndex == lastLayer) 344 | { 345 | layers[layerIndex].Process(condition, headInputs, arrayOutputs, 0, 1); 346 | } 347 | else 348 | { 349 | layers[layerIndex].Process(condition, headInputs, layers[layerIndex + 1].GetLayerBuffer(), layers[layerIndex + 1].bufferStart, 1); 350 | } 351 | } 352 | 353 | headRechannel.Process(headInputs, headOutputs.leftCols(1)); 354 | } 355 | 356 | void Process(const Eigen::MatrixXf& layerInputs, const Eigen::MatrixXf& condition, Eigen::Ref headInputs, const size_t numFrames) 357 | { 358 | rechannel.Process(layerInputs,layers[0].GetLayerBuffer().middleCols(layers[0].bufferStart, numFrames)); 359 | 360 | for (size_t layerIndex = 0; layerIndex < layers.size(); layerIndex++) 361 | { 362 | if (layerIndex == lastLayer) 363 | { 364 | layers[layerIndex].Process(condition, headInputs, arrayOutputs, 0, numFrames); 365 | } 366 | else 367 | { 368 | layers[layerIndex].Process(condition, headInputs, layers[layerIndex + 1].GetLayerBuffer(), layers[layerIndex + 1].bufferStart, numFrames); 369 | } 370 | 371 | layers[layerIndex].AdvanceFrames(numFrames); 372 | } 373 | 374 | headRechannel.Process(headInputs, headOutputs.leftCols(numFrames)); 375 | } 376 | }; 377 | 378 | class WaveNetModel 379 | { 380 | private: 381 | std::vector layerArrays; 382 | size_t lastLayerArray; 383 | Eigen::MatrixXf headArray; 384 | float headScale; 385 | size_t maxFrames; 386 | 387 | public: 388 | WaveNetModel(std::vector& layerArrays) : 389 | layerArrays(layerArrays), // ****** this is making a copy, which is gross 390 | lastLayerArray(layerArrays.size() - 1), 391 | headArray(layerArrays[0].GetNumChannels(), WAVENET_MAX_NUM_FRAMES) 392 | { 393 | size_t allocNum = 0; 394 | 395 | for (auto& layerArray : this->layerArrays) 396 | { 397 | allocNum = layerArray.AllocBuffers(allocNum); 398 | } 399 | } 400 | 401 | void SetWeights(std::vector weights) 402 | { 403 | std::vector::iterator it = weights.begin(); 404 | 405 | for (auto& layerArray : layerArrays) 406 | { 407 | layerArray.SetWeights(it); 408 | } 409 | 410 | headScale = *(it++); 411 | 412 | assert(std::distance(weights.begin(), it) == (long)weights.size()); 413 | } 414 | 415 | size_t GetMaxFrames() 416 | { 417 | return maxFrames; 418 | } 419 | 420 | void SetMaxFrames(const size_t frames) 421 | { 422 | this->maxFrames = frames; 423 | 424 | if (this->maxFrames > WAVENET_MAX_NUM_FRAMES) 425 | this->maxFrames = WAVENET_MAX_NUM_FRAMES; 426 | 427 | for (auto& layerArray : layerArrays) 428 | { 429 | layerArray.SetMaxFrames(this->maxFrames); 430 | } 431 | } 432 | 433 | void Prewarm() 434 | { 435 | float input = 0; 436 | 437 | auto condition = Eigen::Map>(&input, 1, 1); 438 | 439 | for (size_t layerArrayIndex = 0; layerArrayIndex < layerArrays.size(); layerArrayIndex++) 440 | { 441 | if (layerArrayIndex == 0) 442 | { 443 | layerArrays[layerArrayIndex].Prewarm(condition, condition, headArray.leftCols(1)); 444 | } 445 | else 446 | { 447 | layerArrays[layerArrayIndex].Prewarm(layerArrays[layerArrayIndex - 1].GetArrayOutputs().leftCols(1), condition, layerArrays[layerArrayIndex - 1].GetHeadOutputs().leftCols(1)); 448 | } 449 | } 450 | } 451 | 452 | void Process(const float* input, float* output, const size_t numFrames) 453 | { 454 | auto condition = Eigen::Map(input, 1, numFrames); 455 | 456 | headArray.setZero(); 457 | 458 | for (size_t layerArrayIndex = 0; layerArrayIndex < layerArrays.size(); layerArrayIndex++) 459 | { 460 | if (layerArrayIndex == 0) 461 | { 462 | layerArrays[layerArrayIndex].Process(condition, condition, headArray.leftCols(numFrames), numFrames); 463 | } 464 | else 465 | { 466 | layerArrays[layerArrayIndex].Process(layerArrays[layerArrayIndex - 1].GetArrayOutputs().leftCols(numFrames), condition, layerArrays[layerArrayIndex - 1].GetHeadOutputs().leftCols(numFrames), numFrames); 467 | } 468 | } 469 | 470 | const auto& finalHeadArray = layerArrays[lastLayerArray].GetHeadOutputs(); 471 | 472 | auto out = Eigen::Map>(output, 1, numFrames); 473 | 474 | out.noalias() = headScale * finalHeadArray.leftCols(numFrames); 475 | } 476 | }; 477 | } -------------------------------------------------------------------------------- /NeuralAudio/RTNeuralModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NeuralModel.h" 4 | #include 5 | #ifdef BUILD_STATIC_RTNEURAL 6 | #include "wavenet_model.hpp" 7 | #endif 8 | #include "TemplateHelper.h" 9 | 10 | namespace NeuralAudio 11 | { 12 | struct FastMathsProvider 13 | { 14 | template 15 | static auto tanh(const Matrix& x) 16 | { 17 | return x.array().tanh(); 18 | } 19 | 20 | template 21 | static auto sigmoid(const Matrix& x) 22 | { 23 | using T = typename Matrix::Scalar; 24 | 25 | return ((x.array() / (T)2).array().tanh() + (T)1) / (T)2; 26 | } 27 | 28 | template 29 | static auto exp(const Matrix& x) 30 | { 31 | return x.array().exp(); 32 | } 33 | }; 34 | 35 | class RTNeuralModel : public NeuralModel 36 | { 37 | public: 38 | EModelLoadMode GetLoadMode() 39 | { 40 | return EModelLoadMode::RTNeural; 41 | } 42 | 43 | bool LoadFromKerasJson(const nlohmann::json& modelJson) 44 | { 45 | ReadKerasConfig(modelJson); 46 | 47 | return CreateModelFromKerasJson(modelJson); 48 | 49 | return true; 50 | } 51 | 52 | virtual bool CreateModelFromKerasJson(const nlohmann::json& modelJson) 53 | { 54 | (void)modelJson; 55 | 56 | return false; 57 | } 58 | 59 | virtual bool LoadFromNAMJson(const nlohmann::json& modelJson) 60 | { 61 | ReadNAMConfig(modelJson); 62 | 63 | return CreateModelFromNAMJson(modelJson); 64 | } 65 | 66 | virtual bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 67 | { 68 | (void)modelJson; 69 | 70 | return false; 71 | } 72 | }; 73 | 74 | #ifdef BUILD_STATIC_RTNEURAL 75 | template 76 | class RTNeuralLSTMModelT : public RTNeuralModel 77 | { 78 | using ModelType = typename std::conditional, RTNeural::DenseT>, 80 | RTNeural::ModelT, 81 | RTNeural::LSTMLayerT, RTNeural::DenseT> 82 | >::type; 83 | 84 | public: 85 | RTNeuralLSTMModelT() 86 | : model(nullptr) 87 | { 88 | } 89 | 90 | ~RTNeuralLSTMModelT() 91 | { 92 | if (model != nullptr) 93 | { 94 | delete model; 95 | model = nullptr; 96 | } 97 | } 98 | 99 | bool IsStatic() 100 | { 101 | return true; 102 | } 103 | 104 | bool CreateModelFromKerasJson(const nlohmann::json& modelJson) 105 | { 106 | if (model != nullptr) 107 | { 108 | delete model; 109 | model = nullptr; 110 | } 111 | 112 | model = new ModelType; 113 | 114 | model->parseJson(modelJson, false); 115 | model->reset(); 116 | 117 | return true; 118 | } 119 | 120 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 121 | { 122 | if (model != nullptr) 123 | { 124 | delete model; 125 | model = nullptr; 126 | } 127 | 128 | model = new ModelType; 129 | 130 | nlohmann::json config = modelJson.at("config"); 131 | 132 | std::vector weights = modelJson.at("weights"); 133 | 134 | const int networkInputSize = 1; 135 | const int networkOutputSize = 1; 136 | const int gateSize = 4 * hiddenSize; 137 | 138 | auto iter = weights.begin(); 139 | 140 | ForEachIndex([&](auto layer) 141 | { 142 | const int layerInputSize = (layer == 0) ? networkInputSize : hiddenSize; 143 | 144 | Eigen::MatrixXf inputPlusHidden = Eigen::Map(&(*iter), layerInputSize + hiddenSize, gateSize); 145 | 146 | auto& lstmLayer = model->template get(); 147 | 148 | // Input weights 149 | std::vector> inputWeights; 150 | 151 | inputWeights.resize(layerInputSize); 152 | 153 | for (size_t col = 0; col < layerInputSize; col++) 154 | { 155 | inputWeights[col].resize(gateSize); 156 | 157 | for (size_t row = 0; row < gateSize; row++) 158 | { 159 | inputWeights[col][row] = inputPlusHidden(col, row); 160 | } 161 | } 162 | 163 | lstmLayer.setWVals(inputWeights); 164 | 165 | // Recurrent weights 166 | std::vector> hiddenWeights; 167 | 168 | hiddenWeights.resize(hiddenSize); 169 | 170 | for (size_t col = 0; col < hiddenSize; col++) 171 | { 172 | hiddenWeights[col].resize(gateSize); 173 | 174 | for (size_t row = 0; row < gateSize; row++) 175 | { 176 | hiddenWeights[col][row] = inputPlusHidden(col + layerInputSize, row); 177 | } 178 | } 179 | 180 | lstmLayer.setUVals(hiddenWeights); 181 | 182 | iter += (gateSize * (layerInputSize + hiddenSize)); 183 | 184 | // Bias weights 185 | std::vector biasWeights = std::vector(iter, iter + gateSize); 186 | 187 | lstmLayer.setBVals(biasWeights); 188 | 189 | iter += gateSize; 190 | 191 | // initial internal state values follow here in NAM, but aren't supported by RTNeural 192 | 193 | iter += hiddenSize * 2; // (hidden state and cell state) 194 | }); 195 | 196 | // Dense layer weights 197 | auto& denseLayer = model->template get(); 198 | 199 | std::vector> denseWeights; 200 | denseWeights.resize(1); 201 | denseWeights[0] = std::vector(iter, iter + hiddenSize); 202 | 203 | denseLayer.setWeights(denseWeights); 204 | 205 | iter += hiddenSize; 206 | 207 | // Dense layer bias 208 | auto denseBias = std::vector(iter, iter + networkOutputSize); 209 | denseLayer.setBias(&(*iter)); 210 | 211 | iter += networkOutputSize; 212 | 213 | model->reset(); 214 | 215 | return true; 216 | } 217 | 218 | void Process(float* input, float* output, size_t numSamples) 219 | { 220 | for (size_t i = 0; i < numSamples; i++) 221 | output[i] = model->forward(input + i); 222 | } 223 | 224 | void Prewarm() 225 | { 226 | float sample = 0; 227 | 228 | for (size_t i = 0; i < 2048; i++) 229 | model->forward(&sample); 230 | } 231 | 232 | private: 233 | ModelType* model = nullptr; 234 | }; 235 | 236 | using StdDilations = wavenet::Dilations<1, 2, 4, 8, 16, 32, 64, 128, 256, 512>; 237 | using LiteDilations1 = wavenet::Dilations<1, 2, 4, 8, 16, 32, 64>; 238 | using LiteDilations2 = wavenet::Dilations<128, 256, 512, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512>; 239 | 240 | template 241 | class RTNeuralWaveNetModelT : public RTNeuralModel 242 | { 243 | using ModelType = typename std::conditional, 246 | wavenet::Layer_Array>, 247 | wavenet::Wavenet_Model, 249 | wavenet::Layer_Array> 250 | >::type; 251 | 252 | public: 253 | RTNeuralWaveNetModelT() 254 | : model(nullptr) 255 | { 256 | } 257 | 258 | ~RTNeuralWaveNetModelT() 259 | { 260 | if (model != nullptr) 261 | { 262 | delete model; 263 | model = nullptr; 264 | } 265 | } 266 | 267 | bool IsStatic() 268 | { 269 | return true; 270 | } 271 | 272 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 273 | { 274 | if (model != nullptr) 275 | { 276 | delete model; 277 | model = nullptr; 278 | } 279 | 280 | model = new ModelType; 281 | 282 | nlohmann::json config = modelJson.at("config"); 283 | 284 | model->load_weights(modelJson); 285 | 286 | SetMaxAudioBufferSize(defaultMaxAudioBufferSize); 287 | 288 | return true; 289 | } 290 | 291 | void SetMaxAudioBufferSize(int maxSize) 292 | { 293 | model->prepare(maxSize); 294 | } 295 | 296 | void Process(float* input, float* output, size_t numSamples) 297 | { 298 | model->forward(input, output, (int)numSamples); 299 | } 300 | 301 | void Prewarm() 302 | { 303 | float sample = 0; 304 | 305 | for (size_t i = 0; i < 2048; i++) 306 | model->forward(sample); 307 | } 308 | 309 | private: 310 | ModelType* model = nullptr; 311 | }; 312 | 313 | class RTNeuralModelDefinitionBase 314 | { 315 | public: 316 | virtual RTNeuralModel* CreateModel() 317 | { 318 | return nullptr; 319 | } 320 | }; 321 | 322 | class RTNeuralLSTMDefinitionBase : public RTNeuralModelDefinitionBase 323 | { 324 | public: 325 | virtual RTNeuralModel* CreateModel() 326 | { 327 | return nullptr; 328 | } 329 | 330 | virtual size_t GetNumLayers() 331 | { 332 | return 0; 333 | } 334 | 335 | virtual size_t GetHiddenSize() 336 | { 337 | return 0; 338 | } 339 | }; 340 | 341 | template 342 | class RTNeuralLSTMDefinitionT : public RTNeuralLSTMDefinitionBase 343 | { 344 | public: 345 | RTNeuralModel* CreateModel() 346 | { 347 | return new RTNeuralLSTMModelT; 348 | } 349 | 350 | size_t GetNumLayers() 351 | { 352 | return numLayers; 353 | } 354 | 355 | size_t GetHiddenSize() 356 | { 357 | return hiddenSize; 358 | } 359 | }; 360 | 361 | class RTNeuralWaveNetDefinitionBase : public RTNeuralModelDefinitionBase 362 | { 363 | public: 364 | virtual RTNeuralModel* CreateModel() 365 | { 366 | return nullptr; 367 | } 368 | 369 | virtual size_t GetNumChannels() 370 | { 371 | return 0; 372 | } 373 | 374 | virtual size_t GetHeadSize() 375 | { 376 | return 0; 377 | } 378 | }; 379 | 380 | template 381 | class RTNeuralWaveNetDefinitionT : public RTNeuralWaveNetDefinitionBase 382 | { 383 | public: 384 | RTNeuralModel* CreateModel() 385 | { 386 | return new RTNeuralWaveNetModelT; 387 | } 388 | 389 | virtual size_t GetNumChannels() 390 | { 391 | return numChannels; 392 | } 393 | 394 | virtual size_t GetHeadSize() 395 | { 396 | return headSize; 397 | } 398 | }; 399 | 400 | #endif 401 | 402 | class RTNeuralModelDyn : public RTNeuralModel 403 | { 404 | public: 405 | RTNeuralModelDyn() 406 | { 407 | } 408 | 409 | ~RTNeuralModelDyn() 410 | { 411 | if (model) 412 | model.reset(); 413 | } 414 | 415 | EModelLoadMode GetLoadMode() 416 | { 417 | return EModelLoadMode::RTNeural; 418 | } 419 | 420 | bool CreateModelFromKerasJson(const nlohmann::json& modelJson) 421 | { 422 | model = RTNeural::json_parser::parseJson(modelJson, false); 423 | model->reset(); 424 | 425 | return true; 426 | } 427 | 428 | bool CreateModelFromNAMJson(const nlohmann::json& modelJson) 429 | { 430 | model = std::make_unique>(1); 431 | 432 | nlohmann::json config = modelJson.at("config"); 433 | 434 | const size_t numLayers = config.at("num_layers"); 435 | const size_t inputSize = config.at("input_size"); 436 | const size_t hiddenSize = config.at("hidden_size"); 437 | 438 | std::vector weights = modelJson.at("weights"); 439 | 440 | const size_t networkInputSize = inputSize; 441 | const size_t networkOutputSize = inputSize; 442 | const size_t gateSize = 4 * hiddenSize; 443 | 444 | auto iter = weights.begin(); 445 | 446 | for (size_t layer = 0; layer < numLayers; layer++) 447 | { 448 | const size_t layerInputSize = (layer == 0) ? networkInputSize : hiddenSize; 449 | 450 | Eigen::MatrixXf inputPlusHidden = Eigen::Map(&(*iter), layerInputSize + hiddenSize, gateSize); 451 | 452 | auto lstmLayer = new RTNeural::LSTMLayer((int)layerInputSize, (int)hiddenSize); 453 | 454 | model->addLayer(lstmLayer); 455 | 456 | // Input weights 457 | std::vector> inputWeights; 458 | 459 | inputWeights.resize(layerInputSize); 460 | 461 | for (size_t col = 0; col < layerInputSize; col++) 462 | { 463 | inputWeights[col].resize(gateSize); 464 | 465 | for (size_t row = 0; row < gateSize; row++) 466 | { 467 | inputWeights[col][row] = inputPlusHidden(col, row); 468 | } 469 | } 470 | 471 | lstmLayer->setWVals(inputWeights); 472 | 473 | // Recurrent weights 474 | std::vector> hiddenWeights; 475 | 476 | hiddenWeights.resize(hiddenSize); 477 | 478 | for (size_t col = 0; col < hiddenSize; col++) 479 | { 480 | hiddenWeights[col].resize(gateSize); 481 | 482 | for (size_t row = 0; row < gateSize; row++) 483 | { 484 | hiddenWeights[col][row] = inputPlusHidden(col + layerInputSize, row); 485 | } 486 | } 487 | 488 | lstmLayer->setUVals(hiddenWeights); 489 | 490 | iter += (gateSize * (layerInputSize + hiddenSize)); 491 | 492 | // Bias weights 493 | std::vector biasWeights = std::vector(iter, iter + gateSize); 494 | 495 | lstmLayer->setBVals(biasWeights); 496 | 497 | iter += gateSize; 498 | 499 | // initial internal state values follow here in NAM, but aren't supported by RTNeural 500 | 501 | iter += hiddenSize * 2; // (hidden state and cell state) 502 | 503 | //// LSTM hidden state 504 | //auto hiddenState = std::vector(iter, iter + hiddenSize); 505 | 506 | //iter += hiddenSize; 507 | 508 | //// LSTM cell state 509 | //auto cellState = std::vector(iter, iter + hiddenSize); 510 | 511 | //lstmLayer->setHCVals(hiddenState, cellState); 512 | 513 | //iter += hiddenSize; 514 | } 515 | 516 | // Dense layer weights 517 | auto denseLayer = new RTNeural::Dense((int)hiddenSize, (int)networkOutputSize); 518 | model->addLayer(denseLayer); 519 | 520 | std::vector> denseWeights; 521 | denseWeights.resize(1); 522 | denseWeights[0] = std::vector(iter, iter + hiddenSize); 523 | 524 | denseLayer->setWeights(denseWeights); 525 | 526 | iter += hiddenSize; 527 | 528 | // Dense layer bias 529 | auto denseBias = std::vector(iter, iter + networkOutputSize); 530 | denseLayer->setBias(&(*iter)); 531 | 532 | iter += networkOutputSize; 533 | 534 | model->reset(); 535 | 536 | return true; 537 | } 538 | 539 | void Process(float* input, float* output, size_t numSamples) 540 | { 541 | for (size_t i = 0; i < numSamples; i++) 542 | output[i] = model->forward(input + i); 543 | } 544 | 545 | void Prewarm() 546 | { 547 | float sample = 0; 548 | 549 | for (size_t i = 0; i < 2048; i++) 550 | model->forward(&sample); 551 | } 552 | 553 | private: 554 | std::unique_ptr> model; 555 | }; 556 | } 557 | -------------------------------------------------------------------------------- /NeuralAudio/WaveNet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Based on WaveNet model structure from https://github.com/sdatkinson/NeuralAmpModelerCore 4 | // with some template ideas from https://github.com/jatinchowdhury18/RTNeural-NAM 5 | 6 | #include 7 | #include 8 | #include "TemplateHelper.h" 9 | #include "NeuralModel.h" 10 | #include "Activation.h" 11 | 12 | #ifndef WAVENET_MAX_NUM_FRAMES 13 | #define WAVENET_MAX_NUM_FRAMES 64 14 | #endif 15 | 16 | namespace NeuralAudio 17 | { 18 | //int numRewinds = 0; 19 | //int maxRewinds = 0; 20 | 21 | template 22 | class Conv1DT 23 | { 24 | public: 25 | void SetWeights(std::vector::iterator& inWeights) 26 | { 27 | weights.resize(KernelSize); 28 | 29 | for (size_t i = 0; i < OutChannels; i++) 30 | for (size_t j = 0; j < InChannels; j++) 31 | for (size_t k = 0; k < KernelSize; k++) 32 | weights[k](i, j) = *(inWeights++); 33 | 34 | if (DoBias) 35 | { 36 | for (size_t i = 0; i < OutChannels; i++) 37 | bias(i) = *(inWeights++); 38 | } 39 | } 40 | 41 | template 42 | inline void Process(const Eigen::MatrixBase& input, Eigen::MatrixBase const & output, const size_t iStart, const size_t nCols) const 43 | { 44 | for (size_t k = 0; k < KernelSize; k++) 45 | { 46 | auto offset = Dilation * ((int)k + 1 - KernelSize); 47 | 48 | auto inBlock = input.middleCols(iStart + offset, nCols); 49 | 50 | if (k == 0) 51 | const_cast&>(output).noalias() = weights[k] * inBlock; 52 | else 53 | const_cast&>(output).noalias() += weights[k] * inBlock; 54 | } 55 | 56 | if constexpr (DoBias) 57 | const_cast&>(output).colwise() += bias; 58 | } 59 | 60 | private: 61 | std::vector> weights; 62 | Eigen::Vector bias; 63 | }; 64 | 65 | template 66 | class DenseLayerT 67 | { 68 | public: 69 | void SetWeights(std::vector::iterator& inWeights) 70 | { 71 | for (size_t i = 0; i < OutSize; i++) 72 | for (size_t j = 0; j < InSize; j++) 73 | weights(i, j) = *(inWeights++); 74 | 75 | if constexpr (DoBias) 76 | { 77 | for (size_t i = 0; i < OutSize; i++) 78 | bias(i) = *(inWeights++); 79 | } 80 | } 81 | 82 | template 83 | void Process(const Eigen::MatrixBase& input, Eigen::MatrixBase const& output) const 84 | { 85 | if constexpr (DoBias) 86 | { 87 | const_cast&>(output).noalias() = (weights * input).colwise() + bias; 88 | } 89 | else 90 | { 91 | const_cast&>(output).noalias() = weights * input; 92 | } 93 | } 94 | 95 | template 96 | void ProcessAcc(const Eigen::MatrixBase& input, Eigen::MatrixBase const& output) const 97 | { 98 | if constexpr (DoBias) 99 | { 100 | const_cast&>(output).noalias() += (weights * input).colwise() + bias; 101 | } 102 | else 103 | { 104 | const_cast&>(output).noalias() += weights * input; 105 | } 106 | } 107 | 108 | private: 109 | Eigen::Matrix weights; 110 | Eigen::Vector bias; 111 | }; 112 | 113 | template 114 | class WaveNetLayerT 115 | { 116 | private: 117 | Conv1DT conv1D; 118 | DenseLayerT inputMixin; 119 | DenseLayerT oneByOne; 120 | Eigen::Matrix state; 121 | 122 | public: 123 | static constexpr auto ReceptiveFieldSize = (KernelSize - 1) * Dilation; 124 | static constexpr auto BufferSize = (ReceptiveFieldSize * 2) + WAVENET_MAX_NUM_FRAMES; 125 | static constexpr bool TooBigForStatic = ((Channels * BufferSize) * 4) > EIGEN_STACK_ALLOCATION_LIMIT; 126 | 127 | using LayerBufferType = typename std::conditional, 129 | Eigen::Matrix>::type; 130 | 131 | LayerBufferType layerBuffer; 132 | //Eigen::Matrix layerBuffer; 133 | size_t bufferStart; 134 | 135 | WaveNetLayerT() 136 | { 137 | state.setZero(); 138 | } 139 | 140 | void AllocBuffer(int allocNum) 141 | { 142 | long size = BufferSize; 143 | 144 | if constexpr(TooBigForStatic) 145 | { 146 | layerBuffer.resize(Channels, size); 147 | } 148 | 149 | layerBuffer.setZero(); 150 | 151 | //if (offset > (size - (ReceptiveFieldSize + WAVENET_MAX_NUM_FRAMES))) 152 | //{ 153 | // bufferStart = ReceptiveFieldSize; 154 | //} 155 | //else 156 | //{ 157 | // bufferStart = size - offset; 158 | //} 159 | 160 | bufferStart = ReceptiveFieldSize; 161 | 162 | //#if (LAYER_ARRAY_BUFFER_PADDING == 0) 163 | // bufferStart = ReceptiveFieldSize; 164 | //#else 165 | // bufferStart = size - (WAVENET_MAX_NUM_FRAMES * ((allocNum % LAYER_ARRAY_BUFFER_PADDING) + 1)); // Do the modulo to handle cases where LAYER_ARRAY_BUFFER_PADDING is not big enough to handle offset 166 | //#endif 167 | } 168 | 169 | void SetWeights(std::vector::iterator& weights) 170 | { 171 | conv1D.SetWeights(weights); 172 | inputMixin.SetWeights(weights); 173 | oneByOne.SetWeights(weights); 174 | } 175 | 176 | void AdvanceFrames(const size_t numFrames) 177 | { 178 | if constexpr (ReceptiveFieldSize <= WAVENET_MAX_NUM_FRAMES) 179 | { 180 | layerBuffer.middleCols(0, ReceptiveFieldSize).noalias() = layerBuffer.middleCols(numFrames, ReceptiveFieldSize); 181 | } 182 | else 183 | { 184 | layerBuffer.middleCols(bufferStart - ReceptiveFieldSize, numFrames).noalias() = layerBuffer.middleCols(bufferStart, numFrames); 185 | 186 | bufferStart += numFrames; 187 | 188 | if (bufferStart > (BufferSize - WAVENET_MAX_NUM_FRAMES)) 189 | bufferStart -= ReceptiveFieldSize; 190 | } 191 | } 192 | 193 | //void RewindBuffer() 194 | //{ 195 | // //numRewinds++; 196 | 197 | // size_t start = ReceptiveFieldSize; 198 | 199 | // layerBuffer.middleCols(start - ReceptiveFieldSize, ReceptiveFieldSize) = layerBuffer.middleCols(bufferStart - ReceptiveFieldSize, ReceptiveFieldSize); 200 | 201 | // bufferStart = start; 202 | //} 203 | 204 | void CopyBuffer() 205 | { 206 | for (size_t offset = 1; offset < ReceptiveFieldSize + 1; offset++) 207 | { 208 | layerBuffer.col(bufferStart - offset).noalias() = layerBuffer.col(bufferStart); 209 | } 210 | } 211 | 212 | template 213 | void Process(const Eigen::MatrixBase& condition, Eigen::MatrixBase const& headInput, Eigen::MatrixBase const& output, const size_t outputStart, const size_t numFrames) 214 | { 215 | auto block = state.leftCols(numFrames); 216 | 217 | conv1D.Process(layerBuffer, block, bufferStart, numFrames); 218 | 219 | inputMixin.ProcessAcc(condition, block); 220 | 221 | block = WAVENET_MATH::Tanh(block); 222 | 223 | //block = block.array().tanh(); 224 | 225 | //float* data = block.data(); 226 | //size_t size = block.rows() * block.cols(); 227 | 228 | //for (size_t pos = 0; pos < size; pos++) 229 | //{ 230 | // data[pos] = WAVENET_MATH::Tanh(data[pos]); 231 | //} 232 | 233 | const_cast&>(headInput).noalias() += block.topRows(Channels); 234 | 235 | oneByOne.Process(block.topRows(Channels), const_cast&>(output).middleCols(outputStart, numFrames)); 236 | 237 | const_cast&>(output).middleCols(outputStart, numFrames).noalias() += layerBuffer.middleCols(bufferStart, numFrames); 238 | } 239 | }; 240 | 241 | template 242 | using Dilations = std::integer_sequence; 243 | 244 | template 245 | class WaveNetLayerArrayT 246 | { 247 | template 248 | struct LayersHelper 249 | { 250 | }; 251 | 252 | template 253 | struct LayersHelper> 254 | { 255 | using type = std::tuple...>; 256 | }; 257 | 258 | using Layers = typename LayersHelper::type; 259 | 260 | private: 261 | Layers layers; 262 | DenseLayerT rechannel; 263 | DenseLayerT headRechannel; 264 | 265 | static constexpr auto numLayers = std::tuple_size_v; 266 | static constexpr auto lastLayer = numLayers - 1; 267 | 268 | public: 269 | static constexpr auto NumChannelsP = Channels; 270 | static constexpr auto HeadSizeP = HeadSize; 271 | 272 | Eigen::Matrix arrayOutputs; 273 | Eigen::Matrix headOutputs; 274 | int ReceptiveFieldSize = 0; // This should be a static constexpr, but I haven't sorted out the right template magic 275 | 276 | WaveNetLayerArrayT() 277 | { 278 | ForEachIndex([&](auto layerIndex) 279 | { 280 | ReceptiveFieldSize += std::get(layers).ReceptiveFieldSize; 281 | }); 282 | } 283 | 284 | int AllocBuffers(int allocNum) 285 | { 286 | ForEachIndex([&](auto layerIndex) 287 | { 288 | std::get(layers).AllocBuffer(allocNum++); 289 | }); 290 | 291 | return allocNum; 292 | } 293 | 294 | void SetWeights(std::vector::iterator& weights) 295 | { 296 | rechannel.SetWeights(weights); 297 | 298 | ForEachIndex([&](auto layerIndex) 299 | { 300 | std::get(layers).SetWeights(weights); 301 | }); 302 | 303 | headRechannel.SetWeights(weights); 304 | } 305 | 306 | template 307 | void Prewarm(const Eigen::MatrixBase& layerInputs, const Eigen::MatrixBase& condition, Eigen::MatrixBase const& headInputs) 308 | { 309 | rechannel.Process(layerInputs, std::get<0>(layers).layerBuffer.middleCols(std::get<0>(layers).bufferStart, 1)); 310 | 311 | ForEachIndex([&](auto layerIndex) 312 | { 313 | std::get(layers).CopyBuffer(); 314 | 315 | if constexpr (layerIndex == lastLayer) 316 | { 317 | std::get(layers).Process(condition, headInputs, arrayOutputs, 0, 1); 318 | } 319 | else 320 | { 321 | std::get(layers).Process(condition, headInputs, std::get(layers).layerBuffer, std::get(layers).bufferStart, 1); 322 | } 323 | }); 324 | 325 | headRechannel.Process(headInputs, headOutputs.leftCols(1)); 326 | } 327 | 328 | template 329 | void Process(const Eigen::MatrixBase& layerInputs, const Eigen::MatrixBase& condition, Eigen::MatrixBase const& headInputs, const size_t numFrames) 330 | { 331 | rechannel.Process(layerInputs, std::get<0>(layers).layerBuffer.middleCols(std::get<0>(layers).bufferStart, numFrames)); 332 | 333 | ForEachIndex([&](auto layerIndex) 334 | { 335 | if constexpr (layerIndex == lastLayer) 336 | { 337 | std::get(layers).Process(condition, headInputs, arrayOutputs, 0, numFrames); 338 | } 339 | else 340 | { 341 | std::get(layers).Process(condition, headInputs, std::get(layers).layerBuffer, std::get(layers).bufferStart, numFrames); 342 | } 343 | 344 | std::get(layers).AdvanceFrames(numFrames); 345 | }); 346 | 347 | headRechannel.Process(headInputs, headOutputs.leftCols(numFrames)); 348 | } 349 | }; 350 | 351 | template 352 | class WaveNetModelT 353 | { 354 | public: 355 | int ReceptiveFieldSize = 0; // This should be a static constexpr, but I haven't sorted out the right template magic 356 | 357 | WaveNetModelT() 358 | { 359 | int allocNum = 0; 360 | 361 | ForEachIndex([&](auto layerIndex) 362 | { 363 | ReceptiveFieldSize += std::get(layerArrays).ReceptiveFieldSize; 364 | 365 | allocNum = std::get(layerArrays).AllocBuffers(allocNum); 366 | }); 367 | 368 | } 369 | 370 | void SetWeights(std::vector weights) 371 | { 372 | std::vector::iterator it = weights.begin(); 373 | 374 | ForEachIndex([&](auto layerIndex) 375 | { 376 | std::get(layerArrays).SetWeights(it); 377 | }); 378 | 379 | headScale = *(it++); 380 | 381 | assert(std::distance(weights.begin(), it) == (long)weights.size()); 382 | } 383 | 384 | size_t GetMaxFrames() 385 | { 386 | return WAVENET_MAX_NUM_FRAMES; 387 | } 388 | 389 | void Prewarm() 390 | { 391 | float input = 0; 392 | 393 | auto condition = Eigen::Map>(&input, 1, 1); 394 | 395 | ForEachIndex([&](auto layerIndex) 396 | { 397 | if constexpr (layerIndex == 0) 398 | { 399 | std::get(layerArrays).Prewarm(condition, condition, headArray.leftCols(1)); 400 | } 401 | else 402 | { 403 | std::get(layerArrays).Prewarm(std::get(layerArrays).arrayOutputs.leftCols(1), condition, std::get(layerArrays).headOutputs.leftCols(1)); 404 | } 405 | }); 406 | } 407 | 408 | void Process(const float* input, float* output, const size_t numFrames) 409 | { 410 | //numRewinds = 0; 411 | 412 | auto condition = Eigen::Map>(input, 1, numFrames); 413 | 414 | headArray.setZero(); 415 | 416 | ForEachIndex([&](auto layerIndex) 417 | { 418 | if constexpr (layerIndex == 0) 419 | { 420 | std::get(layerArrays).Process(condition, condition, headArray.leftCols(numFrames), numFrames); 421 | } 422 | else 423 | { 424 | std::get(layerArrays).Process(std::get(layerArrays).arrayOutputs.leftCols(numFrames), condition, std::get(layerArrays).headOutputs.leftCols(numFrames), numFrames); 425 | } 426 | }); 427 | 428 | const auto finalHeadArray = std::get(layerArrays).headOutputs; 429 | 430 | auto out = Eigen::Map>(output, 1, numFrames); 431 | 432 | out.noalias() = headScale * finalHeadArray.leftCols(numFrames); 433 | 434 | //if (numRewinds > maxRewinds) 435 | //{ 436 | // maxRewinds = numRewinds; 437 | 438 | // std::cout << "New Max Rewinds: " << maxRewinds << std::endl; 439 | //} 440 | } 441 | 442 | private: 443 | static constexpr auto headLayerChannels = std::tuple_element_t<0, std::tuple>::NumChannelsP; 444 | 445 | std::tuple layerArrays; 446 | Eigen::Matrix headArray; 447 | float headScale; 448 | }; 449 | } -------------------------------------------------------------------------------- /Utils/Models/BossWN-nano.nam: -------------------------------------------------------------------------------- 1 | {"version": "0.5.1", "metadata": {"date": {"year": 2023, "month": 5, "day": 29, "hour": 17, "minute": 5, "second": 4}, "loudness": -11.725313186645508, "gain": 0.5965619512240007}, "architecture": "WaveNet", "config": {"layers": [{"input_size": 1, "condition_size": 1, "head_size": 2, "channels": 4, "kernel_size": 3, "dilations": [1, 2, 4, 8, 16, 32, 64], "activation": "Tanh", "gated": false, "head_bias": false}, {"input_size": 4, "condition_size": 1, "head_size": 1, "channels": 2, "kernel_size": 3, "dilations": [128, 256, 512, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512], "activation": "Tanh", "gated": false, "head_bias": true}], "head": null, "head_scale": 0.02}, "weights": [0.20864363014698029, 0.8024476766586304, -0.5351406335830688, -0.6766833066940308, -0.34967008233070374, -0.33313119411468506, -0.3266916573047638, 0.45169398188591003, 0.04592067748308182, -0.2145940661430359, -0.3234618306159973, -0.12928034365177155, 0.006090836133807898, -0.41874170303344727, -0.19540219008922577, 0.3014377951622009, -0.13174526393413544, 0.20819781720638275, -0.05995114520192146, 0.07647346705198288, 0.22077742218971252, 0.6153808236122131, -0.2509903609752655, 0.10627347975969315, -0.40312454104423523, -0.18083126842975616, 0.14420807361602783, -0.6355199217796326, 0.009535601362586021, -0.06358958035707474, 0.07137507945299149, 0.25922438502311707, -0.5471367835998535, 0.22598060965538025, -0.18669572472572327, 0.09104667603969574, -0.4943769872188568, 0.22829240560531616, 0.47123658657073975, -0.21968361735343933, 0.1364227533340454, -0.1746380627155304, 0.21890497207641602, -0.16407759487628937, -0.45725709199905396, 0.31019991636276245, 0.10639270395040512, 0.4335137903690338, -0.5429285764694214, -0.12037386000156403, 0.4254966378211975, -0.16419951617717743, 0.1343764066696167, 0.040155403316020966, 0.28186115622520447, -0.13638544082641602, -0.0901947170495987, -0.41048893332481384, -0.3539474904537201, -0.08362623304128647, 0.27706611156463623, 0.23463213443756104, -0.15649837255477905, 0.15050551295280457, 0.6457645893096924, -0.012075352482497692, -0.18517644703388214, -0.4029207229614258, 0.5426814556121826, 0.4298790395259857, -0.7424126267433167, -0.5568410754203796, 0.485169917345047, 0.94465172290802, 0.4781884253025055, 0.3434756100177765, 0.14213837683200836, -0.3795415759086609, -0.012367144227027893, -0.14949196577072144, -0.18820875883102417, 0.35070276260375977, 0.17501898109912872, -0.46633145213127136, 0.02167847380042076, 0.03355516865849495, -0.3309360146522522, 0.1417057365179062, 0.2649434506893158, 0.6814652681350708, 0.055419422686100006, 0.22362524271011353, 0.16529835760593414, 0.10497306287288666, -0.3041282594203949, -0.37729310989379883, -0.1043170839548111, -0.04898690804839134, -0.3086366057395935, -0.30639025568962097, 0.5162853598594666, 0.31537044048309326, -0.05774715915322304, 0.11389421671628952, -0.2758869528770447, -0.09938523173332214, -0.16874584555625916, -0.16266457736492157, 0.133386492729187, 0.1586860567331314, -0.30468782782554626, -0.07113407552242279, -0.2288001924753189, 0.19091299176216125, 0.12028315663337708, -0.5499157905578613, -0.2581815719604492, -0.1732410490512848, -0.1390174925327301, 0.007727915421128273, 0.15444596111774445, 0.05326147750020027, -0.284835547208786, 0.2175203114748001, -0.2202218472957611, 0.5161519646644592, -0.26933255791664124, -0.08727499097585678, -0.19608186185359955, -0.2268325537443161, 0.039641689509153366, -0.03849395737051964, -0.3933503031730652, 0.046177081763744354, 1.1257779598236084, 0.014595137909054756, -0.0075904447585344315, -0.11952342092990875, 0.38002678751945496, 0.5729694962501526, 0.5605298280715942, 0.5309514999389648, 0.4867708384990692, -0.049748554825782776, -0.9693282246589661, -0.7323644757270813, 0.21720141172409058, -0.4344051480293274, -0.3852837383747101, -0.6405786871910095, -0.3331708014011383, -0.13761775195598602, -0.047823160886764526, 0.2598940134048462, 0.19993062317371368, -0.3265632688999176, 0.15922948718070984, -0.271950364112854, -0.07885246723890305, -0.1551879346370697, -0.35595402121543884, -0.0979803279042244, -0.09881474822759628, -0.25841253995895386, 0.12716452777385712, -0.08418374508619308, 0.09345589578151703, 0.0066172657534480095, -0.7624689936637878, 0.30889633297920227, 0.45901942253112793, -0.06995777040719986, 1.0311428308486938, -0.07848504930734634, -0.47287288308143616, 0.2688805162906647, -0.10194796323776245, -0.18420341610908508, -0.025037983432412148, -0.029787413775920868, 0.13928817212581635, -0.27533793449401855, -0.058117400854825974, 0.3457411825656891, -0.2315443903207779, 0.014027523808181286, 0.19011111557483673, 0.1551254540681839, -0.1343069076538086, -0.0006524831987917423, 0.117728590965271, -0.1937301754951477, -0.16952009499073029, 0.10883624851703644, -0.2615380883216858, -0.0029417434707283974, -0.30446869134902954, 0.209572434425354, -0.35606133937835693, -0.17628856003284454, 0.2226269245147705, -0.024421196430921555, 0.1063513457775116, -0.16887366771697998, -0.08358752727508545, 0.013867979869246483, -0.048434749245643616, 0.12235179543495178, 0.46638548374176025, -0.1900666058063507, 0.1128849908709526, 0.14415594935417175, 0.19276760518550873, -0.5861256122589111, 0.01208905316889286, 0.25959479808807373, -0.5109381675720215, -0.3242162764072418, 0.3623109757900238, -0.4429630637168884, -0.38406628370285034, 0.7697056531906128, 0.03982864320278168, -0.432326078414917, -0.47478675842285156, 0.6185368299484253, -0.49933403730392456, -0.15505686402320862, -0.19896601140499115, -0.0015872734365984797, -0.06680111587047577, 0.26967135071754456, -0.10501216351985931, 0.12484902888536453, 0.13080841302871704, -0.4030754268169403, 0.12940968573093414, -0.11567485332489014, -0.4904281198978424, 0.08199859410524368, 0.4362495541572571, 0.2275758534669876, -0.4608984887599945, 0.6264516115188599, 0.24373659491539001, -0.11639624834060669, 0.2681194841861725, -0.14858494699001312, 0.06650373339653015, -0.1715184599161148, -0.14535634219646454, -0.11694709211587906, -0.041367679834365845, -0.07860930263996124, -0.02629769966006279, 0.16796882450580597, -0.388328492641449, 0.04883351922035217, -0.17104488611221313, -0.4749859869480133, -0.25821906328201294, 0.3412550389766693, -0.2945702373981476, 0.2744273245334625, 0.41168031096458435, -0.038157399743795395, -0.3877337872982025, 0.6007869839668274, 0.40241730213165283, 0.055215973407030106, -0.1463010609149933, 0.31446459889411926, -0.46335166692733765, -0.27349287271499634, 0.2811707854270935, -0.812662661075592, 0.22522157430648804, 0.36660683155059814, 0.26743969321250916, 0.348289430141449, -0.029670918360352516, -0.31043383479118347, -0.22124800086021423, 0.08376820385456085, 0.022723540663719177, 0.2341347336769104, -0.4776341915130615, 0.6707753539085388, -1.0690922737121582, -0.2768358886241913, -0.9070264101028442, 0.1863124817609787, -0.35829514265060425, -0.2009359747171402, -0.34998849034309387, -0.14754420518875122, 0.7285847663879395, -0.08100294321775436, 0.6085700988769531, -0.25054165720939636, -1.4061897993087769, 0.11507195234298706, -1.3707633018493652, 0.012659700587391853, 0.060469817370176315, -0.28005239367485046, 0.012961327098309994, 0.11236449331045151, 0.2020464539527893, -0.17869749665260315, -0.2076244354248047, 0.09444506466388702, 0.3574914336204529, -0.24286441504955292, 0.30412033200263977, 0.3457343876361847, -0.3110213577747345, 0.004835021682083607, 0.11516936868429184, -0.038562193512916565, 0.10862157493829727, 0.008550574071705341, -0.19451294839382172, -0.053381938487291336, 0.44643887877464294, 0.12563906610012054, -0.08120736479759216, 0.14046986401081085, 0.050001900643110275, -0.2539239525794983, -0.29708290100097656, -0.1229325607419014, 0.13380037248134613, -0.010092107579112053, 0.7491855621337891, 0.0496211014688015, 0.05356866866350174, 0.20159487426280975, 0.24889306724071503, 0.26526114344596863, -0.7540549635887146, 0.005206095986068249, 0.24729463458061218, 0.2977568209171295, 0.12785443663597107, 0.22306349873542786, -0.12045915424823761, 0.09143005311489105, 0.12860897183418274, -0.28284430503845215, 0.09327645599842072, 0.13197222352027893, -0.16113488376140594, 0.009129652753472328, -0.1611490100622177, 0.045920826494693756, -0.06720881909132004, 0.18618907034397125, -0.05492790415883064, -0.03582165762782097, -0.6046820878982544, -0.8585798144340515, -0.9522879123687744, 0.7186452746391296, 0.5855565667152405, 0.4634886384010315, 0.5486227869987488, -0.6366548538208008, 0.47491419315338135, 0.15827514231204987, 0.34508559107780457, 0.49211007356643677, -0.3918399512767792, -0.3794412910938263, -1.0436710119247437, -0.25530165433883667, 1.1826121807098389, -0.5661217570304871, 0.9513280987739563, 0.7475258708000183, 0.3946250379085541, -0.11791203916072845, 0.12456680834293365, 0.2739814221858978, 0.09282245486974716, 0.010471353307366371, -0.18005965650081635, -0.011069866828620434, -0.2991679012775421, 0.27355247735977173, -0.14458951354026794, -0.2853868007659912, -0.09499053657054901, -0.19551150500774384, -0.13954715430736542, 0.12777702510356903, 0.04840053990483284, -0.02074575237929821, 0.4451534152030945, -0.07358992844820023, 0.26623809337615967, 0.014085629023611546, -0.3867853283882141, 0.20509378612041473, -0.38910573720932007, -0.3285519778728485, 0.1059790700674057, 0.3934302031993866, -0.11205197125673294, 0.13547882437705994, -0.294590562582016, 0.046083059161901474, -0.09960402548313141, 0.014528321102261543, 0.1530323624610901, 0.12776297330856323, -0.1390054076910019, 0.21708883345127106, 0.13263431191444397, 0.07283524423837662, 0.019435813650488853, -0.12947066128253937, 0.48921725153923035, -0.05793573334813118, 0.49359673261642456, -0.35184547305107117, -0.04070347920060158, 0.08226534724235535, -0.4424628019332886, -0.03603781387209892, -0.031607262790203094, 0.2584247589111328, 0.21493619680404663, -0.05865464359521866, -0.07097679376602173, -0.1299332082271576, 0.16541306674480438, -0.7111442685127258, 0.3735101819038391, -0.18799802660942078, -1.008781909942627, 0.07588932663202286, 0.6303182244300842, 0.4755847156047821, -0.9138641953468323, 0.40492555499076843, 0.4219602942466736, 0.2231563776731491, -0.26089930534362793, -0.5059844851493835, 0.2708413302898407, 0.12327549606561661, 1.2522242069244385, 1.479981780052185, -0.1904546618461609, 1.370650053024292, 0.4142761528491974, 0.24575141072273254, -0.41496187448501587, -0.3312917947769165, -0.6600657105445862, -0.6495827436447144, 0.5047540068626404, -0.20506158471107483, -0.3584212064743042, 0.6550894975662231, -0.41952070593833923, 0.026988478377461433, -1.332170844078064, 0.05637429282069206, 0.20011800527572632, 1.331405758857727, -0.2277662307024002, 0.05458606407046318, 0.6705957055091858, -0.3989757001399994, -0.7488925457000732, 0.3774028420448303, -0.2071838676929474, 0.23110444843769073, -1.021098256111145, 0.056158773601055145, 0.1825396716594696, 0.7092085480690002, 0.18517129123210907, 0.1749643236398697, -0.5618173480033875, 0.381107896566391, 0.4349059760570526, -0.3494334816932678, 0.0682080015540123, -0.03946933150291443, 0.8264748454093933, -0.10022018104791641, -0.11509948968887329, -0.6022210717201233, -0.2062413990497589, -0.08170755952596664, 0.24384528398513794, 0.05732056125998497, 0.3495329022407532, -0.07420635223388672, -0.2318478673696518, -0.14098836481571198, -0.24989663064479828, -0.05386848375201225, -0.09699983894824982, -0.08495014905929565, -0.45401594042778015, 0.23513807356357574, -0.44874852895736694, -0.049740176647901535, -0.026156632229685783, -0.12054576724767685, 0.07542315870523453, -0.5988317728042603, -0.26534464955329895, 0.29051753878593445, 0.033236872404813766, -0.32111871242523193, 0.3633326292037964, 0.03623674809932709, 0.04003697261214256, -0.4297333061695099, -0.5432133674621582, -0.23804645240306854, 0.4279510974884033, 0.03293211758136749, -0.5029451251029968, -0.19386158883571625, 0.6425396800041199, 0.030248790979385376, -0.43509918451309204, -0.30230599641799927, -0.46349021792411804, -0.08419055491685867, -0.42056867480278015, -0.2858983278274536, -0.2745150625705719, 0.3330672085285187, 0.04435107111930847, 0.07412172853946686, -0.019686775282025337, -0.48194995522499084, -0.1807643324136734, 0.22274702787399292, -0.2917458415031433, -0.08927130699157715, -0.1841384321451187, 0.34758153557777405, -0.3336649537086487, -0.1189955472946167, 0.029721669852733612, -0.3211321234703064, 0.17023269832134247, -0.021519238129258156, 0.25546056032180786, -0.034002259373664856, 0.24004201591014862, 0.03459838032722473, -0.1996818333864212, -0.18937021493911743, -0.033621896058321, 0.5565920472145081, -0.1286909580230713, 0.5501987934112549, 0.061264459043741226, 0.02493317238986492, 0.045563895255327225, 0.21102000772953033, 0.3412156105041504, 0.2193649560213089, -0.20412187278270721, -0.4223940968513489, 0.03816790133714676, -0.3908214271068573, 0.34907081723213196, -0.03008391335606575, 0.308310866355896, 0.883211076259613, 0.12140750139951706, 0.23586603999137878, -0.0515085868537426, -0.09508858621120453, -0.18591821193695068, 0.04394855350255966, 0.2531529366970062, -0.16993343830108643, 0.1536266803741455, 0.997414767742157, -0.528803825378418, -0.3200623095035553, -0.704078197479248, 0.651726484298706, 0.1890174299478531, 0.3111015260219574, 0.10296425223350525, 0.09475219994783401, 0.8552361726760864, -0.08042251318693161, -0.06867890805006027, 0.7753596901893616, -0.03346485272049904, -0.030915841460227966, -0.19989383220672607, 0.02620004676282406, 0.02524632401764393, -0.3269898295402527, -0.030298622325062752, -0.08003957569599152, 0.13457699120044708, -0.47953975200653076, 0.08037231117486954, -0.24255569279193878, 0.13800114393234253, 0.6617993712425232, 0.08792722225189209, 0.09528909623622894, 1.6299957036972046, 0.7958167791366577, -0.23690015077590942, 1.948185682296753, 0.5111375451087952, -0.7309210896492004, -0.09068578481674194, -0.8754600286483765, -0.11945442855358124, 0.10393525660037994, -1.5024023056030273, -0.331937313079834, -0.48988136649131775, 0.18581604957580566, 0.5421373844146729, -0.1425110548734665, 0.32282891869544983, -0.7451228499412537, 0.21768753230571747, -0.6839150786399841, -0.687446653842926, 0.3320693373680115, 0.07954232394695282, 0.3406510651111603, -0.5034711956977844, -0.1769651472568512, 0.6060384511947632, 0.263288289308548, -0.49965164065361023, -0.0864732638001442, -0.303302139043808, 0.12425816804170609, -0.14722298085689545, -0.5538157820701599, -0.27478542923927307, -0.17120887339115143, -0.2816552519798279, -0.06686615198850632, 0.39618927240371704, 0.22756356000900269, 0.7476935386657715, 0.29462018609046936, -0.2673283517360687, -0.09764410555362701, 0.2888241410255432, 0.33215203881263733, -0.2931345999240875, -0.0875421091914177, 0.1975499838590622, 0.17538031935691833, 0.3208978772163391, -0.529474675655365, 0.13844676315784454, -0.4802244007587433, 0.024436229839920998, -0.40870118141174316, 0.1374676525592804, 0.10713968425989151, -0.04820908233523369, 0.31262606382369995, 1.1932706832885742, -0.938508152961731, 1.3791189193725586, -0.512476921081543, -0.2911982834339142, 0.06906116008758545, 0.15656471252441406, 0.4524727463722229, -0.3813854455947876, -0.17929621040821075, -0.38408514857292175, 0.4856735169887543, -0.16472460329532623, -0.17123858630657196, 0.24330174922943115, 0.32092925906181335, 0.30282294750213623, -0.3320239782333374, 0.2658621668815613, -0.17835600674152374, 0.26692646741867065, 0.21273083984851837, 0.16291503608226776, -1.0203617811203003, -0.9661657810211182, -2.230213165283203, -0.7031154632568359, 0.04743751883506775, -0.0167685616761446, 0.29948651790618896, -0.021109288558363914, -0.08070138096809387, -0.47581833600997925, 0.3713856637477875, -0.061236921697854996, 0.7283418774604797, -0.1098901703953743, -0.023812269791960716, -0.7104759812355042, 0.0945456475019455, 0.5103099346160889, 1.1179131269454956, 0.157730832695961, -0.13186590373516083, -0.5865890979766846, 0.6542105674743652, -0.8499389886856079, -0.2112540453672409, 0.7105810642242432, -0.445800244808197, -0.004204657860100269, -0.05813908204436302, -0.3028920888900757, 0.0036529346834868193, 0.013079201802611351, 0.38905707001686096, 0.025245463475584984, 0.3043918311595917, -0.1370486617088318, -0.04681311175227165, -0.27851834893226624, 0.088245689868927, -0.261949747800827, 0.1522347331047058, 0.023283565416932106, -0.00018415349768474698, 1.017866849899292, 1.6193583011627197, 0.4753827750682831, -0.5748708248138428, -0.03546380251646042, -0.018388846889138222, 0.025479324162006378, 0.07961629331111908, -0.15278524160385132, -0.03523343428969383, -0.06575416773557663, 0.45375362038612366, 0.051637690514326096, 0.2078322470188141, -0.19545681774616241, -0.06872053444385529, -0.1849684864282608, 0.08007432520389557, 0.00810382142663002, 0.0019674068316817284, 0.2331007719039917, 0.0033446266315877438, -0.19507154822349548, 1.9471369981765747, -1.2105234861373901, -0.5898672342300415, 0.24325211346149445, -0.6708502173423767, -0.05106326937675476, -0.34619084000587463, 0.1372545212507248, 5.791273360955529e-05, 0.2800217270851135, 0.017352186143398285, 0.07935035228729248, -0.04376789182424545, -0.5838122963905334, -0.08926569670438766, 0.04167559742927551, -0.6513465642929077, 0.17302703857421875, -0.2562836706638336, 0.15385490655899048, -0.6450962424278259, -1.7202309370040894, 0.5130865573883057, 0.5576651096343994, 0.7179814577102661, 0.6018909811973572, 0.13812226057052612, 0.04007091000676155, -0.2549115717411041, 0.12471809983253479, 0.015875717625021935, 0.14996975660324097, 0.3924914300441742, 0.23471403121948242, 0.3563458323478699, -0.013804602436721325, -0.14015023410320282, -0.24425891041755676, -0.21326103806495667, 0.5657997131347656, -0.21701925992965698, -0.004645495675504208, 0.17379677295684814, -1.0660468339920044, 2.456993341445923, 0.01831057108938694, -0.22658857703208923, -0.016282042488455772, 0.39205020666122437, -0.112197145819664, -0.08250997215509415, -0.027184007689356804, -0.03448095917701721, -0.037455346435308456, 0.18192888796329498, 0.01556821446865797, 0.0785229280591011, -0.2914019823074341, 0.012976255267858505, 0.02870139107108116, -0.679554283618927, 0.07304078340530396, -0.16125397384166718, -0.1181095689535141, -0.08900611847639084, 0.07090878486633301, -0.2630368769168854, -0.5921692252159119, 0.2861429452896118, 0.09047992527484894, -0.2831847667694092, -1.7977997064590454, 2.167759895324707, 0.24693205952644348, 0.019999999552965164]} -------------------------------------------------------------------------------- /Utils/Models/BossLSTM-2x8.nam: -------------------------------------------------------------------------------- 1 | {"version": "0.5.1", "metadata": {"date": {"year": 2023, "month": 5, "day": 29, "hour": 16, "minute": 15, "second": 38}, "loudness": -11.83329963684082, "gain": 0.6309808775852367}, "architecture": "LSTM", "config": {"input_size": 1, "hidden_size": 8, "num_layers": 2}, "weights": [1.8648439645767212, -0.6668469309806824, 0.2644658088684082, -0.3754681348800659, -0.6394230723381042, 2.021033525466919, -0.1595885306596756, -0.47707733511924744, 0.2950441837310791, -0.4682726263999939, 1.130904197692871, 0.3165973424911499, 0.922857940196991, -0.3089096248149872, 0.25102564692497253, -0.1949017196893692, -0.2974202632904053, 1.037063479423523, -0.33907490968704224, 0.3404989242553711, -0.8310563564300537, -0.06745976954698563, 1.0016100406646729, -2.496894598007202, -0.5270388126373291, 0.6893699765205383, -1.2391586303710938, -0.35156455636024475, -0.20651322603225708, -0.36748120188713074, -0.5582135319709778, -0.8531280159950256, 1.8267875909805298, 0.2753162086009979, -1.095866084098816, 0.3970065712928772, -1.3625047206878662, -0.18541520833969116, -1.6942859888076782, 2.2006001472473145, 0.7252543568611145, -1.4984451532363892, 3.4595468044281006, 1.702416181564331, 1.7230844497680664, 0.09389885514974594, 1.028800368309021, -0.25958284735679626, 0.17670930922031403, 0.7363085150718689, -1.545017957687378, -1.2144514322280884, -0.4041344225406647, -0.5958771109580994, -0.7102939486503601, 1.0303635597229004, -0.15047112107276917, 0.04767276719212532, 0.9273569583892822, -1.1349189281463623, -0.8652652502059937, 0.2640848755836487, -0.6902044415473938, 0.43939805030822754, 0.4205797612667084, -0.42440065741539, 0.7092759013175964, 1.3187533617019653, -0.4763464331626892, 0.1160372793674469, -0.6031532883644104, -0.11067087948322296, 1.7829817533493042, -0.6178053617477417, 0.44788047671318054, -0.3765927255153656, -0.9549731612205505, 2.015951156616211, 0.3933156132698059, 0.8567903637886047, 0.4857635498046875, -0.8066356778144836, -0.021968383342027664, -0.36829039454460144, -0.4181884229183197, -0.5796788334846497, 1.8996447324752808, -0.792843222618103, 0.44403356313705444, -0.0736226812005043, -0.5488572716712952, 0.4932778775691986, -0.9518990516662598, 0.200552299618721, 0.5674852132797241, -2.3889453411102295, 0.17950591444969177, 1.9712530374526978, 0.1578921377658844, 1.5872585773468018, 0.4039193391799927, -0.4496268332004547, -0.2933633327484131, -0.23565641045570374, 0.5942560434341431, 0.47517895698547363, 0.18996396660804749, 0.33830735087394714, 1.5671701431274414, -2.3622283935546875, -0.0012124796630814672, -1.5980676412582397, -2.0982344150543213, -1.280077576637268, 0.456068217754364, 1.2504503726959229, 0.8160809278488159, -1.5473157167434692, 0.06300471723079681, -0.6305593252182007, 0.529211163520813, 0.21013407409191132, -1.3719208240509033, 0.28986015915870667, 2.010038137435913, 0.31768661737442017, -0.19986818730831146, 0.0005515797529369593, 0.36685118079185486, -0.1298786997795105, -0.5217580795288086, -2.3785879611968994, 0.5820344090461731, -0.09890207648277283, 0.34773167967796326, -0.06968549638986588, -0.4246828556060791, 0.5644348859786987, 0.18237268924713135, 0.336167573928833, -2.1546268463134766, -0.5214061141014099, 0.5491580367088318, -0.4172191023826599, 1.0512969493865967, -0.2518041133880615, 0.028592564165592194, -0.4801647663116455, -0.42811915278434753, 0.955746054649353, -0.09239548444747925, 0.4431132376194, 0.4683121144771576, 0.1705458164215088, -0.6462693810462952, 0.3800564110279083, 0.5755850672721863, -0.35051846504211426, 1.731235384941101, 0.22897250950336456, -0.6918977499008179, 0.7259852886199951, -0.7530871033668518, 0.3094862103462219, -0.5027346014976501, 0.35912173986434937, 0.07219474017620087, 0.0588245615363121, -0.17736218869686127, 0.6268575191497803, -0.09569849818944931, 0.708895206451416, 0.6207911372184753, 0.41654372215270996, 0.2697015702724457, 0.31323057413101196, 0.9784327745437622, 0.3784242570400238, 0.41055411100387573, 0.21371522545814514, 2.538975477218628, -1.4131073951721191, -0.1564459502696991, 1.6552748680114746, -1.6882630586624146, 0.31663140654563904, 1.2821286916732788, -1.673366904258728, -0.1358180195093155, -0.8955349326133728, -0.04216266795992851, -0.3240540623664856, 0.7799767255783081, 0.18231329321861267, -1.2278560400009155, 0.4076506495475769, -0.2756814956665039, 0.2743190824985504, 0.4718535244464874, 0.6725401282310486, 0.15448930859565735, -0.3783546984195709, -0.20007812976837158, 0.9611263275146484, 0.20170824229717255, -0.5194767713546753, 0.2076149582862854, 0.23408354818820953, -0.49244895577430725, -0.7926983833312988, 0.9367784261703491, 0.08724024891853333, -0.28257685899734497, 0.7112628817558289, -0.5478704571723938, 0.25083309412002563, -0.005601968616247177, 2.0321109294891357, 1.8984184265136719, -0.45928043127059937, 1.3431888818740845, 0.2520248293876648, -0.12917689979076385, 0.6387333869934082, 1.3105547428131104, 1.8882911205291748, 0.9392710328102112, 2.3873989582061768, 1.1352965831756592, 1.6303826570510864, -2.876652240753174, 1.4445621967315674, -1.7062193155288696, 1.4193100929260254, 2.1586155891418457, 0.545200526714325, -0.4464227259159088, 0.6645137667655945, 0.19377002120018005, -0.09962493181228638, -0.8419400453567505, -0.3365504741668701, 0.18399205803871155, -3.232921600341797, 2.2872471809387207, 0.40691491961479187, -1.0251842737197876, 1.0560842752456665, 0.49132946133613586, 0.06464450806379318, -0.6870937347412109, -0.34022316336631775, -2.558274507522583, 0.08860107511281967, 1.9926987886428833, 0.0333099327981472, 0.2535146474838257, 3.60964298248291, 0.08052612096071243, 0.5101994872093201, 3.2700304985046387, 4.317213535308838, -0.37981748580932617, 0.6036303043365479, 0.14649692177772522, -0.480960875749588, -1.7782959938049316, -0.27247506380081177, -0.3585968613624573, 0.16898266971111298, -1.625291109085083, 0.6021807789802551, -0.8715996742248535, -1.1656246185302734, 0.15889038145542145, -1.4016027450561523, 0.357891708612442, -1.6053792238235474, 0.4227260649204254, 1.2305521965026855, -0.6439307928085327, 3.296323299407959, -0.18836021423339844, -0.01157744973897934, 4.697570323944092, 0.8499528765678406, -1.1436734199523926, 1.0081297159194946, -4.423055648803711, -2.3332765102386475, -5.334491729736328, -4.270193099975586, -0.012120120227336884, -4.154788017272949, -4.194795608520508, -3.2572519779205322, 4.636308670043945, 2.24702787399292, 4.131824970245361, 4.5251312255859375, 0.5926218032836914, 4.102479934692383, 4.203471660614014, 4.190258026123047, 0.6309705972671509, -0.1638263761997223, 0.072424978017807, 0.10758940130472183, 1.1285423040390015, 0.2760865390300751, 0.16830229759216309, 0.8101726770401001, 0.4371658265590668, 1.3949415683746338, 0.6892248392105103, 0.16597791016101837, 0.6938350200653076, 0.10576660186052322, 0.2812722623348236, 0.4228611886501312, 0.33350327610969543, -0.0561603307723999, 0.15003111958503723, 0.5272149443626404, 0.01705455593764782, 0.35458680987358093, 0.2266756296157837, 0.6877692341804504, 0.3734608590602875, -0.057674307376146317, 0.21765866875648499, 0.9309065341949463, 0.017748190090060234, 1.3424781560897827, 0.386547327041626, 3.0469870567321777, 0.053429074585437775, 0.03278467804193497, 0.1894494742155075, 0.5184465646743774, 0.953521728515625, 0.3229198455810547, -0.03618964925408363, 0.45118358731269836, -0.06846053898334503, -0.20109573006629944, -0.057737600058317184, -0.31235837936401367, 0.803296685218811, 0.018858717754483223, 0.1931949257850647, 0.1751149445772171, -0.5113680362701416, 0.10717026144266129, -0.47528573870658875, -0.1736091822385788, 0.7969585061073303, 0.05204636976122856, 0.35128048062324524, -0.6574519276618958, -0.20445817708969116, 0.420430988073349, -0.12121571600437164, -0.6084310412406921, -1.11895751953125, -0.07008464634418488, -0.23549316823482513, 0.2985723912715912, 0.13709159195423126, -0.07713168859481812, 0.351309210062027, 0.36113879084587097, 0.7306649684906006, -0.16497831046581268, -1.1260348558425903, 0.33014246821403503, -0.3024277091026306, 0.19849789142608643, -0.2484973669052124, 1.0083262920379639, 0.6576657891273499, 0.05516086891293526, 0.20653779804706573, -1.0252189636230469, 0.47309234738349915, -0.35570037364959717, 0.02286558970808983, 0.1113787293434143, 0.6847624182701111, -0.21054866909980774, 0.04622412845492363, -0.05413564294576645, -0.16807201504707336, -0.4470297396183014, 0.774494469165802, -0.33795323967933655, 0.09969249367713928, 0.28709790110588074, -0.8063397407531738, -0.0017324956133961678, 0.10431205481290817, -0.18168745934963226, 0.29668936133384705, 0.22316469252109528, -0.046874210238456726, 0.5483455061912537, -0.5397562980651855, 0.14923037588596344, -0.07543288916349411, 0.1433258354663849, 0.30762308835983276, 0.03807986527681351, -0.09851518273353577, 0.08935370296239853, -0.011364771053195, 0.3461921513080597, -0.10408107936382294, -1.658042550086975, -0.5800697803497314, 0.29757896065711975, 0.5144466757774353, 0.2155575454235077, -0.20143942534923553, 0.5321375727653503, 0.5188344120979309, -0.485002338886261, -0.006649874150753021, -0.24534489214420319, 1.3750696182250977, 0.11334188282489777, 0.09937708079814911, -0.8900991678237915, 0.2861447334289551, -1.2070108652114868, -0.013809475116431713, 0.44310638308525085, 0.4666241407394409, -0.17128205299377441, 0.7762314677238464, 0.44050079584121704, -0.07643231749534607, 0.25986844301223755, -0.11693868786096573, 0.15957501530647278, 0.3210853040218353, -0.09051859378814697, 0.216880664229393, -0.28490734100341797, 0.6873801946640015, 0.08943341672420502, 0.16758444905281067, 0.3113383650779724, -0.1894620805978775, 0.17917589843273163, 1.3295637369155884, 0.21361742913722992, 0.4758121967315674, 0.9290781617164612, 0.5637774467468262, -0.9601523280143738, -0.22803473472595215, 0.637772798538208, 0.022202126681804657, -0.07128117233514786, 0.06832255423069, 0.24109885096549988, 0.20298784971237183, 0.825681746006012, 0.7352378964424133, -0.04136034846305847, 0.6252924799919128, 0.485332727432251, 0.026674503460526466, -0.007261235266923904, 0.01627514325082302, 0.2380923628807068, 0.24506422877311707, 0.04591299593448639, 0.3215133547782898, 0.03264667093753815, 0.09461560100317001, 0.09994446486234665, 0.34760144352912903, 0.03855278715491295, 0.4140065014362335, 0.48846080899238586, -0.39286813139915466, 0.465954065322876, 1.047282338142395, -0.1388331949710846, 0.4601118266582489, 0.02506067231297493, 0.17872105538845062, 0.5218371152877808, 0.5065124034881592, -0.2260442078113556, 0.49813616275787354, -0.26103267073631287, -0.19330446422100067, -0.2705744504928589, 1.4495429992675781, -0.7748972177505493, 0.3660780191421509, -0.32232144474983215, -0.09467878937721252, 1.3964040279388428, -0.26992693543434143, 0.001219038269482553, 0.38226205110549927, -0.09159369766712189, -0.12148729711771011, -0.37192922830581665, -0.7021755576133728, 0.2635011076927185, -0.3211950361728668, 0.04772944003343582, 0.11251407116651535, 0.42348650097846985, 0.5597426295280457, -0.09540707617998123, -0.24654747545719147, 0.017609430477023125, 0.5415802597999573, -0.2510429620742798, -0.6430020332336426, 0.25468093156814575, -0.715648889541626, 0.22561544179916382, 0.21217381954193115, -0.9465939402580261, 0.3484037220478058, 0.29437458515167236, 0.2956562936306, 0.4405251443386078, -0.4616852104663849, 0.3623717725276947, -0.29666417837142944, -0.22637444734573364, -0.14194943010807037, 0.3694900870323181, 0.2181738168001175, 0.20552943646907806, 0.11238432675600052, -0.48532402515411377, -0.03177540749311447, 0.08720125257968903, -1.0634894371032715, -0.4459187984466553, -0.7858465909957886, -0.1962439864873886, -0.2586994171142578, -0.4919901192188263, -0.42885351181030273, -0.35712236166000366, -0.7237943410873413, -0.621320903301239, 0.6514418125152588, 0.2236916422843933, -0.04443516209721565, -0.0507766455411911, 0.23462681472301483, -0.31331953406333923, 0.21435372531414032, -0.021412018686532974, 0.10089347511529922, 0.052152711898088455, 0.4797101318836212, 0.5949156284332275, 0.3569996953010559, -0.3568144142627716, 0.11108875274658203, -0.15833868086338043, 0.1716674417257309, -0.028823979198932648, 0.40088632702827454, -0.21420198678970337, 0.021234286949038506, 0.7806640863418579, 0.4178054928779602, -0.41007399559020996, -0.7545096278190613, -0.1616469770669937, -0.5325844287872314, 0.13859733939170837, 0.1779581904411316, 0.8360463380813599, 0.12384699285030365, -0.985977053642273, -0.5265359878540039, 0.4738330543041229, -0.4858672320842743, 0.7536311745643616, -0.10895966738462448, -0.4348907172679901, -0.17143559455871582, 0.4133155643939972, 0.5534799098968506, 0.39952781796455383, 0.29157939553260803, 0.33432528376579285, -0.03800761327147484, -0.335641086101532, -0.016093784943223, -0.21663549542427063, 0.02955702133476734, -0.04804649204015732, 0.3204461634159088, -0.10283633321523666, -0.16470353305339813, -0.7553263902664185, -0.1102384477853775, -0.028976479545235634, -0.37584805488586426, -0.17569120228290558, 0.3171806335449219, -0.12495873123407364, -0.12798912823200226, -0.10913816839456558, 0.001881069503724575, -0.32313042879104614, 0.39806538820266724, -0.024187946692109108, -0.49395909905433655, -0.3744489848613739, -0.086061991751194, -0.03133168816566467, 0.5276206135749817, 0.19843141734600067, 1.655329942703247, 0.10769341886043549, -0.7994576096534729, 0.3652896583080292, 0.26385968923568726, 0.8088082075119019, -0.26134636998176575, 0.3614804744720459, 0.0026642854791134596, -0.022877106443047523, 0.08561666309833527, -0.455078125, 0.11680550873279572, -0.3833141326904297, 0.03735514357686043, 0.14713193476200104, -0.8560016751289368, -0.06053502857685089, 0.20557580888271332, -0.1208224967122078, 0.42280855774879456, 0.700893223285675, 0.3942282795906067, -0.08091989904642105, -0.818788468837738, 0.03674992173910141, -0.040003612637519836, 0.6681044697761536, 0.0018703602254390717, -0.19888471066951752, 0.17389798164367676, 0.1903211772441864, -0.2288874089717865, 0.030447034165263176, 0.14301829040050507, 0.34910064935684204, -0.17166449129581451, -0.157138392329216, 0.23043416440486908, -0.2695419192314148, 0.25305673480033875, 0.19429081678390503, 0.3409810960292816, -0.29869598150253296, 0.22756171226501465, -0.7482315301895142, 0.2061992734670639, -0.09394602477550507, 0.19422540068626404, 0.08706046640872955, -0.23273253440856934, 0.168768048286438, 0.8546248078346252, -0.31819671392440796, 0.30452489852905273, -0.3264661431312561, 0.17713795602321625, 0.21495342254638672, 0.27918484807014465, -0.2703573703765869, 0.15500064194202423, -0.7909595966339111, 0.48447805643081665, 0.5127758979797363, 0.04024636000394821, -0.1494978666305542, 0.08700307458639145, 0.04309271648526192, -0.2468118667602539, -0.24065440893173218, -0.0691058486700058, -0.2756150960922241, 0.30191537737846375, -0.050963059067726135, 0.017425348982214928, 0.07124324887990952, -0.7836359143257141, -1.0958093404769897, -0.12265366315841675, -0.1585550457239151, 0.7360341548919678, 0.14176349341869354, -0.10647843033075333, -0.8339970111846924, 0.12965865433216095, -0.2447720617055893, -0.4799516499042511, 0.5307968258857727, -0.1548018604516983, -0.15722432732582092, -0.2731895446777344, -0.18699178099632263, 0.06258853524923325, -0.8415037989616394, -0.5976868271827698, -0.0829162746667862, 0.3899247646331787, 0.10498609393835068, 0.9713709950447083, -0.9903234839439392, 1.4983406066894531, -0.2185114622116089, 1.4387505054473877, -0.8319363594055176, -1.1281460523605347, 0.18039099872112274, 1.1697182655334473, 0.9996577501296997, -0.07170785963535309, 0.5880172252655029, 0.05810795724391937, 0.028376346454024315, -0.090826116502285, 0.7738207578659058, 0.3737747073173523, -0.08811156451702118, -1.2314265966415405, -1.0370457172393799, -1.1881372928619385, 0.058977000415325165, 0.8118703365325928, -0.42228105664253235, -0.2895980477333069, -0.49769818782806396, -0.15249398350715637, 0.6172648072242737, -0.09662850946187973, 0.0029938139487057924, -0.41837629675865173, 0.38079512119293213, -0.18547974526882172, -0.7603414058685303, 0.4595540165901184, 1.752930998802185, 2.4201533794403076, -0.7176987528800964, -0.4706166982650757, -0.4609907865524292, 0.3883000910282135, 1.2364901304244995, 0.5420698523521423, -0.14601901173591614, -0.3261716067790985, 0.038190800696611404, -0.0291155893355608, -0.11360963433980942, -0.5089297294616699, -0.26733145117759705, -0.2673296332359314, -0.19497530162334442, 1.2172951698303223, -0.5172461867332458, -0.8472481966018677, 0.08697324246168137, 0.20421797037124634, 0.11309251189231873, -0.5381184220314026, -0.9362198114395142, -0.05213046073913574, -0.044631049036979675, 0.22288788855075836, -0.4126744270324707, -0.12188591063022614, -0.2458852082490921, -0.7388745546340942, -0.18608394265174866, -1.0377542972564697, 0.24955807626247406, 1.410009503364563, 0.44049543142318726, -1.2454246282577515, -0.5515555739402771, -0.5101764798164368, -5.38986349105835, 0.04719949886202812, -0.18384245038032532, 4.804245471954346, -0.17618481814861298, -0.5978720784187317, -1.3073124885559082, 1.4111433029174805, 0.09480690956115723, 1.0380247831344604, -0.8112629652023315, -0.17253132164478302, 1.2562475204467773, 0.3821713924407959, 0.6278160214424133, -0.3068072497844696, 0.97926265001297, 0.08912307024002075, 0.27225223183631897, -0.4522526264190674, 0.511178195476532, 0.34766191244125366, 0.3586307466030121, 0.6134337782859802, -0.23834294080734253, 0.5413486957550049, 0.008972925134003162, -1.0473653078079224, -1.0432108640670776, 0.8404743075370789, 0.49255192279815674, -0.6988464593887329, -1.1627403497695923, -0.1356705129146576, 0.5303474068641663, 0.26340991258621216, -0.1295272558927536, -0.11509327590465546, 0.005420875735580921, -0.8896020650863647, -1.2240897417068481, -1.2903869152069092, -0.5904495716094971, 2.2226076126098633, 1.6679325103759766, -0.7417917251586914, -2.1582281589508057, -3.8084969520568848, -5.291167259216309, -3.2410202026367188, -4.38557243347168, -3.5651650428771973, -2.8222856521606445, -3.6189351081848145, -3.558319568634033, 3.9501848220825195, 4.535614967346191, 3.346848964691162, 3.410242795944214, 4.544981002807617, 4.169620990753174, 4.017064094543457, 3.556389331817627, -0.019580818712711334, -0.23802310228347778, 0.2730100750923157, 0.020784109830856323, 0.05912703275680542, 0.27372169494628906, 0.4105243682861328, -0.34628623723983765, 0.30541545152664185, -0.16762986779212952, -1.128360390663147, -0.028728831559419632, -0.29101645946502686, 0.09743201732635498, 0.09877655655145645, 0.08101104199886322, 0.5818601846694946, -0.06806988269090652, 0.06680646538734436, -0.031195519492030144, 0.3234189748764038, 0.5971579551696777, 0.5150923728942871, -0.8471162915229797, 6.5225749015808105, -0.16600246727466583, 2.132788896560669, -0.08108922094106674, 6.630303382873535, 9.791550636291504, 10.29746150970459, -1.4739247560501099, 0.10277115553617477, 1.4780832529067993, -0.06944442540407181, -3.0032923221588135, -0.620707094669342, 0.01722274161875248, 0.13400065898895264, 0.20198601484298706, 0.24550239741802216]} -------------------------------------------------------------------------------- /Utils/Models/BossLSTM-1x16.nam: -------------------------------------------------------------------------------- 1 | {"version": "0.5.1", "metadata": {"date": {"year": 2023, "month": 5, "day": 29, "hour": 15, "minute": 55, "second": 21}, "loudness": -11.380825996398926, "gain": 0.6450519594674613}, "architecture": "LSTM", "config": {"input_size": 1, "hidden_size": 16, "num_layers": 1}, "weights": [0.3484101891517639, 0.5105561017990112, -0.6521242260932922, 0.30968648195266724, 0.07760696113109589, 0.031766630709171295, 0.46922752261161804, 0.01946133002638817, -0.8320902585983276, -0.4131940007209778, -1.2141033411026, -0.11121901869773865, -0.21513739228248596, 0.8232176303863525, -1.442731499671936, 0.11033237725496292, -1.06989324092865, 0.5846874713897705, -0.055905766785144806, -0.04594077914953232, 0.4146239757537842, -0.07919736951589584, 0.0671318918466568, 0.5204212069511414, 0.2465922236442566, 0.2925594449043274, -0.21610428392887115, -0.889915406703949, 0.5810080766677856, 0.6259633898735046, 0.3383239805698395, 0.19544069468975067, 0.6782737970352173, -0.48647090792655945, -1.2707005739212036, 0.32085907459259033, 0.10060957819223404, 0.12363062798976898, 0.18008042871952057, 0.3501366972923279, -0.41351935267448425, -0.13002613186836243, 0.031206922605633736, -0.5309377908706665, -0.8361729979515076, 0.2917969226837158, -0.42454808950424194, -0.02615172043442726, 0.9115915894508362, -0.5479323863983154, 0.4358704388141632, -0.20025503635406494, -0.23401230573654175, -0.1953018307685852, 0.4519599974155426, 0.0789191722869873, 0.020969979465007782, -0.2558274269104004, 0.29931730031967163, 0.10711414366960526, -0.06631430983543396, 0.32983696460723877, -0.2542092204093933, -0.4838678240776062, -0.3884270489215851, 0.2051224559545517, 0.03540785238146782, -0.5886015892028809, -0.4006824195384979, -0.35506671667099, -0.1321190446615219, -0.519497811794281, 0.31297799944877625, 0.30327171087265015, 0.54744553565979, 0.500339150428772, 0.49252641201019287, 0.632925808429718, -0.25719523429870605, -0.3542245328426361, 0.3113436698913574, 0.31936001777648926, 0.7130799293518066, -0.004324308130890131, -0.33766278624534607, -1.5350875854492188, 0.1755293756723404, 0.0822896882891655, -0.006909198593348265, -0.46510598063468933, 0.2623039484024048, -0.07669112086296082, -1.23306405544281, 0.20335803925991058, 0.019195305183529854, 0.6944811940193176, -1.0629544258117676, 0.22606448829174042, -0.02629987522959709, -0.025560660287737846, 0.6602290272712708, 0.16847677528858185, -3.2035398483276367, -1.0918532609939575, -0.6270332932472229, -0.35456278920173645, 0.6762378215789795, 0.44779038429260254, -0.2187943458557129, -0.4552685022354126, 1.080268383026123, -0.3432568907737732, -0.8007712364196777, 0.4868764877319336, 0.3350440263748169, 0.9767473936080933, 1.1106479167938232, -0.7540839314460754, -0.04689498618245125, -0.12816208600997925, -0.8366533517837524, 0.007669738959521055, -0.28936412930488586, -0.8607317209243774, 0.6463227272033691, 0.5038443803787231, 0.18344883620738983, -0.13467222452163696, 0.5436795949935913, 0.3782884180545807, -0.3699902892112732, -1.0062496662139893, -0.8655653595924377, 1.1568375825881958, -1.000720739364624, 0.2724042534828186, 0.7657566070556641, -0.4358727037906647, -0.0345037505030632, -0.33781975507736206, -0.061009444296360016, -0.09751921892166138, 0.3515334725379944, 0.18251343071460724, -0.07576733827590942, 0.14787907898426056, -0.1470373570919037, -0.4499521553516388, -1.6152757406234741, -0.4345138370990753, 0.8529583215713501, -0.29912084341049194, -0.05639272555708885, 2.236205577850342, -0.7458056211471558, 0.21005675196647644, 0.3468616306781769, 0.12850618362426758, 0.484259694814682, -0.07051467150449753, 0.9897544384002686, -0.47394439578056335, -0.7372322082519531, -0.621234655380249, -0.6879029273986816, 0.7154707312583923, 0.8771488666534424, 3.2394185066223145, -0.015461958944797516, -0.865206241607666, 0.5257376432418823, -0.8410098552703857, 0.39018604159355164, -0.618260383605957, 0.019843513146042824, 0.6603925824165344, 0.11968820542097092, 0.0214220080524683, 0.40068140625953674, 0.47566699981689453, 0.49927574396133423, 0.0573393777012825, -0.15025973320007324, -0.053776681423187256, 0.6139369010925293, -1.0407142639160156, 0.15197673439979553, -2.782865524291992, -1.036817193031311, 0.9426116943359375, -1.3743937015533447, -1.1407605409622192, 1.6845570802688599, 0.31216567754745483, 0.5851746797561646, -0.462094783782959, 0.8566258549690247, -2.0312023162841797, -3.794018268585205, 2.2540805339813232, -0.32639414072036743, -1.7209911346435547, -1.517181396484375, -0.16192907094955444, -0.43750301003456116, -0.25652748346328735, -0.04787857457995415, -0.17757143080234528, -0.32068929076194763, 0.2660008668899536, -0.10636503994464874, -0.048313792794942856, 0.42886224389076233, 0.06081067770719528, -1.115899682044983, -0.6797705292701721, 0.4345826208591461, 0.31719470024108887, -0.29284152388572693, -0.024734413251280785, -0.2437664270401001, -1.7490227222442627, -0.7890762686729431, 0.7533875703811646, -1.1643023490905762, -0.4343752861022949, 0.4412716329097748, -0.27478092908859253, 0.7059522271156311, -0.6866459846496582, 2.1067137718200684, -2.021009922027588, -2.2475779056549072, -1.0485968589782715, -0.2149520069360733, -1.797800898551941, -3.4409029483795166, -1.0181246995925903, -0.341795414686203, -0.15428699553012848, -0.2717163860797882, -0.34784236550331116, 0.24583813548088074, 0.48595622181892395, -0.3607828617095947, 0.01780891604721546, 0.3571164608001709, 0.07089874893426895, -1.7436738014221191, -0.24690701067447662, -0.39677372574806213, -0.013971129432320595, -0.45923176407814026, 0.1289873719215393, -0.2457243949174881, 0.26570361852645874, -0.0466175302863121, 0.22383083403110504, -0.20677465200424194, 0.07228552550077438, 0.1696920096874237, 0.26821598410606384, -0.30798307061195374, -0.16338808834552765, 0.027609657496213913, 0.11075711250305176, 0.13545653223991394, -0.35940271615982056, -0.4258361756801605, -0.5171549320220947, 0.09750813245773315, 0.31824618577957153, 0.5045159459114075, 0.6275054216384888, 0.2106163054704666, -0.24053016304969788, 0.5640103220939636, -0.08919933438301086, 0.6487302184104919, 0.08515439182519913, -0.2220970094203949, -0.21823206543922424, -0.25408250093460083, -0.2149268090724945, 0.32826292514801025, 0.3722354471683502, -1.6476309299468994, -0.09036318957805634, 0.4350115656852722, -0.062185801565647125, -0.22082778811454773, 0.919455885887146, 0.02105332911014557, 0.6021004915237427, 0.6078506708145142, 0.806546151638031, 0.49559783935546875, 1.1790599822998047, 0.15803003311157227, -0.10836096853017807, -0.10140001028776169, 0.6953121423721313, -0.42874330282211304, -0.8262129426002502, -0.013267423026263714, 0.5906112790107727, -1.3367141485214233, 1.003528356552124, 0.45286428928375244, 1.0427281856536865, -0.05124735087156296, -0.7838799357414246, -0.6752508878707886, -1.0096429586410522, -0.513310968875885, 0.022394808009266853, -0.30734559893608093, 0.9263051152229309, -0.4619794189929962, -0.3661165237426758, 0.752799928188324, 0.5964374542236328, 0.40083593130111694, 0.29837676882743835, -0.7297117114067078, 0.16390562057495117, -0.12580934166908264, -0.06521683186292648, -0.22813363373279572, -0.2989250123500824, -0.11750964820384979, 0.09728730469942093, 0.39848992228507996, 0.2371625453233719, 0.40957456827163696, 0.09119249880313873, -0.20820967853069305, 0.929527997970581, -0.22928529977798462, 0.07671676576137543, 0.08486473560333252, -0.24519743025302887, 0.464581161737442, -0.5921655893325806, 0.44574788212776184, 0.43975070118904114, 0.5128680467605591, 0.1855873465538025, 0.4626040458679199, 0.7678274512290955, -0.34667932987213135, -0.6710116267204285, 0.14385299384593964, 0.2565489709377289, 0.23326361179351807, -0.4831509590148926, 0.048631247133016586, -0.6045595407485962, -0.35670241713523865, -0.17724992334842682, -0.7454608678817749, 1.4692069292068481, 0.9896391034126282, -0.3446374237537384, 1.192663311958313, 0.983710765838623, -0.2022216022014618, -0.7123183012008667, -1.4267388582229614, 0.8582916855812073, 0.6709529161453247, 0.3025072515010834, -0.8719998598098755, -0.34138527512550354, -2.3003311157226562, -0.5322820544242859, 0.17552484571933746, -0.3729799687862396, 0.6177693009376526, -0.20992740988731384, -0.9144709706306458, -0.2904992699623108, 0.21337582170963287, 0.18019132316112518, -0.20214614272117615, 0.36435666680336, -0.5947766304016113, -0.12046311050653458, 0.3922857344150543, -0.7724848985671997, -0.2734171748161316, 0.023984385654330254, 0.12223757803440094, 0.32681411504745483, -0.06670500338077545, -1.6912355422973633, 0.23424826562404633, -0.25958800315856934, 0.011359703727066517, -1.0205427408218384, -0.040664415806531906, 0.06530975550413132, -0.2666968107223511, -0.41173404455184937, -0.7551572322845459, -0.7241592407226562, -0.5417535305023193, 0.44803646206855774, 0.6507446765899658, -0.14291912317276, -0.5038678050041199, 0.09449898451566696, 0.5026273727416992, 0.5418733954429626, 0.5172584056854248, 0.685240626335144, 0.47220051288604736, -0.3522146940231323, -0.010143669322133064, -0.2222520411014557, -0.5588194131851196, -0.09010699391365051, 0.21122398972511292, -0.309023380279541, -0.6213817000389099, -1.0601882934570312, -0.8581415414810181, 0.7623887062072754, -0.32268375158309937, -0.40407440066337585, 0.09809516370296478, 0.05833250284194946, -0.048834413290023804, 0.7548672556877136, 0.2125454694032669, 0.17291153967380524, 1.6962428092956543, -1.2464808225631714, -0.542583167552948, 2.5496582984924316, -0.8038309812545776, 0.48572900891304016, 0.13413482904434204, -0.2240782082080841, 0.2973800003528595, -0.335083931684494, 0.28029948472976685, -0.047644201666116714, 0.6303945779800415, 0.5256865620613098, -0.6639432907104492, 0.5800981521606445, 0.31045207381248474, 0.4168247878551483, -0.8239734768867493, 0.024535691365599632, 0.9570388197898865, -0.7934459447860718, -0.07921166718006134, -0.06346268206834793, 0.5305784344673157, -0.13116371631622314, 1.0497785806655884, -0.15281739830970764, -0.1031624972820282, -0.2345322221517563, -0.521263599395752, -0.1943845897912979, -0.03477266803383827, -0.2934368848800659, -0.003527236171066761, -1.4024587869644165, -0.13608905673027039, 0.030916579067707062, 1.1045936346054077, 0.811694860458374, 0.8795294165611267, -0.38496941328048706, -0.26913028955459595, 0.23571565747261047, -0.11107571423053741, -0.015605548396706581, -0.20399963855743408, 0.018911516293883324, 0.13160692155361176, 0.144415020942688, -1.288705825805664, -0.1605357527732849, -0.34907352924346924, -0.04457477852702141, -0.1336873173713684, -0.007835940457880497, -0.5216212272644043, 0.2962411642074585, 0.5039039850234985, -0.2360582798719406, 1.1781039237976074, 0.9765028357505798, 0.020647818222641945, -1.0598257780075073, -1.2073107957839966, -0.4772663712501526, -0.3551301658153534, -2.026804208755493, 2.1395814418792725, 0.2957276701927185, -0.03691912814974785, -1.7144207954406738, 0.9648077487945557, -0.44562721252441406, -0.611819326877594, -0.025608310475945473, -0.39007675647735596, 0.16507647931575775, 0.6693673729896545, -0.008243946358561516, 0.1303592026233673, -0.08831558376550674, -0.007839898578822613, -0.24994131922721863, -1.7465392351150513, 0.2013043761253357, 0.01598738506436348, 0.37914779782295227, 0.27225783467292786, 0.8186196088790894, -0.7261500358581543, 0.6145806312561035, -0.4254467487335205, 0.4337250888347626, -0.8242762684822083, 0.44179990887641907, 0.38344982266426086, 0.664584755897522, -0.07223410904407501, 0.5293589234352112, 0.2518945634365082, 0.4748225510120392, -0.33975130319595337, 1.1354594230651855, -0.2011827975511551, -1.0464190244674683, -0.058005087077617645, 0.580771267414093, -0.8032784461975098, 0.33893853425979614, 0.07544441521167755, 0.1817418783903122, -0.5579062700271606, -0.24658891558647156, -0.2541451156139374, 0.36824509501457214, -0.6835192441940308, 0.5489999055862427, 0.5045948028564453, -0.06515420973300934, -0.04684234410524368, 0.21707846224308014, 0.28008756041526794, 0.3886902332305908, -0.025680797174572945, -0.39549756050109863, 0.19350533187389374, -0.030667399987578392, -0.19091258943080902, 0.4446330964565277, -0.3004043996334076, -0.42571452260017395, 0.4006305932998657, 0.3657592833042145, 0.30400481820106506, -1.3490444421768188, -0.2528427243232727, 0.5289279222488403, 0.11808022111654282, -0.1150927022099495, 0.1557602882385254, -0.5254167914390564, -0.6832166314125061, -0.7406245470046997, -0.12991639971733093, 0.04909475892782211, -0.6862548589706421, -0.0038719559088349342, 0.09396084398031235, 0.0612819530069828, -0.044938813894987106, -0.27086445689201355, 0.9525604248046875, 0.525234043598175, -0.5187637209892273, -0.4275374412536621, 0.3469579219818115, 0.09768369793891907, -0.11407745629549026, -0.4388177990913391, -0.2547149956226349, -0.06746823340654373, 0.26001355051994324, -0.1437559872865677, -0.2126949280500412, -0.16988298296928406, 0.34486323595046997, 0.26343220472335815, 0.4200194180011749, 1.0809385776519775, -0.005217230413109064, -0.17216333746910095, -0.1625595986843109, 0.5847181081771851, -0.31848230957984924, -0.051062989979982376, -0.31494495272636414, -0.46072593331336975, 0.0627337396144867, -0.2497982680797577, 0.26895397901535034, 0.13416577875614166, 0.289431631565094, -0.08173184096813202, 0.4522799551486969, 0.41211581230163574, -0.210021510720253, -0.24596184492111206, -0.05822106823325157, 0.2576873004436493, -0.06651349365711212, -0.6510061621665955, -0.3238816559314728, -0.6850706338882446, -0.000605949608143419, 0.33755213022232056, -0.2350059151649475, 0.21026791632175446, 0.32810500264167786, -0.1495385617017746, -0.08937587589025497, 0.1433408558368683, -0.12192850559949875, -0.03776302561163902, -0.8834924697875977, 0.4382033348083496, 0.2355625331401825, -0.6335943341255188, -0.06538235396146774, 0.05474463105201721, -0.03185056895017624, -0.2442368119955063, -0.5362632274627686, 0.009637979790568352, -0.08096521347761154, -0.34606704115867615, 0.2253091186285019, -0.5593509674072266, 0.22097612917423248, -0.12439977377653122, -1.9678764343261719, -0.06674421578645706, -0.9324021339416504, 0.47746095061302185, 1.7182501554489136, -0.30800288915634155, -0.5831891894340515, -0.2795625627040863, -0.09181080013513565, 0.5716556906700134, -0.6625648736953735, 0.20668049156665802, 0.9577779173851013, 1.0589600801467896, 0.054692015051841736, 0.08959466218948364, 0.8149865865707397, 0.30602046847343445, -0.3771093785762787, 0.37860947847366333, -0.3536452353000641, 0.28691020607948303, -0.6528683304786682, 0.5587955117225647, 0.25675156712532043, -0.6186860799789429, -0.07527332007884979, -0.13356897234916687, 0.2073056548833847, 0.08899589627981186, 0.054006628692150116, 0.21533510088920593, 0.49456027150154114, -0.40044060349464417, -0.27841252088546753, 0.32352215051651, 0.6645329594612122, -0.24496948719024658, 0.9175650477409363, 0.03604792430996895, 0.16764657199382782, 0.8106833100318909, 0.0038818062748759985, 0.10773982107639313, -0.047013379633426666, 0.23468904197216034, -0.19034215807914734, -0.46199044585227966, -0.09266763925552368, 0.1571083515882492, 0.6416624188423157, 0.5184416770935059, 0.6606107950210571, -0.05101492255926132, -0.3301143944263458, 1.8640493154525757, 0.09486143290996552, 0.31083032488822937, -0.0006054283585399389, 0.30347028374671936, -0.30168816447257996, 0.4842640459537506, -0.4156872034072876, -0.8743526339530945, 0.001053522457368672, 0.2101888358592987, -0.331723153591156, -0.47353383898735046, 0.3284011483192444, 0.4647556245326996, 0.21869483590126038, 0.04563869535923004, -0.1709585338830948, 0.5408281087875366, -0.08222388476133347, -1.2381298542022705, 0.17388394474983215, 0.05977876856923103, 0.08318638056516647, 0.3979809582233429, 0.19421112537384033, -0.2023194581270218, -0.022978588938713074, -0.6946120858192444, 0.006002658512443304, 1.229379653930664, -1.448732852935791, 0.9329668283462524, 0.760308027267456, -1.9785784482955933, 0.09389811754226685, 0.315694123506546, -0.01784209907054901, -0.13536302745342255, -0.31269899010658264, 0.692367672920227, -0.40249302983283997, -0.15520179271697998, -0.4296306073665619, 0.32894474267959595, -0.3596150875091553, -0.03743670880794525, 0.18019899725914001, 0.6215844750404358, 0.012529981322586536, -0.07099387794733047, 0.38912880420684814, 0.10896217077970505, -0.20927947759628296, -0.4533209800720215, -2.516922950744629, 0.18414390087127686, 0.7887603640556335, -2.9203414916992188, 0.11358073353767395, 0.5522065758705139, -0.33829453587532043, 0.12295270711183548, 0.3820125162601471, -1.086085557937622, -0.519496500492096, 0.20825374126434326, -0.699958324432373, 0.12282107025384903, 0.28133028745651245, -0.3767646551132202, -0.3138076066970825, 0.5444003343582153, 0.23476797342300415, 0.40847158432006836, -1.1250767707824707, -0.3526707887649536, 0.07255128026008606, 0.38003432750701904, -0.6293864250183105, 0.24509695172309875, 1.6824381351470947, 0.18970659375190735, -1.284271478652954, -0.13794735074043274, -0.3288949131965637, -0.36221131682395935, 0.28749164938926697, -0.3070486783981323, 0.11701855063438416, 0.4242471158504486, -0.4291515648365021, -0.08676398545503616, 0.33913472294807434, -0.422503799200058, 0.004717565607279539, 0.12154427915811539, 0.3967929780483246, 0.10630839318037033, -0.10952626168727875, -0.1977434605360031, -0.3926035463809967, 0.21922971308231354, 0.009846360422670841, 0.3461408317089081, -2.7053778171539307, -1.190564513206482, -0.11063037067651749, 0.017811816185712814, -2.435145139694214, 0.024653617292642593, 0.7098836898803711, 0.42952150106430054, 0.03096058778464794, -0.06678041815757751, -0.9430890679359436, 0.36104342341423035, -0.11457698047161102, 0.09450740367174149, -0.5555627346038818, -0.15444257855415344, -0.4672451317310333, 0.5026847124099731, -0.2079974114894867, 0.31923091411590576, 0.45930519700050354, 0.9817993640899658, -2.4672229290008545, 0.058138567954301834, 0.6087337136268616, -1.7597992420196533, 0.13004305958747864, -0.8534761667251587, 0.8576120138168335, -1.7484086751937866, -0.18950098752975464, -0.020518817007541656, -0.7481975555419922, -0.8196483254432678, 2.2756314277648926, 1.5338728427886963, 0.34635934233665466, -0.39038926362991333, 2.3130462169647217, -0.8106920123100281, -0.775137186050415, 1.1438539028167725, -0.6875633597373962, -0.5610420107841492, -1.2449578046798706, 0.49831604957580566, 0.018036263063549995, 0.7593830227851868, 0.6135480999946594, -0.1732514351606369, -0.34126055240631104, 3.158505439758301, -0.00922243669629097, 0.10119210928678513, -0.2999863922595978, 1.4278212785720825, 0.8167422413825989, 0.25187864899635315, 0.4336368143558502, 0.5061838626861572, 0.9248441457748413, 1.5239286422729492, -0.10742964595556259, 0.16892796754837036, -0.13104203343391418, 0.006745859049260616, -0.2589905261993408, 1.1919440031051636, 0.19814372062683105, 0.3521653413772583, -0.4560179114341736, -0.2585756480693817, -0.5949417352676392, 1.1060432195663452, -0.45483970642089844, -0.13043378293514252, 0.8851266503334045, -0.29998695850372314, 0.6035560369491577, -0.338365375995636, 0.9351630806922913, 0.7029162049293518, 0.5546512603759766, 1.7496304512023926, 0.8888721466064453, 0.26760557293891907, -0.5850768685340881, 0.6944006085395813, 0.1488923877477646, 0.17499515414237976, 0.6781788468360901, 1.1193474531173706, 0.7972050309181213, 0.46191757917404175, 0.8947229981422424, -0.2691316306591034, -0.40006014704704285, -0.1961064338684082, -0.4772369861602783, -0.14214454591274261, -1.077415943145752, -0.015200993046164513, -0.06819498538970947, 1.5106602907180786, -0.0718601644039154, -0.05608192831277847, 1.693564772605896, -0.6604170799255371, -0.8320456147193909, 1.3691766262054443, -0.7086248397827148, -0.29536014795303345, -0.6574450731277466, 1.2251054048538208, -1.957575798034668, 1.184716820716858, 0.17844368517398834, -0.09682560712099075, 0.37822389602661133, 0.8366237878799438, -0.9581413269042969, -0.6485810875892639, -0.5565148591995239, -1.567938208580017, 2.261594772338867, 0.4589138925075531, -1.5633482933044434, 1.6096752882003784, -0.4456193149089813, 0.43363091349601746, -0.48328959941864014, 1.3339282274246216, -0.019816242158412933, 0.935255229473114, 1.7788536548614502, 0.1902131736278534, 0.2751774787902832, -0.7057653665542603, 0.537734866142273, 0.6110764741897583, 0.6683136820793152, 0.10535459220409393, 1.3178225755691528, 1.3828535079956055, 0.33679714798927307, 1.3444691896438599, 0.1386357694864273, -1.0135831832885742, 1.2135610580444336, -0.8433626294136047, -0.03872787952423096, -1.433955430984497, -0.6282625794410706, 2.5873937606811523, 0.10824958235025406, 0.5094051957130432, -1.0547176599502563, 0.36293160915374756, -1.146419882774353, -0.46619826555252075, -0.760664165019989, 0.12042198330163956, 0.40440723299980164, 0.2809875011444092, -0.40208789706230164, 0.16985556483268738, -1.2774138450622559, 0.8596258163452148, -0.09108488261699677, 0.16485801339149475, -0.5176597237586975, 1.5061253309249878, -0.4615687429904938, 0.21223770081996918, 0.39008575677871704, 0.8964657187461853, -0.43366897106170654, 0.1698785126209259, -0.4728669226169586, -0.04495374113321304, 0.33647266030311584, -0.9282230734825134, 0.4094870686531067, 0.7590768337249756, -3.225501537322998, 0.7126359343528748, 0.6587256789207458, 0.4215548038482666, 0.055544979870319366, -0.5057477355003357, -0.18813075125217438, -0.13369403779506683, 1.243740439414978, 0.01611297018826008, 0.42144539952278137, 0.13899630308151245, -0.006558433175086975, -2.4236738681793213, -1.5537266731262207, -0.3140948414802551, 0.5486692786216736, 1.4590293169021606, -1.1421284675598145, -1.0449634790420532, 0.9125984907150269, 0.2183346003293991, 0.3874940574169159, -0.22984308004379272, 0.13040561974048615, -0.48631757497787476, -0.22091498970985413, 0.7827465534210205, -0.8134075403213501, 0.5521605014801025, -1.273236870765686, 0.40134698152542114, -0.31557121872901917, -0.1913883090019226, 1.0071377754211426, -0.3538486957550049, 0.06333928555250168, 0.20849919319152832, -1.16081702709198, 1.3668427467346191, -1.7283233404159546, 0.49973270297050476, 1.0298717021942139, 0.8657426238059998, 1.2357615232467651, 0.929039716720581, 2.0519943237304688, -0.764573335647583, -1.0617293119430542, -0.26160576939582825, -0.30174344778060913, 0.07751428335905075, -4.278489112854004, 0.19638097286224365, 0.08805806189775467, 0.8478558659553528, 0.7250784039497375, 0.39159801602363586, 0.5441452264785767, -1.4579510688781738, -0.2949789762496948, 1.3015276193618774, -1.2954819202423096, 0.07039386034011841, -1.1653711795806885, 0.2938552796840668, -0.40639743208885193, -0.25175851583480835, -0.2298138588666916, -1.6715145111083984, 0.17504312098026276, -0.9852495193481445, 0.2957437336444855, -0.09149981290102005, -0.2906808853149414, -0.4610590934753418, -1.202615737915039, -1.5308105945587158, -0.19344262778759003, -0.8481433987617493, -0.6274411082267761, 0.48310795426368713, 0.3838958740234375, -0.6878030300140381, -0.01113041676580906, -0.03763768821954727, -0.08085386455059052, -0.23858410120010376, -4.052666664123535, -5.419669151306152, -3.340925693511963, -4.174272060394287, -3.4418210983276367, -4.647164344787598, -3.307584762573242, -2.2166049480438232, -4.119994163513184, -5.028444766998291, -2.9114348888397217, -0.6923954486846924, -3.9491891860961914, -0.5002360343933105, -3.3893370628356934, -3.8889379501342773, 3.875833511352539, 4.052119255065918, 2.941344738006592, 4.603815078735352, 4.882518291473389, 4.852052688598633, 3.9608144760131836, 3.949268341064453, 3.977647304534912, 5.037757873535156, 4.487565040588379, 2.185215473175049, 4.166187286376953, 2.0988211631774902, 3.5249228477478027, 4.033005714416504, -0.7432068586349487, 0.13463380932807922, -0.8519880771636963, 0.7828671932220459, 0.4705842137336731, 0.013415291905403137, -0.030551377683877945, 1.155907154083252, 0.5723925828933716, 0.005291074514389038, -0.6657510995864868, -0.2913699746131897, -0.2871006727218628, 0.3975200951099396, -0.2748500108718872, 0.33762943744659424, 0.9164924025535583, -0.29365769028663635, -0.4134483337402344, 0.6103003025054932, -1.0854606628417969, 1.3828438520431519, -1.5559470653533936, 1.0911431312561035, 1.4037458896636963, 0.6099805235862732, -1.3021076917648315, -0.5477231740951538, -0.2590363621711731, 3.169711112976074, -0.26377707719802856, -0.8378516435623169, -0.35707026720046997, 0.4847942888736725, -0.024858687072992325, 0.8631450533866882, 0.04117744415998459, 0.8672158718109131, -0.06651894003152847, 0.453453004360199, 0.9259830713272095, 0.0019477881724014878, -0.13770022988319397, -0.04903797805309296, -0.3512464165687561, -0.27797821164131165, -0.3510986268520355, 0.024373479187488556, -1.0312258005142212, 1.2563472986221313, -0.08360517024993896, 1.433483362197876, 120.96049499511719, 1.3541803359985352, -1.9520033597946167, 3.098644971847534, 1.6493511199951172, 0.002391512505710125, -56.482723236083984, -0.1626344472169876, -1.1465449333190918, -0.28551214933395386, -0.8443914651870728, 10.978757858276367, 0.34756264090538025, -1.0233991146087646, 0.3987221121788025, 1.6070929765701294, -0.4243023097515106, -0.06921444088220596, 0.4616783559322357, 0.13539570569992065, 0.202493816614151, -2.470529556274414, 0.05458962917327881, 0.05335228145122528, 0.26100459694862366, 0.05413813143968582, 0.3592208921909332, -0.5942432880401611, -0.6352035999298096]} --------------------------------------------------------------------------------