├── .clang-format ├── .github └── workflows │ ├── build.yaml │ └── release.yaml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── bin └── build.sh ├── cmake └── MakePackage.cmake ├── compile_commands.json ├── extras ├── iir-modal.maxpat └── occupancy_map.png ├── package-info.json.in └── src ├── common ├── test_torchwrapper │ ├── CMakeLists.txt │ └── main.cpp └── torchwrapper │ ├── CMakeLists.txt │ ├── include │ ├── log.h │ └── model.h │ └── model.cpp └── maxmsp ├── encoder ├── CMakeLists.txt ├── encoder.cpp └── encoder.maxhelp ├── fc ├── CMakeLists.txt ├── fc.cpp ├── fc.maxhelp └── fc_test.cpp └── filterbank_tilde ├── CMakeLists.txt ├── filterbank_tilde.cpp ├── filterbank_tilde_test.cpp ├── filterbank~.maxhelp └── twoPole.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | SortIncludes: false 4 | AlignEscapedNewlines: Left 5 | AllowShortBlocksOnASingleLine: true 6 | AllowShortCaseLabelsOnASingleLine: true 7 | AllowShortFunctionsOnASingleLine: Inline 8 | AllowShortIfStatementsOnASingleLine: true 9 | AllowShortLoopsOnASingleLine: true 10 | AllowAllParametersOfDeclarationOnNextLine: false 11 | AllowAllArgumentsOnNextLine: false 12 | ColumnLimit: 78 13 | IndentWidth: 4 14 | SpacesInAngles: false 15 | SpaceInEmptyParentheses: false 16 | SpacesInContainerLiterals: false 17 | IndentFunctionDeclarationAfterType: true 18 | PenaltyBreakComment: 0 19 | BreakBeforeBraces: Allman 20 | UseTab: Never 21 | AlignAfterOpenBracket: BlockIndent 22 | BinPackArguments: false 23 | BinPackParameters: false 24 | # Contructor initializers 25 | PackConstructorInitializers: Never 26 | BreakConstructorInitializersBeforeComma: true 27 | BreakConstructorInitializers: BeforeComma 28 | IndentAccessModifiers: false 29 | AccessModifierOffset: -4 30 | ... 31 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | workflow_call: 9 | inputs: 10 | build_type: 11 | description: "The CMake build type to use" 12 | required: false 13 | default: "Release" 14 | type: string 15 | 16 | jobs: 17 | arm64-build: 18 | runs-on: macos-latest 19 | steps: 20 | 21 | - name: Check out code 22 | uses: actions/checkout@v3 23 | with: 24 | submodules: recursive 25 | 26 | - name: Build 27 | run: | 28 | bash bin/build.sh -r 29 | 30 | - name: Package creation 31 | run: | 32 | tar -czvf torchplugins_macOS_arm64.tar.gz torchplugins 33 | 34 | - name: Upload binaries 35 | uses: actions/upload-artifact@v2 36 | with: 37 | name: torchplugins 38 | path: torchplugins_macOS_arm64.tar.gz 39 | 40 | x86_64-build: 41 | runs-on: macos-latest 42 | steps: 43 | - name: Check out code 44 | uses: actions/checkout@v3 45 | with: 46 | submodules: recursive 47 | 48 | - name: Build 49 | run: | 50 | bash bin/build.sh -r 51 | 52 | - name: Package creation 53 | run: | 54 | tar -czvf torchplugins_macOS_x86_64.tar.gz torchplugins 55 | 56 | - name: Upload binaries 57 | uses: actions/upload-artifact@v2 58 | with: 59 | name: torchplugins 60 | path: torchplugins_macOS_x86_64.tar.gz 61 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: "tagged-release" 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | 8 | jobs: 9 | build: 10 | uses: ./.github/workflows/build.yaml 11 | with: 12 | build_type: "Release" 13 | 14 | tagged-release: 15 | name: "Tagged Release" 16 | runs-on: "ubuntu-latest" 17 | needs: [build] 18 | 19 | steps: 20 | - name: Download build binaries 21 | uses: actions/download-artifact@v3 22 | with: 23 | name: torchplugins 24 | 25 | - name: "Create release" 26 | uses: "marvinpinto/action-automatic-releases@latest" 27 | with: 28 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 29 | prerelease: false 30 | files: | 31 | torchplugins_macOS_x86_64.tar.gz 32 | torchplugins_macOS_arm64.tar.gz -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/c++,osx 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=c++,osx 3 | 4 | build/ 5 | docs/ 6 | externals/ 7 | third_party/libtorch 8 | third_party/libtorch.zip 9 | tests/ 10 | .vscode/ 11 | 12 | *.pt 13 | ### C++ ### 14 | # Prerequisites 15 | *.d 16 | 17 | # Compiled Object files 18 | *.slo 19 | *.lo 20 | *.o 21 | *.obj 22 | 23 | # Precompiled Headers 24 | *.gch 25 | *.pch 26 | 27 | # Compiled Dynamic libraries 28 | *.so 29 | *.dylib 30 | *.dll 31 | 32 | # Fortran module files 33 | *.mod 34 | *.smod 35 | 36 | # Compiled Static libraries 37 | *.lai 38 | *.la 39 | *.a 40 | *.lib 41 | 42 | # Executables 43 | *.exe 44 | *.out 45 | *.app 46 | 47 | ### OSX ### 48 | # General 49 | .DS_Store 50 | .AppleDouble 51 | .LSOverride 52 | 53 | # Icon must end with two \r 54 | Icon 55 | 56 | 57 | # Thumbnails 58 | ._* 59 | 60 | # Files that might appear in the root of a volume 61 | .DocumentRevisions-V100 62 | .fseventsd 63 | .Spotlight-V100 64 | .TemporaryItems 65 | .Trashes 66 | .VolumeIcon.icns 67 | .com.apple.timemachine.donotpresent 68 | 69 | # Directories potentially created on remote AFP share 70 | .AppleDB 71 | .AppleDesktop 72 | Network Trash Folder 73 | Temporary Items 74 | .apdisk 75 | 76 | # End of https://www.toptal.com/developers/gitignore/api/c++,osx 77 | torchplugins/ 78 | package-info.json 79 | .cache/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/min-api"] 2 | path = third_party/min-api 3 | url = https://github.com/Cycling74/min-api.git 4 | branch = main 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19) 2 | project(torchplugins VERSION 0.1.1) 3 | message(STATUS "Version: ${PROJECT_VERSION}") 4 | 5 | # We need C++17 because torch is compiled with C++17 on linux 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15") 9 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 10 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 11 | 12 | enable_testing() 13 | 14 | string(REGEX REPLACE "(.*)/" "" THIS_PACKAGE_NAME "${CMAKE_CURRENT_SOURCE_DIR}") 15 | message(STATUS "This package name is ${THIS_PACKAGE_NAME}") 16 | 17 | if(APPLE) 18 | if(${CMAKE_GENERATOR} MATCHES "Xcode") 19 | if(${XCODE_VERSION} VERSION_LESS 10) 20 | message(STATUS "Xcode 10 or higher is required. Please install from the Mac App Store.") 21 | return() 22 | elseif(${XCODE_VERSION} VERSION_GREATER_EQUAL 12) 23 | set(C74_BUILD_FAT YES) 24 | endif() 25 | endif() 26 | 27 | if(NOT CMAKE_OSX_ARCHITECTURES) 28 | if(C74_BUILD_FAT) 29 | set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "macOS architecture" FORCE) 30 | else() 31 | set(CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "macOS architecture" FORCE) 32 | endif() 33 | 34 | message("CMAKE_OSX_ARCHITECTURES set to ${CMAKE_OSX_ARCHITECTURES}") 35 | endif() 36 | endif() 37 | 38 | if(APPLE) 39 | set(CMAKE_CXX_FLAGS "-faligned-allocation") 40 | 41 | if(CMAKE_OSX_ARCHITECTURES STREQUAL "") 42 | set(CMAKE_OSX_ARCHITECTURES ${CMAKE_HOST_SYSTEM_PROCESSOR}) 43 | endif() 44 | 45 | message("CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") 46 | endif() 47 | 48 | # Torch 49 | find_package(Torch REQUIRED) 50 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") 51 | 52 | # Max SDK 53 | # include(${CMAKE_CURRENT_SOURCE_DIR}/third_party/min-api/script/min-package.cmake) 54 | set(C74_MIN_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/min-api) 55 | 56 | # Argparse 57 | # set(FETCHCONTENT_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party) 58 | include(FetchContent) 59 | option(ARGPARSE_INSTALL "Install argparse" OFF) 60 | FetchContent_Declare( 61 | argparse 62 | GIT_REPOSITORY https://github.com/p-ranav/argparse.git 63 | ) 64 | FetchContent_MakeAvailable(argparse) 65 | 66 | # Misc setup and subroutines 67 | include(${CMAKE_CURRENT_SOURCE_DIR}/third_party/min-api/script/min-package.cmake) 68 | 69 | # Set RPATH 70 | set(CMAKE_MACOSX_RPATH TRUE) 71 | set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 72 | set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE) 73 | set(CMAKE_INSTALL_RPATH "@loader_path") 74 | 75 | # Add subdirectories 76 | add_subdirectory(src/common/torchwrapper) 77 | add_subdirectory(src/common/test_torchwrapper) 78 | add_subdirectory(src/maxmsp/fc) 79 | add_subdirectory(src/maxmsp/encoder) 80 | add_subdirectory(src/maxmsp/filterbank_tilde) 81 | 82 | # Install 83 | 84 | # Install the Max package 85 | install( 86 | DIRECTORY 87 | ${CMAKE_CURRENT_SOURCE_DIR}/externals 88 | DESTINATION 89 | ${CMAKE_CURRENT_SOURCE_DIR}/torchplugins 90 | ) 91 | 92 | # install the extras directory 93 | install( 94 | DIRECTORY 95 | ${CMAKE_CURRENT_SOURCE_DIR}/extras 96 | DESTINATION 97 | ${CMAKE_CURRENT_SOURCE_DIR}/torchplugins 98 | ) 99 | 100 | # install the package info, readme and license 101 | install( 102 | FILES 103 | ${CMAKE_CURRENT_SOURCE_DIR}/package-info.json 104 | ${CMAKE_CURRENT_SOURCE_DIR}/README.md 105 | ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE 106 | DESTINATION 107 | ${CMAKE_CURRENT_SOURCE_DIR}/torchplugins 108 | ) 109 | 110 | # Install the help files 111 | install( 112 | FILES 113 | ${CMAKE_CURRENT_SOURCE_DIR}/src/maxmsp/fc/fc.maxhelp 114 | ${CMAKE_CURRENT_SOURCE_DIR}/src/maxmsp/encoder/encoder.maxhelp 115 | ${CMAKE_CURRENT_SOURCE_DIR}/src/maxmsp/filterbank_tilde/filterbank~.maxhelp 116 | DESTINATION 117 | ${CMAKE_CURRENT_SOURCE_DIR}/torchplugins/help 118 | ) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Rodrigo Diaz 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Torchplugins 2 | 3 | This repository contains a collection of plugins for loading pytorch models in Max/MSP, Unity and other engines/frameworks. 4 | 5 | They can load different models, but they were developed to load the models used for [this project.](https://arxiv.org/abs/2210.15306) 6 | 7 | ## Cloning 8 | 9 | ```bash 10 | git clone --recursive git@github.com:rodrigodzf/torchplugins.git 11 | ``` 12 | 13 | ## Building 14 | 15 | From the root directory, run: 16 | 17 | ```bash 18 | sh ./bin/build.sh -r 19 | ``` 20 | 21 | The plugins will be available in the `torchplugins` directory. It is recommended to copy the folder `torchplugins` to the Package directory of your Max installation e.g `~/Documents/Max 8/Packages/torchplugins`. 22 | 23 | ### Development 24 | 25 | It is useful to link the folder `torchplugins` to the packages directory of your Max installation e.g `~/Documents/Max 8/Packages`. This way, you can edit the source code and the changes will be reflected in Max. 26 | 27 | ## Usage 28 | 29 | ### Max/MSP 30 | 31 | An exemplary patcher is available in the `extras` directory. The patcher loads a model and runs inference on a given image. 32 | 33 | The path to the models must be specified in Max settings. 34 | 35 | ### Unity 36 | 37 | ### Related repositories 38 | 39 | [nn-tilde](https://github.com/acids-ircam/nn_tilde) - A Max/MSP, PureData external for loading pytorch models. 40 | -------------------------------------------------------------------------------- /bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # parse command line arguments 4 | while [[ $# -gt 0 ]]; do 5 | key="$1" 6 | case $key in 7 | -h|--help) 8 | echo "Usage: ./build.sh [options]" 9 | echo "Options:" 10 | echo " -h, --help show this help message and exit" 11 | echo " -c, --clean clean build directory" 12 | echo " -d, --debug build in debug mode" 13 | echo " -r, --release build in release mode" 14 | echo " -t, --test build and run tests" 15 | echo " -i, --install install to system" 16 | exit 0 17 | ;; 18 | -c|--clean) 19 | rm -rf build 20 | rm -rf torchplugins 21 | rm -rf externals 22 | rm -rf tests 23 | rm -rf package-info.json 24 | exit 0 25 | ;; 26 | -d|--debug) 27 | build_type="Debug" 28 | shift 29 | ;; 30 | -r|--release) 31 | build_type="Release" 32 | shift 33 | ;; 34 | -t|--test) 35 | build_type="Release" 36 | test="ON" 37 | shift 38 | ;; 39 | -i|--install) 40 | build_type="Release" 41 | install="ON" 42 | shift 43 | ;; 44 | *) 45 | echo "Unknown option: $key" 46 | exit 1 47 | ;; 48 | esac 49 | done 50 | 51 | 52 | uname=$(uname) 53 | arch=$(uname -m) 54 | 55 | # macos (intel) 56 | 57 | if [[ "$uname" == "Darwin" ]] && [[ "$arch" == "x86_64" ]]; then 58 | # download libtorch if it doesn't exist already 59 | if ! [[ -d "./third_party/libtorch" ]]; then 60 | cd ./third_party 61 | curl -L https://download.pytorch.org/libtorch/cpu/libtorch-macos-2.0.0.zip -o libtorch.zip 62 | unzip libtorch.zip 63 | rm -rf libtorch.zip 64 | cd ../ 65 | fi 66 | fi 67 | 68 | # macos (arm) 69 | 70 | if [[ "$uname" == "Darwin" ]] && [[ "$arch" == "arm64" ]]; then 71 | # download libtorch if it doesn't exist already 72 | if ! [[ -d "./third_party/libtorch" ]]; then 73 | cd ./third_party 74 | curl -L https://anaconda.org/pytorch/pytorch/2.0.0/download/osx-arm64/pytorch-2.0.0-py3.9_0.tar.bz2 -o pytorch.tar.bz2 75 | mkdir pytorch 76 | tar -xvf pytorch.tar.bz2 -C pytorch 77 | cp -r pytorch/lib/python3.9/site-packages/torch libtorch 78 | rm -rf pytorch pytorch.tar.bz2 79 | cd ../ 80 | fi 81 | fi 82 | 83 | cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=./third_party/libtorch 84 | cmake --build build -j 85 | cmake --install build 86 | -------------------------------------------------------------------------------- /cmake/MakePackage.cmake: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigodzf/torchplugins/535c0ddf3a2570434158fbd8b9e53be897f5bace/cmake/MakePackage.cmake -------------------------------------------------------------------------------- /compile_commands.json: -------------------------------------------------------------------------------- 1 | build/compile_commands.json -------------------------------------------------------------------------------- /extras/occupancy_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rodrigodzf/torchplugins/535c0ddf3a2570434158fbd8b9e53be897f5bace/extras/occupancy_map.png -------------------------------------------------------------------------------- /package-info.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "author" : "Rodrigo Diaz", 3 | "description" : "Lightweight reference implementation of a package built using the Min-API.", 4 | "homepatcher" : "", 5 | "max_version_min" : "8.0", "max_version_max" : "none", 6 | "name" : "@C74_PACKAGE_NAME@", 7 | "os" : { 8 | "macintosh" : { 9 | "platform" : [ "x64", "arm64" ], 10 | "min_version" : "none" 11 | }, 12 | }, 13 | "package_extra" : { 14 | "copyright" : "Copyright (c) 2023 Rodrigo Diaz" 15 | }, 16 | "tags" : [ ], 17 | "version" : "@GIT_VERSION_MAJ@.@GIT_VERSION_MIN@.@GIT_VERSION_SUB@", 18 | "website" : "https://github.com/rodrigodzf/torchplugins" 19 | } -------------------------------------------------------------------------------- /src/common/test_torchwrapper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXE_NAME test_torchwrapper) 2 | set(SRC_FILES main.cpp) 3 | 4 | add_executable(${EXE_NAME} ${SRC_FILES}) 5 | # set_target_properties(${EXE_NAME} PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64") 6 | target_link_libraries( 7 | ${EXE_NAME} 8 | PUBLIC 9 | torchwrapper 10 | argparse 11 | ) 12 | set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") 13 | -------------------------------------------------------------------------------- /src/common/test_torchwrapper/main.cpp: -------------------------------------------------------------------------------- 1 | #include "model.h" 2 | #include "log.h" 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char** argv) 8 | { 9 | argparse::ArgumentParser program("test_torchwrapper"); 10 | 11 | // Add arguments 12 | program.add_argument("-i", "--input") 13 | .help("input model file") 14 | .required() 15 | .default_value("model_wrap.pt"); 16 | 17 | try 18 | { 19 | program.parse_args(argc, argv); 20 | } 21 | catch (const std::runtime_error& err) 22 | { 23 | std::cerr << err.what() << std::endl; 24 | std::cerr << program; 25 | std::exit(1); 26 | } 27 | 28 | auto modelPath = std::filesystem::path(program.get("input")); 29 | 30 | // Check if the model exists 31 | if (!std::filesystem::exists(modelPath)) 32 | { 33 | LOG_MSG("Model file not found: " << modelPath) 34 | return -1; 35 | } 36 | 37 | auto& model = Model::getInstance(); 38 | model.loadModel(modelPath, "cpu"); 39 | 40 | std::vector< float > x = { 41 | -0.001436, -0.084742, -0.001168, 0.009148, 0.000078, 0.000604, 42 | -0.000064, -0.000955, 0.017789, -0.001886, 0.018542, 0.018337, 43 | -0.001704, 0.009327, 0.008669, 0.009197, -0.15291, 0.004286, 44 | -0.005986, 0.026129, -0.106516, -0.004522, 0.011924, -0.004578, 45 | 0.020894, -0.006322, -0.001541, -0.006778, -0.001413, 0.009577, 46 | -0.001028, 0.000699, -0.153747, 0.04489, 0.022687, -0.008212, 47 | 0.014208, -0.000049, 0.002666, -0.191132, 0.002093, -0.015681, 48 | 0.000948, -0.017899, -0.003699, 0.010871, -0.002394, 0.023453, 49 | 0.002108, 0.007641, -0.000608, 0.029507, -0.01465, -0.013023, 50 | -0.001592, 0.001291, -0.011376, -0.010331, 0.003608, -0.012557, 51 | -0.007716, -0.002631, -0.007365, -0.014146, -0.006523, -0.022319, 52 | -0.003283, -0.018123, -0.00759, 0.011322, 0.002598, -0.005482, 53 | 0.003064, 0.005696, -0.00425, 0.001423, 0.009213, -0.012387, 54 | 0.012635, -0.009828, 0.001038, -0.15181, 0.000905, -0.150899, 55 | -0.082256, 0.001591, 0.010371, 0.008849, -0.019096, 0.009867, 56 | 0.003806, 0.008231, -0.020204, -0.188321, -0.199304, 0.001263, 57 | 0.006002, -0.008799, 0.004953, 0.003348, 0.000957, -0.001703, 58 | 0.001737, 0.023382, -0.005791, 0.017804, -0.011797, 0.008968, 59 | 0.001397, 0.001008, -0.004283, -0.030426, 0.0172, -0.154391, 60 | 0.002479, -0.334384, 0.006329, -0.005863, -0.023262, 0.004825, 61 | -0.006396, -0.013807, -0.032162, -0.029546, -0.01009, -0.00821, 62 | -0.010677, -0.022719, -0.000519, 0.012734, 0.003049, 0.003176, 63 | -0.000515, 0.00304, -0.007022, -0.180766, 0.000613, 0.007419, 64 | -0.181312, 0.006089, 0.010831, 0.004552, 0.020826, 0.005722, 65 | 0.022911, 0.005529, -0.000242, 0.005835, 0.016652, -0.001969, 66 | 0.006749, 0.010181, 0.007711, -0.012764, -0.000897, 0.000426, 67 | 0.002478, -0.013662, -0.000696, -0.009817, -0.067881, 0.001095, 68 | -0.000836, 0.006357, -0.004801, -0.002279, 0.000569, 0.005846, 69 | 0.00761, -0.019098, 0.001698, -0.003143, -0.007982, -0.008044, 70 | -0.002689, -0.104677, 0.019251, 0.000888, -0.004612, 0.006267, 71 | -0.000693, -0.004777, -0.001345, -0.001368, -0.004875, 0.004619, 72 | -0.000445, -0.001388, 0.00679, 0.008148, 0.009588, -0.012191, 73 | -0.006955, 0.001207, 0.017781, -0.004355, -0.009411, -0.017909, 74 | 0.003013, -0.009718, 0.002931, -0.002078, -0.000918, -0.000175, 75 | -0.007282, 0.006609, -0.001276, 0.003774, 0.001425, 0.003638, 76 | 0.003279, 0.002724, 0.004239, 0.000632, -0.005267, 0.007879, 77 | 0.000128, 0.007178, -0.000121, 0.003318, 0.010845, 0.0014, 78 | 0.001992, -0.009588, 0.002686, 0.005963, 0.002612, -0.007078, 79 | -0.001321, 0.005873, -0.001051, 0.007384, 0.000523, -0.010531, 80 | -0.005724, -0.0005, -0.004705, 0.003262, 0.002909, -0.001674, 81 | 0.002785, 0.007161, -0.007708, -0.010593, 0.001971, 0.007321, 82 | -0.004188, 0.005602, -0.002469, -0.015599, -0.002564, -0.001034, 83 | 0.000376, 0.003355, 0.013886, -0.004575, 0.004085, -0.045288, 84 | 0.000811, -0.010742, 0.001904, -0.014251, 0.024856, -0.005405, 85 | 0.009725, 0.001488, 0.000799, 0.005525, 0.023225, 0.009771, 86 | 0.012521, 0.015012, 0.004677, 0.005727, 0.012546, -0.008754, 87 | 0.005571, -0.013009, 0.008005, -0.0158, 0.02035, 0.00474, 88 | -0.002868, 0.003773, -0.009864, 0.008165, -0.003107, -0.002485, 89 | -0.002388, 0.00705, -0.008558, -0.232494, -0.004173, -0.013182, 90 | -0.128209, -0.005926, 0.014043, -0.001002, -0.00945, -0.007661, 91 | 0.005835, -0.003247, 0.01159, -0.001993, -0.001637, -0.011058, 92 | -0.00173, -0.001294, 0.016453, 0.025234, 0.006788, 0.018587, 93 | 0.005299, -0.000036, -0.024275, 0.006221, 0.002008, -0.004799, 94 | -0.000097, -0.010017, -0.001126, -0.035341, 0.013673, 0.009518, 95 | -0.005044, 0.003671, -0.007451, 0.005147, -0.002055, 0.008131, 96 | -0.00283, -0.007551, -0.022131, -0.013839, 0.015264, -0.033698, 97 | 0.016165, 0.010379, -0.001234, -0.040652, -0.003696, -0.118265, 98 | -0.008137, 0.004949, 0.000382, 0.009006, -0.015876, -0.009207, 99 | -0.022828, -0.003669, 0.004109, -0.028882, -0.01312, -0.007095, 100 | -0.099535, 0.004143, -0.003469, -0.013916, -0.006633, -0.005428, 101 | 0.002659, -0.018252, -0.00084, -0.003366, -0.002754, -0.004693, 102 | -0.005026, 0.000268, 0.010497, -0.017421, -0.002866, -0.015518, 103 | -0.011503, 0.00259, 0.002488, 0.004795, 0.020166, 0.007952, 104 | 0.00625, 0.000583, -0.001197, -0.000871, -0.002576, -0.000954, 105 | 0.014026, 0.014319, 0.001349, -0.014331, -0.003494, 0.000534, 106 | -0.131035, 0.018867, -0.006003, 0.000965, 0.010058, 0.015642, 107 | -0.009097, 0.009812, -0.005994, 0.009903, -0.008114, 0.009834, 108 | -0.005238, 0.002553, -0.135593, -0.004792, -0.018289, 0.009139, 109 | -0.05649, -0.016537, 0.018035, -0.011089, 0.00141, 0.001168, 110 | 0.001363, -0.006452, 0.003859, 0.003893, -0.012357, -0.000159, 111 | 0.006479, 0.000569, -0.011705, 0.013024, 0.028201, -0.01773, 112 | 0.006492, 0.000685, 0.003662, 0.003197, 0.003886, -0.000028, 113 | -0.014837, 0.015099, 0.010634, -0.012359, -0.018322, 0.002993, 114 | 0.022758, -0.005762, 0.008889, 0.017836, -0.005567, 0.006706, 115 | -0.018746, -0.007786, 0.000132, -0.014969, -0.005434, -0.000702, 116 | 0.003928, -0.005732, -0.039695, -0.007676, -0.001931, 0.003229, 117 | -0.02353, -0.012267, -0.003603, 0.010417, -0.002422, -0.01032, 118 | -0.011607, -0.005287, -0.00674, 0.005537, 0.007106, -0.00167, 119 | -0.010801, -0.013647, 0.021011, -0.01095, 0.002169, 0.008268, 120 | -0.014663, -0.002658, -0.187914, 0.009155, 0.007471, -0.003715, 121 | 0.016294, 0.001736, -0.011613, -0.004629, 0.028509, 0.000207, 122 | -0.011869, 0.007445, -0.006877, -0.015775, 0.000696, -0.121196, 123 | -0.022752, 0.067813, -0.004551, -0.00998, 0.000492, 0.006904, 124 | 0.009693, -0.005779, 0.00754, -0.003448, -0.004168, -0.003673, 125 | 0.00158, -0.001361, 0.000716, 0.012141, -0.004064, -0.021169, 126 | -0.005268, -0.004577, 0.000461, -0.011963, -0.005776, -0.004998, 127 | -0.008934, 0.002898, -0.053773, 0.010167, -0.009447, 0.006634, 128 | -0.012081, 0.011154, -0.005575, -0.140487, -0.013123, 0.003075, 129 | 0.002877, -0.003135, -0.005237, -0.007142, 0.004358, 0.006297, 130 | 0.011497, 0.005083, 0.006186, 0.060522, 0.000422, -0.002813, 131 | 0.001202, -0.005791, -0.000393, -0.002274, -0.000861, -0.009265, 132 | -0.006919, 0.009944, -0.001989, 0.002732, -0.004722, 0.009802, 133 | -0.002168, 0.003879, -0.001305, -0.004104, -0.080626, -0.004807, 134 | -0.008838, -0.003781, 0.008383, -0.004961, -0.003109, 0.003496, 135 | -0.005155, -0.005103, -0.012386, 0.011285, 0.006509, -0.003528, 136 | 0.000975, 0.0031, 0.003408, -0.008843, -0.006933, 0.004979, 137 | 0.000322, -0.004078, 0.003122, 0.00657, 0.010129, -0.012298, 138 | 0.03472, 0.010127, -0.090554, 0.00144, -0.008444, -0.019227, 139 | -0.016015, -0.014317, -0.000929, 0.015286, 0.002597, 0.005767, 140 | 0.016872, -0.001331, -0.015372, 0.006157, -0.003142, 0.000696, 141 | 0.058645, -0.003675, 0.001135, -0.001352, -0.027688, 0.011416, 142 | -0.001176, 0.000308, 0.014893, -0.013973, -0.009076, -0.001539, 143 | -0.013992, 0.003033, -0.074761, 0.010909, -0.010814, -0.004852, 144 | 0.004865, 0.008309, -0.009463, -0.015571, 0.014212, 0.009967, 145 | -0.008289, 0.021197, -0.004742, -0.007321, -0.004521, -0.010085, 146 | 0.000058, -0.000915, -0.002885, -0.035277, 0.001016, 0.006543, 147 | -0.003769, 0.001304, -0.001264, -0.008523, -0.002811, -0.007788, 148 | 0.001937, -0.006417, 0.036309, -0.004915, 0.011154, -0.00902, 149 | -0.002208, -0.005909, -0.002372, 0.001679, -0.006918, -0.010647, 150 | -0.004834, 0.000947, -0.002797, 0.008997, 0.001598, -0.002951, 151 | -0.001087, 0.010361, 0.022658, -0.011985, -0.008932, 0.00435, 152 | 0.010792, -0.001877, 0.004927, 0.004865, 0.004527, -0.014257, 153 | 0.00592, 0.006164, 0.021233, 0.005056, -0.000355, 0.009513, 154 | 0.007763, -0.002888, -0.011767, 0.002847, 0.00371, 0.007904, 155 | -0.015524, -0.008167, 0.016921, 0.015306, -0.007595, -0.007145, 156 | 0.006006, 0.01885, -0.00262, 0.008053, 0.015118, 0.001533, 157 | 0.013707, -0.032463, 0.004469, -0.017901, 0.014373, -0.003319, 158 | 0.010613, -0.005018, 0.003813, 0.003132, 0.002167, 0.016087, 159 | -0.00022, -0.005656, 0.006416, -0.00625, -0.088381, 0.006459, 160 | 0.003673, -0.048971, 0.002364, 0.000593, -0.008084, -0.012874, 161 | 0.004789, 0.011649, 0.005119, -0.004233, -0.063377, 0.001234, 162 | -0.00509, 0.00733, -0.005617, 0.035202, -0.004745, -0.014507, 163 | -0.006427, 0.003399, 0.008933, -0.018188, -0.01535, 0.008449, 164 | -0.04025, 0.000563, -0.001754, -0.007206, -0.004526, 0.009923, 165 | 0.000798, 0.022226, -0.002354, 0.02062, -0.007756, -0.009406, 166 | -0.005041, -0.003406, -0.17471, 0.00181, -0.012603, -0.058205, 167 | 0.003839, 0.002956, -0.127921, -0.004301, 0.004836, 0.010076, 168 | -0.001815, -0.004208, -0.011268, 0.005471, 0.00909, -0.00278, 169 | -0.008222, 0.010663, -0.075837, -0.007987, -0.017326, 0.017418, 170 | -0.007132, -0.060782, -0.011505, 0.015251, -0.0042, 0.002985, 171 | 0.014532, 0.000545, -0.001459, -0.010182, 0.008446, -0.01206, 172 | -0.01378, -0.23899, 0.015163, -0.012319, 0.011901, -0.021051, 173 | -0.005367, 0.012039, -0.113217, -0.001092, 0.009678, 0.008476, 174 | -0.005475, -0.008413, 0.00829, 0.010766, -0.006414, 0.000608, 175 | 0.010206, 0.08515, -0.006003, 0.019473, -0.002901, -0.003725, 176 | 0.008744, 0.009099, -0.00303, 0.005029, -0.000019, 0.002249, 177 | -0.009164, 0.007397, -0.011807, 0.003767, 0.005305, -0.008574, 178 | 0.025048, -0.013395, -0.01216, 0.002891, -0.007684, -0.000832, 179 | 0.019987, 0.020279, 0.00669, 0.002955, -0.004013, 0.010471, 180 | -0.005603, 0.016908, -0.01068, 0.017262, 0.006634, 0.001368, 181 | 0.002753, 0.007672, 0.003272, 0.006333, 0.017309, 0.000356, 182 | -0.015958, -0.00382, 0.000516, -0.007893, -0.001172, -0.002527, 183 | -0.003681, -0.008133, 0.008906, -0.002793, -0.0046, 0.005957, 184 | -0.013566, 0.004035, 0.003184, 0.011741, 0.009567, -0.000023, 185 | -0.010518, -0.010086, -0.071174, -0.076767, 0.024674, 0.003798, 186 | -0.008718, -0.001428, -0.02271, 0.007235, 0.005295, -0.016024, 187 | -0.000225, -0.001787, -0.059491, -0.047463, -0.005654, 0.000723, 188 | -0.002038, -0.131294, -0.000972, 0.043259, -0.012443, -0.147929, 189 | -0.00188, -0.006961, -0.004052, -0.090805, -0.017038, 0.023425, 190 | -0.028434, 0.008876, 0.008792, -0.006643, 0.007837, 0.003569, 191 | 0.001743, 0.011008, -0.007794, 0.000563, 0.001136, -0.000937, 192 | -0.003716, -0.00037, 0.005442, -0.01118, -0.005892, 0.006535, 193 | -0.013898, 0.000382, 0.021605, -0.000284, -0.013897, -0.006885, 194 | 0.002012, -0.009488, -0.012978, 0.01008, -0.003156, 0.00069, 195 | -0.001457, -0.000045, 0.003406, 0.001713, 0.008585, 0.000982, 196 | -0.012498, -0.000121, -0.009666, 0.007935, 0.005871, 0.003485, 197 | -0.02934, 0.004426, -0.000365, -0.003684, 0.002486, -0.010341, 198 | 0.007202, 0.002742, 0.013999, 0.003345, -0.001137, 0.003039, 199 | -0.003712, -0.014173, -0.019813, -0.013311, -0.062469, 0.000722, 200 | 0.010764, 0.007579, 0.002587, 0.002041, -0.021646, -0.004963, 201 | 0.000597, -0.019059, -0.025656, -0.012275, 0.006219, 0.009415, 202 | 0.010004, 0.020989, 0.000672, 0.014709, 0.001036, -0.014056, 203 | -0.009339, -0.009672, -0.009201, -0.022899, 0.008337, -0.000797, 204 | -0.000451, -0.002685, -0.008416, -0.001374, 0.008043, 0.011682, 205 | -0.008223, -0.00297, 0.001464, -0.007625, -0.000529, -0.006902, 206 | -0.009836, 0.010059, -0.001538, 0.001922, -0.031893, 0.008967, 207 | -0.008679, -0.234851, 0.000973, -0.000656, 0.498047, 0.441406, 208 | 0.9, 0.2, 0.5, 1., 0.01}; 209 | 210 | // do inference 211 | auto tensor = Model::getInstance().toTensor(x.data(), 1, 1, 1, x.size()); 212 | 213 | auto output = std::vector< float >(32 * 2 * 6); 214 | 215 | model.process(tensor, output.data()); 216 | 217 | LOG_MSG("TEST SUCCESS"); 218 | return 0; 219 | } -------------------------------------------------------------------------------- /src/common/torchwrapper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIB_NAME torchwrapper) 2 | set(SRC_FILES model.cpp) 3 | 4 | add_library(${LIB_NAME} STATIC ${SRC_FILES}) 5 | target_include_directories(${LIB_NAME} PUBLIC "include") 6 | # set_target_properties(${LIB_NAME} PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64") 7 | target_link_libraries(${LIB_NAME} PUBLIC ${TORCH_LIBRARIES}) 8 | 9 | -------------------------------------------------------------------------------- /src/common/torchwrapper/include/log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define LOG_MSG(msg) std::cout << "[CPP] " << msg << std::endl; 4 | -------------------------------------------------------------------------------- /src/common/torchwrapper/include/model.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class Model 9 | { 10 | private: 11 | Model() {} 12 | 13 | public: 14 | Model(Model const &) = delete; 15 | void operator=(Model const &) = delete; 16 | 17 | private: 18 | torch::jit::Module mNetwork; 19 | 20 | public: 21 | static Model &getInstance() 22 | { 23 | static Model instance; // Guaranteed to be destroyed. 24 | return instance; 25 | } 26 | 27 | int loadModel( 28 | const std::string &modelPath, 29 | const std::string &deviceString 30 | ); 31 | 32 | torch::Tensor toTensor( 33 | float *input, 34 | const int batchSize, 35 | const int channels, 36 | const int height, 37 | const int width 38 | ); 39 | 40 | void process(torch::Tensor &inputTensor, float *output); 41 | 42 | std::vector getMethods(); 43 | 44 | void callMethod(const std::string &methodName, float param); 45 | }; 46 | -------------------------------------------------------------------------------- /src/common/torchwrapper/model.cpp: -------------------------------------------------------------------------------- 1 | #include "model.h" 2 | #include "log.h" 3 | 4 | int Model::loadModel( 5 | const std::string &modelPath, 6 | const std::string &deviceString 7 | ) 8 | { 9 | auto device = torch::Device(deviceString); 10 | try 11 | { 12 | // Deserialize the ScriptModule from a file using torch::jit::load(). 13 | mNetwork = torch::jit::load(modelPath, device); 14 | mNetwork.eval(); 15 | } 16 | catch (const c10::Error &e) 17 | { 18 | // Return a value of -1 if the model fails to load 19 | LOG_MSG("Error loading model: " << e.what()) 20 | return -1; 21 | } 22 | 23 | LOG_MSG("Model loaded successfully"); 24 | 25 | // Return a value of 0 if the model loads successfully 26 | return 0; 27 | } 28 | 29 | torch::Tensor Model::toTensor( 30 | float *input, 31 | const int batchSize, 32 | const int channels, 33 | const int height, 34 | const int width 35 | ) 36 | { 37 | // Create a vector of inputs. 38 | auto options = torch::TensorOptions().dtype(torch::kFloat); 39 | auto tensor = torch::from_blob( 40 | input, 41 | {batchSize, channels, height, width}, 42 | options 43 | ); 44 | 45 | return tensor; 46 | } 47 | 48 | void Model::process(torch::Tensor &inputTensor, float *output) 49 | { 50 | c10::InferenceMode guard; 51 | 52 | try 53 | { 54 | // Create a vector of inputs. 55 | std::vector inputs; 56 | inputs.push_back(inputTensor); 57 | 58 | // Execute the model and turn its output into a tensor. 59 | auto outputTensor = mNetwork.forward(inputs).toTensor(); 60 | 61 | // Copy the tensor data to the output array 62 | memcpy( 63 | output, 64 | outputTensor.data_ptr(), 65 | outputTensor.numel() * sizeof(float) 66 | ); 67 | } 68 | catch (const c10::Error &e) 69 | { 70 | // Return a value of -1 if the model fails to load 71 | LOG_MSG("Error processing model: " << e.what()); 72 | std::exit(-1); 73 | } 74 | } 75 | 76 | std::vector Model::getMethods() 77 | { 78 | std::vector methods; 79 | for (const auto &method : mNetwork.get_methods()) 80 | { 81 | methods.push_back(method.name()); 82 | } 83 | return methods; 84 | } 85 | 86 | void Model::callMethod(const std::string &methodName, float param) 87 | { 88 | c10::InferenceMode guard; 89 | 90 | try 91 | { 92 | mNetwork.get_method(methodName)({param}); 93 | } 94 | catch (const c10::Error &e) 95 | { 96 | // Return a value of -1 if the model fails to load 97 | LOG_MSG("Error processing model: " << e.what()); 98 | std::exit(-1); 99 | } 100 | } -------------------------------------------------------------------------------- /src/maxmsp/encoder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(${C74_MIN_API_DIR}/script/min-pretarget.cmake) 2 | 3 | include_directories( 4 | "${C74_INCLUDES}" 5 | ) 6 | 7 | set( SOURCE_FILES 8 | ${PROJECT_NAME}.cpp 9 | ) 10 | 11 | add_library( 12 | ${PROJECT_NAME} 13 | MODULE 14 | ${SOURCE_FILES} 15 | ) 16 | 17 | target_compile_definitions( 18 | ${PROJECT_NAME} 19 | PUBLIC 20 | VERSION="${CMAKE_PROJECT_VERSION}" 21 | ) 22 | 23 | target_link_libraries( 24 | ${PROJECT_NAME} 25 | PUBLIC 26 | torchwrapper 27 | ) 28 | 29 | include(${C74_MIN_API_DIR}/script/min-posttarget.cmake) 30 | 31 | if (APPLE) 32 | add_custom_command( 33 | TARGET ${PROJECT_NAME} 34 | POST_BUILD 35 | COMMAND cp "${TORCH_INSTALL_PREFIX}/lib/*.dylib" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${${PROJECT_NAME}_EXTERN_OUTPUT_NAME}.mxo/Contents/MacOS/" 36 | COMMENT "Copy Torch Libraries" 37 | ) 38 | 39 | if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") 40 | add_custom_command( 41 | TARGET ${PROJECT_NAME} 42 | POST_BUILD 43 | COMMAND "codesign" "--force" "--deep" "-s" "-" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${${PROJECT_NAME}_EXTERN_OUTPUT_NAME}.mxo" 44 | COMMENT "Codesign external" 45 | ) 46 | endif() 47 | endif() 48 | 49 | ############################################################# 50 | # UNIT TEST 51 | ############################################################# 52 | 53 | # include(${C74_MIN_API_DIR}/test/min-object-unittest.cmake) 54 | -------------------------------------------------------------------------------- /src/maxmsp/encoder/encoder.cpp: -------------------------------------------------------------------------------- 1 | #include "c74_min.h" 2 | 3 | #include "model.h" 4 | #include "log.h" 5 | 6 | #ifndef VERSION 7 | #define VERSION "0.0.0" 8 | #endif 9 | 10 | using namespace c74::min; 11 | 12 | class Encoder : public object { 13 | public: 14 | MIN_DESCRIPTION {"Encode an image to a vector of floats."}; 15 | MIN_TAGS {"torch"}; 16 | MIN_AUTHOR {"Rodrigo Diaz"}; 17 | MIN_RELATED {"print"}; 18 | 19 | Encoder(const atoms &args = {}); 20 | ~Encoder(); 21 | 22 | inlet<> input { this, "(list) input values" }; 23 | outlet<> output { this, "(list) output" }; 24 | 25 | message<> load { this, "load", "Load a model from a file", 26 | MIN_FUNCTION { 27 | if (args.size() == 1) 28 | { 29 | auto modelPath = std::string(args[0]); 30 | loadModel(modelPath); 31 | } 32 | return {}; 33 | } 34 | }; 35 | 36 | attribute width 37 | { 38 | this, 39 | "width", 40 | 64, 41 | description {"Width of the input image."}, 42 | }; 43 | 44 | attribute height 45 | { 46 | this, 47 | "height", 48 | 64, 49 | description {"Height of the input image."}, 50 | }; 51 | 52 | attribute channels 53 | { 54 | this, 55 | "channels", 56 | 1, 57 | description {"Number of channels of the input image."}, 58 | }; 59 | 60 | attribute batch_size 61 | { 62 | this, 63 | "batch_size", 64 | 1, 65 | description {"Number of images to encode."}, 66 | }; 67 | 68 | attribute num_features 69 | { 70 | this, 71 | "num_features", 72 | 1000, 73 | description {"Number of features to encode."}, 74 | }; 75 | 76 | message<> list { this, "list", "Input to the convolution function.", 77 | MIN_FUNCTION { 78 | lock lock {m_mutex}; 79 | 80 | if (!m_loaded) 81 | { 82 | error("Model not loaded."); 83 | return {}; 84 | } 85 | 86 | std::vector x = from_atoms>(args); 87 | if (m_output.size() != num_features) 88 | { 89 | m_output.resize(num_features); 90 | } 91 | 92 | auto tensor = Model::getInstance().toTensor( 93 | x.data(), 94 | batch_size, 95 | channels, 96 | height, 97 | width 98 | ); 99 | 100 | // for images we need to repeat the tensor to match the number of channels 101 | tensor = tensor.repeat({1, 3, 1, 1}); 102 | 103 | Model::getInstance().process( 104 | tensor, 105 | m_output.data() 106 | ); 107 | 108 | lock.unlock(); 109 | output.send(to_atoms(m_output)); 110 | 111 | return {}; 112 | } 113 | }; 114 | 115 | message<> maxclass_setup { this, "maxclass_setup", 116 | MIN_FUNCTION 117 | { 118 | cout << "encoder - " << VERSION << " - 2022 - Rodrigo Diaz" << endl; 119 | return {}; 120 | } 121 | }; 122 | private: 123 | void loadModel(const std::string &path); 124 | 125 | private: 126 | bool m_loaded {false}; 127 | std::mutex m_mutex; 128 | std::vector m_output; 129 | }; 130 | 131 | Encoder::Encoder(const atoms &args) 132 | { 133 | if (!args.empty()) 134 | { 135 | auto modelPath = std::string(args[0]); 136 | loadModel(modelPath); 137 | } 138 | } 139 | 140 | void Encoder::loadModel(const std::string &path) 141 | { 142 | if (0 == Model::getInstance().loadModel(path, "cpu")) 143 | { 144 | cout << "model with path: " << path << " loaded" << endl; 145 | m_loaded = true; 146 | } 147 | else 148 | { 149 | cout << "model with path: " << path << " could not be loaded" << endl; 150 | } 151 | } 152 | 153 | Encoder::~Encoder() {} 154 | 155 | 156 | MIN_EXTERNAL(Encoder); 157 | -------------------------------------------------------------------------------- /src/maxmsp/encoder/encoder.maxhelp: -------------------------------------------------------------------------------- 1 | { 2 | "patcher" : { 3 | "fileversion" : 1, 4 | "appversion" : { 5 | "major" : 8, 6 | "minor" : 5, 7 | "revision" : 2, 8 | "architecture" : "x64", 9 | "modernui" : 1 10 | } 11 | , 12 | "classnamespace" : "box", 13 | "rect" : [ 34.0, 100.0, 1220.0, 767.0 ], 14 | "bglocked" : 0, 15 | "openinpresentation" : 0, 16 | "default_fontsize" : 12.0, 17 | "default_fontface" : 0, 18 | "default_fontname" : "Arial", 19 | "gridonopen" : 1, 20 | "gridsize" : [ 15.0, 15.0 ], 21 | "gridsnaponopen" : 1, 22 | "objectsnaponopen" : 1, 23 | "statusbarvisible" : 2, 24 | "toolbarvisible" : 1, 25 | "lefttoolbarpinned" : 0, 26 | "toptoolbarpinned" : 0, 27 | "righttoolbarpinned" : 0, 28 | "bottomtoolbarpinned" : 0, 29 | "toolbars_unpinned_last_save" : 0, 30 | "tallnewobj" : 0, 31 | "boxanimatetime" : 200, 32 | "enablehscroll" : 1, 33 | "enablevscroll" : 1, 34 | "devicewidth" : 0.0, 35 | "description" : "", 36 | "digest" : "", 37 | "tags" : "", 38 | "style" : "", 39 | "subpatcher_template" : "", 40 | "assistshowspatchername" : 0, 41 | "boxes" : [ { 42 | "box" : { 43 | "id" : "obj-26", 44 | "maxclass" : "newobj", 45 | "numinlets" : 1, 46 | "numoutlets" : 2, 47 | "outlettype" : [ "jit_matrix", "" ], 48 | "patching_rect" : [ 92.0, 378.0, 165.0, 22.0 ], 49 | "text" : "jit.matrix conv 4 float32 64 64" 50 | } 51 | 52 | } 53 | , { 54 | "box" : { 55 | "id" : "obj-21", 56 | "maxclass" : "jit.pwindow", 57 | "numinlets" : 1, 58 | "numoutlets" : 2, 59 | "outlettype" : [ "jit_matrix", "" ], 60 | "patching_rect" : [ 92.0, 418.0, 80.0, 60.0 ], 61 | "sync" : 1 62 | } 63 | 64 | } 65 | , { 66 | "box" : { 67 | "id" : "obj-25", 68 | "maxclass" : "button", 69 | "numinlets" : 1, 70 | "numoutlets" : 1, 71 | "outlettype" : [ "bang" ], 72 | "parameter_enable" : 0, 73 | "patching_rect" : [ 340.0, 295.0, 24.0, 24.0 ] 74 | } 75 | 76 | } 77 | , { 78 | "box" : { 79 | "fontface" : 0, 80 | "fontname" : "Arial", 81 | "fontsize" : 12.0, 82 | "id" : "obj-16", 83 | "maxclass" : "jit.fpsgui", 84 | "numinlets" : 1, 85 | "numoutlets" : 2, 86 | "outlettype" : [ "", "" ], 87 | "patching_rect" : [ 160.5, 40.5, 80.0, 35.0 ] 88 | } 89 | 90 | } 91 | , { 92 | "box" : { 93 | "id" : "obj-46", 94 | "maxclass" : "newobj", 95 | "numinlets" : 1, 96 | "numoutlets" : 2, 97 | "outlettype" : [ "", "" ], 98 | "patching_rect" : [ 340.0, 359.0, 189.0, 22.0 ], 99 | "text" : "jit.spill @plane 1 @listlength 4096" 100 | } 101 | 102 | } 103 | , { 104 | "box" : { 105 | "id" : "obj-57", 106 | "maxclass" : "newobj", 107 | "numinlets" : 1, 108 | "numoutlets" : 2, 109 | "outlettype" : [ "jit_matrix", "" ], 110 | "patching_rect" : [ 340.0, 326.0, 165.0, 22.0 ], 111 | "text" : "jit.matrix conv 1 float32 64 64" 112 | } 113 | 114 | } 115 | , { 116 | "box" : { 117 | "id" : "obj-17", 118 | "maxclass" : "newobj", 119 | "numinlets" : 1, 120 | "numoutlets" : 3, 121 | "outlettype" : [ "jit_gl_texture", "", "" ], 122 | "patching_rect" : [ 92.0, 241.0, 125.0, 22.0 ], 123 | "text" : "jit.gl.node @capture 1" 124 | } 125 | 126 | } 127 | , { 128 | "box" : { 129 | "id" : "obj-15", 130 | "maxclass" : "newobj", 131 | "numinlets" : 1, 132 | "numoutlets" : 2, 133 | "outlettype" : [ "jit_matrix", "" ], 134 | "patching_rect" : [ 92.0, 336.0, 107.0, 22.0 ], 135 | "text" : "jit.gl.asyncread ctx" 136 | } 137 | 138 | } 139 | , { 140 | "box" : { 141 | "fontname" : "Arial", 142 | "fontsize" : 13.0, 143 | "id" : "obj-12", 144 | "maxclass" : "message", 145 | "numinlets" : 2, 146 | "numoutlets" : 1, 147 | "outlettype" : [ "" ], 148 | "patching_rect" : [ 39.5, 188.0, 209.0, 23.0 ], 149 | "text" : "reset, glcolor 1. 1. 1. 1., sphere 0.5" 150 | } 151 | 152 | } 153 | , { 154 | "box" : { 155 | "fontname" : "Arial", 156 | "fontsize" : 13.0, 157 | "id" : "obj-14", 158 | "maxclass" : "newobj", 159 | "numinlets" : 1, 160 | "numoutlets" : 2, 161 | "outlettype" : [ "", "" ], 162 | "patching_rect" : [ 39.5, 298.0, 93.0, 23.0 ], 163 | "text" : "jit.gl.sketch ctx" 164 | } 165 | 166 | } 167 | , { 168 | "box" : { 169 | "id" : "obj-9", 170 | "maxclass" : "toggle", 171 | "numinlets" : 1, 172 | "numoutlets" : 1, 173 | "outlettype" : [ "int" ], 174 | "parameter_enable" : 0, 175 | "patching_rect" : [ 37.5, 36.5, 24.0, 24.0 ] 176 | } 177 | 178 | } 179 | , { 180 | "box" : { 181 | "id" : "obj-10", 182 | "linecount" : 3, 183 | "maxclass" : "newobj", 184 | "numinlets" : 1, 185 | "numoutlets" : 3, 186 | "outlettype" : [ "jit_matrix", "bang", "" ], 187 | "patching_rect" : [ 37.5, 79.0, 203.0, 49.0 ], 188 | "text" : "jit.world ctx @visible 0 @fps 30 @displaylink 0 @erase_color 0 0 0 1 @output_matrix 1 @size 128 128" 189 | } 190 | 191 | } 192 | , { 193 | "box" : { 194 | "id" : "obj-19", 195 | "maxclass" : "newobj", 196 | "numinlets" : 1, 197 | "numoutlets" : 0, 198 | "patching_rect" : [ 420.0, 453.0, 81.0, 22.0 ], 199 | "text" : "print @popup" 200 | } 201 | 202 | } 203 | , { 204 | "box" : { 205 | "fontname" : "Arial", 206 | "fontsize" : 13.0, 207 | "id" : "obj-23", 208 | "maxclass" : "comment", 209 | "numinlets" : 1, 210 | "numoutlets" : 0, 211 | "patching_rect" : [ 362.0, 267.0, 195.0, 21.0 ], 212 | "text" : "Send the matrix as list" 213 | } 214 | 215 | } 216 | , { 217 | "box" : { 218 | "id" : "obj-11", 219 | "maxclass" : "button", 220 | "numinlets" : 1, 221 | "numoutlets" : 1, 222 | "outlettype" : [ "bang" ], 223 | "parameter_enable" : 0, 224 | "patching_rect" : [ 39.25, 152.5, 24.0, 24.0 ] 225 | } 226 | 227 | } 228 | , { 229 | "box" : { 230 | "fontname" : "Arial", 231 | "fontsize" : 13.0, 232 | "id" : "obj-22", 233 | "maxclass" : "comment", 234 | "numinlets" : 1, 235 | "numoutlets" : 0, 236 | "patching_rect" : [ 464.0, 40.5, 195.0, 21.0 ], 237 | "text" : "Load the model" 238 | } 239 | 240 | } 241 | , { 242 | "box" : { 243 | "id" : "obj-8", 244 | "maxclass" : "newobj", 245 | "numinlets" : 1, 246 | "numoutlets" : 1, 247 | "outlettype" : [ "" ], 248 | "patching_rect" : [ 448.0, 165.5, 79.0, 22.0 ], 249 | "text" : "prepend load" 250 | } 251 | 252 | } 253 | , { 254 | "box" : { 255 | "id" : "obj-7", 256 | "maxclass" : "newobj", 257 | "numinlets" : 1, 258 | "numoutlets" : 2, 259 | "outlettype" : [ "", "int" ], 260 | "patching_rect" : [ 448.0, 132.5, 137.0, 22.0 ], 261 | "text" : "conformpath native boot" 262 | } 263 | 264 | } 265 | , { 266 | "box" : { 267 | "id" : "obj-5", 268 | "maxclass" : "message", 269 | "numinlets" : 2, 270 | "numoutlets" : 1, 271 | "outlettype" : [ "" ], 272 | "patching_rect" : [ 448.0, 63.5, 65.0, 22.0 ], 273 | "text" : "encoder.pt" 274 | } 275 | 276 | } 277 | , { 278 | "box" : { 279 | "id" : "obj-2", 280 | "maxclass" : "newobj", 281 | "numinlets" : 1, 282 | "numoutlets" : 1, 283 | "outlettype" : [ "" ], 284 | "patching_rect" : [ 448.0, 97.5, 77.0, 22.0 ], 285 | "text" : "absolutepath" 286 | } 287 | 288 | } 289 | , { 290 | "box" : { 291 | "id" : "obj-1", 292 | "maxclass" : "newobj", 293 | "numinlets" : 2, 294 | "numoutlets" : 1, 295 | "outlettype" : [ "" ], 296 | "patching_rect" : [ 420.0, 417.0, 52.0, 22.0 ], 297 | "text" : "encoder" 298 | } 299 | 300 | } 301 | , { 302 | "box" : { 303 | "background" : 1, 304 | "bgcolor" : [ 1.0, 0.788235, 0.470588, 1.0 ], 305 | "fontface" : 1, 306 | "hint" : "", 307 | "id" : "obj-6", 308 | "ignoreclick" : 1, 309 | "legacytextcolor" : 1, 310 | "maxclass" : "textbutton", 311 | "numinlets" : 1, 312 | "numoutlets" : 3, 313 | "outlettype" : [ "", "", "int" ], 314 | "parameter_enable" : 0, 315 | "patching_rect" : [ 340.0, 267.0, 20.0, 20.0 ], 316 | "rounded" : 60.0, 317 | "text" : "4", 318 | "textcolor" : [ 0.34902, 0.34902, 0.34902, 1.0 ] 319 | } 320 | 321 | } 322 | , { 323 | "box" : { 324 | "background" : 1, 325 | "bgcolor" : [ 1.0, 0.788235, 0.470588, 1.0 ], 326 | "fontface" : 1, 327 | "hint" : "", 328 | "id" : "obj-24", 329 | "ignoreclick" : 1, 330 | "legacytextcolor" : 1, 331 | "maxclass" : "textbutton", 332 | "numinlets" : 1, 333 | "numoutlets" : 3, 334 | "outlettype" : [ "", "", "int" ], 335 | "parameter_enable" : 0, 336 | "patching_rect" : [ 70.0, 152.5, 20.0, 20.0 ], 337 | "rounded" : 60.0, 338 | "text" : "2", 339 | "textcolor" : [ 0.34902, 0.34902, 0.34902, 1.0 ] 340 | } 341 | 342 | } 343 | , { 344 | "box" : { 345 | "background" : 1, 346 | "bgcolor" : [ 1.0, 0.788235, 0.470588, 1.0 ], 347 | "fontface" : 1, 348 | "hint" : "", 349 | "id" : "obj-4", 350 | "ignoreclick" : 1, 351 | "legacytextcolor" : 1, 352 | "maxclass" : "textbutton", 353 | "numinlets" : 1, 354 | "numoutlets" : 3, 355 | "outlettype" : [ "", "", "int" ], 356 | "parameter_enable" : 0, 357 | "patching_rect" : [ 444.0, 40.5, 20.0, 20.0 ], 358 | "rounded" : 60.0, 359 | "text" : "3", 360 | "textcolor" : [ 0.34902, 0.34902, 0.34902, 1.0 ] 361 | } 362 | 363 | } 364 | , { 365 | "box" : { 366 | "background" : 1, 367 | "bgcolor" : [ 1.0, 0.788235, 0.470588, 1.0 ], 368 | "bgoncolor" : [ 0.55, 0.55, 0.55, 1.0 ], 369 | "fontname" : "Arial Bold", 370 | "hint" : "", 371 | "id" : "obj-93", 372 | "ignoreclick" : 1, 373 | "legacytextcolor" : 1, 374 | "maxclass" : "textbutton", 375 | "numinlets" : 1, 376 | "numoutlets" : 3, 377 | "outlettype" : [ "", "", "int" ], 378 | "parameter_enable" : 0, 379 | "patching_rect" : [ 63.5, 40.5, 20.0, 20.0 ], 380 | "rounded" : 60.0, 381 | "text" : "1", 382 | "textcolor" : [ 0.34902, 0.34902, 0.34902, 1.0 ], 383 | "textoncolor" : [ 1.0, 1.0, 1.0, 1.0 ], 384 | "textovercolor" : [ 0.2, 0.2, 0.2, 1.0 ], 385 | "usebgoncolor" : 1, 386 | "usetextovercolor" : 1 387 | } 388 | 389 | } 390 | ], 391 | "lines" : [ { 392 | "patchline" : { 393 | "destination" : [ "obj-19", 0 ], 394 | "source" : [ "obj-1", 0 ] 395 | } 396 | 397 | } 398 | , { 399 | "patchline" : { 400 | "destination" : [ "obj-16", 0 ], 401 | "source" : [ "obj-10", 1 ] 402 | } 403 | 404 | } 405 | , { 406 | "patchline" : { 407 | "destination" : [ "obj-12", 0 ], 408 | "source" : [ "obj-11", 0 ] 409 | } 410 | 411 | } 412 | , { 413 | "patchline" : { 414 | "destination" : [ "obj-14", 0 ], 415 | "source" : [ "obj-12", 0 ] 416 | } 417 | 418 | } 419 | , { 420 | "patchline" : { 421 | "destination" : [ "obj-26", 0 ], 422 | "source" : [ "obj-15", 0 ] 423 | } 424 | 425 | } 426 | , { 427 | "patchline" : { 428 | "destination" : [ "obj-14", 0 ], 429 | "source" : [ "obj-17", 1 ] 430 | } 431 | 432 | } 433 | , { 434 | "patchline" : { 435 | "destination" : [ "obj-15", 0 ], 436 | "source" : [ "obj-17", 0 ] 437 | } 438 | 439 | } 440 | , { 441 | "patchline" : { 442 | "destination" : [ "obj-7", 0 ], 443 | "source" : [ "obj-2", 0 ] 444 | } 445 | 446 | } 447 | , { 448 | "patchline" : { 449 | "destination" : [ "obj-57", 0 ], 450 | "source" : [ "obj-25", 0 ] 451 | } 452 | 453 | } 454 | , { 455 | "patchline" : { 456 | "destination" : [ "obj-21", 0 ], 457 | "source" : [ "obj-26", 0 ] 458 | } 459 | 460 | } 461 | , { 462 | "patchline" : { 463 | "destination" : [ "obj-1", 0 ], 464 | "source" : [ "obj-46", 0 ] 465 | } 466 | 467 | } 468 | , { 469 | "patchline" : { 470 | "destination" : [ "obj-2", 0 ], 471 | "source" : [ "obj-5", 0 ] 472 | } 473 | 474 | } 475 | , { 476 | "patchline" : { 477 | "destination" : [ "obj-46", 0 ], 478 | "source" : [ "obj-57", 0 ] 479 | } 480 | 481 | } 482 | , { 483 | "patchline" : { 484 | "destination" : [ "obj-8", 0 ], 485 | "source" : [ "obj-7", 0 ] 486 | } 487 | 488 | } 489 | , { 490 | "patchline" : { 491 | "destination" : [ "obj-1", 0 ], 492 | "source" : [ "obj-8", 0 ] 493 | } 494 | 495 | } 496 | , { 497 | "patchline" : { 498 | "destination" : [ "obj-10", 0 ], 499 | "source" : [ "obj-9", 0 ] 500 | } 501 | 502 | } 503 | ], 504 | "dependency_cache" : [ { 505 | "name" : "encoder.mxo", 506 | "type" : "iLaX" 507 | } 508 | ], 509 | "autosave" : 0 510 | } 511 | 512 | } 513 | -------------------------------------------------------------------------------- /src/maxmsp/fc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(${C74_MIN_API_DIR}/script/min-pretarget.cmake) 2 | 3 | include_directories( 4 | "${C74_INCLUDES}" 5 | ) 6 | 7 | set( SOURCE_FILES 8 | ${PROJECT_NAME}.cpp 9 | ) 10 | 11 | add_library( 12 | ${PROJECT_NAME} 13 | MODULE 14 | ${SOURCE_FILES} 15 | ) 16 | 17 | target_compile_definitions( 18 | ${PROJECT_NAME} 19 | PUBLIC 20 | VERSION="${CMAKE_PROJECT_VERSION}" 21 | ) 22 | 23 | target_link_libraries( 24 | ${PROJECT_NAME} 25 | PUBLIC 26 | torchwrapper 27 | ) 28 | 29 | include(${C74_MIN_API_DIR}/script/min-posttarget.cmake) 30 | 31 | if (APPLE) 32 | add_custom_command( 33 | TARGET ${PROJECT_NAME} 34 | POST_BUILD 35 | COMMAND cp "${TORCH_INSTALL_PREFIX}/lib/*.dylib" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${${PROJECT_NAME}_EXTERN_OUTPUT_NAME}.mxo/Contents/MacOS/" 36 | COMMENT "Copy Torch Libraries" 37 | ) 38 | 39 | if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") 40 | add_custom_command( 41 | TARGET ${PROJECT_NAME} 42 | POST_BUILD 43 | COMMAND "codesign" "--force" "--deep" "-s" "-" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${${PROJECT_NAME}_EXTERN_OUTPUT_NAME}.mxo" 44 | COMMENT "Codesign external" 45 | ) 46 | endif() 47 | endif() 48 | 49 | ############################################################# 50 | # UNIT TEST 51 | ############################################################# 52 | 53 | include(${C74_MIN_API_DIR}/test/min-object-unittest.cmake) 54 | target_link_libraries( 55 | "${PROJECT_NAME}_test" 56 | PUBLIC 57 | torchwrapper 58 | ) 59 | target_compile_options( 60 | "${PROJECT_NAME}_test" 61 | PUBLIC 62 | -Wno-deprecated-declarations 63 | ) 64 | -------------------------------------------------------------------------------- /src/maxmsp/fc/fc.cpp: -------------------------------------------------------------------------------- 1 | #include "c74_min.h" 2 | 3 | #include "model.h" 4 | #include "log.h" 5 | 6 | #ifndef VERSION 7 | #define VERSION "0.0.0" 8 | #endif 9 | 10 | using namespace c74::min; 11 | 12 | class FC : public object { 13 | public: 14 | MIN_DESCRIPTION {"Loads and runs a NN."}; 15 | MIN_TAGS {"torch"}; 16 | MIN_AUTHOR {"Rodrigo Diaz"}; 17 | MIN_RELATED {"print"}; 18 | 19 | FC(const atoms &args = {}); 20 | ~FC(); 21 | 22 | inlet<> input { this, "(list) flattened input" }; 23 | outlet<> output { this, "(list) features" }; 24 | 25 | message<> load { this, "load", "Load a model from a file", 26 | MIN_FUNCTION { 27 | if (args.size() == 1) 28 | { 29 | auto modelPath = std::string(args[0]); 30 | loadModel(modelPath); 31 | } 32 | return {}; 33 | } 34 | }; 35 | 36 | attribute out_features 37 | { 38 | this, 39 | "out_features", 40 | 32 * 2 * 6, 41 | description {"Number of output features."}, 42 | }; 43 | 44 | message<> set { this, "set", "Set a parameter of the model.", 45 | MIN_FUNCTION { 46 | if (args.size() == 2) 47 | { 48 | auto name = std::string(args[0]); 49 | auto value = args[1]; 50 | 51 | lock lock {m_mutex}; 52 | Model::getInstance().callMethod(name, value); 53 | lock.unlock(); 54 | } 55 | return {}; 56 | } 57 | }; 58 | message<> list { this, "list", "Input to the network.", 59 | MIN_FUNCTION { 60 | lock lock {m_mutex}; 61 | 62 | if (!m_loaded) 63 | { 64 | cout << "Model not loaded." << endl; 65 | return {}; 66 | } 67 | 68 | std::vector x = from_atoms>(args); 69 | if (m_output.size() != out_features) 70 | { 71 | m_output.resize(out_features); 72 | } 73 | 74 | auto tensor = Model::getInstance().toTensor( 75 | x.data(), 76 | 1, 77 | 1, 78 | 1, 79 | x.size() 80 | ); 81 | 82 | Model::getInstance().process( 83 | tensor, 84 | m_output.data() 85 | ); 86 | 87 | lock.unlock(); 88 | output.send(to_atoms(m_output)); 89 | 90 | return {}; 91 | } 92 | }; 93 | 94 | message<> maxclass_setup { this, "maxclass_setup", 95 | MIN_FUNCTION 96 | { 97 | cout << "fc - " << VERSION << " - 2022 - Rodrigo Diaz" << endl; 98 | return {}; 99 | } 100 | }; 101 | private: 102 | void loadModel(const std::string &path); 103 | 104 | private: 105 | bool m_loaded {false}; 106 | std::mutex m_mutex; 107 | std::vector m_output; 108 | }; 109 | 110 | FC::FC(const atoms &args) 111 | { 112 | if (!args.empty()) 113 | { 114 | auto modelPath = std::string(args[0]); 115 | loadModel(modelPath); 116 | } 117 | } 118 | 119 | void FC::loadModel(const std::string &path) 120 | { 121 | if (0 == Model::getInstance().loadModel(path, "cpu")) 122 | { 123 | cout << "model with path: " << path << " loaded" << endl; 124 | m_loaded = true; 125 | } 126 | else 127 | { 128 | cout << "model with path: " << path << " could not be loaded" << endl; 129 | } 130 | } 131 | 132 | FC::~FC() {} 133 | 134 | MIN_EXTERNAL(FC); 135 | -------------------------------------------------------------------------------- /src/maxmsp/fc/fc.maxhelp: -------------------------------------------------------------------------------- 1 | { 2 | "patcher" : { 3 | "fileversion" : 1, 4 | "appversion" : { 5 | "major" : 8, 6 | "minor" : 5, 7 | "revision" : 2, 8 | "architecture" : "x64", 9 | "modernui" : 1 10 | } 11 | , 12 | "classnamespace" : "box", 13 | "rect" : [ 588.0, 242.0, 640.0, 480.0 ], 14 | "bglocked" : 0, 15 | "openinpresentation" : 0, 16 | "default_fontsize" : 12.0, 17 | "default_fontface" : 0, 18 | "default_fontname" : "Arial", 19 | "gridonopen" : 1, 20 | "gridsize" : [ 15.0, 15.0 ], 21 | "gridsnaponopen" : 1, 22 | "objectsnaponopen" : 1, 23 | "statusbarvisible" : 2, 24 | "toolbarvisible" : 1, 25 | "lefttoolbarpinned" : 0, 26 | "toptoolbarpinned" : 0, 27 | "righttoolbarpinned" : 0, 28 | "bottomtoolbarpinned" : 0, 29 | "toolbars_unpinned_last_save" : 0, 30 | "tallnewobj" : 0, 31 | "boxanimatetime" : 200, 32 | "enablehscroll" : 1, 33 | "enablevscroll" : 1, 34 | "devicewidth" : 0.0, 35 | "description" : "", 36 | "digest" : "", 37 | "tags" : "", 38 | "style" : "", 39 | "subpatcher_template" : "", 40 | "assistshowspatchername" : 0, 41 | "boxes" : [ { 42 | "box" : { 43 | "fontname" : "Arial", 44 | "fontsize" : 13.0, 45 | "id" : "obj-23", 46 | "linecount" : 5, 47 | "maxclass" : "comment", 48 | "numinlets" : 1, 49 | "numoutlets" : 0, 50 | "patching_rect" : [ 93.5, 73.0, 195.0, 79.0 ], 51 | "text" : "Send the values, depending on the loaded model we will need to make sure the input size corresponds to the model's input size." 52 | } 53 | 54 | } 55 | , { 56 | "box" : { 57 | "fontname" : "Arial", 58 | "fontsize" : 13.0, 59 | "id" : "obj-22", 60 | "maxclass" : "comment", 61 | "numinlets" : 1, 62 | "numoutlets" : 0, 63 | "patching_rect" : [ 344.0, 66.0, 195.0, 21.0 ], 64 | "text" : "Load the model" 65 | } 66 | 67 | } 68 | , { 69 | "box" : { 70 | "id" : "obj-21", 71 | "maxclass" : "newobj", 72 | "numinlets" : 1, 73 | "numoutlets" : 1, 74 | "outlettype" : [ "" ], 75 | "patcher" : { 76 | "fileversion" : 1, 77 | "appversion" : { 78 | "major" : 8, 79 | "minor" : 5, 80 | "revision" : 2, 81 | "architecture" : "x64", 82 | "modernui" : 1 83 | } 84 | , 85 | "classnamespace" : "box", 86 | "rect" : [ 59.0, 119.0, 640.0, 480.0 ], 87 | "bglocked" : 0, 88 | "openinpresentation" : 0, 89 | "default_fontsize" : 12.0, 90 | "default_fontface" : 0, 91 | "default_fontname" : "Arial", 92 | "gridonopen" : 1, 93 | "gridsize" : [ 15.0, 15.0 ], 94 | "gridsnaponopen" : 1, 95 | "objectsnaponopen" : 1, 96 | "statusbarvisible" : 2, 97 | "toolbarvisible" : 1, 98 | "lefttoolbarpinned" : 0, 99 | "toptoolbarpinned" : 0, 100 | "righttoolbarpinned" : 0, 101 | "bottomtoolbarpinned" : 0, 102 | "toolbars_unpinned_last_save" : 0, 103 | "tallnewobj" : 0, 104 | "boxanimatetime" : 200, 105 | "enablehscroll" : 1, 106 | "enablevscroll" : 1, 107 | "devicewidth" : 0.0, 108 | "description" : "", 109 | "digest" : "", 110 | "tags" : "", 111 | "style" : "", 112 | "subpatcher_template" : "", 113 | "assistshowspatchername" : 0, 114 | "boxes" : [ { 115 | "box" : { 116 | "id" : "obj-11", 117 | "linecount" : 313, 118 | "maxclass" : "message", 119 | "numinlets" : 2, 120 | "numoutlets" : 1, 121 | "outlettype" : [ "" ], 122 | "patching_rect" : [ 50.0, 100.0, 222.0, 4205.0 ], 123 | "presentation" : 1, 124 | "presentation_linecount" : 313, 125 | "presentation_rect" : [ 369.0, 299.0, 222.0, 4205.0 ], 126 | "text" : "-0.001436 -0.084742 -0.001168 0.009148 0.000078 0.000604 -0.000064 -0.000955 0.017789 -0.001886 0.018542 0.018337 -0.001704 0.009327 0.008669 0.009197 -0.15291 0.004286 -0.005986 0.026129 -0.106516 -0.004522 0.011924 -0.004578 0.020894 -0.006322 -0.001541 -0.006778 -0.001413 0.009577 -0.001028 0.000699 -0.153747 0.04489 0.022687 -0.008212 0.014208 -0.000049 0.002666 -0.191132 0.002093 -0.015681 0.000948 -0.017899 -0.003699 0.010871 -0.002394 0.023453 0.002108 0.007641 -0.000608 0.029507 -0.01465 -0.013023 -0.001592 0.001291 -0.011376 -0.010331 0.003608 -0.012557 -0.007716 -0.002631 -0.007365 -0.014146 -0.006523 -0.022319 -0.003283 -0.018123 -0.00759 0.011322 0.002598 -0.005482 0.003064 0.005696 -0.00425 0.001423 0.009213 -0.012387 0.012635 -0.009828 0.001038 -0.15181 0.000905 -0.150899 -0.082256 0.001591 0.010371 0.008849 -0.019096 0.009867 0.003806 0.008231 -0.020204 -0.188321 -0.199304 0.001263 0.006002 -0.008799 0.004953 0.003348 0.000957 -0.001703 0.001737 0.023382 -0.005791 0.017804 -0.011797 0.008968 0.001397 0.001008 -0.004283 -0.030426 0.0172 -0.154391 0.002479 -0.334384 0.006329 -0.005863 -0.023262 0.004825 -0.006396 -0.013807 -0.032162 -0.029546 -0.01009 -0.00821 -0.010677 -0.022719 -0.000519 0.012734 0.003049 0.003176 -0.000515 0.00304 -0.007022 -0.180766 0.000613 0.007419 -0.181312 0.006089 0.010831 0.004552 0.020826 0.005722 0.022911 0.005529 -0.000242 0.005835 0.016652 -0.001969 0.006749 0.010181 0.007711 -0.012764 -0.000897 0.000426 0.002478 -0.013662 -0.000696 -0.009817 -0.067881 0.001095 -0.000836 0.006357 -0.004801 -0.002279 0.000569 0.005846 0.00761 -0.019098 0.001698 -0.003143 -0.007982 -0.008044 -0.002689 -0.104677 0.019251 0.000888 -0.004612 0.006267 -0.000693 -0.004777 -0.001345 -0.001368 -0.004875 0.004619 -0.000445 -0.001388 0.00679 0.008148 0.009588 -0.012191 -0.006955 0.001207 0.017781 -0.004355 -0.009411 -0.017909 0.003013 -0.009718 0.002931 -0.002078 -0.000918 -0.000175 -0.007282 0.006609 -0.001276 0.003774 0.001425 0.003638 0.003279 0.002724 0.004239 0.000632 -0.005267 0.007879 0.000128 0.007178 -0.000121 0.003318 0.010845 0.0014 0.001992 -0.009588 0.002686 0.005963 0.002612 -0.007078 -0.001321 0.005873 -0.001051 0.007384 0.000523 -0.010531 -0.005724 -0.0005 -0.004705 0.003262 0.002909 -0.001674 0.002785 0.007161 -0.007708 -0.010593 0.001971 0.007321 -0.004188 0.005602 -0.002469 -0.015599 -0.002564 -0.001034 0.000376 0.003355 0.013886 -0.004575 0.004085 -0.045288 0.000811 -0.010742 0.001904 -0.014251 0.024856 -0.005405 0.009725 0.001488 0.000799 0.005525 0.023225 0.009771 0.012521 0.015012 0.004677 0.005727 0.012546 -0.008754 0.005571 -0.013009 0.008005 -0.0158 0.02035 0.00474 -0.002868 0.003773 -0.009864 0.008165 -0.003107 -0.002485 -0.002388 0.00705 -0.008558 -0.232494 -0.004173 -0.013182 -0.128209 -0.005926 0.014043 -0.001002 -0.00945 -0.007661 0.005835 -0.003247 0.01159 -0.001993 -0.001637 -0.011058 -0.00173 -0.001294 0.016453 0.025234 0.006788 0.018587 0.005299 -0.000036 -0.024275 0.006221 0.002008 -0.004799 -0.000097 -0.010017 -0.001126 -0.035341 0.013673 0.009518 -0.005044 0.003671 -0.007451 0.005147 -0.002055 0.008131 -0.00283 -0.007551 -0.022131 -0.013839 0.015264 -0.033698 0.016165 0.010379 -0.001234 -0.040652 -0.003696 -0.118265 -0.008137 0.004949 0.000382 0.009006 -0.015876 -0.009207 -0.022828 -0.003669 0.004109 -0.028882 -0.01312 -0.007095 -0.099535 0.004143 -0.003469 -0.013916 -0.006633 -0.005428 0.002659 -0.018252 -0.00084 -0.003366 -0.002754 -0.004693 -0.005026 0.000268 0.010497 -0.017421 -0.002866 -0.015518 -0.011503 0.00259 0.002488 0.004795 0.020166 0.007952 0.00625 0.000583 -0.001197 -0.000871 -0.002576 -0.000954 0.014026 0.014319 0.001349 -0.014331 -0.003494 0.000534 -0.131035 0.018867 -0.006003 0.000965 0.010058 0.015642 -0.009097 0.009812 -0.005994 0.009903 -0.008114 0.009834 -0.005238 0.002553 -0.135593 -0.004792 -0.018289 0.009139 -0.05649 -0.016537 0.018035 -0.011089 0.00141 0.001168 0.001363 -0.006452 0.003859 0.003893 -0.012357 -0.000159 0.006479 0.000569 -0.011705 0.013024 0.028201 -0.01773 0.006492 0.000685 0.003662 0.003197 0.003886 -0.000028 -0.014837 0.015099 0.010634 -0.012359 -0.018322 0.002993 0.022758 -0.005762 0.008889 0.017836 -0.005567 0.006706 -0.018746 -0.007786 0.000132 -0.014969 -0.005434 -0.000702 0.003928 -0.005732 -0.039695 -0.007676 -0.001931 0.003229 -0.02353 -0.012267 -0.003603 0.010417 -0.002422 -0.01032 -0.011607 -0.005287 -0.00674 0.005537 0.007106 -0.00167 -0.010801 -0.013647 0.021011 -0.01095 0.002169 0.008268 -0.014663 -0.002658 -0.187914 0.009155 0.007471 -0.003715 0.016294 0.001736 -0.011613 -0.004629 0.028509 0.000207 -0.011869 0.007445 -0.006877 -0.015775 0.000696 -0.121196 -0.022752 0.067813 -0.004551 -0.00998 0.000492 0.006904 0.009693 -0.005779 0.00754 -0.003448 -0.004168 -0.003673 0.00158 -0.001361 0.000716 0.012141 -0.004064 -0.021169 -0.005268 -0.004577 0.000461 -0.011963 -0.005776 -0.004998 -0.008934 0.002898 -0.053773 0.010167 -0.009447 0.006634 -0.012081 0.011154 -0.005575 -0.140487 -0.013123 0.003075 0.002877 -0.003135 -0.005237 -0.007142 0.004358 0.006297 0.011497 0.005083 0.006186 0.060522 0.000422 -0.002813 0.001202 -0.005791 -0.000393 -0.002274 -0.000861 -0.009265 -0.006919 0.009944 -0.001989 0.002732 -0.004722 0.009802 -0.002168 0.003879 -0.001305 -0.004104 -0.080626 -0.004807 -0.008838 -0.003781 0.008383 -0.004961 -0.003109 0.003496 -0.005155 -0.005103 -0.012386 0.011285 0.006509 -0.003528 0.000975 0.0031 0.003408 -0.008843 -0.006933 0.004979 0.000322 -0.004078 0.003122 0.00657 0.010129 -0.012298 0.03472 0.010127 -0.090554 0.00144 -0.008444 -0.019227 -0.016015 -0.014317 -0.000929 0.015286 0.002597 0.005767 0.016872 -0.001331 -0.015372 0.006157 -0.003142 0.000696 0.058645 -0.003675 0.001135 -0.001352 -0.027688 0.011416 -0.001176 0.000308 0.014893 -0.013973 -0.009076 -0.001539 -0.013992 0.003033 -0.074761 0.010909 -0.010814 -0.004852 0.004865 0.008309 -0.009463 -0.015571 0.014212 0.009967 -0.008289 0.021197 -0.004742 -0.007321 -0.004521 -0.010085 0.000058 -0.000915 -0.002885 -0.035277 0.001016 0.006543 -0.003769 0.001304 -0.001264 -0.008523 -0.002811 -0.007788 0.001937 -0.006417 0.036309 -0.004915 0.011154 -0.00902 -0.002208 -0.005909 -0.002372 0.001679 -0.006918 -0.010647 -0.004834 0.000947 -0.002797 0.008997 0.001598 -0.002951 -0.001087 0.010361 0.022658 -0.011985 -0.008932 0.00435 0.010792 -0.001877 0.004927 0.004865 0.004527 -0.014257 0.00592 0.006164 0.021233 0.005056 -0.000355 0.009513 0.007763 -0.002888 -0.011767 0.002847 0.00371 0.007904 -0.015524 -0.008167 0.016921 0.015306 -0.007595 -0.007145 0.006006 0.01885 -0.00262 0.008053 0.015118 0.001533 0.013707 -0.032463 0.004469 -0.017901 0.014373 -0.003319 0.010613 -0.005018 0.003813 0.003132 0.002167 0.016087 -0.00022 -0.005656 0.006416 -0.00625 -0.088381 0.006459 0.003673 -0.048971 0.002364 0.000593 -0.008084 -0.012874 0.004789 0.011649 0.005119 -0.004233 -0.063377 0.001234 -0.00509 0.00733 -0.005617 0.035202 -0.004745 -0.014507 -0.006427 0.003399 0.008933 -0.018188 -0.01535 0.008449 -0.04025 0.000563 -0.001754 -0.007206 -0.004526 0.009923 0.000798 0.022226 -0.002354 0.02062 -0.007756 -0.009406 -0.005041 -0.003406 -0.17471 0.00181 -0.012603 -0.058205 0.003839 0.002956 -0.127921 -0.004301 0.004836 0.010076 -0.001815 -0.004208 -0.011268 0.005471 0.00909 -0.00278 -0.008222 0.010663 -0.075837 -0.007987 -0.017326 0.017418 -0.007132 -0.060782 -0.011505 0.015251 -0.0042 0.002985 0.014532 0.000545 -0.001459 -0.010182 0.008446 -0.01206 -0.01378 -0.23899 0.015163 -0.012319 0.011901 -0.021051 -0.005367 0.012039 -0.113217 -0.001092 0.009678 0.008476 -0.005475 -0.008413 0.00829 0.010766 -0.006414 0.000608 0.010206 0.08515 -0.006003 0.019473 -0.002901 -0.003725 0.008744 0.009099 -0.00303 0.005029 -0.000019 0.002249 -0.009164 0.007397 -0.011807 0.003767 0.005305 -0.008574 0.025048 -0.013395 -0.01216 0.002891 -0.007684 -0.000832 0.019987 0.020279 0.00669 0.002955 -0.004013 0.010471 -0.005603 0.016908 -0.01068 0.017262 0.006634 0.001368 0.002753 0.007672 0.003272 0.006333 0.017309 0.000356 -0.015958 -0.00382 0.000516 -0.007893 -0.001172 -0.002527 -0.003681 -0.008133 0.008906 -0.002793 -0.0046 0.005957 -0.013566 0.004035 0.003184 0.011741 0.009567 -0.000023 -0.010518 -0.010086 -0.071174 -0.076767 0.024674 0.003798 -0.008718 -0.001428 -0.02271 0.007235 0.005295 -0.016024 -0.000225 -0.001787 -0.059491 -0.047463 -0.005654 0.000723 -0.002038 -0.131294 -0.000972 0.043259 -0.012443 -0.147929 -0.00188 -0.006961 -0.004052 -0.090805 -0.017038 0.023425 -0.028434 0.008876 0.008792 -0.006643 0.007837 0.003569 0.001743 0.011008 -0.007794 0.000563 0.001136 -0.000937 -0.003716 -0.00037 0.005442 -0.01118 -0.005892 0.006535 -0.013898 0.000382 0.021605 -0.000284 -0.013897 -0.006885 0.002012 -0.009488 -0.012978 0.01008 -0.003156 0.00069 -0.001457 -0.000045 0.003406 0.001713 0.008585 0.000982 -0.012498 -0.000121 -0.009666 0.007935 0.005871 0.003485 -0.02934 0.004426 -0.000365 -0.003684 0.002486 -0.010341 0.007202 0.002742 0.013999 0.003345 -0.001137 0.003039 -0.003712 -0.014173 -0.019813 -0.013311 -0.062469 0.000722 0.010764 0.007579 0.002587 0.002041 -0.021646 -0.004963 0.000597 -0.019059 -0.025656 -0.012275 0.006219 0.009415 0.010004 0.020989 0.000672 0.014709 0.001036 -0.014056 -0.009339 -0.009672 -0.009201 -0.022899 0.008337 -0.000797 -0.000451 -0.002685 -0.008416 -0.001374 0.008043 0.011682 -0.008223 -0.00297 0.001464 -0.007625 -0.000529 -0.006902 -0.009836 0.010059 -0.001538 0.001922 -0.031893 0.008967 -0.008679 -0.234851 0.000973 -0.000656 0.498047 0.441406 0.9 0.2 0.5 1. 0.01" 127 | } 128 | 129 | } 130 | , { 131 | "box" : { 132 | "comment" : "", 133 | "id" : "obj-19", 134 | "index" : 1, 135 | "maxclass" : "inlet", 136 | "numinlets" : 0, 137 | "numoutlets" : 1, 138 | "outlettype" : [ "bang" ], 139 | "patching_rect" : [ 50.0, 40.0, 30.0, 30.0 ] 140 | } 141 | 142 | } 143 | , { 144 | "box" : { 145 | "comment" : "", 146 | "id" : "obj-20", 147 | "index" : 1, 148 | "maxclass" : "outlet", 149 | "numinlets" : 1, 150 | "numoutlets" : 0, 151 | "patching_rect" : [ 50.0, 4458.0, 30.0, 30.0 ] 152 | } 153 | 154 | } 155 | ], 156 | "lines" : [ { 157 | "patchline" : { 158 | "destination" : [ "obj-20", 0 ], 159 | "source" : [ "obj-11", 0 ] 160 | } 161 | 162 | } 163 | , { 164 | "patchline" : { 165 | "destination" : [ "obj-11", 0 ], 166 | "source" : [ "obj-19", 0 ] 167 | } 168 | 169 | } 170 | ] 171 | } 172 | , 173 | "patching_rect" : [ 45.5, 162.0, 53.0, 22.0 ], 174 | "saved_object_attributes" : { 175 | "description" : "", 176 | "digest" : "", 177 | "globalpatchername" : "", 178 | "tags" : "" 179 | } 180 | , 181 | "text" : "p values" 182 | } 183 | 184 | } 185 | , { 186 | "box" : { 187 | "id" : "obj-16", 188 | "maxclass" : "button", 189 | "numinlets" : 1, 190 | "numoutlets" : 1, 191 | "outlettype" : [ "bang" ], 192 | "parameter_enable" : 0, 193 | "patching_rect" : [ 45.5, 73.0, 24.0, 24.0 ] 194 | } 195 | 196 | } 197 | , { 198 | "box" : { 199 | "id" : "obj-8", 200 | "maxclass" : "newobj", 201 | "numinlets" : 1, 202 | "numoutlets" : 1, 203 | "outlettype" : [ "" ], 204 | "patching_rect" : [ 328.0, 191.0, 79.0, 22.0 ], 205 | "text" : "prepend load" 206 | } 207 | 208 | } 209 | , { 210 | "box" : { 211 | "id" : "obj-7", 212 | "maxclass" : "newobj", 213 | "numinlets" : 1, 214 | "numoutlets" : 2, 215 | "outlettype" : [ "", "int" ], 216 | "patching_rect" : [ 328.0, 158.0, 137.0, 22.0 ], 217 | "text" : "conformpath native boot" 218 | } 219 | 220 | } 221 | , { 222 | "box" : { 223 | "id" : "obj-5", 224 | "maxclass" : "message", 225 | "numinlets" : 2, 226 | "numoutlets" : 1, 227 | "outlettype" : [ "" ], 228 | "patching_rect" : [ 328.0, 89.0, 55.0, 22.0 ], 229 | "text" : "model.pt" 230 | } 231 | 232 | } 233 | , { 234 | "box" : { 235 | "id" : "obj-2", 236 | "maxclass" : "newobj", 237 | "numinlets" : 1, 238 | "numoutlets" : 1, 239 | "outlettype" : [ "" ], 240 | "patching_rect" : [ 328.0, 123.0, 77.0, 22.0 ], 241 | "text" : "absolutepath" 242 | } 243 | 244 | } 245 | , { 246 | "box" : { 247 | "id" : "obj-9", 248 | "maxclass" : "newobj", 249 | "numinlets" : 1, 250 | "numoutlets" : 0, 251 | "patching_rect" : [ 45.5, 276.0, 81.0, 22.0 ], 252 | "text" : "print @popup" 253 | } 254 | 255 | } 256 | , { 257 | "box" : { 258 | "id" : "obj-1", 259 | "maxclass" : "newobj", 260 | "numinlets" : 1, 261 | "numoutlets" : 1, 262 | "outlettype" : [ "" ], 263 | "patching_rect" : [ 45.5, 229.0, 20.0, 22.0 ], 264 | "text" : "fc" 265 | } 266 | 267 | } 268 | , { 269 | "box" : { 270 | "background" : 1, 271 | "bgcolor" : [ 1.0, 0.788235, 0.470588, 1.0 ], 272 | "fontface" : 1, 273 | "hint" : "", 274 | "id" : "obj-93", 275 | "ignoreclick" : 1, 276 | "legacytextcolor" : 1, 277 | "maxclass" : "textbutton", 278 | "numinlets" : 1, 279 | "numoutlets" : 3, 280 | "outlettype" : [ "", "", "int" ], 281 | "parameter_enable" : 0, 282 | "patching_rect" : [ 324.0, 66.0, 20.0, 20.0 ], 283 | "rounded" : 60.0, 284 | "text" : "1", 285 | "textcolor" : [ 0.34902, 0.34902, 0.34902, 1.0 ] 286 | } 287 | 288 | } 289 | , { 290 | "box" : { 291 | "background" : 1, 292 | "bgcolor" : [ 1.0, 0.788235, 0.470588, 1.0 ], 293 | "fontface" : 1, 294 | "hint" : "", 295 | "id" : "obj-24", 296 | "ignoreclick" : 1, 297 | "legacytextcolor" : 1, 298 | "maxclass" : "textbutton", 299 | "numinlets" : 1, 300 | "numoutlets" : 3, 301 | "outlettype" : [ "", "", "int" ], 302 | "parameter_enable" : 0, 303 | "patching_rect" : [ 71.5, 73.0, 20.0, 20.0 ], 304 | "rounded" : 60.0, 305 | "text" : "2", 306 | "textcolor" : [ 0.34902, 0.34902, 0.34902, 1.0 ] 307 | } 308 | 309 | } 310 | ], 311 | "lines" : [ { 312 | "patchline" : { 313 | "destination" : [ "obj-9", 0 ], 314 | "source" : [ "obj-1", 0 ] 315 | } 316 | 317 | } 318 | , { 319 | "patchline" : { 320 | "destination" : [ "obj-21", 0 ], 321 | "source" : [ "obj-16", 0 ] 322 | } 323 | 324 | } 325 | , { 326 | "patchline" : { 327 | "destination" : [ "obj-7", 0 ], 328 | "source" : [ "obj-2", 0 ] 329 | } 330 | 331 | } 332 | , { 333 | "patchline" : { 334 | "destination" : [ "obj-1", 0 ], 335 | "source" : [ "obj-21", 0 ] 336 | } 337 | 338 | } 339 | , { 340 | "patchline" : { 341 | "destination" : [ "obj-2", 0 ], 342 | "source" : [ "obj-5", 0 ] 343 | } 344 | 345 | } 346 | , { 347 | "patchline" : { 348 | "destination" : [ "obj-8", 0 ], 349 | "source" : [ "obj-7", 0 ] 350 | } 351 | 352 | } 353 | , { 354 | "patchline" : { 355 | "destination" : [ "obj-1", 0 ], 356 | "source" : [ "obj-8", 0 ] 357 | } 358 | 359 | } 360 | ], 361 | "dependency_cache" : [ { 362 | "name" : "fc.mxo", 363 | "type" : "iLaX" 364 | } 365 | ], 366 | "autosave" : 0 367 | } 368 | 369 | } 370 | -------------------------------------------------------------------------------- /src/maxmsp/fc/fc_test.cpp: -------------------------------------------------------------------------------- 1 | #include "c74_min_unittest.h" // required unit test header 2 | #include "fc.cpp" 3 | 4 | 5 | SCENARIO("object produces correct output") { 6 | ext_main(nullptr); // every unit test must call ext_main() once to configure the class 7 | 8 | GIVEN("Instantiating a fc object") 9 | { 10 | atoms args = {4, 2}; 11 | FC fc = FC(); 12 | 13 | std::vector x = { 14 | -0.001436,-0.084742,-0.001168,0.009148,0.000078,0.000604,-0.000064, 15 | -0.000955,0.017789,-0.001886,0.018542,0.018337,-0.001704,0.009327,0.008669, 16 | 0.009197,-0.15291,0.004286,-0.005986,0.026129,-0.106516,-0.004522,0.011924, 17 | -0.004578,0.020894,-0.006322,-0.001541,-0.006778,-0.001413,0.009577, 18 | -0.001028,0.000699,-0.153747,0.04489,0.022687,-0.008212,0.014208,-0.000049, 19 | 0.002666,-0.191132,0.002093,-0.015681,0.000948,-0.017899,-0.003699,0.010871, 20 | -0.002394,0.023453,0.002108,0.007641,-0.000608,0.029507,-0.01465,-0.013023, 21 | -0.001592,0.001291,-0.011376,-0.010331,0.003608,-0.012557,-0.007716, 22 | -0.002631,-0.007365,-0.014146,-0.006523,-0.022319,-0.003283,-0.018123, 23 | -0.00759,0.011322,0.002598,-0.005482,0.003064,0.005696,-0.00425,0.001423, 24 | 0.009213,-0.012387,0.012635,-0.009828,0.001038,-0.15181,0.000905,-0.150899, 25 | -0.082256,0.001591,0.010371,0.008849,-0.019096,0.009867,0.003806,0.008231, 26 | -0.020204,-0.188321,-0.199304,0.001263,0.006002,-0.008799,0.004953,0.003348, 27 | 0.000957,-0.001703,0.001737,0.023382,-0.005791,0.017804,-0.011797,0.008968, 28 | 0.001397,0.001008,-0.004283,-0.030426,0.0172,-0.154391,0.002479,-0.334384, 29 | 0.006329,-0.005863,-0.023262,0.004825,-0.006396,-0.013807,-0.032162, 30 | -0.029546,-0.01009,-0.00821,-0.010677,-0.022719,-0.000519,0.012734,0.003049, 31 | 0.003176,-0.000515,0.00304,-0.007022,-0.180766,0.000613,0.007419,-0.181312, 32 | 0.006089,0.010831,0.004552,0.020826,0.005722,0.022911,0.005529,-0.000242, 33 | 0.005835,0.016652,-0.001969,0.006749,0.010181,0.007711,-0.012764,-0.000897, 34 | 0.000426,0.002478,-0.013662,-0.000696,-0.009817,-0.067881,0.001095, 35 | -0.000836,0.006357,-0.004801,-0.002279,0.000569,0.005846,0.00761,-0.019098, 36 | 0.001698,-0.003143,-0.007982,-0.008044,-0.002689,-0.104677,0.019251, 37 | 0.000888,-0.004612,0.006267,-0.000693,-0.004777,-0.001345,-0.001368, 38 | -0.004875,0.004619,-0.000445,-0.001388,0.00679,0.008148,0.009588,-0.012191, 39 | -0.006955,0.001207,0.017781,-0.004355,-0.009411,-0.017909,0.003013, 40 | -0.009718,0.002931,-0.002078,-0.000918,-0.000175,-0.007282,0.006609, 41 | -0.001276,0.003774,0.001425,0.003638,0.003279,0.002724,0.004239,0.000632, 42 | -0.005267,0.007879,0.000128,0.007178,-0.000121,0.003318,0.010845,0.0014, 43 | 0.001992,-0.009588,0.002686,0.005963,0.002612,-0.007078,-0.001321,0.005873, 44 | -0.001051,0.007384,0.000523,-0.010531,-0.005724,-0.0005,-0.004705,0.003262, 45 | 0.002909,-0.001674,0.002785,0.007161,-0.007708,-0.010593,0.001971,0.007321, 46 | -0.004188,0.005602,-0.002469,-0.015599,-0.002564,-0.001034,0.000376, 47 | 0.003355,0.013886,-0.004575,0.004085,-0.045288,0.000811,-0.010742,0.001904, 48 | -0.014251,0.024856,-0.005405,0.009725,0.001488,0.000799,0.005525,0.023225, 49 | 0.009771,0.012521,0.015012,0.004677,0.005727,0.012546,-0.008754,0.005571, 50 | -0.013009,0.008005,-0.0158,0.02035,0.00474,-0.002868,0.003773,-0.009864, 51 | 0.008165,-0.003107,-0.002485,-0.002388,0.00705,-0.008558,-0.232494, 52 | -0.004173,-0.013182,-0.128209,-0.005926,0.014043,-0.001002,-0.00945, 53 | -0.007661,0.005835,-0.003247,0.01159,-0.001993,-0.001637,-0.011058,-0.00173, 54 | -0.001294,0.016453,0.025234,0.006788,0.018587,0.005299,-0.000036,-0.024275, 55 | 0.006221,0.002008,-0.004799,-0.000097,-0.010017,-0.001126,-0.035341, 56 | 0.013673,0.009518,-0.005044,0.003671,-0.007451,0.005147,-0.002055,0.008131, 57 | -0.00283,-0.007551,-0.022131,-0.013839,0.015264,-0.033698,0.016165,0.010379, 58 | -0.001234,-0.040652,-0.003696,-0.118265,-0.008137,0.004949,0.000382, 59 | 0.009006,-0.015876,-0.009207,-0.022828,-0.003669,0.004109,-0.028882, 60 | -0.01312,-0.007095,-0.099535,0.004143,-0.003469,-0.013916,-0.006633, 61 | -0.005428,0.002659,-0.018252,-0.00084,-0.003366,-0.002754,-0.004693, 62 | -0.005026,0.000268,0.010497,-0.017421,-0.002866,-0.015518,-0.011503,0.00259, 63 | 0.002488,0.004795,0.020166,0.007952,0.00625,0.000583,-0.001197,-0.000871, 64 | -0.002576,-0.000954,0.014026,0.014319,0.001349,-0.014331,-0.003494,0.000534, 65 | -0.131035,0.018867,-0.006003,0.000965,0.010058,0.015642,-0.009097,0.009812, 66 | -0.005994,0.009903,-0.008114,0.009834,-0.005238,0.002553,-0.135593, 67 | -0.004792,-0.018289,0.009139,-0.05649,-0.016537,0.018035,-0.011089,0.00141, 68 | 0.001168,0.001363,-0.006452,0.003859,0.003893,-0.012357,-0.000159,0.006479, 69 | 0.000569,-0.011705,0.013024,0.028201,-0.01773,0.006492,0.000685,0.003662, 70 | 0.003197,0.003886,-0.000028,-0.014837,0.015099,0.010634,-0.012359,-0.018322, 71 | 0.002993,0.022758,-0.005762,0.008889,0.017836,-0.005567,0.006706,-0.018746, 72 | -0.007786,0.000132,-0.014969,-0.005434,-0.000702,0.003928,-0.005732, 73 | -0.039695,-0.007676,-0.001931,0.003229,-0.02353,-0.012267,-0.003603, 74 | 0.010417,-0.002422,-0.01032,-0.011607,-0.005287,-0.00674,0.005537,0.007106, 75 | -0.00167,-0.010801,-0.013647,0.021011,-0.01095,0.002169,0.008268,-0.014663, 76 | -0.002658,-0.187914,0.009155,0.007471,-0.003715,0.016294,0.001736,-0.011613, 77 | -0.004629,0.028509,0.000207,-0.011869,0.007445,-0.006877,-0.015775,0.000696, 78 | -0.121196,-0.022752,0.067813,-0.004551,-0.00998,0.000492,0.006904,0.009693, 79 | -0.005779,0.00754,-0.003448,-0.004168,-0.003673,0.00158,-0.001361,0.000716, 80 | 0.012141,-0.004064,-0.021169,-0.005268,-0.004577,0.000461,-0.011963, 81 | -0.005776,-0.004998,-0.008934,0.002898,-0.053773,0.010167,-0.009447, 82 | 0.006634,-0.012081,0.011154,-0.005575,-0.140487,-0.013123,0.003075,0.002877, 83 | -0.003135,-0.005237,-0.007142,0.004358,0.006297,0.011497,0.005083,0.006186, 84 | 0.060522,0.000422,-0.002813,0.001202,-0.005791,-0.000393,-0.002274, 85 | -0.000861,-0.009265,-0.006919,0.009944,-0.001989,0.002732,-0.004722, 86 | 0.009802,-0.002168,0.003879,-0.001305,-0.004104,-0.080626,-0.004807, 87 | -0.008838,-0.003781,0.008383,-0.004961,-0.003109,0.003496,-0.005155, 88 | -0.005103,-0.012386,0.011285,0.006509,-0.003528,0.000975,0.0031,0.003408, 89 | -0.008843,-0.006933,0.004979,0.000322,-0.004078,0.003122,0.00657,0.010129, 90 | -0.012298,0.03472,0.010127,-0.090554,0.00144,-0.008444,-0.019227,-0.016015, 91 | -0.014317,-0.000929,0.015286,0.002597,0.005767,0.016872,-0.001331,-0.015372, 92 | 0.006157,-0.003142,0.000696,0.058645,-0.003675,0.001135,-0.001352,-0.027688, 93 | 0.011416,-0.001176,0.000308,0.014893,-0.013973,-0.009076,-0.001539, 94 | -0.013992,0.003033,-0.074761,0.010909,-0.010814,-0.004852,0.004865,0.008309, 95 | -0.009463,-0.015571,0.014212,0.009967,-0.008289,0.021197,-0.004742, 96 | -0.007321,-0.004521,-0.010085,0.000058,-0.000915,-0.002885,-0.035277, 97 | 0.001016,0.006543,-0.003769,0.001304,-0.001264,-0.008523,-0.002811, 98 | -0.007788,0.001937,-0.006417,0.036309,-0.004915,0.011154,-0.00902,-0.002208, 99 | -0.005909,-0.002372,0.001679,-0.006918,-0.010647,-0.004834,0.000947, 100 | -0.002797,0.008997,0.001598,-0.002951,-0.001087,0.010361,0.022658,-0.011985, 101 | -0.008932,0.00435,0.010792,-0.001877,0.004927,0.004865,0.004527,-0.014257, 102 | 0.00592,0.006164,0.021233,0.005056,-0.000355,0.009513,0.007763,-0.002888, 103 | -0.011767,0.002847,0.00371,0.007904,-0.015524,-0.008167,0.016921,0.015306, 104 | -0.007595,-0.007145,0.006006,0.01885,-0.00262,0.008053,0.015118,0.001533, 105 | 0.013707,-0.032463,0.004469,-0.017901,0.014373,-0.003319,0.010613,-0.005018, 106 | 0.003813,0.003132,0.002167,0.016087,-0.00022,-0.005656,0.006416,-0.00625, 107 | -0.088381,0.006459,0.003673,-0.048971,0.002364,0.000593,-0.008084,-0.012874, 108 | 0.004789,0.011649,0.005119,-0.004233,-0.063377,0.001234,-0.00509,0.00733, 109 | -0.005617,0.035202,-0.004745,-0.014507,-0.006427,0.003399,0.008933, 110 | -0.018188,-0.01535,0.008449,-0.04025,0.000563,-0.001754,-0.007206,-0.004526, 111 | 0.009923,0.000798,0.022226,-0.002354,0.02062,-0.007756,-0.009406,-0.005041, 112 | -0.003406,-0.17471,0.00181,-0.012603,-0.058205,0.003839,0.002956,-0.127921, 113 | -0.004301,0.004836,0.010076,-0.001815,-0.004208,-0.011268,0.005471,0.00909, 114 | -0.00278,-0.008222,0.010663,-0.075837,-0.007987,-0.017326,0.017418, 115 | -0.007132,-0.060782,-0.011505,0.015251,-0.0042,0.002985,0.014532,0.000545, 116 | -0.001459,-0.010182,0.008446,-0.01206,-0.01378,-0.23899,0.015163,-0.012319, 117 | 0.011901,-0.021051,-0.005367,0.012039,-0.113217,-0.001092,0.009678,0.008476, 118 | -0.005475,-0.008413,0.00829,0.010766,-0.006414,0.000608,0.010206,0.08515, 119 | -0.006003,0.019473,-0.002901,-0.003725,0.008744,0.009099,-0.00303,0.005029, 120 | -0.000019,0.002249,-0.009164,0.007397,-0.011807,0.003767,0.005305,-0.008574, 121 | 0.025048,-0.013395,-0.01216,0.002891,-0.007684,-0.000832,0.019987,0.020279, 122 | 0.00669,0.002955,-0.004013,0.010471,-0.005603,0.016908,-0.01068,0.017262, 123 | 0.006634,0.001368,0.002753,0.007672,0.003272,0.006333,0.017309,0.000356, 124 | -0.015958,-0.00382,0.000516,-0.007893,-0.001172,-0.002527,-0.003681, 125 | -0.008133,0.008906,-0.002793,-0.0046,0.005957,-0.013566,0.004035,0.003184, 126 | 0.011741,0.009567,-0.000023,-0.010518,-0.010086,-0.071174,-0.076767, 127 | 0.024674,0.003798,-0.008718,-0.001428,-0.02271,0.007235,0.005295,-0.016024, 128 | -0.000225,-0.001787,-0.059491,-0.047463,-0.005654,0.000723,-0.002038, 129 | -0.131294,-0.000972,0.043259,-0.012443,-0.147929,-0.00188,-0.006961, 130 | -0.004052,-0.090805,-0.017038,0.023425,-0.028434,0.008876,0.008792, 131 | -0.006643,0.007837,0.003569,0.001743,0.011008,-0.007794,0.000563,0.001136, 132 | -0.000937,-0.003716,-0.00037,0.005442,-0.01118,-0.005892,0.006535,-0.013898, 133 | 0.000382,0.021605,-0.000284,-0.013897,-0.006885,0.002012,-0.009488, 134 | -0.012978,0.01008,-0.003156,0.00069,-0.001457,-0.000045,0.003406,0.001713, 135 | 0.008585,0.000982,-0.012498,-0.000121,-0.009666,0.007935,0.005871,0.003485, 136 | -0.02934,0.004426,-0.000365,-0.003684,0.002486,-0.010341,0.007202,0.002742, 137 | 0.013999,0.003345,-0.001137,0.003039,-0.003712,-0.014173,-0.019813, 138 | -0.013311,-0.062469,0.000722,0.010764,0.007579,0.002587,0.002041,-0.021646, 139 | -0.004963,0.000597,-0.019059,-0.025656,-0.012275,0.006219,0.009415,0.010004, 140 | 0.020989,0.000672,0.014709,0.001036,-0.014056,-0.009339,-0.009672,-0.009201, 141 | -0.022899,0.008337,-0.000797,-0.000451,-0.002685,-0.008416,-0.001374, 142 | 0.008043,0.011682,-0.008223,-0.00297,0.001464,-0.007625,-0.000529,-0.006902, 143 | -0.009836,0.010059,-0.001538,0.001922,-0.031893,0.008967,-0.008679, 144 | -0.234851,0.000973,-0.000656,0.498047,0.441406,0.9,0.2,0.5,1.,0.01 145 | }; 146 | 147 | atoms pz = to_atoms(x); 148 | 149 | fc.list(pz); // wont produce any out 150 | // auto& out = *c74::max::object_getoutput(fc, 0); 151 | // REQUIRE(out.size() == 0); 152 | 153 | // Load a model 154 | atom path("extras/pretrained/model.pt"); 155 | fc.load(path); 156 | 157 | // now proceed to testing various sequences of events 158 | WHEN("list is passed") { 159 | //! We need to check that the input size equals the input size of the model 160 | std::cout << "Input size: " << x.size() << std::endl; 161 | 162 | fc.list(pz); // will produce output 163 | THEN("will produce output") { 164 | // TODO: This is not working 165 | // auto& output = *c74::max::object_getoutput(fc, 0); 166 | // std::cout << output[0][0] << std::endl; 167 | // REQUIRE((output.size() == 1)); 168 | // REQUIRE((output[0].size() == 1)); 169 | // REQUIRE((output[0][0] == symbol("hello world"))); 170 | } 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/maxmsp/filterbank_tilde/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(${C74_MIN_API_DIR}/script/min-pretarget.cmake) 2 | 3 | include_directories( 4 | "${C74_INCLUDES}" 5 | ) 6 | 7 | set( SOURCE_FILES 8 | ${PROJECT_NAME}.cpp 9 | ) 10 | 11 | add_library( 12 | ${PROJECT_NAME} 13 | MODULE 14 | ${SOURCE_FILES} 15 | ) 16 | 17 | target_compile_definitions( 18 | ${PROJECT_NAME} 19 | PUBLIC 20 | VERSION="${CMAKE_PROJECT_VERSION}" 21 | ) 22 | 23 | include(${C74_MIN_API_DIR}/script/min-posttarget.cmake) 24 | 25 | if (APPLE) 26 | if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") 27 | add_custom_command( 28 | TARGET ${PROJECT_NAME} 29 | POST_BUILD 30 | COMMAND "codesign" "--force" "--deep" "-s" "-" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${${PROJECT_NAME}_EXTERN_OUTPUT_NAME}.mxo" 31 | COMMENT "Codesign external" 32 | ) 33 | endif() 34 | endif() 35 | 36 | ############################################################# 37 | # UNIT TEST 38 | ############################################################# 39 | 40 | include(${C74_MIN_API_DIR}/test/min-object-unittest.cmake) 41 | -------------------------------------------------------------------------------- /src/maxmsp/filterbank_tilde/filterbank_tilde.cpp: -------------------------------------------------------------------------------- 1 | #include "c74_min.h" 2 | #include "twoPole.h" 3 | 4 | #ifndef VERSION 5 | #define VERSION "0.0.0" 6 | #endif 7 | 8 | using namespace c74::min; 9 | 10 | class Filterbank : public object, public sample_operator<1, 1> 11 | { 12 | 13 | public: 14 | MIN_DESCRIPTION { "Filterbank." }; 15 | MIN_TAGS { "audio" }; 16 | MIN_AUTHOR { "Rodrigo Diaz" }; 17 | MIN_RELATED { "biquad~" }; 18 | 19 | inlet<> input { this, "(signal) input", "signal" }; 20 | outlet<> output { this, "(signal) output", "signal" }; 21 | outlet<> output_list { this, "(list) dump output" }; 22 | 23 | message<> dump { this, "dump", "Dump the filterbank coefficients to the Max window.", 24 | MIN_FUNCTION { 25 | int n_parallel = m_filters.size(); 26 | int n_biquads = m_filters[0].size(); 27 | std::vector out_coeffs; 28 | for (int i = 0; i < n_parallel; i++) 29 | { 30 | for (int j = 0; j < n_biquads; j++) 31 | { 32 | auto coeffs = m_filters[i][j].get_coefficients(); 33 | for (int k = 0; k < coeffs.size(); k++) 34 | { 35 | out_coeffs.push_back(atom(coeffs[k])); 36 | } 37 | } 38 | } 39 | 40 | output_list.send(out_coeffs); 41 | return {}; 42 | } 43 | }; 44 | 45 | message<> list { this, "list", "Coefficients for the filterbank.", 46 | MIN_FUNCTION 47 | { 48 | lock lock {m_mutex}; 49 | auto coefficients = from_atoms>(args); 50 | 51 | // initialize coefficients 52 | int n_parallel = m_filters.size(); 53 | int n_biquads = m_filters[0].size(); 54 | int stride = n_biquads * 3; 55 | 56 | // cout << "n_parallel: " << n_parallel << endl; 57 | // cout << "n_biquads: " << n_biquads << endl; 58 | // cout << "stride: " << stride << endl; 59 | 60 | for (int i = 0; i < n_parallel; i++) 61 | { 62 | for (int j = 0; j < n_biquads; j++) 63 | { 64 | m_filters[i][j].set_coefficients( 65 | coefficients[i * n_biquads * stride + j * stride + 0], 66 | coefficients[i * n_biquads * stride + j * stride + 1], 67 | coefficients[i * n_biquads * stride + j * stride + 2], 68 | coefficients[i * n_biquads * stride + j * stride + 4], 69 | coefficients[i * n_biquads * stride + j * stride + 5] 70 | ); 71 | } 72 | } 73 | return {}; 74 | } 75 | }; 76 | 77 | 78 | message<> maxclass_setup { this, "maxclass_setup", 79 | MIN_FUNCTION 80 | { 81 | cout << "filterbank~ - " << VERSION << " - 2022 - Rodrigo Diaz" << endl; 82 | return {}; 83 | } 84 | }; 85 | 86 | 87 | public: 88 | 89 | Filterbank(const atoms &args = {}); 90 | ~Filterbank(); 91 | sample operator()(sample x); 92 | std::vector>> m_filters; 93 | 94 | private: 95 | std::mutex m_mutex; 96 | }; 97 | 98 | Filterbank::Filterbank(const atoms &args) 99 | { 100 | if (args.empty()) { 101 | error("Please provide a number of parallel filters."); 102 | return; 103 | } 104 | 105 | int n_parallel = int(args[0]); 106 | int n_biquads = int(args[1]); 107 | 108 | cout << "n_parallel: " << n_parallel << endl; 109 | cout << "n_biquads: " << n_biquads << endl; 110 | 111 | m_filters.resize(n_parallel); 112 | for (int i = 0; i < n_parallel; i++) { 113 | m_filters[i].resize(n_biquads); 114 | } 115 | 116 | // initialize coefficients 117 | for (int i = 0; i < n_parallel; i++) { 118 | for (int j = 0; j < n_biquads; j++) { 119 | m_filters[i][j].set_coefficients(0.0, 0.0, 0.0, 0.0, 0.0); 120 | } 121 | } 122 | 123 | } 124 | 125 | Filterbank::~Filterbank(){} 126 | 127 | sample Filterbank::operator()(sample x) 128 | { 129 | // we need to process in parallel for each filter 130 | sample out = 0.0; 131 | for (int i = 0; i < m_filters.size(); i++) 132 | { 133 | // for each filter 134 | double y = x; 135 | for (int j = 0; j < m_filters[i].size(); j++) 136 | { 137 | y = m_filters[i][j].process(y); 138 | } 139 | 140 | // add to output 141 | out += y; 142 | } 143 | 144 | return out; 145 | } 146 | 147 | MIN_EXTERNAL(Filterbank); 148 | -------------------------------------------------------------------------------- /src/maxmsp/filterbank_tilde/filterbank_tilde_test.cpp: -------------------------------------------------------------------------------- 1 | #include "c74_min_unittest.h" // required unit test header 2 | #include "filterbank_tilde.cpp" 3 | 4 | 5 | SCENARIO("object produces correct output") { 6 | ext_main(nullptr); // every unit test must call ext_main() once to configure the class 7 | 8 | GIVEN("Instantiating a filterbank~ object") 9 | { 10 | atoms args = {4, 2}; 11 | Filterbank filterbank = Filterbank(args); 12 | 13 | REQUIRE(filterbank.m_filters.size() == 4); 14 | REQUIRE(filterbank.m_filters[0].size() == 2); 15 | 16 | WHEN("Receiving a list of coefficients") 17 | { 18 | std::vector coefficients = { 19 | 1.0, 0.1, 0.2, 1.0, 0.4, 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 20 | 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 21 | 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 22 | 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 23 | }; 24 | atoms coeffs = to_atoms(coefficients); 25 | 26 | filterbank.list(coeffs); 27 | 28 | std::cout << "filterbank.m_filters[0][0].get_coefficients() " << filterbank.m_filters[0][0].to_string() << std::endl; 29 | 30 | 31 | REQUIRE(filterbank.m_filters[0][0].get_coefficients()[0] == 1.0f); 32 | REQUIRE(filterbank.m_filters[0][0].get_coefficients()[1] == 0.1f); 33 | REQUIRE(filterbank.m_filters[0][0].get_coefficients()[2] == 0.2f); 34 | REQUIRE(filterbank.m_filters[0][0].get_coefficients()[3] == 0.4f); 35 | REQUIRE(filterbank.m_filters[0][0].get_coefficients()[4] == 0.5f); 36 | 37 | } 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/maxmsp/filterbank_tilde/filterbank~.maxhelp: -------------------------------------------------------------------------------- 1 | { 2 | "patcher" : { 3 | "fileversion" : 1, 4 | "appversion" : { 5 | "major" : 8, 6 | "minor" : 5, 7 | "revision" : 2, 8 | "architecture" : "x64", 9 | "modernui" : 1 10 | } 11 | , 12 | "classnamespace" : "box", 13 | "rect" : [ 87.0, 315.0, 891.0, 643.0 ], 14 | "bglocked" : 0, 15 | "openinpresentation" : 0, 16 | "default_fontsize" : 12.0, 17 | "default_fontface" : 0, 18 | "default_fontname" : "Arial", 19 | "gridonopen" : 1, 20 | "gridsize" : [ 15.0, 15.0 ], 21 | "gridsnaponopen" : 1, 22 | "objectsnaponopen" : 1, 23 | "statusbarvisible" : 2, 24 | "toolbarvisible" : 1, 25 | "lefttoolbarpinned" : 0, 26 | "toptoolbarpinned" : 0, 27 | "righttoolbarpinned" : 0, 28 | "bottomtoolbarpinned" : 0, 29 | "toolbars_unpinned_last_save" : 0, 30 | "tallnewobj" : 0, 31 | "boxanimatetime" : 200, 32 | "enablehscroll" : 1, 33 | "enablevscroll" : 1, 34 | "devicewidth" : 0.0, 35 | "description" : "", 36 | "digest" : "", 37 | "tags" : "", 38 | "style" : "", 39 | "subpatcher_template" : "", 40 | "assistshowspatchername" : 0, 41 | "boxes" : [ { 42 | "box" : { 43 | "id" : "obj-12", 44 | "maxclass" : "comment", 45 | "numinlets" : 1, 46 | "numoutlets" : 0, 47 | "patching_rect" : [ 243.0, 215.0, 196.0, 20.0 ], 48 | "text" : "dumps b0, b1, b2, a1, a2" 49 | } 50 | 51 | } 52 | , { 53 | "box" : { 54 | "id" : "obj-9", 55 | "maxclass" : "message", 56 | "numinlets" : 2, 57 | "numoutlets" : 1, 58 | "outlettype" : [ "" ], 59 | "patching_rect" : [ 203.0, 330.0, 292.0, 22.0 ], 60 | "text" : "0.000962 0.001923 0.000962 -1.910393 0.914239" 61 | } 62 | 63 | } 64 | , { 65 | "box" : { 66 | "id" : "obj-5", 67 | "maxclass" : "newobj", 68 | "numinlets" : 1, 69 | "numoutlets" : 1, 70 | "outlettype" : [ "" ], 71 | "patching_rect" : [ 572.0, 52.0, 90.0, 22.0 ], 72 | "text" : "loadmess 1000" 73 | } 74 | 75 | } 76 | , { 77 | "box" : { 78 | "id" : "obj-22", 79 | "maxclass" : "newobj", 80 | "numinlets" : 1, 81 | "numoutlets" : 1, 82 | "outlettype" : [ "signal" ], 83 | "patching_rect" : [ 42.0, 58.0, 44.0, 22.0 ], 84 | "text" : "noise~" 85 | } 86 | 87 | } 88 | , { 89 | "box" : { 90 | "id" : "obj-21", 91 | "maxclass" : "newobj", 92 | "numinlets" : 1, 93 | "numoutlets" : 5, 94 | "outlettype" : [ "float", "float", "float", "float", "float" ], 95 | "patching_rect" : [ 64.0, 167.0, 81.000000000000114, 22.0 ], 96 | "text" : "unpack f f f f f" 97 | } 98 | 99 | } 100 | , { 101 | "box" : { 102 | "id" : "obj-20", 103 | "maxclass" : "newobj", 104 | "numinlets" : 6, 105 | "numoutlets" : 1, 106 | "outlettype" : [ "" ], 107 | "patching_rect" : [ 64.0, 215.0, 96.500000000000114, 22.0 ], 108 | "text" : "pack f f f 1. f f" 109 | } 110 | 111 | } 112 | , { 113 | "box" : { 114 | "id" : "obj-19", 115 | "maxclass" : "message", 116 | "numinlets" : 2, 117 | "numoutlets" : 1, 118 | "outlettype" : [ "" ], 119 | "patching_rect" : [ 203.0, 303.5, 292.0, 22.0 ], 120 | "text" : "0.004604 0.009208 0.004604 1. -1.799096 0.817512" 121 | } 122 | 123 | } 124 | , { 125 | "box" : { 126 | "id" : "obj-17", 127 | "maxclass" : "newobj", 128 | "numinlets" : 1, 129 | "numoutlets" : 1, 130 | "outlettype" : [ "" ], 131 | "patching_rect" : [ 64.0, 124.0, 121.0, 22.0 ], 132 | "text" : "dict.unpack cascade:" 133 | } 134 | 135 | } 136 | , { 137 | "box" : { 138 | "bubble" : 1, 139 | "fontname" : "Arial", 140 | "fontsize" : 13.0, 141 | "id" : "obj-38", 142 | "maxclass" : "comment", 143 | "numinlets" : 1, 144 | "numoutlets" : 0, 145 | "patching_rect" : [ 96.0, 303.5, 79.0, 25.0 ], 146 | "text" : "start dsp" 147 | } 148 | 149 | } 150 | , { 151 | "box" : { 152 | "attr" : "frequency", 153 | "fontface" : 0, 154 | "fontname" : "Arial", 155 | "fontsize" : 13.0, 156 | "id" : "obj-15", 157 | "lock" : 1, 158 | "maxclass" : "attrui", 159 | "numinlets" : 1, 160 | "numoutlets" : 1, 161 | "orientation" : 1, 162 | "outlettype" : [ "" ], 163 | "parameter_enable" : 0, 164 | "patching_rect" : [ 572.0, 91.0, 111.0, 46.0 ], 165 | "text_width" : 83.0 166 | } 167 | 168 | } 169 | , { 170 | "box" : { 171 | "attr" : "response", 172 | "fontface" : 0, 173 | "fontname" : "Arial", 174 | "fontsize" : 13.0, 175 | "id" : "obj-14", 176 | "lock" : 1, 177 | "maxclass" : "attrui", 178 | "numinlets" : 1, 179 | "numoutlets" : 1, 180 | "orientation" : 1, 181 | "outlettype" : [ "" ], 182 | "parameter_enable" : 0, 183 | "patching_rect" : [ 685.5, 91.0, 111.0, 46.0 ], 184 | "text_width" : 83.0 185 | } 186 | 187 | } 188 | , { 189 | "box" : { 190 | "attr" : "topology", 191 | "fontface" : 0, 192 | "fontname" : "Arial", 193 | "fontsize" : 13.0, 194 | "id" : "obj-2", 195 | "lock" : 1, 196 | "maxclass" : "attrui", 197 | "numinlets" : 1, 198 | "numoutlets" : 1, 199 | "orientation" : 1, 200 | "outlettype" : [ "" ], 201 | "parameter_enable" : 0, 202 | "patching_rect" : [ 801.0, 91.0, 111.0, 46.0 ], 203 | "text_width" : 83.0 204 | } 205 | 206 | } 207 | , { 208 | "box" : { 209 | "id" : "obj-11", 210 | "local" : 1, 211 | "maxclass" : "ezdac~", 212 | "numinlets" : 2, 213 | "numoutlets" : 0, 214 | "patching_rect" : [ 42.0, 324.0, 44.0, 44.0 ], 215 | "prototypename" : "helpfile" 216 | } 217 | 218 | } 219 | , { 220 | "box" : { 221 | "fontname" : "Arial", 222 | "fontsize" : 13.0, 223 | "id" : "obj-4", 224 | "maxclass" : "newobj", 225 | "numinlets" : 0, 226 | "numoutlets" : 1, 227 | "outlettype" : [ "" ], 228 | "patcher" : { 229 | "fileversion" : 1, 230 | "appversion" : { 231 | "major" : 8, 232 | "minor" : 5, 233 | "revision" : 2, 234 | "architecture" : "x64", 235 | "modernui" : 1 236 | } 237 | , 238 | "classnamespace" : "box", 239 | "rect" : [ 765.0, 356.0, 640.0, 480.0 ], 240 | "bglocked" : 0, 241 | "openinpresentation" : 0, 242 | "default_fontsize" : 13.0, 243 | "default_fontface" : 0, 244 | "default_fontname" : "Helvetica Neue Light", 245 | "gridonopen" : 1, 246 | "gridsize" : [ 15.0, 15.0 ], 247 | "gridsnaponopen" : 1, 248 | "objectsnaponopen" : 1, 249 | "statusbarvisible" : 2, 250 | "toolbarvisible" : 1, 251 | "lefttoolbarpinned" : 0, 252 | "toptoolbarpinned" : 0, 253 | "righttoolbarpinned" : 0, 254 | "bottomtoolbarpinned" : 0, 255 | "toolbars_unpinned_last_save" : 0, 256 | "tallnewobj" : 0, 257 | "boxanimatetime" : 200, 258 | "enablehscroll" : 1, 259 | "enablevscroll" : 1, 260 | "devicewidth" : 0.0, 261 | "description" : "", 262 | "digest" : "", 263 | "tags" : "", 264 | "style" : "", 265 | "subpatcher_template" : "", 266 | "assistshowspatchername" : 0, 267 | "boxes" : [ { 268 | "box" : { 269 | "fontname" : "Helvetica Neue Light", 270 | "fontsize" : 13.0, 271 | "id" : "obj-7", 272 | "maxclass" : "message", 273 | "numinlets" : 2, 274 | "numoutlets" : 1, 275 | "outlettype" : [ "" ], 276 | "patching_rect" : [ 125.0, 265.0, 173.0, 20.0 ], 277 | "text" : "domainlabel \"frequency (hz)\"" 278 | } 279 | 280 | } 281 | , { 282 | "box" : { 283 | "fontname" : "Helvetica Neue Light", 284 | "fontsize" : 13.0, 285 | "id" : "obj-6", 286 | "maxclass" : "message", 287 | "numinlets" : 2, 288 | "numoutlets" : 1, 289 | "outlettype" : [ "" ], 290 | "patching_rect" : [ 100.0, 230.0, 382.0, 20.0 ], 291 | "text" : "definexlabels 10 \"10\" 100 \"100\" 1000 1K 10000 10K 20000 20K" 292 | } 293 | 294 | } 295 | , { 296 | "box" : { 297 | "fontname" : "Helvetica Neue Light", 298 | "fontsize" : 13.0, 299 | "id" : "obj-5", 300 | "linecount" : 2, 301 | "maxclass" : "message", 302 | "numinlets" : 2, 303 | "numoutlets" : 1, 304 | "outlettype" : [ "" ], 305 | "patching_rect" : [ 75.0, 185.0, 555.0, 36.0 ], 306 | "text" : "definexgrid 0 10 20 30 40 50 60 70 80 90 100 200 300 400 500 600 700 800 900 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 20000 22050" 307 | } 308 | 309 | } 310 | , { 311 | "box" : { 312 | "fontname" : "Helvetica Neue Light", 313 | "fontsize" : 13.0, 314 | "id" : "obj-4", 315 | "maxclass" : "message", 316 | "numinlets" : 2, 317 | "numoutlets" : 1, 318 | "outlettype" : [ "" ], 319 | "patching_rect" : [ 30.0, 160.0, 168.0, 20.0 ], 320 | "text" : "definedomain 0. 22050. log" 321 | } 322 | 323 | } 324 | , { 325 | "box" : { 326 | "comment" : "", 327 | "id" : "obj-1", 328 | "index" : 1, 329 | "maxclass" : "outlet", 330 | "numinlets" : 1, 331 | "numoutlets" : 0, 332 | "patching_rect" : [ 100.0, 335.0, 25.0, 25.0 ] 333 | } 334 | 335 | } 336 | ], 337 | "lines" : [ { 338 | "patchline" : { 339 | "destination" : [ "obj-1", 0 ], 340 | "source" : [ "obj-4", 0 ] 341 | } 342 | 343 | } 344 | , { 345 | "patchline" : { 346 | "destination" : [ "obj-1", 0 ], 347 | "source" : [ "obj-5", 0 ] 348 | } 349 | 350 | } 351 | , { 352 | "patchline" : { 353 | "destination" : [ "obj-1", 0 ], 354 | "source" : [ "obj-6", 0 ] 355 | } 356 | 357 | } 358 | , { 359 | "patchline" : { 360 | "destination" : [ "obj-1", 0 ], 361 | "source" : [ "obj-7", 0 ] 362 | } 363 | 364 | } 365 | ] 366 | } 367 | , 368 | "patching_rect" : [ 691.0, 174.0, 83.0, 23.0 ], 369 | "saved_object_attributes" : { 370 | "description" : "", 371 | "digest" : "", 372 | "fontname" : "Helvetica Neue Light", 373 | "fontsize" : 13.0, 374 | "globalpatchername" : "", 375 | "tags" : "" 376 | } 377 | , 378 | "text" : "p plot_setup" 379 | } 380 | 381 | } 382 | , { 383 | "box" : { 384 | "domainlabel" : "frequency (hz)", 385 | "id" : "obj-35", 386 | "margins" : [ 8.0, 8.0, 20.0, 50.0 ], 387 | "maxclass" : "plot~", 388 | "numinlets" : 1, 389 | "numoutlets" : 1, 390 | "numpoints" : 512, 391 | "outlettype" : [ "" ], 392 | "patching_rect" : [ 582.0, 204.0, 347.0, 212.0 ], 393 | "rangelabel" : "magnitude (db)", 394 | "subplots" : [ { 395 | "color" : [ 0.400000005960464, 0.400000005960464, 0.75, 1.0 ], 396 | "thickness" : 1.5, 397 | "point_style" : "none", 398 | "line_style" : "linear", 399 | "number_style" : "none", 400 | "filter" : "atodb", 401 | "domain_start" : 0.0, 402 | "domain_end" : 22050.0, 403 | "domain_style" : "log", 404 | "domain_markers" : [ 22050.0, 20000.0, 10000.0, 9000.0, 8000.0, 7000.0, 6000.0, 5000.0, 4000.0, 3000.0, 2000.0, 1000.0, 900.0, 800.0, 700.0, 600.0, 500.0, 400.0, 300.0, 200.0, 100.0, 90.0, 80.0, 70.0, 60.0, 50.0, 40.0, 30.0, 20.0, 10.0, 0.0 ], 405 | "domain_labels" : [ 10.0, "10", 100.0, "100", 1000.0, "1K", 10000.0, "10K", 20000.0, "20K" ], 406 | "range_start" : -120.0, 407 | "range_end" : 24.0, 408 | "range_style" : "linear", 409 | "range_markers" : [ -120.0, -108.0, -96.0, -84.0, -72.0, -60.0, -48.0, -36.0, -24.0, -12.0, 0.0, 12.0, 24.0 ], 410 | "range_labels" : [ -120.0, "-120", -108.0, "-108", -96.0, "-96", -84.0, "-84", -72.0, "-72", -60.0, "-60", -48.0, "-48", -36.0, "-36", -24.0, "-24", -12.0, "-12", 0.0, "0", 12.0, "12", 24.0, "24" ], 411 | "origin_x" : 0.0, 412 | "origin_y" : 0.0 413 | } 414 | ] 415 | } 416 | 417 | } 418 | , { 419 | "box" : { 420 | "fontname" : "Arial", 421 | "fontsize" : 13.0, 422 | "id" : "obj-7", 423 | "maxclass" : "newobj", 424 | "numinlets" : 1, 425 | "numoutlets" : 6, 426 | "outlettype" : [ "", "", "", "", "", "" ], 427 | "patching_rect" : [ 582.0, 174.0, 96.0, 23.0 ], 428 | "text" : "filterdetail" 429 | } 430 | 431 | } 432 | , { 433 | "box" : { 434 | "fontname" : "Arial", 435 | "fontsize" : 13.0, 436 | "id" : "obj-8", 437 | "maxclass" : "newobj", 438 | "numinlets" : 1, 439 | "numoutlets" : 1, 440 | "outlettype" : [ "dictionary" ], 441 | "patching_rect" : [ 572.0, 143.0, 264.0, 23.0 ], 442 | "text" : "filterdesign @order 2 @topology butterworth" 443 | } 444 | 445 | } 446 | , { 447 | "box" : { 448 | "id" : "obj-10", 449 | "maxclass" : "comment", 450 | "numinlets" : 1, 451 | "numoutlets" : 0, 452 | "patching_rect" : [ 170.0, 167.0, 196.0, 20.0 ], 453 | "text" : "It accepts b0, b1, b2, 1, a1, a2" 454 | } 455 | 456 | } 457 | , { 458 | "box" : { 459 | "id" : "obj-3", 460 | "maxclass" : "message", 461 | "numinlets" : 2, 462 | "numoutlets" : 1, 463 | "outlettype" : [ "" ], 464 | "patching_rect" : [ 195.5, 215.0, 39.0, 22.0 ], 465 | "text" : "dump" 466 | } 467 | 468 | } 469 | , { 470 | "box" : { 471 | "id" : "obj-1", 472 | "maxclass" : "newobj", 473 | "numinlets" : 1, 474 | "numoutlets" : 2, 475 | "outlettype" : [ "signal", "" ], 476 | "patching_rect" : [ 42.0, 261.0, 84.0, 22.0 ], 477 | "text" : "filterbank~ 1 1" 478 | } 479 | 480 | } 481 | ], 482 | "lines" : [ { 483 | "patchline" : { 484 | "destination" : [ "obj-11", 1 ], 485 | "order" : 0, 486 | "source" : [ "obj-1", 0 ] 487 | } 488 | 489 | } 490 | , { 491 | "patchline" : { 492 | "destination" : [ "obj-11", 0 ], 493 | "order" : 1, 494 | "source" : [ "obj-1", 0 ] 495 | } 496 | 497 | } 498 | , { 499 | "patchline" : { 500 | "destination" : [ "obj-9", 1 ], 501 | "source" : [ "obj-1", 1 ] 502 | } 503 | 504 | } 505 | , { 506 | "patchline" : { 507 | "destination" : [ "obj-8", 0 ], 508 | "source" : [ "obj-14", 0 ] 509 | } 510 | 511 | } 512 | , { 513 | "patchline" : { 514 | "destination" : [ "obj-8", 0 ], 515 | "source" : [ "obj-15", 0 ] 516 | } 517 | 518 | } 519 | , { 520 | "patchline" : { 521 | "destination" : [ "obj-21", 0 ], 522 | "source" : [ "obj-17", 0 ] 523 | } 524 | 525 | } 526 | , { 527 | "patchline" : { 528 | "destination" : [ "obj-8", 0 ], 529 | "source" : [ "obj-2", 0 ] 530 | } 531 | 532 | } 533 | , { 534 | "patchline" : { 535 | "destination" : [ "obj-1", 0 ], 536 | "order" : 1, 537 | "source" : [ "obj-20", 0 ] 538 | } 539 | 540 | } 541 | , { 542 | "patchline" : { 543 | "destination" : [ "obj-19", 1 ], 544 | "order" : 0, 545 | "source" : [ "obj-20", 0 ] 546 | } 547 | 548 | } 549 | , { 550 | "patchline" : { 551 | "destination" : [ "obj-20", 5 ], 552 | "source" : [ "obj-21", 4 ] 553 | } 554 | 555 | } 556 | , { 557 | "patchline" : { 558 | "destination" : [ "obj-20", 4 ], 559 | "source" : [ "obj-21", 3 ] 560 | } 561 | 562 | } 563 | , { 564 | "patchline" : { 565 | "destination" : [ "obj-20", 2 ], 566 | "source" : [ "obj-21", 2 ] 567 | } 568 | 569 | } 570 | , { 571 | "patchline" : { 572 | "destination" : [ "obj-20", 1 ], 573 | "source" : [ "obj-21", 1 ] 574 | } 575 | 576 | } 577 | , { 578 | "patchline" : { 579 | "destination" : [ "obj-20", 0 ], 580 | "source" : [ "obj-21", 0 ] 581 | } 582 | 583 | } 584 | , { 585 | "patchline" : { 586 | "destination" : [ "obj-1", 0 ], 587 | "source" : [ "obj-22", 0 ] 588 | } 589 | 590 | } 591 | , { 592 | "patchline" : { 593 | "destination" : [ "obj-1", 0 ], 594 | "source" : [ "obj-3", 0 ] 595 | } 596 | 597 | } 598 | , { 599 | "patchline" : { 600 | "destination" : [ "obj-35", 0 ], 601 | "midpoints" : [ 700.5, 200.0, 591.5, 200.0 ], 602 | "source" : [ "obj-4", 0 ] 603 | } 604 | 605 | } 606 | , { 607 | "patchline" : { 608 | "destination" : [ "obj-15", 0 ], 609 | "source" : [ "obj-5", 0 ] 610 | } 611 | 612 | } 613 | , { 614 | "patchline" : { 615 | "destination" : [ "obj-35", 0 ], 616 | "source" : [ "obj-7", 0 ] 617 | } 618 | 619 | } 620 | , { 621 | "patchline" : { 622 | "destination" : [ "obj-17", 0 ], 623 | "order" : 1, 624 | "source" : [ "obj-8", 0 ] 625 | } 626 | 627 | } 628 | , { 629 | "patchline" : { 630 | "destination" : [ "obj-7", 0 ], 631 | "order" : 0, 632 | "source" : [ "obj-8", 0 ] 633 | } 634 | 635 | } 636 | ], 637 | "dependency_cache" : [ { 638 | "name" : "filterbank~.mxo", 639 | "type" : "iLaX" 640 | } 641 | ], 642 | "autosave" : 0 643 | } 644 | 645 | } 646 | -------------------------------------------------------------------------------- /src/maxmsp/filterbank_tilde/twoPole.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class TwoPole 5 | { 6 | public: 7 | TwoPole() {} 8 | 9 | void set_coefficients(T b0, T b1, T b2, T a1, T a2) 10 | { 11 | m_a1 = a1; 12 | m_a2 = a2; 13 | m_b0 = b0; 14 | m_b1 = b1; 15 | m_b2 = b2; 16 | } 17 | 18 | std::vector get_coefficients() 19 | { 20 | std::vector coefficients = {m_b0, m_b1, m_b2, m_a1, m_a2}; 21 | return coefficients; 22 | } 23 | 24 | T process(T x) 25 | { 26 | T y = m_b0 * x + m_s0; 27 | m_s0 = m_b1 * x - m_a1 * y + m_s1; 28 | m_s1 = m_b2 * x - m_a2 * y; 29 | return y; 30 | } 31 | 32 | std::string to_string() 33 | { 34 | std::stringstream ss; 35 | ss << "a1: " << m_a1 << " a2: " << m_a2 << " b0: " << m_b0 << " b1: " << m_b1 << " b2: " << m_b2; 36 | return ss.str(); 37 | } 38 | private: 39 | T m_a1, m_a2, m_b0, m_b1, m_b2 = 0.0f; 40 | T m_s0, m_s1 = 0.0f; 41 | }; --------------------------------------------------------------------------------