├── .cproject ├── .github ├── FUNDING.yml └── workflows │ ├── build.yml │ └── valgrind.supp ├── .gitignore ├── .project ├── CHANGELOG ├── COPYING ├── COPYING.LESSER ├── Makefile ├── README.md ├── dependencies.mk ├── include ├── lsp-plug.in │ └── dsp-units │ │ ├── 3d │ │ ├── Allocator3D.h │ │ ├── Object3D.h │ │ ├── RayTrace3D.h │ │ ├── Scene3D.h │ │ ├── bsp │ │ │ ├── context.h │ │ │ └── types.h │ │ ├── raytrace.h │ │ ├── rt │ │ │ ├── context.h │ │ │ ├── mesh.h │ │ │ ├── plan.h │ │ │ └── types.h │ │ ├── types.h │ │ └── view │ │ │ └── types.h │ │ ├── const.h │ │ ├── ctl │ │ ├── Blink.h │ │ ├── Bypass.h │ │ ├── Counter.h │ │ ├── Crossfade.h │ │ └── Toggle.h │ │ ├── dynamics │ │ ├── AutoGain.h │ │ ├── Compressor.h │ │ ├── DynamicProcessor.h │ │ ├── Expander.h │ │ ├── Gate.h │ │ ├── Limiter.h │ │ ├── SimpleAutoGain.h │ │ └── SurgeProtector.h │ │ ├── filters │ │ ├── ButterworthFilter.h │ │ ├── DynamicFilters.h │ │ ├── Equalizer.h │ │ ├── Filter.h │ │ ├── FilterBank.h │ │ ├── SpectralTilt.h │ │ └── common.h │ │ ├── iface │ │ └── IStateDumper.h │ │ ├── meters │ │ ├── Correlometer.h │ │ ├── ILUFSMeter.h │ │ ├── LoudnessMeter.h │ │ ├── Panometer.h │ │ └── TruePeakMeter.h │ │ ├── misc │ │ ├── broadcast.h │ │ ├── envelope.h │ │ ├── fade.h │ │ ├── fft_crossover.h │ │ ├── interpolation.h │ │ ├── lfo.h │ │ ├── quickmath.h │ │ ├── sigmoid.h │ │ └── windows.h │ │ ├── noise │ │ ├── Generator.h │ │ ├── LCG.h │ │ ├── MLS.h │ │ └── Velvet.h │ │ ├── sampling │ │ ├── InSampleStream.h │ │ ├── PlaySettings.h │ │ ├── Playback.h │ │ ├── Sample.h │ │ ├── SamplePlayer.h │ │ ├── helpers │ │ │ ├── batch.h │ │ │ └── playback.h │ │ └── types.h │ │ ├── shared │ │ ├── AudioStream.h │ │ └── Catalog.h │ │ ├── stat │ │ └── QuantizedCounter.h │ │ ├── units.h │ │ ├── util │ │ ├── Analyzer.h │ │ ├── Convolver.h │ │ ├── Crossover.h │ │ ├── Delay.h │ │ ├── Depopper.h │ │ ├── Dither.h │ │ ├── DynamicDelay.h │ │ ├── FFTCrossover.h │ │ ├── LatencyDetector.h │ │ ├── MeterGraph.h │ │ ├── Oscillator.h │ │ ├── Oversampler.h │ │ ├── Randomizer.h │ │ ├── RawRingBuffer.h │ │ ├── ResponseTaker.h │ │ ├── RingBuffer.h │ │ ├── ScaledMeterGraph.h │ │ ├── ShiftBuffer.h │ │ ├── Sidechain.h │ │ ├── SpectralProcessor.h │ │ ├── SpectralSplitter.h │ │ ├── SyncChirpProcessor.h │ │ └── Trigger.h │ │ └── version.h └── private │ └── 3d │ └── scene │ └── obj.h ├── make ├── configure.mk ├── functions.mk ├── ld-windows.script ├── modules.mk ├── paths.mk ├── system.mk └── tools.mk ├── modules.mk ├── project.mk ├── res └── test │ ├── corr │ ├── guitar1-di.wav │ ├── guitar1-od.wav │ ├── guitar2-di.wav │ ├── guitar2-od.wav │ └── mix-dirty.wav │ ├── f32.wav │ ├── meters │ └── loop.wav │ └── util │ └── noise.wav └── src ├── Makefile ├── main ├── 3d │ ├── Allocator.cpp │ ├── Object3D.cpp │ ├── RayTrace3D.cpp │ ├── Scene3D.cpp │ ├── bsp │ │ └── context.cpp │ ├── raytrace.cpp │ └── rt │ │ ├── context.cpp │ │ ├── mesh.cpp │ │ └── plan.cpp ├── ctl │ ├── Blink.cpp │ ├── Bypass.cpp │ ├── Counter.cpp │ ├── Crossfade.cpp │ └── Toggle.cpp ├── dynamics │ ├── AutoGain.cpp │ ├── Compressor.cpp │ ├── DynamicProcessor.cpp │ ├── Expander.cpp │ ├── Gate.cpp │ ├── Limiter.cpp │ ├── SimpleAutoGain.cpp │ └── SurgeProtector.cpp ├── filters │ ├── ButterworthFilter.cpp │ ├── DynamicFilters.cpp │ ├── Equalizer.cpp │ ├── Filter.cpp │ ├── FilterBank.cpp │ └── SpectralTilt.cpp ├── iface │ └── IStateDumper.cpp ├── meters │ ├── Correlometer.cpp │ ├── ILUFSMeter.cpp │ ├── LoudnessMeter.cpp │ ├── Panometer.cpp │ └── TruePeakMeter.cpp ├── misc │ ├── broadcast.cpp │ ├── envelope.cpp │ ├── fade.cpp │ ├── fft_crossover.cpp │ ├── interpolation.cpp │ ├── lfo.cpp │ ├── sigmoid.cpp │ └── windows.cpp ├── noise │ ├── Generator.cpp │ ├── LCG.cpp │ ├── MLS.cpp │ └── Velvet.cpp ├── sampling │ ├── InSampleStream.cpp │ ├── PlaySettings.cpp │ ├── Playback.cpp │ ├── Sample.cpp │ ├── SamplePlayer.cpp │ └── helpers │ │ ├── batch.cpp │ │ └── playback.cpp ├── shared │ ├── AudioStream.cpp │ └── Catalog.cpp ├── stat │ └── QuantizedCounter.cpp └── util │ ├── Analyzer.cpp │ ├── Convolver.cpp │ ├── Crossover.cpp │ ├── Delay.cpp │ ├── Depopper.cpp │ ├── Dither.cpp │ ├── DynamicDelay.cpp │ ├── FFTCrossover.cpp │ ├── LatencyDetector.cpp │ ├── MeterGraph.cpp │ ├── Oscillator.cpp │ ├── Oversampler.cpp │ ├── Randomizer.cpp │ ├── RawRingBuffer.cpp │ ├── ResponseTaker.cpp │ ├── RingBuffer.cpp │ ├── ScaledMeterGraph.cpp │ ├── ShiftBuffer.cpp │ ├── Sidechain.cpp │ ├── SpectralProcessor.cpp │ ├── SpectralSplitter.cpp │ ├── SyncChirpProcessor.cpp │ └── Trigger.cpp └── test ├── init └── init.cpp ├── main.cpp ├── mtest ├── demo.cpp ├── filters │ ├── ButterworthFilter.cpp │ └── SpectralTilt.cpp ├── meters │ ├── ilufs.cpp │ ├── psr.cpp │ └── true_peak.cpp ├── misc │ ├── envelope.cpp │ ├── fft_crossover.cpp │ └── windows.cpp ├── noise │ └── MLS.cpp ├── sampling │ └── resample.cpp └── util │ ├── convolver.cpp │ ├── fft_crossover.cpp │ ├── latency_detector.cpp │ ├── randomizer.cpp │ ├── spectral_splitter.cpp │ └── sync_chirp.cpp └── utest ├── 3d └── scene_load.cpp ├── dynamics └── limiter.cpp ├── filters └── equalizer.cpp ├── meters └── correlometer.cpp ├── noise └── MLS.cpp ├── sampling ├── helpers │ ├── batch.cpp │ └── playback.cpp ├── player.cpp └── sample.cpp ├── shared ├── audiostream.cpp └── catalog.cpp └── util ├── convolver.cpp ├── counter.cpp ├── crossfade.cpp ├── ringbuffer.cpp ├── sidechain.cpp └── spectral_proc.cpp /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | liberapay: sadko4u 2 | patreon: sadko4u 3 | custom: 4 | - https://www.blockchain.com/btc/address/15X3AfDRF3EshSLBoK8UfHAsFr2TQsH8pk 5 | - https://etherscan.io/address/0x079b24da78d78302cd3cfbb80c728cd554606cc6 6 | - https://www.bountysource.com/teams/lsp-plugins 7 | - https://paypal.me/sadko4u 8 | -------------------------------------------------------------------------------- /.github/workflows/valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | libdl is full of leaks 3 | Memcheck:Leak 4 | ... 5 | fun:_dl_open 6 | ... 7 | } 8 | { 9 | libdl is full of leaks 10 | Memcheck:Leak 11 | ... 12 | fun:_dl_close 13 | ... 14 | } 15 | { 16 | libdl is full of leaks 17 | Memcheck:Leak 18 | ... 19 | fun:_dl_init 20 | } 21 | { 22 | libdl is full of leaks 23 | Memcheck:Leak 24 | ... 25 | fun:_dl_allocate_tls 26 | ... 27 | } 28 | { 29 | libdl is full of leaks 30 | Memcheck:Leak 31 | ... 32 | fun:call_init.part.0 33 | } 34 | { 35 | ignore XInitThreads 36 | Memcheck:Leak 37 | ... 38 | fun:XInitThreads 39 | ... 40 | } 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.svn/* 2 | /.settings/* 3 | /.build/* 4 | /.test/* 5 | *.log 6 | /gmon.out 7 | **/*.gmon 8 | *.core 9 | /.config.mk 10 | /modules/ 11 | /Release/ 12 | /DebugLinux/ 13 | /DebugWin/ -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lsp-dsp-units 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # 3 | # Copyright (C) 2024 Linux Studio Plugins Project 4 | # (C) 2024 Vladimir Sadovnikov 5 | # 6 | # This file is part of lsp-dsp-units 7 | # 8 | # lsp-dsp-units is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesser General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # any later version. 12 | # 13 | # lsp-dsp-units is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with lsp-dsp-units. If not, see . 20 | # 21 | 22 | # Command-line flag to silence nested $(MAKE). 23 | ifneq ($(VERBOSE),1) 24 | .SILENT: 25 | endif 26 | 27 | # Location 28 | BASEDIR := $(CURDIR) 29 | MODULES := $(BASEDIR)/modules 30 | BUILDDIR := $(BASEDIR)/.build 31 | CONFIG := $(BASEDIR)/.config.mk 32 | 33 | # Basic initialization 34 | # Checks 35 | ifeq ("$(wildcard $(CONFIG))", "") 36 | CONFIGURED = 0 37 | else 38 | CONFIGURED = 1 39 | endif 40 | 41 | include $(BASEDIR)/project.mk 42 | 43 | # Setup paths 44 | CHK_CONFIG = test -f "$(CONFIG)" || (echo "System not properly configured. Please launch 'make config' first" && exit 1) 45 | DISTSRC_PATH = $(BUILDDIR)/distsrc 46 | DISTSRC = $(DISTSRC_PATH)/$(ARTIFACT_NAME) 47 | 48 | .DEFAULT_GOAL := all 49 | .PHONY: all compile install uninstall clean 50 | 51 | compile all install uninstall: 52 | $(CHK_CONFIG) 53 | $(MAKE) -C "$(BASEDIR)/src" $(@) VERBOSE="$(VERBOSE)" CONFIG="$(CONFIG)" DESTDIR="$(DESTDIR)" 54 | 55 | clean: 56 | echo "Cleaning build directory $(BUILDDIR)" 57 | -rm -rf $(BUILDDIR) 58 | echo "Clean OK" 59 | 60 | # Module-related tasks 61 | .PHONY: fetch tree prune 62 | fetch: 63 | $(CHK_CONFIG) 64 | echo "Fetching desired source code dependencies" 65 | $(MAKE) -f "$(BASEDIR)/make/modules.mk" $(@) VERBOSE="$(VERBOSE)" BASEDIR="$(BASEDIR)" CONFIG="$(CONFIG)" 66 | echo "Fetch OK" 67 | 68 | tree: 69 | echo "Fetching all possible source code dependencies" 70 | $(MAKE) -f "$(BASEDIR)/make/modules.mk" $(@) VERBOSE="$(VERBOSE)" BASEDIR="$(BASEDIR)" TREE="1" 71 | echo "Fetch OK" 72 | 73 | prune: clean 74 | echo "Pruning the whole project tree" 75 | $(MAKE) -f "$(BASEDIR)/make/modules.mk" prune VERBOSE="$(VERBOSE)" BASEDIR="$(BASEDIR)" CONFIG="$(CONFIG)" 76 | $(MAKE) -f "$(BASEDIR)/make/modules.mk" prune VERBOSE="$(VERBOSE)" BASEDIR="$(BASEDIR)" TREE="1" 77 | -rm -rf "$(CONFIG)" 78 | echo "Prune OK" 79 | 80 | # Configuration-related targets 81 | .PHONY: config help chkconfig 82 | 83 | testconfig: 84 | $(MAKE) -f "$(BASEDIR)/make/configure.mk" $(@) VERBOSE="$(VERBOSE)" CONFIG="$(CONFIG)" TEST="1" -$(MAKEFLAGS) 85 | 86 | config: 87 | $(MAKE) -f "$(BASEDIR)/make/configure.mk" $(@) VERBOSE="$(VERBOSE)" CONFIG="$(CONFIG)" -$(MAKEFLAGS) 88 | 89 | # Release-related targets 90 | .PHONY: distsrc 91 | distsrc: 92 | echo "Building source code archive" 93 | mkdir -p "$(DISTSRC)/modules" 94 | $(MAKE) -f "$(BASEDIR)/make/modules.mk" tree VERBOSE="$(VERBOSE)" BASEDIR="$(BASEDIR)" MODULES="$(DISTSRC)/modules" TREE="1" 95 | cp -R $(BASEDIR)/include $(BASEDIR)/make $(BASEDIR)/src "$(DISTSRC)/" 96 | cp $(BASEDIR)/CHANGELOG $(BASEDIR)/COPYING* $(BASEDIR)/Makefile $(BASEDIR)/*.mk "$(DISTSRC)/" 97 | find "$(DISTSRC)" -iname '.git' | xargs rm -rf {} 98 | find "$(DISTSRC)" -iname '.gitignore' | xargs rm -rf {} 99 | tar -C $(DISTSRC_PATH) -czf "$(BUILDDIR)/$(ARTIFACT_NAME)-src-$(ARTIFACT_VERSION).tar.gz" "$(ARTIFACT_NAME)" 100 | echo "Created archive: $(BUILDDIR)/$(ARTIFACT_NAME)-src-$(ARTIFACT_VERSION).tar.gz" 101 | rm -rf $(DISTSRC_PATH) 102 | echo "Build OK" 103 | 104 | # Help 105 | help: 106 | echo "Available targets:" 107 | echo " all Build all binaries" 108 | echo " clean Clean all build files and configuration file" 109 | echo " config Configure build" 110 | echo " distsrc Make tarball with source code for packagers" 111 | echo " fetch Fetch all desired source code dependencies from git" 112 | echo " help Print this help message" 113 | echo " info Output build configuration" 114 | echo " install Install all binaries into the system" 115 | echo " prune Cleanup build and all fetched dependencies from git" 116 | echo " tree Fetch all possible source code dependencies from git" 117 | echo " to make source code portable between machines" 118 | echo " uninstall Uninstall binaries" 119 | echo "" 120 | $(MAKE) -f "$(BASEDIR)/make/configure.mk" $(@) VERBOSE="$(VERBOSE)" 121 | echo "" 122 | -------------------------------------------------------------------------------- /dependencies.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2025 Linux Studio Plugins Project 3 | # (C) 2025 Vladimir Sadovnikov 4 | # 5 | # This file is part of lsp-dsp-units 6 | # 7 | # lsp-dsp-units is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # any later version. 11 | # 12 | # lsp-dsp-units is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with lsp-dsp-units. If not, see . 19 | # 20 | 21 | #------------------------------------------------------------------------------ 22 | # List of common dependencies 23 | DEPENDENCIES = \ 24 | LSP_COMMON_LIB \ 25 | LSP_DSP_LIB \ 26 | LSP_LLTL_LIB \ 27 | LSP_RUNTIME_LIB 28 | 29 | TEST_DEPENDENCIES = \ 30 | LSP_TEST_FW 31 | 32 | #------------------------------------------------------------------------------ 33 | # Linux dependencies 34 | LINUX_DEPENDENCIES = \ 35 | LIBPTHREAD \ 36 | LIBDL \ 37 | LIBRT \ 38 | LIBSNDFILE 39 | 40 | LINUX_TEST_DEPENDENCIES = 41 | 42 | ifeq ($(PLATFORM),Linux) 43 | DEPENDENCIES += $(LINUX_DEPENDENCIES) 44 | TEST_DEPENDENCIES += $(LINUX_TEST_DEPENDENCIES) 45 | endif 46 | 47 | #------------------------------------------------------------------------------ 48 | # BSD dependencies 49 | BSD_DEPENDENCIES = \ 50 | LIBPTHREAD \ 51 | LIBDL \ 52 | LIBICONV \ 53 | LIBRT \ 54 | LIBSNDFILE 55 | 56 | BSD_TEST_DEPENDENCIES = 57 | 58 | ifeq ($(PLATFORM),BSD) 59 | DEPENDENCIES += $(BSD_DEPENDENCIES) 60 | TEST_DEPENDENCIES += $(BSD_TEST_DEPENDENCIES) 61 | endif 62 | 63 | #------------------------------------------------------------------------------ 64 | # Windows dependencies 65 | WINDOWS_DEPENDENCIES = \ 66 | LIBSHLWAPI \ 67 | LIBWINMM \ 68 | LIBMSACM 69 | 70 | WINDOWS_TEST_DEPENDENCIES = 71 | 72 | ifeq ($(PLATFORM),Windows) 73 | DEPENDENCIES += $(WINDOWS_DEPENDENCIES) 74 | TEST_DEPENDENCIES += $(WINDOWS_TEST_DEPENDENCIES) 75 | endif 76 | 77 | #------------------------------------------------------------------------------ 78 | # MacOS dependencies 79 | MACOS_DEPENDENCIES = \ 80 | LIBAUDIOTOOLBOX \ 81 | LIBCOREFOUNDATION \ 82 | LIBICONV 83 | 84 | MACOS_TEST_DEPENDENCIES = 85 | 86 | ifeq ($(PLATFORM),MacOS) 87 | DEPENDENCIES += $(MACOS_DEPENDENCIES) 88 | TEST_DEPENDENCIES += $(MACOS_TEST_DEPENDENCIES) 89 | endif 90 | 91 | #------------------------------------------------------------------------------ 92 | # Overall system dependencies 93 | ALL_DEPENDENCIES = \ 94 | $(DEPENDENCIES) \ 95 | $(LINUX_DEPENDENCIES) \ 96 | $(BSD_DEPENDENCIES) \ 97 | $(WINDOWS_DEPENDENCIES) \ 98 | $(MACOS_DEPENDENCIES) \ 99 | $(TEST_DEPENDENCIES) \ 100 | $(LINUX_TEST_DEPENDENCIES) \ 101 | $(BSD_TEST_DEPENDENCIES) \ 102 | $(WINDOWS_TEST_DEPENDENCIES) \ 103 | $(MACOS_TEST_DEPENDENCIES) 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/3d/bsp/context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2025 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 9 авг. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_3D_BSP_CONTEXT_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_3D_BSP_CONTEXT_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | namespace lsp 36 | { 37 | namespace dspu 38 | { 39 | namespace bsp 40 | { 41 | typedef struct LSP_DSP_UNITS_PUBLIC context_t 42 | { 43 | public: 44 | Allocator3D node; 45 | Allocator3D triangle; 46 | bsp::node_t *root; 47 | 48 | public: 49 | explicit context_t(); 50 | context_t (const context_t &) = delete; 51 | context_t (context_t &&) = delete; 52 | ~context_t(); 53 | 54 | context_t & operator = (const context_t &) = delete; 55 | context_t & operator = (context_t &&) = delete; 56 | 57 | protected: 58 | status_t split(lltl::parray &queue, bsp::node_t *task); 59 | 60 | public: 61 | void clear(); 62 | void flush(); 63 | 64 | inline void swap(context_t *dst) 65 | { 66 | lsp::swap(root, dst->root); 67 | node.swap(&dst->node); 68 | triangle.swap(&dst->triangle); 69 | } 70 | 71 | /** 72 | * Add object to context 73 | * @param obj object to add 74 | * @param col object color 75 | * @return status of operation 76 | */ 77 | inline status_t add_object(Object3D *obj, const dsp::color3d_t *col) 78 | { 79 | return add_object(obj, obj->matrix(), col); 80 | } 81 | 82 | /** 83 | * Add object to context 84 | * @param obj object to add 85 | * @param transform transformation matrix to apply to object 86 | * @param col object color 87 | * @return status of operation 88 | */ 89 | status_t add_object(Object3D *obj, const dsp::matrix3d_t *transform, const dsp::color3d_t *col); 90 | 91 | /** 92 | * Add triangles to the BSP tree 93 | * @param v_vertices list of triangle vertices 94 | * @param n_triangles number of triangles 95 | * @param transform object transformation 96 | * @param color the color for all triangles 97 | * @return status of operation 98 | */ 99 | status_t add_triangles 100 | ( 101 | const dsp::point3d_t *v_vertices, 102 | size_t n_triangles, 103 | const dsp::matrix3d_t *transform, 104 | const dsp::color3d_t *color 105 | ); 106 | 107 | /** 108 | * Build the BSP tree 109 | * @return status of operation 110 | */ 111 | status_t build_tree(); 112 | 113 | /** 114 | * Build the final mesh according to the viewer's plane 115 | * @param dst collection to store the mesh 116 | * @param pov the viewer's point-of-view location 117 | * @return status of operation 118 | */ 119 | status_t build_mesh(lltl::darray *dst, const dsp::point3d_t *pov); 120 | 121 | } context_t; 122 | } /* namespace bsp */ 123 | } /* namespace dspu */ 124 | } /* namespace lsp */ 125 | 126 | #endif /* LSP_PLUG_IN_DSP_UNITS_3D_BSP_CONTEXT_H_ */ 127 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/3d/bsp/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 9 авг. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_3D_BSP_TYPES_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_3D_BSP_TYPES_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | namespace bsp 33 | { 34 | #pragma pack(push, 1) 35 | typedef struct triangle_t: public dsp::raw_triangle_t 36 | { 37 | dsp::vector3d_t n[3]; // Normals 38 | dsp::color3d_t c; // Color 39 | bsp::triangle_t *next; // Pointer to next triangle 40 | size_t __pad; // Alignment to be sizeof() multiple of 16 41 | } triangle_t; 42 | #pragma pack(pop) 43 | 44 | typedef struct node_t 45 | { 46 | dsp::vector3d_t pl; 47 | bsp::node_t *in; 48 | bsp::node_t *out; 49 | bsp::triangle_t *on; 50 | bool emit; 51 | } node_t; 52 | } // namespace bsp 53 | } // namespace dspu 54 | } // namespace lsp 55 | 56 | 57 | 58 | #endif /* LSP_PLUG_IN_DSP_UNITS_3D_BSP_TYPES_H_ */ 59 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/3d/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 9 авг. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_3D_TYPES_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_3D_TYPES_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace lsp 31 | { 32 | namespace dspu 33 | { 34 | typedef ssize_t vertex_index_t; // Vertex index 35 | typedef ssize_t normal_index_t; // Normal index 36 | typedef ssize_t edge_index_t; // Edge index 37 | typedef ssize_t triangle_index_t; // Triangle index 38 | typedef ssize_t face_index_t; // Face index 39 | 40 | // Object structures 41 | struct obj_normal_t; 42 | struct obj_vertex_t; 43 | struct obj_edge_t; 44 | struct obj_triangle_t; 45 | struct obj_boundbox_t; 46 | 47 | typedef struct obj_normal_t: public dsp::vector3d_t 48 | { 49 | normal_index_t id; // Normal index 50 | void *ptag; // Pointer tag, may be used by user for any data manipulation purpose 51 | ssize_t itag; // Integer tag, may be used by user for any data manipulation purpose 52 | } obj_normal_t; 53 | 54 | typedef struct obj_vertex_t: public dsp::point3d_t 55 | { 56 | vertex_index_t id; // Vertex index 57 | obj_edge_t *ve; // Edge list 58 | void *ptag; // Pointer tag, may be used by user for any data manipulation purpose 59 | ssize_t itag; // Integer tag, may be used by user for any data manipulation purpose 60 | } obj_vertex_t; 61 | 62 | typedef struct obj_edge_t 63 | { 64 | edge_index_t id; // Edge index 65 | obj_vertex_t *v[2]; // Pointers to vertexes 66 | obj_edge_t *vlnk[2]; // Link to next edge for the vertex v[i] 67 | void *ptag; // Pointer tag, may be used by user for any data manipulation purpose 68 | ssize_t itag; // Integer tag, may be used by user for any data manipulation purpose 69 | } obj_edge_t; 70 | 71 | typedef struct obj_triangle_t 72 | { 73 | triangle_index_t id; // Triangle index 74 | face_index_t face; // Face number 75 | obj_vertex_t *v[3]; // Vertexes 76 | obj_edge_t *e[3]; // Edges 77 | obj_normal_t *n[3]; // Normals 78 | void *ptag; // Pointer tag, may be used by user for any data manipulation purpose 79 | ssize_t itag; // Integer tag, may be used by user for any data manipulation purpose 80 | } obj_triangle_t; 81 | 82 | typedef struct obj_boundbox_t: public dsp::bound_box3d_t 83 | { 84 | } obj_boundbox_t; 85 | } 86 | } 87 | 88 | 89 | 90 | #endif /* LSP_PLUG_IN_DSP_UNITS_3D_TYPES_H_ */ 91 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/3d/view/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 9 авг. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_3D_VIEW_TYPES_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_3D_VIEW_TYPES_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | namespace view 33 | { 34 | // Viewing structures 35 | #pragma pack(push, 1) 36 | typedef struct vertex3d_t 37 | { 38 | dsp::point3d_t p; // Position 39 | dsp::vector3d_t n; // Normal 40 | dsp::color3d_t c; // Color 41 | } v_vertex3d_t; 42 | 43 | typedef struct triangle3d_t 44 | { 45 | dsp::point3d_t p[3]; // Positions 46 | dsp::vector3d_t n[3]; // Normals 47 | } v_triangle3d_t; 48 | 49 | typedef struct point3d_t 50 | { 51 | dsp::point3d_t p; // Position 52 | dsp::color3d_t c; // Color 53 | } v_point3d_t; 54 | 55 | typedef struct ray3d_t 56 | { 57 | dsp::point3d_t p; // Position 58 | dsp::vector3d_t v; // Direction 59 | dsp::color3d_t c; // Color 60 | } v_ray3d_t; 61 | 62 | typedef struct segment3d_t 63 | { 64 | dsp::point3d_t p[2]; // Position 65 | dsp::color3d_t c[2]; // Color 66 | } v_segment3d_t; 67 | 68 | #pragma pack(pop) 69 | } // namespace view 70 | } // namespace dspu 71 | } // namespace lsp 72 | 73 | 74 | 75 | #endif /* LSP_PLUG_IN_DSP_UNITS_3D_VIEW_TYPES_H_ */ 76 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/ctl/Blink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 08 апр. 2016 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_CTL_BLINK_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_CTL_BLINK_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | /** Simple blink counter 33 | * 34 | */ 35 | class LSP_DSP_UNITS_PUBLIC Blink 36 | { 37 | private: 38 | Blink & operator = (const Blink &); 39 | Blink(const Blink &); 40 | 41 | protected: 42 | ssize_t nCounter; 43 | ssize_t nTime; 44 | float fOnValue; 45 | float fOffValue; 46 | float fTime; 47 | 48 | public: 49 | explicit Blink(); 50 | ~Blink(); 51 | 52 | /** 53 | * Construct object 54 | */ 55 | void construct(); 56 | 57 | /** 58 | * Destroy object 59 | */ 60 | void destroy(); 61 | 62 | public: 63 | /** Initialize blink 64 | * 65 | * @param sample_rate sample rate 66 | * @param time activity time 67 | */ 68 | void init(size_t sample_rate, float time = 0.1f); 69 | 70 | /** Update current sample rate 71 | * 72 | * @param sample_rate current sample rate 73 | */ 74 | void set_sample_rate(size_t sample_rate); 75 | 76 | /** Make blinking 77 | * 78 | */ 79 | void blink(); 80 | 81 | /** Make blinking 82 | * @param value value to display 83 | */ 84 | void blink(float value); 85 | 86 | /** Make blinking 87 | * 88 | * @param value value that will be displayed if less than max value 89 | */ 90 | void blink_max(float value); 91 | 92 | /** Make blinking 93 | * 94 | * @param value value that will be displayed if less than max value 95 | */ 96 | void blink_min(float value); 97 | 98 | /** Set default values 99 | * 100 | * @param on default value for on state 101 | * @param off default value for off state 102 | */ 103 | void set_default(float on, float off); 104 | 105 | /** Set default value for off state 106 | * 107 | * @param off default value for off state 108 | */ 109 | void set_default_off(float off); 110 | 111 | /** Process blinking 112 | * 113 | * @return activity value 114 | */ 115 | float process(size_t samples); 116 | 117 | /** Get current activity value of the blink 118 | * 119 | * @return current activity value of the blink 120 | */ 121 | inline float value() const 122 | { 123 | return (nCounter > 0) ? fOnValue : fOffValue; 124 | } 125 | 126 | /** 127 | * Dump the state 128 | * @param v state dumper 129 | */ 130 | void dump(IStateDumper *v) const; 131 | }; 132 | } /* namespace dspu */ 133 | } /* namespace lsp */ 134 | 135 | #endif /* LSP_PLUG_IN_DSP_UNITS_CTL_BLINK_H_ */ 136 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/ctl/Crossfade.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2025 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 22 янв. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_CTL_CROSSFADE_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_CTL_CROSSFADE_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | class LSP_DSP_UNITS_PUBLIC Crossfade 33 | { 34 | protected: 35 | size_t nSamples; 36 | size_t nCounter; 37 | float fDelta; 38 | float fGain; 39 | 40 | public: 41 | explicit Crossfade(); 42 | 43 | Crossfade(const Crossfade &) = delete; 44 | Crossfade(Crossfade &&) = delete; 45 | ~Crossfade(); 46 | 47 | Crossfade & operator = (const Crossfade &) = delete; 48 | Crossfade & operator = (Crossfade &&) = delete; 49 | 50 | /** 51 | * Construct object 52 | */ 53 | void construct(); 54 | 55 | /** 56 | * Destroy object 57 | */ 58 | void destroy(); 59 | 60 | public: 61 | /** 62 | * Initialize crossfade 63 | * @param sample_rate sample rate of the signal 64 | * @param time crossfade time, by default 5 msec 65 | */ 66 | void init(int sample_rate, float time = 0.005f); 67 | 68 | /** 69 | * Crossfade the signal 70 | * @param dst destination buffer 71 | * @param fade_out the signal that will fade out, may be NULL 72 | * @param fade_in the signal that will fade in, may be NULL 73 | * @param count number of samples to process 74 | */ 75 | void process(float *dst, const float *fade_out, const float *fade_in, size_t count); 76 | 77 | /** 78 | * Return the remaining number of samples to process 79 | * @return the remaining number of samples to process before crossfade becomes inactive 80 | */ 81 | inline size_t remaining() const { return nCounter; } 82 | 83 | /** 84 | * Check if crossfade is currently active 85 | * @return true if crossfade is currently active 86 | */ 87 | inline bool active() const { return nCounter > 0; } 88 | 89 | /** 90 | * Reset the crossfade state, immediately interrupt it's processing 91 | */ 92 | void reset(); 93 | 94 | /** 95 | * Toggle crossfade processing 96 | * @return true if crossfade has been toggled, false 97 | * if crossfade is currently active 98 | */ 99 | bool toggle(); 100 | 101 | /** 102 | * Dump the state 103 | * @param v state dumper 104 | */ 105 | void dump(IStateDumper *v) const; 106 | }; 107 | } /* namespace dspu */ 108 | } /* namespace lsp */ 109 | 110 | #endif /* LSP_PLUG_IN_DSP_UNITS_CTL_CROSSFADE_H_ */ 111 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/ctl/Toggle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 08 апр. 2016 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_CTL_TOGGLE_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_CTL_TOGGLE_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | /** Simple toggle class 33 | * 34 | */ 35 | class LSP_DSP_UNITS_PUBLIC Toggle 36 | { 37 | private: 38 | Toggle &operator = (const Toggle &); 39 | Toggle(const Toggle &); 40 | 41 | private: 42 | enum state_t 43 | { 44 | TRG_OFF, 45 | TRG_PENDING, 46 | TRG_ON 47 | }; 48 | 49 | float fValue; 50 | state_t nState; 51 | 52 | public: 53 | explicit Toggle(); 54 | ~Toggle(); 55 | 56 | /** 57 | * Construct object 58 | */ 59 | void construct(); 60 | 61 | /** 62 | * Destroy object 63 | */ 64 | void destroy(); 65 | 66 | 67 | public: 68 | /** Initialize toggle 69 | * 70 | */ 71 | void init(); 72 | 73 | /** Submit toggle state 74 | * 75 | * @param value toggle value [0..1] 76 | */ 77 | void submit(float value); 78 | 79 | /** Check that there is pending request for the toggle 80 | * 81 | * @return true if there is pending request for the toggle 82 | */ 83 | inline bool pending() const 84 | { 85 | return nState == TRG_PENDING; 86 | } 87 | 88 | /** Check that toggle is in 'ON' state 89 | * 90 | * @return true toggle is in 'ON' state 91 | */ 92 | inline bool on() const 93 | { 94 | return nState == TRG_ON; 95 | } 96 | 97 | /** Check that toggle is in 'OFF' state 98 | * 99 | * @return true toggle is in 'OFF' state 100 | */ 101 | inline bool off() const 102 | { 103 | return nState == TRG_OFF; 104 | } 105 | 106 | /** Commit the pending request of the toggle 107 | * @param off disable pending state only if toggle is in OFF state 108 | * @return true if current state of the toggle is ON 109 | */ 110 | bool commit(bool off = false); 111 | 112 | /** 113 | * Dump internal state 114 | * @param v state dumper 115 | */ 116 | void dump(IStateDumper *v) const; 117 | }; 118 | } /* namespace dspu */ 119 | } /* namespace lsp */ 120 | 121 | #endif /* LSP_PLUG_IN_DSP_UNITS_CTL_H_ */ 122 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/filters/ButterworthFilter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2021 Stefano Tronci 4 | * (C) 2025 Vladimir Sadovnikov 5 | * 6 | * This file is part of lsp-dsp-units 7 | * Created on: 28 Sept 2021 8 | * 9 | * lsp-dsp-units is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * any later version. 13 | * 14 | * lsp-dsp-units is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with lsp-dsp-units. If not, see . 21 | */ 22 | 23 | 24 | #ifndef LSP_PLUG_IN_DSP_UNITS_FILTERS_BUTTER_H_ 25 | #define LSP_PLUG_IN_DSP_UNITS_FILTERS_BUTTER_H_ 26 | 27 | #include 28 | #include 29 | 30 | namespace lsp 31 | { 32 | namespace dspu 33 | { 34 | 35 | enum bw_filt_type_t 36 | { 37 | BW_FLT_TYPE_LOWPASS, 38 | BW_FLT_TYPE_HIGHPASS, 39 | BW_FLT_TYPE_NONE, 40 | BW_FLT_TYPE_MAX 41 | }; 42 | 43 | /** Even order high-pass and low-pass Butterworth filter, implemented as second order section. 44 | * Pre-warped bilinear transform of analog Butterworth prototype. 45 | */ 46 | class LSP_DSP_UNITS_PUBLIC ButterworthFilter 47 | { 48 | private: 49 | size_t nOrder; 50 | float fCutoffFreq; 51 | size_t nSampleRate; 52 | bw_filt_type_t enFilterType; 53 | bool bBypass; 54 | bool bSync; 55 | dspu::FilterBank sFilter; 56 | 57 | public: 58 | explicit ButterworthFilter(); 59 | ButterworthFilter(const ButterworthFilter &) = delete; 60 | ButterworthFilter(ButterworthFilter &&) = delete; 61 | ~ButterworthFilter(); 62 | 63 | ButterworthFilter & operator = (const ButterworthFilter &) = delete; 64 | ButterworthFilter & operator = (ButterworthFilter &&) = delete; 65 | 66 | void construct(); 67 | void destroy(); 68 | void init(); 69 | 70 | protected: 71 | void update_settings(); 72 | 73 | public: 74 | /** Set the order of the filter. 75 | * 76 | * @param order order of the filter. 77 | */ 78 | void set_order(size_t order); 79 | 80 | /** Set the cutoff frequency of the filter. 81 | * 82 | * @param frequency cutoff frequency. 83 | */ 84 | void set_cutoff_frequency(float frequency); 85 | 86 | /** Set filter type. 87 | * 88 | * @param type filter type. 89 | */ 90 | void set_filter_type(bw_filt_type_t type); 91 | 92 | /** Set sample rate for the filter. 93 | * 94 | * @param sr sample rate. 95 | */ 96 | void set_sample_rate(size_t sr); 97 | 98 | /** Output sequence to the destination buffer in additive mode 99 | * 100 | * @param dst output wave destination 101 | * @param src input source, allowed to be NULL 102 | * @param count number of samples to synthesise 103 | */ 104 | void process_add(float *dst, const float *src, size_t count); 105 | 106 | /** Output sequence to the destination buffer in multiplicative mode 107 | * 108 | * @param dst output wave destination 109 | * @param src input source, allowed to be NULL 110 | * @param count number of samples to process 111 | */ 112 | void process_mul(float *dst, const float *src, size_t count); 113 | 114 | /** Output sequence to a destination buffer overwriting its content 115 | * 116 | * @param dst output wave destination 117 | * @param src input source, allowed to be NULLL 118 | * @param count number of samples to process 119 | */ 120 | void process_overwrite(float *dst, const float *src, size_t count); 121 | 122 | /** 123 | * Dump the state 124 | * @param v state dumper 125 | */ 126 | void dump(IStateDumper *v) const; 127 | }; 128 | 129 | } /* namespace dspu */ 130 | } /* namespace lsp */ 131 | 132 | #endif /* LSP_PLUG_IN_DSP_UNITS_FILTERS_BUTTER_H_ */ 133 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/misc/envelope.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 20 февр. 2016 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_MISC_ENVELOPE_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_MISC_ENVELOPE_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | namespace envelope 33 | { 34 | enum envelope_t 35 | { 36 | VIOLET_NOISE, 37 | BLUE_NOISE, 38 | WHITE_NOISE, 39 | PINK_NOISE, 40 | BROWN_NOISE, 41 | MINUS_4_5_DB, 42 | PLUS_4_5_DB, 43 | 44 | // Special variables 45 | TOTAL, 46 | FIRST = VIOLET_NOISE, 47 | LAST = TOTAL - 1 48 | }; 49 | 50 | LSP_DSP_UNITS_PUBLIC 51 | void noise(float *dst, size_t n, envelope_t type); 52 | 53 | LSP_DSP_UNITS_PUBLIC 54 | void reverse_noise(float *dst, size_t n, envelope_t type); 55 | 56 | LSP_DSP_UNITS_PUBLIC 57 | void white_noise(float *dst, size_t n); 58 | 59 | LSP_DSP_UNITS_PUBLIC 60 | void pink_noise(float *dst, size_t n); 61 | 62 | LSP_DSP_UNITS_PUBLIC 63 | void brown_noise(float *dst, size_t n); 64 | 65 | LSP_DSP_UNITS_PUBLIC 66 | void blue_noise(float *dst, size_t n); 67 | 68 | LSP_DSP_UNITS_PUBLIC 69 | void violet_noise(float *dst, size_t n); 70 | } 71 | } 72 | } 73 | 74 | #endif /* LSP_PLUG_IN_DSP_UNITS_MISC_ENVELOPE_H_ */ 75 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/misc/fade.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 21 февр. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_MISC_FADE_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_MISC_FADE_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | /** Apply linear fade-in to the signal (with range check) 33 | * 34 | * @param dst destination buffer 35 | * @param src source buffer 36 | * @param fade_len length of fade (in elements) 37 | * @param buf_len length of the buffer 38 | */ 39 | LSP_DSP_UNITS_PUBLIC 40 | void fade_in(float *dst, const float *src, size_t fade_len, size_t buf_len); 41 | 42 | /** Apply linear fade-out to the signal (with range check) 43 | * 44 | * @param dst destination buffer 45 | * @param src source buffer 46 | * @param fade_len length of fade (in elements) 47 | * @param buf_len length of the buffer 48 | */ 49 | LSP_DSP_UNITS_PUBLIC 50 | void fade_out(float *dst, const float *src, size_t fade_len, size_t buf_len); 51 | } 52 | } 53 | 54 | 55 | 56 | #endif /* INCLUDE_LSP_PLUG_IN_DSP_UNITS_MISC_FADE_H_ */ 57 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/misc/interpolation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 23 сент. 2016 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_MISC_INTERPOLATION_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_MISC_INTERPOLATION_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | namespace interpolation 33 | { 34 | /** Perform quadratic Hermite interpolation 35 | * 36 | * The resulting polynom equation is the following: 37 | * y(x) = p[0]*x^2 + p[1]*x^ + p[2] 38 | * 39 | * @param p destination (3 floats) to store the final hermite polynom 40 | * @param x0 x-coordinate of first point used for interpolation 41 | * @param y0 y-coordinate of first point used for interpolation 42 | * @param k0 the tangent angle of the line at first point 43 | * @param x1 x-coordinate of second point used for interpolation 44 | * @param k1 the tangent angle of the line at second point 45 | */ 46 | LSP_DSP_UNITS_PUBLIC 47 | void hermite_quadratic(float *p, float x0, float y0, float k0, float x1, float k1); 48 | 49 | /** Perform cubic Hermite interpolation. 50 | * 51 | * The resulting polynom equation is the following: 52 | * y(x) = p[0]*x^3 + p[1]*x^2 + p[2]*x + p[3] 53 | * 54 | * @param p destination (4 floats) to store the final hermite polynom 55 | * @param x0 x-coordinate of first point used for interpolation 56 | * @param y0 y-coordinate of first point used for interpolation 57 | * @param k0 the tangent angle of the line at first point 58 | * @param x1 x-coordinate of second point used for interpolation 59 | * @param y1 y-coordinate of second point used for interpolation 60 | * @param k1 the tangent angle of the line at second point 61 | */ 62 | LSP_DSP_UNITS_PUBLIC 63 | void hermite_cubic(float *p, float x0, float y0, float k0, float x1, float y1, float k1); 64 | 65 | /** Perform exponent interpolation 66 | * 67 | * @param p destination (3 floats) to store the formula: y(x) = p[0] + p[1] * exp(p[2] * x) 68 | * @param x0 x-coordinate of first point used for interpolation 69 | * @param y0 y-coordinate of first point used for interpolation 70 | * @param x1 x-coordinate of second point used for interpolation 71 | * @param y1 y-coordinate of second point used for interpolation 72 | * @param k growing/lowering coefficient 73 | */ 74 | LSP_DSP_UNITS_PUBLIC 75 | void exponent(float *p, float x0, float y0, float x1, float y1, float k); 76 | 77 | /** Perform linear interpolation 78 | * 79 | * @param p destination (2 floats) to store the formula: y(x) = p[0]*x + p[1] 80 | * @param x0 x-coordinate of first point used for interpolation 81 | * @param y0 y-coordinate of first point used for interpolation 82 | * @param x1 x-coordinate of second point used for interpolation 83 | * @param y1 y-coordinate of second point used for interpolation 84 | */ 85 | LSP_DSP_UNITS_PUBLIC 86 | void linear(float *p, float x0, float y0, float x1, float y1); 87 | 88 | } /* namespace interpolation */ 89 | } /* namespace dspu */ 90 | } /* namespace lsp */ 91 | 92 | #endif /* LSP_PLUG_IN_DSP_UNITS_MISC_INTERPOLATION_H_ */ 93 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/misc/sigmoid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Linux Studio Plugins Project 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 18 нояб. 2023 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_MISC_SIGMOID_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_MISC_SIGMOID_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | /** 33 | * This header defines different kind of sigmoid functions. 34 | * 35 | * Each function computes an output value in range of [-1.0 .. +1.0] 36 | * depending on the input argument. The function is odd and symmetric 37 | * across the zero. For the zero value, the function value is 0.0 and 38 | * the first derivative is 1.0. 39 | */ 40 | namespace sigmoid 41 | { 42 | /** 43 | * Pointer to sigmoid function 44 | * @param x argument for sigmoid function 45 | * @return computed value 46 | */ 47 | typedef float (* function_t)(float x); 48 | 49 | /** Hard-clipping function 50 | * @param x argument for the sigmoid function 51 | * @return computed value 52 | */ 53 | LSP_DSP_UNITS_PUBLIC 54 | float hard_clip(float x); 55 | 56 | /** Quadratic function 57 | * @param x argument for the sigmoid function 58 | * @return computed value 59 | */ 60 | LSP_DSP_UNITS_PUBLIC 61 | float quadratic(float x); 62 | 63 | /** Sine function 64 | * @param x argument for the sigmoid function 65 | * @return computed value 66 | */ 67 | LSP_DSP_UNITS_PUBLIC 68 | float sine(float x); 69 | 70 | /** Logistic function 71 | * @param x argument for the sigmoid function 72 | * @return computed value 73 | */ 74 | LSP_DSP_UNITS_PUBLIC 75 | float logistic(float x); 76 | 77 | /** Arctangent function 78 | * @param x argument for the sigmoid function 79 | * @return computed value 80 | */ 81 | LSP_DSP_UNITS_PUBLIC 82 | float arctangent(float x); 83 | 84 | /** Hyperbolic tangent function 85 | * @param x argument for the sigmoid function 86 | * @return computed value 87 | */ 88 | LSP_DSP_UNITS_PUBLIC 89 | float hyperbolic_tangent(float x); 90 | 91 | /** Hyperbolic function 92 | * @param x argument for the sigmoid function 93 | * @return computed value 94 | */ 95 | LSP_DSP_UNITS_PUBLIC 96 | float hyperbolic(float x); 97 | 98 | /** Guidermannian function 99 | * @param x argument for the sigmoid function 100 | * @return computed value 101 | */ 102 | LSP_DSP_UNITS_PUBLIC 103 | float guidermannian(float x); 104 | 105 | /** Error function 106 | * @param x argument for the sigmoid function 107 | * @return computed value 108 | */ 109 | LSP_DSP_UNITS_PUBLIC 110 | float error(float x); 111 | 112 | /** Smoothstep function 113 | * @param x argument for the sigmoid function 114 | * @return computed value 115 | */ 116 | LSP_DSP_UNITS_PUBLIC 117 | float smoothstep(float x); 118 | 119 | /** Smootherstep function 120 | * @param x argument for the sigmoid function 121 | * @return computed value 122 | */ 123 | LSP_DSP_UNITS_PUBLIC 124 | float smootherstep(float x); 125 | 126 | /** Circle function 127 | * @param x argument for the sigmoid function 128 | * @return computed value 129 | */ 130 | LSP_DSP_UNITS_PUBLIC 131 | float circle(float x); 132 | 133 | } /* namespace sigmoid */ 134 | } /* dspu */ 135 | } /* namespace lsp */ 136 | 137 | 138 | 139 | 140 | #endif /* LSP_PLUG_IN_DSP_UNITS_MISC_SIGMOID_H_ */ 141 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/sampling/InSampleStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Linux Studio Plugins Project 3 | * (C) 2022 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 30 окт. 2022 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_SAMPLING_INSAMPLESTREAM_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_SAMPLING_INSAMPLESTREAM_H_ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace lsp 31 | { 32 | namespace dspu 33 | { 34 | /** 35 | * Input audio stream that allows to wrap a sample and perform streaming reads from it. 36 | */ 37 | class LSP_DSP_UNITS_PUBLIC InSampleStream: public mm::IInAudioStream 38 | { 39 | private: 40 | InSampleStream(const InSampleStream &); 41 | InSampleStream & operator = (const InSampleStream &); 42 | 43 | protected: 44 | const Sample *pSample; 45 | bool bDelete; 46 | 47 | protected: 48 | void do_close(); 49 | 50 | protected: 51 | virtual ssize_t direct_read(void *dst, size_t nframes, size_t fmt) override; 52 | virtual size_t select_format(size_t fmt) override; 53 | 54 | public: 55 | InSampleStream(); 56 | InSampleStream(const Sample *s, bool drop = false); 57 | virtual ~InSampleStream() override; 58 | 59 | public: 60 | status_t wrap(const dspu::Sample *s, bool drop = false); 61 | 62 | public: 63 | virtual status_t info(mm::audio_stream_t *dst) const override; 64 | virtual size_t sample_rate() const override; 65 | virtual size_t channels() const override; 66 | virtual wssize_t length() const override; 67 | virtual size_t format() const override; 68 | 69 | virtual status_t close() override; 70 | virtual wssize_t skip(wsize_t nframes) override; 71 | virtual wssize_t seek(wsize_t nframes) override; 72 | }; 73 | 74 | } /* namespace dspu */ 75 | } /* namespace lsp */ 76 | 77 | #endif /* LSP_PLUG_IN_DSP_UNITS_SAMPLING_INSAMPLESTREAM_H_ */ 78 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/sampling/helpers/batch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Linux Studio Plugins Project 3 | * (C) 2022 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 24 нояб. 2022 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_SAMPLING_HELPERS_BATCH_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_SAMPLING_HELPERS_BATCH_H_ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace lsp 32 | { 33 | namespace dspu 34 | { 35 | namespace playback 36 | { 37 | /** 38 | * The type of the sample range 39 | */ 40 | enum batch_type_t 41 | { 42 | BATCH_NONE, // The batch is empty, nothing to do 43 | BATCH_HEAD, // The batch is associated with the head part of the sample 44 | BATCH_LOOP, // The batch is associated with the loop part of the sample 45 | BATCH_TAIL // The batch is associated with the tail part of the sample 46 | }; 47 | 48 | /** 49 | * Low-level data stucture that defines the range of the sample that should be played 50 | */ 51 | typedef struct batch_t 52 | { 53 | wsize_t nTimestamp; // The start of the batch in the sample timeline 54 | size_t nStart; // Start of the sample segment to play 55 | size_t nEnd; // End of the sample segment to play 56 | size_t nFadeIn; // The fade-in time in samples 57 | size_t nFadeOut; // The fade-out time in samples 58 | batch_type_t enType; // Type of the batch 59 | } play_batch_t; 60 | 61 | LSP_DSP_UNITS_PUBLIC 62 | void clear_batch(batch_t *b); 63 | 64 | LSP_DSP_UNITS_PUBLIC 65 | void dump_batch_plain(IStateDumper *v, const batch_t *b); 66 | 67 | LSP_DSP_UNITS_PUBLIC 68 | void dump_batch(IStateDumper *v, const batch_t *b); 69 | 70 | LSP_DSP_UNITS_PUBLIC 71 | void dump_batch(IStateDumper *v, const char *name, const batch_t *b); 72 | 73 | LSP_DSP_UNITS_PUBLIC 74 | size_t put_batch_linear_direct(float *dst, const float *src, const batch_t *b, wsize_t timestamp, size_t samples); 75 | 76 | LSP_DSP_UNITS_PUBLIC 77 | size_t put_batch_const_power_direct(float *dst, const float *src, const batch_t *b, wsize_t timestamp, size_t samples); 78 | 79 | LSP_DSP_UNITS_PUBLIC 80 | size_t put_batch_linear_reverse(float *dst, const float *src, const batch_t *b, wsize_t timestamp, size_t samples); 81 | 82 | LSP_DSP_UNITS_PUBLIC 83 | size_t put_batch_const_power_reverse(float *dst, const float *src, const batch_t *b, wsize_t timestamp, size_t samples); 84 | 85 | } /* namespace playback */ 86 | } /* namespace dspu */ 87 | } /* namespace lsp */ 88 | 89 | #endif /* LSP_PLUG_IN_DSP_UNITS_SAMPLING_HELPERS_BATCH_H_ */ 90 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/sampling/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Linux Studio Plugins Project 3 | * (C) 2022 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins-sampler 6 | * Created on: 18 нояб. 2022 г. 7 | * 8 | * lsp-plugins-sampler is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins-sampler is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins-sampler. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_SAMPLING_TYPES_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_SAMPLING_TYPES_H_ 24 | 25 | #include 26 | #include 27 | 28 | #define AUDIO_SAMPLE_CONTENT_TYPE "application/x-lsp-audio-sample" 29 | 30 | namespace lsp 31 | { 32 | namespace dspu 33 | { 34 | #pragma pack(push, 1) 35 | typedef struct sample_header_t 36 | { 37 | uint16_t version; // Version + endianess 38 | uint16_t channels; 39 | uint32_t sample_rate; 40 | uint32_t samples; 41 | } sample_header_t; 42 | #pragma pack(pop) 43 | 44 | enum sample_normalize_t 45 | { 46 | /** 47 | * No normalization 48 | */ 49 | SAMPLE_NORM_NONE, 50 | 51 | /** 52 | * Normalize if maximum peak is above threshold 53 | */ 54 | SAMPLE_NORM_ABOVE, 55 | 56 | /** 57 | * Normalize if maximum peak is below threshold 58 | */ 59 | SAMPLE_NORM_BELOW, 60 | 61 | /** 62 | * Normalize in any case 63 | */ 64 | SAMPLE_NORM_ALWAYS 65 | }; 66 | 67 | enum sample_crossfade_t 68 | { 69 | /** 70 | * Linear crossfade 71 | */ 72 | SAMPLE_CROSSFADE_LINEAR, 73 | 74 | /** 75 | * Constant-power crossfade 76 | */ 77 | SAMPLE_CROSSFADE_CONST_POWER 78 | }; 79 | 80 | enum sample_loop_t 81 | { 82 | /** 83 | * The loop mode is disabled 84 | */ 85 | SAMPLE_LOOP_NONE, 86 | 87 | /** 88 | * The loop part of sample is always played from the start to the end of the range 89 | */ 90 | SAMPLE_LOOP_DIRECT, 91 | 92 | /** 93 | * The loop part of sample is always played from the end to the start of the range 94 | */ 95 | SAMPLE_LOOP_REVERSE, 96 | 97 | /** 98 | * The loop part of sample is played in ping-pong mode, the first repeat is played from the 99 | * start to the end. Leaving the loop is allowed at any direction of the playback 100 | */ 101 | SAMPLE_LOOP_DIRECT_HALF_PP, 102 | 103 | /** 104 | * The loop part of sample is played in ping-pong mode, the first repeat is played from the 105 | * start to the end. Leaving the loop is allowed at any direction of the playback 106 | */ 107 | SAMPLE_LOOP_REVERSE_HALF_PP, 108 | 109 | /** 110 | * The loop part of sample is played in ping-pong mode, the first repeat is played from the 111 | * start to the end. Leaving the loop is allowed only after the reversed playback part 112 | */ 113 | SAMPLE_LOOP_DIRECT_FULL_PP, 114 | 115 | /** 116 | * The loop part of sample is played in ping-pong mode, the first repeat is played from the 117 | * end to the start (in reverse mode) Leaving the loop is allowed only after the direct playback part 118 | */ 119 | SAMPLE_LOOP_REVERSE_FULL_PP, 120 | 121 | /** 122 | * The loop part of sample is played in ping-pong mode, the first repeat is played from the 123 | * start to the end. Leaving the loop is allowed only after the direct playback part 124 | */ 125 | SAMPLE_LOOP_DIRECT_SMART_PP, 126 | 127 | /** 128 | * The loop part of sample is played in ping-pong mode, the first repeat is played from the 129 | * end to the start (in reverse mode). Leaving the loop is allowed only after the direct playback part 130 | */ 131 | SAMPLE_LOOP_REVERSE_SMART_PP, 132 | }; 133 | 134 | } /* namesapace dspu */ 135 | } /* namespace lsp */ 136 | 137 | 138 | #endif /* LSP_PLUG_IN_DSP_UNITS_SAMPLING_TYPES_H_ */ 139 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/util/Dither.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2025 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 21 дек. 2016 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_UTIL_DITHER_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_UTIL_DITHER_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace lsp 30 | { 31 | namespace dspu 32 | { 33 | /** 34 | * Dither class: generates dither noise with specified characteristics 35 | */ 36 | class LSP_DSP_UNITS_PUBLIC Dither 37 | { 38 | private: 39 | 40 | 41 | protected: 42 | size_t nBits; 43 | float fGain; 44 | float fDelta; 45 | Randomizer sRandom; 46 | 47 | public: 48 | explicit Dither(); 49 | Dither(const Dither &) = delete; 50 | Dither(Dither &&) = delete; 51 | ~Dither(); 52 | 53 | Dither &operator = (const Dither &) = delete; 54 | Dither &operator = (Dither &&) = delete; 55 | 56 | /** 57 | * Create object 58 | */ 59 | void construct(); 60 | 61 | /** 62 | * Destroy object 63 | */ 64 | void destroy(); 65 | 66 | public: 67 | /** Initialize dither 68 | * 69 | */ 70 | inline void init() { sRandom.init(); }; 71 | 72 | /** Set number of bits per sample 73 | * 74 | * @param bits number of bits per sample 75 | */ 76 | void set_bits(size_t bits); 77 | 78 | /** Process signal 79 | * 80 | * @param out output signal 81 | * @param in input signal 82 | * @param count number of samples to process 83 | */ 84 | void process(float *out, const float *in, size_t count); 85 | 86 | /** 87 | * Dump the state 88 | * @param v state dumper 89 | */ 90 | void dump(IStateDumper *v) const; 91 | }; 92 | } /* namespace dspu */ 93 | } /* namespace lsp */ 94 | 95 | #endif /* LSP_PLUG_IN_DSP_UNITS_UTIL_DITHER_H_ */ 96 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/util/DynamicDelay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2025 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 15 дек. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_UTIL_DYNAMICDELAY_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_UTIL_DYNAMICDELAY_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace lsp 30 | { 31 | namespace dspu 32 | { 33 | /** 34 | * Dynamic Delay: Delay with varying in time delay, gain and feedback gain 35 | */ 36 | class LSP_DSP_UNITS_PUBLIC DynamicDelay 37 | { 38 | protected: 39 | float *vDelay; 40 | uint32_t nHead; 41 | uint32_t nCapacity; 42 | int32_t nMaxDelay; 43 | uint8_t *pData; 44 | 45 | public: 46 | explicit DynamicDelay(); 47 | DynamicDelay(const DynamicDelay &) = delete; 48 | DynamicDelay(DynamicDelay &&) = delete; 49 | ~DynamicDelay(); 50 | 51 | DynamicDelay & operator = (const DynamicDelay &) = delete; 52 | DynamicDelay & operator = (DynamicDelay &&) = delete; 53 | 54 | void construct(); 55 | void destroy(); 56 | 57 | public: 58 | /** 59 | * Obtain the maximum possible value for the delay 60 | * @return the maximum possible value for the delay in samples 61 | */ 62 | inline size_t max_delay() const { return nMaxDelay; } 63 | 64 | /** 65 | * Obtain the overall delay capacity 66 | * @return the overall delay capacity in samples 67 | */ 68 | inline size_t capacity() const { return nCapacity; } 69 | 70 | /** 71 | * Initialize delay 72 | * @param max_size maximum delay size 73 | * @return status of operation 74 | */ 75 | status_t init(size_t max_size); 76 | 77 | /** 78 | * Process the signal using dynamic settings of delay and feedback 79 | * @param out output buffer 80 | * @param in input buffer 81 | * @param delay the delay values 82 | * @param fgain feedback gain values 83 | * @param fdelay feedback delay values 84 | * @param samples number of samples to process 85 | */ 86 | void process(float *out, const float *in, 87 | const float *delay, const float *fgain, const float *fdelay, 88 | size_t samples); 89 | 90 | /** 91 | * Clear delay state 92 | */ 93 | void clear(); 94 | 95 | /** 96 | * Copy the contents of the dynamic delay 97 | * @param s delay to copy contents from 98 | */ 99 | void copy(DynamicDelay *s); 100 | 101 | /** 102 | * Swap contents with some another delay 103 | * @param d delay to swap contents 104 | */ 105 | void swap(DynamicDelay *d); 106 | 107 | /** 108 | * Dump internal state 109 | * @param v state dumper 110 | */ 111 | void dump(IStateDumper *v) const; 112 | }; 113 | 114 | } /* namespace dspu */ 115 | } /* namespace lsp */ 116 | 117 | #endif /* LSP_PLUG_IN_DSP_UNITS_UTIL_DYNAMICDELAY_H_ */ 118 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/util/Randomizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Linux Studio Plugins Project 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 23 марта 2016 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_UTIL_RANDOMIZER_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_UTIL_RANDOMIZER_H_ 24 | 25 | #include 26 | #include 27 | 28 | namespace lsp 29 | { 30 | namespace dspu 31 | { 32 | enum random_function_t 33 | { 34 | RND_LINEAR, // Uniform over [0, 1) 35 | RND_EXP, // Decaying exponential over [0, 1] 36 | RND_TRIANGLE, // Triangle over [0, 1] 37 | RND_GAUSSIAN, // Gaussian of mean 0 and standard deviation 1 (has negative values) 38 | RND_MAX 39 | }; 40 | 41 | class LSP_DSP_UNITS_PUBLIC Randomizer 42 | { 43 | private: 44 | static const uint32_t vMul1[]; 45 | static const uint32_t vMul2[]; 46 | static const uint32_t vAdders[]; 47 | 48 | typedef struct randgen_t 49 | { 50 | uint32_t vLast; 51 | uint32_t vMul1; 52 | uint32_t vMul2; 53 | uint32_t vAdd; 54 | } randgen_t; 55 | 56 | randgen_t vRandom[4]; 57 | size_t nBufID; 58 | 59 | protected: 60 | float generate_linear(); 61 | 62 | public: 63 | explicit Randomizer(); 64 | Randomizer(const Randomizer &) = delete; 65 | Randomizer(Randomizer &&) = delete; 66 | ~Randomizer(); 67 | 68 | Randomizer &operator = (const Randomizer &) = delete; 69 | Randomizer &operator = (Randomizer &&) = delete; 70 | 71 | /** 72 | * Construct the randomizer 73 | */ 74 | void construct(); 75 | 76 | /** 77 | * Destroy the randomizer 78 | */ 79 | void destroy(); 80 | 81 | /** Initialize random generator 82 | * 83 | * @param seed seed 84 | */ 85 | void init(uint32_t seed); 86 | 87 | /** Initialize random generator, take current time as seed 88 | */ 89 | void init(); 90 | 91 | public: 92 | /** Generate float random number in range of [0..1) - excluding 1.0f 93 | * The guaranteed tolerance is 1e-6 or 0.000001 94 | * 95 | * @param func function 96 | * @return random number 97 | */ 98 | float random(random_function_t func = RND_LINEAR); 99 | 100 | /** 101 | * Dump the state 102 | * @param v state dumper 103 | */ 104 | void dump(IStateDumper *v) const; 105 | }; 106 | } 107 | } /* namespace lsp */ 108 | 109 | #endif /* LSP_PLUG_IN_DSP_UNITS_UTIL_RANDOMIZER_H_ */ 110 | -------------------------------------------------------------------------------- /include/lsp-plug.in/dsp-units/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 19 нояб. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #ifndef LSP_PLUG_IN_DSP_UNITS_VERSION_H_ 23 | #define LSP_PLUG_IN_DSP_UNITS_VERSION_H_ 24 | 25 | // Define version of headers 26 | #define LSP_DSP_UNITS_MAJOR 1 27 | #define LSP_DSP_UNITS_MINOR 0 28 | #define LSP_DSP_UNITS_MICRO 29 29 | 30 | #if defined(LSP_DSP_UNITS_PUBLISHER) 31 | #define LSP_DSP_UNITS_PUBLIC LSP_EXPORT_MODIFIER 32 | #elif defined(LSP_DSP_UNITS_BUILTIN) || defined(LSP_IDE_DEBUG) 33 | #define LSP_DSP_UNITS_PUBLIC 34 | #else 35 | #define LSP_DSP_UNITS_PUBLIC LSP_IMPORT_MODIFIER 36 | #endif 37 | 38 | #endif /* LSP_PLUG_IN_DSP_UNITS_VERSION_H_ */ 39 | -------------------------------------------------------------------------------- /make/functions.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2024 Linux Studio Plugins Project 3 | # (C) 2024 Vladimir Sadovnikov 4 | # 5 | # This file is part of lsp-dsp-units 6 | # 7 | # lsp-dsp-units is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # any later version. 11 | # 12 | # lsp-dsp-units is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with lsp-dsp-units. If not, see . 19 | # 20 | 21 | # Deduplicates all strings in the list 22 | # $(call uniq, ) 23 | # $(call uniq, $(DEPENDENCIES)) 24 | uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) 25 | 26 | # Recursively lookup directory for specific file pattern 27 | # $(call rwildcard, , ) 28 | # $(call rwildcard, main, *.cpp) 29 | rwildcard = $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) 30 | 31 | # Fetch different flags from symbolic dependencies 32 | # $(call query, , ) 33 | # $(call query, CFLAGS, $(DEPENDENCIES)) 34 | query = $(foreach d,$(call uniq, $2),$($(d)_$(strip $1))) 35 | 36 | # Fetch conditionally if dependency field is present 37 | # $(call dquery, , ) 38 | # $(call dquery, OBJ, $(DEPENDENCIES)) 39 | dquery = $(foreach d,$(call uniq, $2),$(if $($(d)_$(strip $1)),$(d))) 40 | 41 | # Fetch different flags from symbolic dependencies 42 | # $(call cquery, , , ) 43 | # $(call cquery, OBJ_META, BIN, $(DEPENDENCIES)) 44 | cquery = $(foreach d,$(call uniq, $3),$(if $($(d)_$(strip $1)),$($(d)_$(strip $2)))) 45 | 46 | # Find intersection between two sets 47 | # $(call intersection, list1, list2) 48 | intersection = $(sort $(foreach v,$1,$(if $(findstring $(v),$2),$(v)))) 49 | 50 | # Subtract the first set from second set 51 | # $(call subtraction, list1, list2) 52 | subtraction = $(sort $(foreach v,$2,$(if $(findstring $(v),$1),,$(v)))) 53 | 54 | # Check feature presence in list 55 | # $(call fcheck, features-to-check, all-feature-list, action-if-enabled, action-if-disabled) 56 | fcheck = $(if $(call intersection,$1,$2),$3,$4) 57 | 58 | # Fetch different versions from version string 59 | # $(call vmajor, ) 60 | vmajor = $(shell echo "$(strip $1)" | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-(.*))?/\1/') 61 | vminor = $(shell echo "$(strip $1)" | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-(.*))?/\2/') 62 | vmicro = $(shell echo "$(strip $1)" | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-(.*))?/\3/') 63 | vbranch = $(shell echo "$(strip $1)" | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)(-(.*))?/\5/') 64 | 65 | ifeq ("$(MSYSTEM)","") 66 | pathconv = $1 67 | else 68 | pathconv = $(shell cygpath -w "$1") 69 | endif 70 | -------------------------------------------------------------------------------- /make/ld-windows.script: -------------------------------------------------------------------------------- 1 | /* Script for ld -r: link without relocation */ 2 | /* Copyright (C) 2014-2018 Free Software Foundation, Inc. 3 | Copying and distribution of this script, with or without modification, 4 | are permitted in any medium without royalty provided the copyright 5 | notice and this notice are preserved. */ 6 | OUTPUT_FORMAT(default) 7 | SECTIONS 8 | { 9 | .text : 10 | { 11 | *(.text) 12 | /* ??? Why is .gcc_exc here? */ 13 | } 14 | /* The Cygwin32 library uses a section to avoid copying certain data 15 | on fork. This used to be named ".data". The linker used 16 | to include this between __data_start__ and __data_end__, but that 17 | breaks building the cygwin32 dll. Instead, we name the section 18 | ".data_cygwin_nocopy" and explicitly include it after __data_end__. */ 19 | .data : 20 | { 21 | *(.data) 22 | KEEP(*(.jcr)) 23 | } 24 | .rdata : 25 | { 26 | *(.rdata) 27 | } 28 | .eh_frame : 29 | { 30 | KEEP(*(.eh_frame)) 31 | } 32 | .pdata : 33 | { 34 | KEEP(*(.pdata)) 35 | } 36 | .bss : 37 | { 38 | *(.bss) 39 | *(COMMON) 40 | } 41 | .edata : 42 | { 43 | *(.edata) 44 | } 45 | .drectve : 46 | { 47 | *(.drectve) 48 | } 49 | /DISCARD/ : 50 | { 51 | *(.debug$S) 52 | *(.debug$T) 53 | *(.debug$F) 54 | } 55 | .idata : 56 | { 57 | /* This cannot currently be handled with grouped sections. 58 | See pe.em:sort_sections. */ 59 | } 60 | .CRT : 61 | { 62 | /* ___crt_xl_end__ is defined in the TLS Directory support code */ 63 | } 64 | /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be 65 | at the end of section. This is important because _tls_start MUST 66 | be at the beginning of the section to enable SECREL32 relocations with TLS 67 | data. */ 68 | .tls : 69 | { 70 | *(.tls) 71 | } 72 | .endjunk : 73 | { 74 | /* end is deprecated, don't use it */ 75 | } 76 | .rsrc : SUBALIGN(4) 77 | { 78 | *(.rsrc) 79 | } 80 | .reloc : 81 | { 82 | *(.reloc) 83 | } 84 | .stab : 85 | { 86 | *(.stab) 87 | } 88 | .stabstr : 89 | { 90 | *(.stabstr) 91 | } 92 | /* DWARF debug sections. 93 | Symbols in the DWARF debugging sections are relative to the beginning 94 | of the section. Unlike other targets that fake this by putting the 95 | section VMA at 0, the PE format will not allow it. */ 96 | /* DWARF 1.1 and DWARF 2. */ 97 | .debug_aranges : 98 | { 99 | *(.debug_aranges) 100 | } 101 | .zdebug_aranges : 102 | { 103 | *(.zdebug_aranges) 104 | } 105 | .debug_pubnames : 106 | { 107 | *(.debug_pubnames) 108 | } 109 | .zdebug_pubnames : 110 | { 111 | *(.zdebug_pubnames) 112 | } 113 | .debug_pubtypes : 114 | { 115 | *(.debug_pubtypes) 116 | } 117 | .zdebug_pubtypes : 118 | { 119 | *(.zdebug_pubtypes) 120 | } 121 | /* DWARF 2. */ 122 | .debug_info : 123 | { 124 | *(.debug_info) 125 | } 126 | .zdebug_info : 127 | { 128 | *(.zdebug_info) 129 | } 130 | .debug_abbrev : 131 | { 132 | *(.debug_abbrev) 133 | } 134 | .zdebug_abbrev : 135 | { 136 | *(.zdebug_abbrev) 137 | } 138 | .debug_line : 139 | { 140 | *(.debug_line) 141 | } 142 | .zdebug_line : 143 | { 144 | *(.zdebug_line) 145 | } 146 | .debug_frame : 147 | { 148 | *(.debug_frame*) 149 | } 150 | .zdebug_frame : 151 | { 152 | *(.zdebug_frame*) 153 | } 154 | .debug_str : 155 | { 156 | *(.debug_str) 157 | } 158 | .zdebug_str : 159 | { 160 | *(.zdebug_str) 161 | } 162 | .debug_loc : 163 | { 164 | *(.debug_loc) 165 | } 166 | .zdebug_loc : 167 | { 168 | *(.zdebug_loc) 169 | } 170 | .debug_macinfo : 171 | { 172 | *(.debug_macinfo) 173 | } 174 | .zdebug_macinfo : 175 | { 176 | *(.zdebug_macinfo) 177 | } 178 | /* SGI/MIPS DWARF 2 extensions. */ 179 | .debug_weaknames : 180 | { 181 | *(.debug_weaknames) 182 | } 183 | .zdebug_weaknames : 184 | { 185 | *(.zdebug_weaknames) 186 | } 187 | .debug_funcnames : 188 | { 189 | *(.debug_funcnames) 190 | } 191 | .zdebug_funcnames : 192 | { 193 | *(.zdebug_funcnames) 194 | } 195 | .debug_typenames : 196 | { 197 | *(.debug_typenames) 198 | } 199 | .zdebug_typenames : 200 | { 201 | *(.zdebug_typenames) 202 | } 203 | .debug_varnames : 204 | { 205 | *(.debug_varnames) 206 | } 207 | .zdebug_varnames : 208 | { 209 | *(.zdebug_varnames) 210 | } 211 | .debug_macro : 212 | { 213 | *(.debug_macro) 214 | } 215 | .zdebug_macro : 216 | { 217 | *(.zdebug_macro) 218 | } 219 | /* DWARF 3. */ 220 | .debug_ranges : 221 | { 222 | *(.debug_ranges) 223 | } 224 | .zdebug_ranges : 225 | { 226 | *(.zdebug_ranges) 227 | } 228 | /* DWARF 4. */ 229 | .debug_types : 230 | { 231 | *(.debug_types) 232 | } 233 | .zdebug_types : 234 | { 235 | *(.zdebug_types) 236 | } 237 | /* For Go and Rust. */ 238 | .debug_gdb_scripts : 239 | { 240 | *(.debug_gdb_scripts) 241 | } 242 | .zdebug_gdb_scripts : 243 | { 244 | *(.zdebug_gdb_scripts) 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /make/modules.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2024 Linux Studio Plugins Project 3 | # (C) 2024 Vladimir Sadovnikov 4 | # 5 | # This file is part of lsp-dsp-units 6 | # 7 | # lsp-dsp-units is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # any later version. 11 | # 12 | # lsp-dsp-units is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with lsp-dsp-units. If not, see . 19 | # 20 | ifneq ($(VERBOSE),1) 21 | .SILENT: 22 | endif 23 | 24 | BASEDIR := $(CURDIR) 25 | CONFIG := $(BASEDIR)/.config.mk 26 | 27 | include $(BASEDIR)/project.mk 28 | include $(BASEDIR)/make/functions.mk 29 | ifeq ($(TREE),1) 30 | include $(BASEDIR)/make/system.mk 31 | include $(BASEDIR)/make/tools.mk 32 | include $(BASEDIR)/modules.mk 33 | else 34 | -include $(CONFIG) 35 | endif 36 | include $(BASEDIR)/dependencies.mk 37 | 38 | MERGED_DEPENDENCIES := \ 39 | $(DEPENDENCIES) \ 40 | $(TEST_DEPENDENCIES) 41 | UNIQ_MERGED_DEPENDENCIES := $(filter-out $(ARTIFACT_ID),$(call uniq, $(MERGED_DEPENDENCIES))) 42 | UNIQ_ALL_DEPENDENCIES := $(filter-out $(ARTIFACT_ID),$(call uniq, $(ALL_DEPENDENCIES))) 43 | 44 | # Find the proper branch of the GIT repository 45 | MODULES ?= $(BASEDIR)/modules 46 | GIT ?= git 47 | 48 | ifeq ($(DEVEL),1) 49 | X_URL_SUFFIX = _RW 50 | else 51 | X_URL_SUFFIX = _RO 52 | endif 53 | 54 | ifeq ($(TREE),1) 55 | $(foreach dep,$(UNIQ_ALL_DEPENDENCIES), \ 56 | $(eval $(dep)_URL=$($(dep)_URL$(X_URL_SUFFIX))) \ 57 | ) 58 | 59 | ifeq ($(findstring -devel,$(ARTIFACT_VERSION)),-devel) 60 | $(foreach dep, $(UNIQ_ALL_DEPENDENCIES), \ 61 | $(eval $(dep)_BRANCH=devel) \ 62 | $(eval $(dep)_PATH=$(MODULES)/$($(dep)_NAME)) \ 63 | ) 64 | else 65 | $(foreach dep, $(UNIQ_ALL_DEPENDENCIES), \ 66 | $(eval $(dep)_BRANCH="$($(dep)_VERSION)") \ 67 | $(eval $(dep)_PATH=$(MODULES)/$($(dep)_NAME)) \ 68 | ) 69 | endif 70 | endif 71 | 72 | # Form list of modules, exclude all modules that have 'system' version 73 | SRC_MODULES = $(foreach dep, $(UNIQ_MERGED_DEPENDENCIES), $(if $(findstring src,$($(dep)_TYPE)),$(dep))) 74 | HDR_MODULES = $(foreach dep, $(UNIQ_MERGED_DEPENDENCIES), $(if $(findstring hdr,$($(dep)_TYPE)),$(dep))) 75 | ALL_SRC_MODULES = $(foreach dep, $(UNIQ_ALL_DEPENDENCIES), $(if $(findstring src,$($(dep)_TYPE)),$(dep))) 76 | ALL_HDR_MODULES = $(foreach dep, $(UNIQ_ALL_DEPENDENCIES), $(if $(findstring hdr,$($(dep)_TYPE)),$(dep))) 77 | 78 | # Branches 79 | .PHONY: $(ALL_SRC_MODULES) $(ALL_HDR_MODULES) 80 | .PHONY: fetch prune clean 81 | 82 | $(ALL_SRC_MODULES) $(ALL_HDR_MODULES): 83 | echo "Cloning $($(@)_URL) -> $($(@)_PATH) [$($(@)_BRANCH)]" 84 | test -f "$($(@)_PATH)/.git/config" || $(GIT) clone "$($(@)_URL)" "$($(@)_PATH)" 85 | mkdir -p $(dir $($(@)_PATH)) 86 | $(GIT) -C "$($(@)_PATH)" reset --hard 87 | $(GIT) -C "$($(@)_PATH)" fetch origin --force --prune --prune-tags 88 | $(GIT) -C "$($(@)_PATH)" fetch origin 'refs/tags/*:refs/tags/*' --force 89 | if $(GIT) -C "$($(@)_PATH)" rev-parse -q --verify "origin/$($(@)_BRANCH)" >/dev/null; then \ 90 | $(GIT) -c advice.detachedHead=false -C "$($(@)_PATH)" checkout -B "$($(@)_BRANCH)" "origin/$($(@)_BRANCH)" >/dev/null; \ 91 | elif $(GIT) -C "$($(@)_PATH)" rev-parse -q --verify "refs/tags/$($(@)_BRANCH)" >/dev/null; then \ 92 | $(GIT) -c advice.detachedHead=false -C "$($(@)_PATH)" checkout "refs/tags/$($(@)_BRANCH)"; \ 93 | elif $(GIT) -C "$($(@)_PATH)" rev-parse -q --verify "origin/$($(@)_NAME)-$($(@)_BRANCH)" >/dev/null; then \ 94 | $(GIT) -c advice.detachedHead=false -C "$($(@)_PATH)" checkout -B "$($(@)_NAME)-$($(@)_BRANCH)" "origin/$($(@)_NAME)-$($(@)_BRANCH)"; \ 95 | else \ 96 | $(GIT) -c advice.detachedHead=false -C "$($(@)_PATH)" checkout "refs/tags/$($(@)_NAME)-$($(@)_BRANCH)"; \ 97 | fi 98 | 99 | fetch: $(SRC_MODULES) $(HDR_MODULES) 100 | 101 | tree: $(ALL_SRC_MODULES) $(ALL_HDR_MODULES) 102 | 103 | clean: 104 | echo rm -rf "$($(ARTIFACT_VARS)_BIN)/$(ARTIFACT_NAME)" 105 | -rm -rf "$($(ARTIFACT_VARS)_BIN)/$(ARTIFACT_NAME)" 106 | 107 | prune: 108 | echo "Removing $(notdir $(MODULES))" 109 | -rm -rf $(MODULES) 110 | 111 | 112 | -------------------------------------------------------------------------------- /make/paths.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2024 Linux Studio Plugins Project 3 | # (C) 2024 Vladimir Sadovnikov 4 | # 5 | # This file is part of lsp-dsp-units 6 | # 7 | # lsp-dsp-units is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # any later version. 11 | # 12 | # lsp-dsp-units is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with lsp-dsp-units. If not, see . 19 | # 20 | 21 | # Installation prefix 22 | ifndef PREFIX 23 | ifeq ($(PLATFORM),Windows) 24 | PREFIX := $(BASEDIR)/INSTALL 25 | else ifeq ($(CROSS_COMPILE),1) 26 | PREFIX := $(BASEDIR)/INSTALL 27 | else 28 | PREFIX := /usr/local 29 | endif 30 | endif 31 | 32 | # Path to configuration 33 | ifndef ETCDIR 34 | ifeq ($(PLATFORM),Windows) 35 | ETCDIR := $(PREFIX)/etc 36 | else 37 | ETCDIR := /etc 38 | endif 39 | endif 40 | 41 | LIBDIR := $(PREFIX)/lib 42 | BINDIR := $(PREFIX)/bin 43 | INCDIR := $(PREFIX)/include 44 | BUILDDIR := $(BASEDIR)/.build 45 | TARGET_BUILDDIR := $(BUILDDIR)/target 46 | ifeq ($(CROSS_COMPILE),1) 47 | HOST_BUILDDIR := $(BUILDDIR)/host 48 | else 49 | HOST_BUILDDIR := $(TARGET_BUILDDIR) 50 | endif 51 | MODULES := $(BASEDIR)/modules 52 | CONFIG := $(BASEDIR)/.config.mk 53 | 54 | # Library prefix 55 | ifndef LIBDIR 56 | LIBDIR := $(PREFIX)/lib 57 | endif 58 | 59 | # Binaries prefix 60 | ifndef BINDIR 61 | BINDIR := $(PREFIX)/bin 62 | endif 63 | 64 | # Binaries prefix 65 | ifndef INCDIR 66 | INCDIR := $(PREFIX)/include 67 | endif 68 | 69 | # Shared resources 70 | ifndef SHAREDDIR 71 | ifeq ($(PLATFORM),Haiku) 72 | SHAREDDIR := $(PREFIX)/data 73 | else 74 | SHAREDDIR := $(PREFIX)/share 75 | endif 76 | endif 77 | 78 | # Temporary directory 79 | ifndef TEMPDIR 80 | ifeq ($(PLATFORM),Windows) 81 | TEMPDIR := $(TEMP) 82 | else 83 | TEMPDIR := /tmp 84 | endif 85 | endif 86 | 87 | # Set-up list of common variables 88 | PATH_VARS = \ 89 | BINDIR \ 90 | BUILDDIR \ 91 | ETCDIR \ 92 | INCDIR \ 93 | LIBDIR \ 94 | PREFIX \ 95 | ROOTDIR \ 96 | SHAREDDIR \ 97 | TEMPDIR 98 | 99 | .PHONY: pathvars 100 | 101 | pathvars: 102 | echo "List of available path variables:" 103 | echo " BINDIR location of the binaries" 104 | echo " BUILDDIR location of the build directory" 105 | echo " ETCDIR location of system configuration files" 106 | echo " INCDIR location of the header files" 107 | echo " LIBDIR location of the library" 108 | echo " PREFIX installation prefix for binary files" 109 | echo " SHAREDDIR location of the shared files" 110 | echo " TEMPDIR location of temporary directory" 111 | 112 | 113 | -------------------------------------------------------------------------------- /modules.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2025 Linux Studio Plugins Project 3 | # (C) 2025 Vladimir Sadovnikov 4 | # 5 | # This file is part of lsp-dsp-units 6 | # 7 | # lsp-dsp-units is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # any later version. 11 | # 12 | # lsp-dsp-units is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with lsp-dsp-units. If not, see . 19 | # 20 | 21 | #------------------------------------------------------------------------------ 22 | # Variables that describe source code dependencies 23 | LSP_COMMON_LIB_VERSION := 1.0.42 24 | LSP_COMMON_LIB_NAME := lsp-common-lib 25 | LSP_COMMON_LIB_TYPE := src 26 | LSP_COMMON_LIB_URL_RO := https://github.com/lsp-plugins/$(LSP_COMMON_LIB_NAME).git 27 | LSP_COMMON_LIB_URL_RW := git@github.com:lsp-plugins/$(LSP_COMMON_LIB_NAME).git 28 | 29 | LSP_DSP_LIB_VERSION := 1.0.30 30 | LSP_DSP_LIB_NAME := lsp-dsp-lib 31 | LSP_DSP_LIB_TYPE := src 32 | LSP_DSP_LIB_URL_RO := https://github.com/lsp-plugins/$(LSP_DSP_LIB_NAME).git 33 | LSP_DSP_LIB_URL_RW := git@github.com:lsp-plugins/$(LSP_DSP_LIB_NAME).git 34 | 35 | LSP_LLTL_LIB_VERSION := 1.0.25 36 | LSP_LLTL_LIB_NAME := lsp-lltl-lib 37 | LSP_LLTL_LIB_TYPE := src 38 | LSP_LLTL_LIB_URL_RO := https://github.com/lsp-plugins/$(LSP_LLTL_LIB_NAME).git 39 | LSP_LLTL_LIB_URL_RW := git@github.com:lsp-plugins/$(LSP_LLTL_LIB_NAME).git 40 | 41 | LSP_RUNTIME_LIB_VERSION := 1.0.28 42 | LSP_RUNTIME_LIB_NAME := lsp-runtime-lib 43 | LSP_RUNTIME_LIB_TYPE := src 44 | LSP_RUNTIME_LIB_URL_RO := https://github.com/lsp-plugins/$(LSP_RUNTIME_LIB_NAME).git 45 | LSP_RUNTIME_LIB_URL_RW := git@github.com:lsp-plugins/$(LSP_RUNTIME_LIB_NAME).git 46 | 47 | LSP_TEST_FW_VERSION := 1.0.31 48 | LSP_TEST_FW_NAME := lsp-test-fw 49 | LSP_TEST_FW_TYPE := src 50 | LSP_TEST_FW_URL_RO := https://github.com/lsp-plugins/$(LSP_TEST_FW_NAME).git 51 | LSP_TEST_FW_URL_RW := git@github.com:lsp-plugins/$(LSP_TEST_FW_NAME).git 52 | 53 | #------------------------------------------------------------------------------ 54 | # Variables that describe system dependencies 55 | LIBAUDIOTOOLBOX_VERSION := system 56 | LIBAUDIOTOOLBOX_NAME := libaudiotoolbox 57 | LIBAUDIOTOOLBOX_TYPE := opt 58 | LIBAUDIOTOOLBOX_LDFLAGS := -framework AudioToolbox 59 | 60 | LIBCOREFOUNDATION_VERSION := system 61 | LIBCOREFOUNDATION_NAME := libcorefoundation 62 | LIBCOREFOUNDATION_TYPE := opt 63 | LIBCOREFOUNDATION_LDFLAGS := -framework CoreFoundation 64 | 65 | LIBDL_VERSION := system 66 | LIBDL_NAME := libdl 67 | LIBDL_TYPE := opt 68 | LIBDL_LDFLAGS := -ldl 69 | 70 | LIBICONV_VERSION := system 71 | LIBICONV_NAME := libiconv 72 | LIBICONV_TYPE := opt 73 | LIBICONV_LDFLAGS := -liconv 74 | 75 | LIBMSACM_VERSION := system 76 | LIBMSACM_NAME := libmsacm 77 | LIBMSACM_TYPE := opt 78 | LIBMSACM_LDFLAGS := -lmsacm32 79 | 80 | LIBPTHREAD_VERSION := system 81 | LIBPTHREAD_NAME := libpthread 82 | LIBPTHREAD_TYPE := opt 83 | LIBPTHREAD_LDFLAGS := -lpthread 84 | 85 | LIBRT_VERSION := system 86 | LIBRT_NAME := librt 87 | LIBRT_TYPE := opt 88 | LIBRT_LDFLAGS := -lrt 89 | 90 | LIBSHLWAPI_VERSION := system 91 | LIBSHLWAPI_NAME := libshlwapi 92 | LIBSHLWAPI_TYPE := opt 93 | LIBSHLWAPI_LDFLAGS := -lshlwapi 94 | 95 | LIBSNDFILE_VERSION := system 96 | LIBSNDFILE_NAME := sndfile 97 | LIBSNDFILE_TYPE := pkg 98 | 99 | LIBWINMM_VERSION := system 100 | LIBWINMM_NAME := libwinmm 101 | LIBWINMM_TYPE := opt 102 | LIBWINMM_LDFLAGS := -lwinmm 103 | 104 | -------------------------------------------------------------------------------- /project.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Linux Studio Plugins Project 3 | # (C) 2020 Vladimir Sadovnikov 4 | # 5 | # This file is part of lsp-dsp-units 6 | # 7 | # lsp-dsp-units is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # any later version. 11 | # 12 | # lsp-dsp-units is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public License 18 | # along with lsp-dsp-units. If not, see . 19 | # 20 | 21 | # Package version 22 | ARTIFACT_ID = LSP_DSP_UNITS 23 | ARTIFACT_NAME = lsp-dsp-units 24 | ARTIFACT_DESC = High-level classes for performing DSP 25 | ARTIFACT_HEADERS = lsp-plug.in 26 | ARTIFACT_VERSION = 1.0.29 27 | 28 | -------------------------------------------------------------------------------- /res/test/corr/guitar1-di.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/corr/guitar1-di.wav -------------------------------------------------------------------------------- /res/test/corr/guitar1-od.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/corr/guitar1-od.wav -------------------------------------------------------------------------------- /res/test/corr/guitar2-di.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/corr/guitar2-di.wav -------------------------------------------------------------------------------- /res/test/corr/guitar2-od.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/corr/guitar2-od.wav -------------------------------------------------------------------------------- /res/test/corr/mix-dirty.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/corr/mix-dirty.wav -------------------------------------------------------------------------------- /res/test/f32.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/f32.wav -------------------------------------------------------------------------------- /res/test/meters/loop.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/meters/loop.wav -------------------------------------------------------------------------------- /res/test/util/noise.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lsp-plugins/lsp-dsp-units/2bfee22c7ee1d4481b11afbdbb28db1ea27824bf/res/test/util/noise.wav -------------------------------------------------------------------------------- /src/main/ctl/Blink.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 9 июл. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace lsp 26 | { 27 | namespace dspu 28 | { 29 | Blink::Blink() 30 | { 31 | construct(); 32 | } 33 | 34 | Blink::~Blink() 35 | { 36 | destroy(); 37 | } 38 | 39 | void Blink::construct() 40 | { 41 | nCounter = 0.0f; 42 | nTime = 0.0f; 43 | fOnValue = 1.0f; 44 | fOffValue = 0.0f; 45 | fTime = 0.1f; 46 | } 47 | 48 | void Blink::destroy() 49 | { 50 | nCounter = 0.0f; 51 | nTime = 0.0f; 52 | } 53 | 54 | void Blink::init(size_t sample_rate, float time) 55 | { 56 | nCounter = 0; 57 | nTime = seconds_to_samples(sample_rate, time); 58 | fTime = time; 59 | } 60 | 61 | void Blink::set_sample_rate(size_t sample_rate) 62 | { 63 | nTime = seconds_to_samples(sample_rate, fTime); 64 | } 65 | 66 | void Blink::blink() 67 | { 68 | nCounter = nTime; 69 | fOnValue = 1.0f; 70 | } 71 | 72 | void Blink::blink(float value) 73 | { 74 | nCounter = nTime; 75 | fOnValue = value; 76 | } 77 | 78 | void Blink::blink_max(float value) 79 | { 80 | if ((nCounter <= 0) || (fOnValue < value)) 81 | { 82 | fOnValue = value; 83 | nCounter = nTime; 84 | } 85 | } 86 | 87 | void Blink::blink_min(float value) 88 | { 89 | if ((nCounter <= 0) || (fOnValue > value)) 90 | { 91 | fOnValue = value; 92 | nCounter = nTime; 93 | } 94 | } 95 | 96 | void Blink::set_default(float on, float off) 97 | { 98 | fOffValue = off; 99 | fOnValue = on; 100 | } 101 | 102 | void Blink::set_default_off(float off) 103 | { 104 | fOffValue = off; 105 | } 106 | 107 | float Blink::process(size_t samples) 108 | { 109 | float result = (nCounter > 0) ? fOnValue : fOffValue; 110 | nCounter -= samples; 111 | return result; 112 | } 113 | 114 | void Blink::dump(IStateDumper *v) const 115 | { 116 | v->write("nCounter", nCounter); 117 | v->write("nTime", nTime); 118 | v->write("fOnValue", fOnValue); 119 | v->write("fOffValue", fOffValue); 120 | v->write("fTime", fTime); 121 | } 122 | } 123 | } 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/main/ctl/Counter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 27 нояб. 2018 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace lsp 26 | { 27 | namespace dspu 28 | { 29 | Counter::Counter() 30 | { 31 | construct(); 32 | } 33 | 34 | Counter::~Counter() 35 | { 36 | destroy(); 37 | } 38 | 39 | void Counter::construct() 40 | { 41 | nCurrent = LSP_DSP_UNITS_DEFAULT_SAMPLE_RATE; 42 | nInitial = LSP_DSP_UNITS_DEFAULT_SAMPLE_RATE; 43 | nSampleRate = LSP_DSP_UNITS_DEFAULT_SAMPLE_RATE; 44 | fFrequency = 1.0f; 45 | nFlags = 0; 46 | } 47 | 48 | void Counter::destroy() 49 | { 50 | } 51 | 52 | void Counter::set_sample_rate(size_t sr, bool reset) 53 | { 54 | nSampleRate = sr; 55 | 56 | if (nFlags & F_INITIAL) 57 | fFrequency = float(nSampleRate) / float(nInitial); 58 | else 59 | nInitial = nSampleRate / fFrequency; 60 | 61 | if (reset) 62 | nCurrent = nInitial; 63 | } 64 | 65 | void Counter::set_frequency(float freq, bool reset) 66 | { 67 | nFlags &= ~F_INITIAL; 68 | fFrequency = freq; 69 | nInitial = nSampleRate / fFrequency; 70 | 71 | if (reset) 72 | nCurrent = nInitial; 73 | } 74 | 75 | void Counter::set_initial_value(size_t value, bool reset) 76 | { 77 | nFlags |= F_INITIAL; 78 | nInitial = value; 79 | fFrequency = float(nSampleRate) / float(nInitial); 80 | 81 | if (reset) 82 | nCurrent = nInitial; 83 | } 84 | 85 | bool Counter::commit() 86 | { 87 | bool res = nFlags & F_FIRED; 88 | nFlags &= ~F_FIRED; 89 | return res; 90 | } 91 | 92 | bool Counter::reset() 93 | { 94 | bool res = nFlags & F_FIRED; 95 | nCurrent = nInitial; 96 | return res; 97 | } 98 | 99 | bool Counter::submit(size_t samples) 100 | { 101 | ssize_t left = ssize_t(nCurrent) - ssize_t(samples); 102 | if (left <= 0) 103 | { 104 | nCurrent = nInitial + (left % ssize_t(nInitial)); 105 | nFlags |= F_FIRED; 106 | } 107 | else 108 | nCurrent = left; 109 | 110 | return nFlags & F_FIRED; 111 | } 112 | 113 | void Counter::dump(IStateDumper *v) const 114 | { 115 | v->write("nCurrent", nCurrent); 116 | v->write("nInitial", nInitial); 117 | v->write("nSampleRate", nSampleRate); 118 | v->write("fFrequency", fFrequency); 119 | v->write("nFlags", nFlags); 120 | } 121 | } 122 | } /* namespace lsp */ 123 | -------------------------------------------------------------------------------- /src/main/ctl/Toggle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 9 июл. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | 24 | namespace lsp 25 | { 26 | namespace dspu 27 | { 28 | Toggle::Toggle() 29 | { 30 | construct(); 31 | } 32 | 33 | Toggle::~Toggle() 34 | { 35 | destroy(); 36 | } 37 | 38 | void Toggle::construct() 39 | { 40 | fValue = 0.0f; 41 | nState = TRG_OFF; 42 | } 43 | 44 | void Toggle::destroy() 45 | { 46 | fValue = 0.0f; 47 | nState = TRG_OFF; 48 | } 49 | 50 | void Toggle::init() 51 | { 52 | fValue = 0.0f; 53 | nState = TRG_OFF; 54 | } 55 | 56 | void Toggle::submit(float value) 57 | { 58 | if (value >= 0.5f) 59 | { 60 | if (nState == TRG_OFF) 61 | nState = TRG_PENDING; 62 | } 63 | else 64 | { 65 | if (nState == TRG_ON) 66 | nState = TRG_OFF; 67 | } 68 | fValue = value; 69 | } 70 | 71 | bool Toggle::commit(bool off) 72 | { 73 | if (nState != TRG_PENDING) 74 | return nState == TRG_ON; 75 | if (off) 76 | { 77 | if (fValue < 0.5f) 78 | nState = TRG_OFF; 79 | } 80 | else 81 | nState = (fValue >= 0.5f) ? TRG_ON : TRG_OFF; 82 | return nState == TRG_ON; 83 | } 84 | 85 | void Toggle::dump(IStateDumper *v) const 86 | { 87 | v->write("fValue", fValue); 88 | v->write("nState", nState); 89 | } 90 | } 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/misc/broadcast.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Linux Studio Plugins Project 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 19 сент. 2023 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace lsp 26 | { 27 | namespace dspu 28 | { 29 | namespace bs 30 | { 31 | LSP_DSP_UNITS_PUBLIC 32 | float channel_weighting(channel_t designation) 33 | { 34 | switch (designation) 35 | { 36 | case CHANNEL_FRONT_LEFT: // BS.2051-3 M+060 37 | case CHANNEL_FRONT_RIGHT: // BS.2051-3 M-060 38 | case CHANNEL_LEFT_SIDE: // BS.2051-3 M+090 39 | case CHANNEL_RIGHT_SIDE: // BS.2051-3 M-090 40 | case CHANNEL_LEFT_SURROUND: // BS.2051-3 M+110 41 | case CHANNEL_RIGHT_SURROUND: // BS.2051-3 M-110 42 | // ~ +1.5 dB 43 | return 1.41f; 44 | 45 | case CHANNEL_LFE1: 46 | case CHANNEL_LFE2: 47 | // BS.1770-4: The low frequency effects (LFE) channel is not included in the measurement 48 | return 0.0f; 49 | 50 | default: 51 | break; 52 | } 53 | 54 | return 1.0f; 55 | } 56 | 57 | } /* namespace bs */ 58 | } /* namespace dspu */ 59 | } /* namespace lsp */ 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/misc/envelope.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 20 февр. 2016 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace lsp 27 | { 28 | namespace dspu 29 | { 30 | namespace envelope 31 | { 32 | static void basic_noise(float *dst, size_t n, float k) 33 | { 34 | if (n == 0) 35 | return; 36 | 37 | dst[0] = 1.0f; 38 | float kd = (LSP_DSP_UNITS_SPEC_FREQ_MAX / LSP_DSP_UNITS_SPEC_FREQ_MIN) / n; 39 | for (size_t i=1; i < n; ++i) 40 | dst[i] = expf(k * logf(i * kd)); 41 | } 42 | 43 | LSP_DSP_UNITS_PUBLIC 44 | void noise(float *dst, size_t n, envelope_t type) 45 | { 46 | switch (type) 47 | { 48 | case WHITE_NOISE: white_noise(dst, n); return; 49 | case PINK_NOISE: pink_noise(dst, n); return; 50 | case BROWN_NOISE: brown_noise(dst, n); return; 51 | case BLUE_NOISE: blue_noise(dst, n); return; 52 | case VIOLET_NOISE: violet_noise(dst, n); return; 53 | case PLUS_4_5_DB: basic_noise(dst, n, 4.5 / (20.0 * M_LOG10_2)); return; 54 | case MINUS_4_5_DB: basic_noise(dst, n, -4.5 / (20.0 * M_LOG10_2)); return; 55 | default: 56 | return; 57 | } 58 | } 59 | 60 | LSP_DSP_UNITS_PUBLIC 61 | void reverse_noise(float *dst, size_t n, envelope_t type) 62 | { 63 | switch (type) 64 | { 65 | case WHITE_NOISE: white_noise(dst, n); return; 66 | case PINK_NOISE: blue_noise(dst, n); return; 67 | case BROWN_NOISE: violet_noise(dst, n); return; 68 | case BLUE_NOISE: pink_noise(dst, n); return; 69 | case VIOLET_NOISE: brown_noise(dst, n); return; 70 | case PLUS_4_5_DB: basic_noise(dst, n, -4.5 / (20.0 * M_LOG10_2)); return; 71 | case MINUS_4_5_DB: basic_noise(dst, n, 4.5 / (20.0 * M_LOG10_2)); return; 72 | default: 73 | return; 74 | } 75 | } 76 | 77 | LSP_DSP_UNITS_PUBLIC 78 | void white_noise(float *dst, size_t n) 79 | { 80 | while (n--) 81 | *(dst++) = 1.0f; 82 | } 83 | 84 | LSP_DSP_UNITS_PUBLIC 85 | void pink_noise(float *dst, size_t n) 86 | { 87 | basic_noise(dst, n, logf(0.5) / logf(4)); 88 | } 89 | 90 | LSP_DSP_UNITS_PUBLIC 91 | void brown_noise(float *dst, size_t n) 92 | { 93 | basic_noise(dst, n, -1); 94 | } 95 | 96 | LSP_DSP_UNITS_PUBLIC 97 | void blue_noise(float *dst, size_t n) 98 | { 99 | basic_noise(dst, n, logf(2) / logf(4)); 100 | } 101 | 102 | LSP_DSP_UNITS_PUBLIC 103 | void violet_noise(float *dst, size_t n) 104 | { 105 | basic_noise(dst, n, 1); 106 | } 107 | } 108 | } 109 | } 110 | 111 | -------------------------------------------------------------------------------- /src/main/misc/fade.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 21 февр. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace lsp 26 | { 27 | namespace dspu 28 | { 29 | LSP_DSP_UNITS_PUBLIC 30 | void fade_in(float *dst, const float *src, size_t fade_len, size_t buf_len) 31 | { 32 | // Apply fade at the head part 33 | float k = 1.0f / fade_len; 34 | fade_len = lsp_min(fade_len, buf_len); 35 | for (size_t i=0; i < fade_len; ++i) 36 | dst[i] = src[i] * i * k; 37 | 38 | // Copy the tail part 39 | if (buf_len > fade_len) 40 | dsp::move(&dst[fade_len], &src[fade_len], buf_len - fade_len); 41 | } 42 | 43 | LSP_DSP_UNITS_PUBLIC 44 | void fade_out(float *dst, const float *src, size_t fade_len, size_t buf_len) 45 | { 46 | // Copy the head part 47 | if (buf_len > fade_len) 48 | dsp::move(dst, src, buf_len - fade_len); 49 | 50 | // Apply fade at the tail part 51 | float k = 1.0f / fade_len; 52 | fade_len = lsp_min(fade_len, buf_len); 53 | src += buf_len - fade_len; 54 | dst += buf_len - fade_len; 55 | 56 | for (size_t i=fade_len; i > 0; ) 57 | *(dst++) = *(src++) * ((--i) * k); 58 | } 59 | } 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/misc/interpolation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 23 сент. 2016 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace lsp 26 | { 27 | namespace dspu 28 | { 29 | namespace interpolation 30 | { 31 | LSP_DSP_UNITS_PUBLIC 32 | void hermite_quadratic(float *p, float x0, float y0, float k0, float x1, float k1) 33 | { 34 | // y = p[0]*x^2 + p[1]*x + p[2] 35 | p[0] = (k0 - k1)*0.5f / (x0 - x1); 36 | p[1] = k0 - 2.0f*p[0]*x0; 37 | p[2] = y0 - (p[0]*x0 + p[1])*x0; 38 | } 39 | 40 | LSP_DSP_UNITS_PUBLIC 41 | void hermite_cubic(float *p, float x0, float y0, float k0, float x1, float y1, float k1) 42 | { 43 | // y = p[0]*x^3 + p[1]*x^2 + p[2]*x + p[3] 44 | // dy/dx = 3*p[0]*x^2 + 2*p[1]*x + p[2] 45 | double dx = x1 - x0; 46 | double dy = y1 - y0; 47 | double kx = dy / dx; 48 | double xx1 = x1*x1; 49 | double xx2 = x0 + x1; 50 | 51 | double a = ((k0 + k1)*dx - 2.0f*dy) / (dx*dx*dx); 52 | double b = ((kx - k0) + a*((2.0f*x0-x1)*x0 - xx1))/dx; 53 | double c = kx - a*(xx1+xx2*x0) - b*xx2; 54 | double d = y0 - x0*(c+x0*(b+x0*a)); 55 | 56 | p[0] = a; 57 | p[1] = b; 58 | p[2] = c; 59 | p[3] = d; 60 | } 61 | 62 | LSP_DSP_UNITS_PUBLIC 63 | void exponent(float *p, float x0, float y0, float x1, float y1, float k) 64 | { 65 | double e = exp(k*(x0 - x1)); 66 | p[0] = (y0 - e*y1) / (1.0 - e); 67 | p[1] = (y0 - p[0]) / exp(k*x0); 68 | p[2] = k; 69 | } 70 | 71 | LSP_DSP_UNITS_PUBLIC 72 | void linear(float *p, float x0, float y0, float x1, float y1) 73 | { 74 | p[0] = (y1 - y0) / (x1 - x0); 75 | p[1] = y0 - p[0]*x0; 76 | } 77 | } /* namespace interpolation */ 78 | } /* namespace dspu */ 79 | } /* namespace lsp */ 80 | 81 | -------------------------------------------------------------------------------- /src/main/misc/sigmoid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Linux Studio Plugins Project 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 18 нояб. 2023 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace lsp 28 | { 29 | namespace dspu 30 | { 31 | namespace sigmoid 32 | { 33 | LSP_DSP_UNITS_PUBLIC 34 | float hard_clip(float x) 35 | { 36 | if (x < -1.0f) 37 | return -1.0f; 38 | if (x > 1.0f) 39 | return 1.0f; 40 | return x; 41 | } 42 | 43 | LSP_DSP_UNITS_PUBLIC 44 | float quadratic(float x) 45 | { 46 | if (x < 0.0f) 47 | return (x > -2.0f) ? x * (1.0f + 0.25f * x) : -1.0f; 48 | 49 | return (x < 2.0f) ? x * (1.0f - 0.25f * x) : 1.0f; 50 | } 51 | 52 | LSP_DSP_UNITS_PUBLIC 53 | float sine(float x) 54 | { 55 | if (x < -M_PI_2) 56 | return -1.0f; 57 | if (x > M_PI_2) 58 | return 1.0f; 59 | return sinf(x); 60 | } 61 | 62 | LSP_DSP_UNITS_PUBLIC 63 | float logistic(float x) 64 | { 65 | return 1.0f - 2.0f / (1.0f + expf(2.0f * x)); 66 | } 67 | 68 | LSP_DSP_UNITS_PUBLIC 69 | float arctangent(float x) 70 | { 71 | return M_2_PI * atanf(M_PI_2 * x); 72 | } 73 | 74 | LSP_DSP_UNITS_PUBLIC 75 | float hyperbolic_tangent(float x) 76 | { 77 | const float lx = lsp_limit(x, -7.0f, 7.0f); 78 | const float t = expf(2.0f * lx); 79 | return (t - 1.0f) / (t + 1.0f); 80 | } 81 | 82 | LSP_DSP_UNITS_PUBLIC 83 | float hyperbolic(float x) 84 | { 85 | return x / (1.0f + fabsf(x)); 86 | } 87 | 88 | LSP_DSP_UNITS_PUBLIC 89 | float guidermannian(float x) 90 | { 91 | const float lx = lsp_limit(x, -7.0f, 7.0f); 92 | const float t = expf(M_PI_2 * lx); 93 | return 4.0f * M_1_PI * atanf((t - 1.0f) / (t + 1.0f)); 94 | } 95 | 96 | LSP_DSP_UNITS_PUBLIC 97 | float error(float x) 98 | { 99 | float t; 100 | const float nx = (1.0f/M_2_SQRTPI) * x; 101 | const float ex = expf(-nx*nx); 102 | 103 | if (x >= 0.0f) 104 | { 105 | t = 1.0f / (1.0f + 0.3275911f * x); 106 | return 1.0f - t * ex * (0.254829592f + t*(-0.284496736f + t*(1.421413741f + t*(-1.453152027f + t*1.061405429f)))); 107 | } 108 | 109 | t = 1.0f / (1.0f - 0.3275911f * x); 110 | return -1.0f + t * ex * (0.254829592f + t*(-0.284496736f + t*(1.421413741f + t*(-1.453152027f + t*1.061405429f)))); 111 | } 112 | 113 | LSP_DSP_UNITS_PUBLIC 114 | float smoothstep(float x) 115 | { 116 | const float t = x * M_SQRT1_2; 117 | if (t <= -1.0f) 118 | return -1.0f; 119 | if (t >= 1.0f) 120 | return 1.0f; 121 | 122 | const float s = 0.5f * (t + 1.0f); 123 | return 2.0f * s*s * (3.0f - 2.0f*s) - 1.0f; 124 | } 125 | 126 | LSP_DSP_UNITS_PUBLIC 127 | float smootherstep(float x) 128 | { 129 | const float t = 0.5f * M_2_SQRTPI * x; 130 | if (t <= -1.0f) 131 | return -1.0f; 132 | if (t >= 1.0f) 133 | return 1.0f; 134 | 135 | const float s = 0.5f * (t + 1.0f); 136 | return 2.0f * s*s*s * (10.0f + s*(-15.0f + 6.0f*s)) - 1.0f; 137 | } 138 | 139 | LSP_DSP_UNITS_PUBLIC 140 | float circle(float x) 141 | { 142 | return x / sqrtf(1.0f + x*x); 143 | } 144 | } /* namespace sigmoid */ 145 | } /* dspu */ 146 | } /* namespace lsp */ 147 | 148 | 149 | -------------------------------------------------------------------------------- /src/main/noise/LCG.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Stefano Tronci 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 13 Jun 2021 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | 24 | namespace lsp 25 | { 26 | namespace dspu 27 | { 28 | LCG::LCG() 29 | { 30 | construct(); 31 | } 32 | 33 | LCG::~LCG() 34 | { 35 | destroy(); 36 | } 37 | 38 | void LCG::construct() 39 | { 40 | enDistribution = LCG_UNIFORM; 41 | fAmplitude = 1.0f; 42 | fOffset = 0.0f; 43 | } 44 | 45 | void LCG::destroy() 46 | { 47 | 48 | } 49 | 50 | void LCG::init(uint32_t seed) 51 | { 52 | sRand.init(seed); 53 | } 54 | 55 | void LCG::init() 56 | { 57 | sRand.init(); 58 | } 59 | 60 | float LCG::process_single() 61 | { 62 | switch (enDistribution) 63 | { 64 | case LCG_EXPONENTIAL: 65 | { 66 | float sign; 67 | if (sRand.random(RND_LINEAR) >= 0.5f) 68 | sign = 1.0f; 69 | else 70 | sign = -1.0f; 71 | 72 | return sign * fAmplitude * sRand.random(RND_EXP) + fOffset; 73 | } 74 | 75 | case LCG_TRIANGULAR: 76 | return 2.0f * fAmplitude * sRand.random(RND_TRIANGLE) - 0.5f + fOffset; 77 | 78 | case LCG_GAUSSIAN: 79 | return fAmplitude * sRand.random(RND_GAUSSIAN) + fOffset; 80 | 81 | default: 82 | case LCG_UNIFORM: 83 | return 2.0f * fAmplitude * (sRand.random(RND_LINEAR) - 0.5f) + fOffset; 84 | } 85 | } 86 | 87 | void LCG::process_add(float *dst, const float *src, size_t count) 88 | { 89 | while (count--) 90 | *(dst++) = *(src++) + process_single(); 91 | } 92 | 93 | void LCG::process_mul(float *dst, const float *src, size_t count) 94 | { 95 | while (count--) 96 | *(dst++) = *(src++) * process_single(); 97 | } 98 | 99 | void LCG::process_overwrite(float *dst, size_t count) 100 | { 101 | while (count--) 102 | *(dst++) = process_single(); 103 | } 104 | 105 | void LCG::dump(IStateDumper *v) const 106 | { 107 | v->write_object("sRand", &sRand); 108 | 109 | v->write("enDistribution", enDistribution); 110 | 111 | v->write("fAmplitude", fAmplitude); 112 | v->write("fOffset", fOffset); 113 | } 114 | } 115 | } 116 | 117 | -------------------------------------------------------------------------------- /src/main/sampling/PlaySettings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Linux Studio Plugins Project 3 | * (C) 2022 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins-sampler 6 | * Created on: 18 нояб. 2022 г. 7 | * 8 | * lsp-plugins-sampler is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins-sampler is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins-sampler. If not, see . 20 | */ 21 | 22 | #include 23 | 24 | namespace lsp 25 | { 26 | namespace dspu 27 | { 28 | const PlaySettings PlaySettings::default_settings; 29 | 30 | PlaySettings::PlaySettings() 31 | { 32 | construct(); 33 | } 34 | 35 | PlaySettings::~PlaySettings() 36 | { 37 | destroy(); 38 | } 39 | 40 | void PlaySettings::construct() 41 | { 42 | nID = 0; 43 | nChannel = 0; 44 | fVolume = 1.0f; 45 | bReverse = false; 46 | bListen = false; 47 | nDelay = 0; 48 | nStart = 0; 49 | nLoopMode = SAMPLE_LOOP_NONE; 50 | nLoopStart = 0; 51 | nLoopEnd = 0; 52 | nLoopXFadeType = SAMPLE_CROSSFADE_CONST_POWER; 53 | nLoopXFadeLength= 0; 54 | } 55 | 56 | void PlaySettings::destroy() 57 | { 58 | } 59 | } /* namespace dspu */ 60 | } /* namespace lsp */ 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/util/Dither.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Linux Studio Plugins Project 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 21 дек. 2016 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #define DITHER_8BIT 0.00390625 /* 1 / 256 */ 26 | 27 | namespace lsp 28 | { 29 | namespace dspu 30 | { 31 | Dither::Dither() 32 | { 33 | construct(); 34 | } 35 | 36 | Dither::~Dither() 37 | { 38 | destroy(); 39 | } 40 | 41 | void Dither::construct() 42 | { 43 | nBits = 0; 44 | fGain = 1.0f; 45 | fDelta = 0.0f; 46 | } 47 | 48 | void Dither::destroy() 49 | { 50 | } 51 | 52 | void Dither::set_bits(size_t bits) 53 | { 54 | nBits = bits; 55 | if (bits <= 0) 56 | return; 57 | 58 | fDelta = 4.0f; // 4 = 2 to compensate random in range -0.5 .. 0.5 * 2 to compensate (-1.0 .. 1.0 = 2.0) polarity 59 | while (bits >= 8) 60 | { 61 | fDelta *= DITHER_8BIT; 62 | bits -= 8; 63 | } 64 | if (bits > 0) 65 | fDelta /= float(1 << bits); 66 | fGain = 1.0f - 0.5f * fDelta; 67 | } 68 | 69 | void Dither::process(float *out, const float *in, size_t count) 70 | { 71 | if (!nBits) 72 | { 73 | dsp::copy(out, in, count); 74 | return; 75 | } 76 | 77 | while (count--) 78 | *(out++) = *(in++) * fGain + (sRandom.random(RND_TRIANGLE) - 0.5f) * fDelta; 79 | } 80 | 81 | void Dither::dump(IStateDumper *v) const 82 | { 83 | v->write("nBits", nBits); 84 | v->write("fGain", fGain); 85 | v->write("fDelta", fDelta); 86 | v->write_object("sRandom", &sRandom); 87 | } 88 | } /* namespace dspu */ 89 | } /* namespace lsp */ 90 | -------------------------------------------------------------------------------- /src/test/init/init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-tk-lib 6 | * Created on: 13 мая 2020 г. 7 | * 8 | * lsp-tk-lib is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-tk-lib is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-tk-lib. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | INIT_BEGIN(test_initializer) 26 | 27 | INIT_FUNC 28 | { 29 | dsp::init(); 30 | } 31 | 32 | INIT_END 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/test/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-lib 6 | * Created on: 31 мар. 2020 г. 7 | * 8 | * lsp-dsp-lib is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-lib is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-lib. If not, see . 20 | */ 21 | 22 | #include 23 | 24 | #ifndef LSP_BUILTIN_MODULE 25 | int main(int argc, const char **argv) 26 | { 27 | lsp::test::main(argc, argv); 28 | } 29 | #endif 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/mtest/demo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2025 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 22 нояб. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace 33 | { 34 | static int process_file(const char *in, const char *out) 35 | { 36 | // We will process file as a single audio sample 37 | // That can take many memory for large files 38 | // but for demo it's OK 39 | lsp::dspu::Sample s; 40 | lsp::dspu::Filter f; 41 | lsp::dspu::filter_params_t fp; 42 | lsp::io::Path path; 43 | 44 | // We consider pathnames encoded using native system encoding. 45 | // That's why we use io::Path::set_native() method 46 | path.set_native(in); 47 | if (s.load(&path) != lsp::STATUS_OK) 48 | { 49 | fprintf(stderr, "Error loading audio sample from file: %s\n", in); 50 | return -1; 51 | } 52 | 53 | // Apply +6 dB hi-shelf filter at 1 kHz 54 | fp.nType = lsp::dspu::FLT_BT_BWC_HISHELF; 55 | fp.fFreq = 1000.0f; 56 | fp.fFreq2 = 1000.0f; 57 | fp.fGain = lsp::dspu::db_to_gain(6.0f); 58 | fp.nSlope = 2; 59 | fp.fQuality = 0.0f; 60 | 61 | f.init(NULL); // Use own internal filter bank 62 | f.update(s.sample_rate(), &fp); // Apply filter settings 63 | 64 | // Now we need to process each channel in the sample 65 | for (size_t i=0; i args; 113 | char stub[0x10]; 114 | strcpy(stub, "test"); 115 | 116 | MTEST_ASSERT(args.add(stub)); 117 | for (int i=0; i(argv[i])); 119 | 120 | MTEST_ASSERT(demo_main(int(args.size()), const_cast(args.array())) == 0); 121 | } 122 | 123 | MTEST_END 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /src/test/mtest/filters/ButterworthFilter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Stefano Tronci 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 5 Dec 2021 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define MAX_N_BITS 32u 28 | 29 | using namespace lsp; 30 | 31 | MTEST_BEGIN("dspu.filters", BUTTERWORTHFILTER) 32 | 33 | void write_buffer(const char *filePath, const char *description, const float *buf, size_t count) 34 | { 35 | printf("Writing %s to file %s\n", description, filePath); 36 | 37 | FILE *fp = NULL; 38 | fp = fopen(filePath, "w"); 39 | 40 | if (fp == NULL) 41 | return; 42 | 43 | while (count--) 44 | fprintf(fp, "%.30f\n", *(buf++)); 45 | 46 | if(fp) 47 | fclose(fp); 48 | } 49 | 50 | MTEST_MAIN 51 | { 52 | size_t nBits = 22; 53 | nBits = lsp_min(nBits, MAX_N_BITS); 54 | dspu::MLS::mls_t nState = 0; // Use 0 to force default state. 55 | 56 | size_t nOrder = 32; 57 | size_t nSampleRate = 48000; 58 | dspu::bw_filt_type_t enFilterType = dspu::BW_FLT_TYPE_HIGHPASS; 59 | float fCutoff; 60 | switch (enFilterType) 61 | { 62 | case dspu::BW_FLT_TYPE_LOWPASS: fCutoff = 0.005f * nSampleRate; break; 63 | default: 64 | case dspu::BW_FLT_TYPE_HIGHPASS: fCutoff = 0.48f * nSampleRate; break; 65 | } 66 | 67 | dspu::MLS mls; 68 | mls.set_n_bits(nBits); 69 | mls.set_state(nState); 70 | dspu::MLS::mls_t nPeriod = mls.get_period(); 71 | 72 | dspu::ButterworthFilter filter; 73 | filter.set_order(nOrder); 74 | filter.set_cutoff_frequency(fCutoff); 75 | filter.set_filter_type(enFilterType); 76 | filter.set_sample_rate(nSampleRate); 77 | 78 | float *vIn = new float[nPeriod]; 79 | float *vOut = new float[nPeriod]; 80 | 81 | for (size_t n = 0; n < nPeriod; ++n) 82 | vIn[n] = mls.process_single(); 83 | 84 | filter.process_overwrite(vOut, vIn, nPeriod); 85 | 86 | io::Path path_in; 87 | MTEST_ASSERT(path_in.fmt("%s/btwf_in-%s.csv", tempdir(), full_name())); 88 | write_buffer(path_in.as_native(), "MLS Period - In", vIn, nPeriod); 89 | 90 | io::Path path_out; 91 | MTEST_ASSERT(path_out.fmt("%s/btwf_out-%s.csv", tempdir(), full_name())); 92 | write_buffer(path_out.as_native(), "MLS Period - Out", vOut, nPeriod); 93 | 94 | delete [] vIn; 95 | delete [] vOut; 96 | 97 | mls.destroy(); 98 | } 99 | 100 | MTEST_END 101 | -------------------------------------------------------------------------------- /src/test/mtest/filters/SpectralTilt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Stefano Tronci 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 21 Nov 2021 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define MAX_N_BITS 32u 28 | 29 | using namespace lsp; 30 | 31 | MTEST_BEGIN("dspu.filters", SPECTRALTILT) 32 | 33 | void write_buffer(const char *filePath, const char *description, const float *buf, size_t count) 34 | { 35 | printf("Writing %s to file %s\n", description, filePath); 36 | 37 | FILE *fp = NULL; 38 | fp = fopen(filePath, "w"); 39 | 40 | if (fp == NULL) 41 | return; 42 | 43 | while (count--) 44 | fprintf(fp, "%.30f\n", *(buf++)); 45 | 46 | if(fp) 47 | fclose(fp); 48 | } 49 | 50 | MTEST_MAIN 51 | { 52 | size_t nBits = 18; 53 | nBits = lsp_min(nBits, MAX_N_BITS); 54 | dspu::MLS::mls_t nState = 0; // Use 0 to force default state. 55 | 56 | size_t nOrder = 32; 57 | float fSlope = -0.5f; 58 | dspu::stlt_slope_unit_t enSlopeUnit = dspu::STLT_SLOPE_UNIT_NEPER_PER_NEPER; 59 | size_t nSampleRate = 48000; 60 | float fLowFreq = 10.0f; 61 | float fUpFreq = 0.45f * nSampleRate; 62 | 63 | dspu::MLS mls; 64 | mls.set_n_bits(nBits); 65 | mls.set_state(nState); 66 | dspu::MLS::mls_t nPeriod = mls.get_period(); 67 | 68 | dspu::SpectralTilt filter; 69 | filter.set_order(nOrder); 70 | filter.set_slope(fSlope, enSlopeUnit); 71 | filter.set_lower_frequency(fLowFreq); 72 | filter.set_upper_frequency(fUpFreq); 73 | filter.set_sample_rate(nSampleRate); 74 | 75 | float *vIn = new float[nPeriod]; 76 | float *vOut = new float[nPeriod]; 77 | 78 | size_t n_freqs = nSampleRate / 2; 79 | float *freqs = new float[n_freqs]; 80 | float *re_h = new float[n_freqs]; 81 | float *im_h = new float[n_freqs]; 82 | float *c_h = new float[2 * n_freqs]; 83 | 84 | for (size_t k = 0; k < n_freqs; ++k) 85 | freqs[k] = k; 86 | 87 | for (size_t n = 0; n < nPeriod; ++n) 88 | vIn[n] = mls.process_single(); 89 | 90 | filter.process_overwrite(vOut, vIn, nPeriod); 91 | 92 | filter.freq_chart(re_h, im_h, freqs, n_freqs); 93 | filter.freq_chart(c_h, freqs, n_freqs); 94 | 95 | io::Path path_in; 96 | MTEST_ASSERT(path_in.fmt("%s/stilt_in-%s.csv", tempdir(), full_name())); 97 | write_buffer(path_in.as_native(), "MLS Period - In", vIn, nPeriod); 98 | 99 | io::Path path_out; 100 | MTEST_ASSERT(path_out.fmt("%s/stilt_out-%s.csv", tempdir(), full_name())); 101 | write_buffer(path_out.as_native(), "MLS Period - Out", vOut, nPeriod); 102 | 103 | io::Path path_freqs; 104 | MTEST_ASSERT(path_freqs.fmt("%s/stilt_freqs-%s.csv", tempdir(), full_name())); 105 | write_buffer(path_freqs.as_native(), "Frequency Axis", freqs, n_freqs); 106 | 107 | io::Path path_re_h; 108 | MTEST_ASSERT(path_re_h.fmt("%s/stilt_re_h-%s.csv", tempdir(), full_name())); 109 | write_buffer(path_re_h.as_native(), "Frequency Response Real Part", re_h, n_freqs); 110 | 111 | io::Path path_im_h; 112 | MTEST_ASSERT(path_im_h.fmt("%s/stilt_im_h-%s.csv", tempdir(), full_name())); 113 | write_buffer(path_im_h.as_native(), "Frequency Response Imaginary Part", im_h, n_freqs); 114 | 115 | io::Path path_c_h; 116 | MTEST_ASSERT(path_c_h.fmt("%s/stilt_c_h-%s.csv", tempdir(), full_name())); 117 | write_buffer(path_c_h.as_native(), "Frequency Response Packed Complex", c_h, 2 * n_freqs); 118 | 119 | delete [] vIn; 120 | delete [] vOut; 121 | delete [] freqs; 122 | delete [] re_h; 123 | delete [] im_h; 124 | delete [] c_h; 125 | 126 | mls.destroy(); 127 | } 128 | 129 | MTEST_END 130 | -------------------------------------------------------------------------------- /src/test/mtest/meters/ilufs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Linux Studio Plugins Project 3 | * (C) 2024 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 16 нояб. 2024 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | MTEST_BEGIN("dspu.meters", ilufs) 30 | 31 | static constexpr size_t BUFFER_SIZE = 0x400; 32 | 33 | MTEST_MAIN 34 | { 35 | dspu::Sample src, lufs, tpeak, psr; 36 | io::Path src_path, dst_path; 37 | 38 | // Load source file 39 | MTEST_ASSERT(src_path.fmt("%s/meters/loop.wav", resources()) > 0); 40 | printf("Loading file %s...\n", src_path.as_native()); 41 | 42 | MTEST_ASSERT(src.load(&src_path) == STATUS_OK); 43 | MTEST_ASSERT(src.channels() == 2); 44 | 45 | // Initialize meter 46 | dspu::ILUFSMeter lm; 47 | const float integration_period = dspu::samples_to_seconds(src.sample_rate(), src.length()); 48 | 49 | lm.init(2, integration_period, dspu::bs::LUFS_MEASURE_PERIOD_MS); 50 | lm.set_sample_rate(src.sample_rate()); 51 | lm.set_integration_period(integration_period); 52 | lm.set_weighting(dspu::bs::WEIGHT_K); 53 | lm.set_active(0, true); 54 | lm.set_active(1, true); 55 | lm.set_designation(0, dspu::bs::CHANNEL_LEFT); 56 | lm.set_designation(1, dspu::bs::CHANNEL_RIGHT); 57 | 58 | dspu::Sample out; 59 | MTEST_ASSERT(out.init(1, src.length(), src.length())); 60 | out.set_sample_rate(src.sample_rate()); 61 | 62 | for (size_t offset=0; offset < src.length(); ) 63 | { 64 | size_t to_process = lsp_min(src.length() - offset, BUFFER_SIZE); 65 | 66 | lm.bind(0, src.channel(0, offset)); 67 | lm.bind(1, src.channel(1, offset)); 68 | lm.process(out.channel(0, offset), to_process); 69 | 70 | offset += to_process; 71 | 72 | printf("Integrated LUFS: %.2f LUFS\n", dspu::gain_to_db(lm.loudness() * dspu::bs::DBFS_TO_LUFS_SHIFT_GAIN)); 73 | } 74 | 75 | // Save the results 76 | MTEST_ASSERT(dst_path.fmt("%s/%s-lufs.wav", tempdir(), full_name()) > 0); 77 | printf("Saving LUFS curve to %s...\n", dst_path.as_native()); 78 | MTEST_ASSERT(src.save(&dst_path) > 0); 79 | } 80 | 81 | MTEST_END 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/test/mtest/meters/true_peak.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 Linux Studio Plugins Project 3 | * (C) 2025 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 17 окт. 2024 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | MTEST_BEGIN("dspu.meters", true_peak) 31 | 32 | MTEST_MAIN 33 | { 34 | dspu::Sample src, dst; 35 | io::Path src_path, dst_path; 36 | 37 | // Load source file 38 | MTEST_ASSERT(src_path.fmt("%s/meters/loop.wav", resources()) > 0); 39 | MTEST_ASSERT(src.load(&src_path) == STATUS_OK); 40 | printf("Loading file %s...\n", src_path.as_native()); 41 | 42 | // Initialize meter 43 | dspu::TruePeakMeter tpm; 44 | tpm.init(); 45 | tpm.set_sample_rate(uint32_t(src.sample_rate())); 46 | tpm.update_settings(); 47 | const size_t latency = tpm.latency(); 48 | 49 | MTEST_ASSERT(src.append(latency * 2) == STATUS_OK); 50 | 51 | MTEST_ASSERT(dst.init(src.channels(), src.length(), src.length())); 52 | dst.set_sample_rate(src.sample_rate()); 53 | 54 | for (size_t i=0; i 1.0f) 66 | c[i] = -c[i]; 67 | } 68 | 69 | printf("channel %d true peak level = %.2f\n", int(i), dspu::gain_to_db(tpl)); 70 | } 71 | 72 | // Save the sample 73 | MTEST_ASSERT(dst_path.fmt("%s/%s-tpm.wav", tempdir(), full_name()) > 0); 74 | printf("Saving file %s...\n", dst_path.as_native()); 75 | MTEST_ASSERT(dst.save(&dst_path) > 0); 76 | } 77 | 78 | MTEST_END 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/test/mtest/misc/envelope.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 24 авг. 2018 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static const char *xenvelopes[] = 29 | { 30 | "Violet noise", 31 | "Blue noise", 32 | "White noise", 33 | "Pink noise", 34 | "Brown noise", 35 | "Fall-off 4.5dB/oct", 36 | "Raise 4.5dB/oct", 37 | NULL 38 | }; 39 | 40 | MTEST_BEGIN("dspu.misc", envelope) 41 | 42 | MTEST_MAIN 43 | { 44 | float *buf = NULL; 45 | float *envelopes[dspu::envelope::TOTAL]; 46 | 47 | size_t points = 1024; 48 | if (argc > 0) 49 | points = atoi(argv[0]); 50 | if (points < 10) 51 | points = 10; 52 | 53 | buf = new float[points * dspu::envelope::TOTAL]; 54 | MTEST_ASSERT(buf != NULL); 55 | 56 | float *ptr = buf; 57 | for (size_t i=0; i 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 28 авг. 2018 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | static const char *xwindows[] = 26 | { 27 | "Hann", 28 | "Hamming", 29 | "Blackman", 30 | "Lanczos", 31 | "Gaussian", 32 | "Poisson", 33 | "Parzen", 34 | "Tukey", 35 | "Welch", 36 | "Nuttall", 37 | "Blackman-Nuttall", 38 | "Blackman-Harris", 39 | "Hann-Poisson", 40 | "Bartlett-Hann", 41 | "Bartlett-Fejer", 42 | "Triangular", 43 | "Rectangular", 44 | "Flat top", 45 | "Cosine", 46 | "Squared Cosine", 47 | "Cubic", 48 | NULL 49 | }; 50 | 51 | MTEST_BEGIN("dspu.misc", windows) 52 | 53 | MTEST_MAIN 54 | { 55 | float *buf = NULL; 56 | float *windows[dspu::windows::TOTAL]; 57 | 58 | size_t points = 2400; 59 | if (argc > 0) 60 | points = atoi(argv[0]); 61 | if (points < 10) 62 | points = 10; 63 | 64 | size_t count = points * dspu::windows::TOTAL; 65 | buf = new float[count]; 66 | MTEST_ASSERT(buf != NULL); 67 | 68 | float *ptr = buf; 69 | for (size_t i=0; i 3 | * (C) 2021 Stefano Tronci 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 10 Oct 2021 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #define MAX_N_BITS 32u 27 | 28 | using namespace lsp; 29 | 30 | MTEST_BEGIN("dspu.noise", MLS) 31 | 32 | void write_buffer(const char *filePath, const char *description, const float *buf, size_t count) 33 | { 34 | printf("Writing %s to file %s\n", description, filePath); 35 | 36 | FILE *fp = NULL; 37 | fp = fopen(filePath, "w"); 38 | 39 | if (fp == NULL) 40 | return; 41 | 42 | while (count--) 43 | fprintf(fp, "%.30f\n", *(buf++)); 44 | 45 | if(fp) 46 | fclose(fp); 47 | } 48 | 49 | MTEST_MAIN 50 | { 51 | size_t nBits = 24; 52 | nBits = lsp_min(nBits, MAX_N_BITS); 53 | dspu::MLS::mls_t nState = 0; // Use 0 to force default state. 54 | 55 | dspu::MLS mls; 56 | mls.set_n_bits(nBits); 57 | mls.set_state(nState); 58 | dspu::MLS::mls_t nPeriod = mls.get_period(); 59 | 60 | float *vBuffer = new float[nPeriod]; 61 | for (size_t n = 0; n < nPeriod; ++n) 62 | vBuffer[n] = mls.process_single(); 63 | 64 | io::Path path; 65 | MTEST_ASSERT(path.fmt("%s/mls-%s.csv", tempdir(), full_name())); 66 | write_buffer(path.as_native(), "MLS Period", vBuffer, nPeriod); 67 | 68 | delete [] vBuffer; 69 | 70 | mls.destroy(); 71 | } 72 | 73 | MTEST_END 74 | -------------------------------------------------------------------------------- /src/test/mtest/sampling/resample.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 29 авг. 2018 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | static const char *SRC_FILE = "test_data/source.wav"; 26 | static const char *DST_FILE = "test_data/destination.wav"; 27 | 28 | MTEST_BEGIN("dspu.sampling", resample) 29 | 30 | MTEST_MAIN 31 | { 32 | const char *src = (argc >= 1) ? argv[0] : SRC_FILE; 33 | const char *dst = (argc >= 2) ? argv[1] : DST_FILE; 34 | 35 | dspu::Sample af; 36 | 37 | MTEST_ASSERT(af.load(src) == STATUS_OK); // Load audio file 38 | size_t sr = (af.sample_rate() == 44100) ? 48000 : 44100; 39 | printf("Resampling %d -> %d", int(af.sample_rate()), int(sr)); 40 | 41 | MTEST_ASSERT(af.resample(sr) == STATUS_OK); // Resample audio file 42 | MTEST_ASSERT(af.save(dst) == wssize_t(af.length())); // Store file 43 | 44 | // Destroy data 45 | af.destroy(); 46 | } 47 | 48 | MTEST_END 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/test/mtest/util/convolver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 5 сент. 2020 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace lsp; 29 | 30 | MTEST_BEGIN("dspu.util", convolver) 31 | 32 | MTEST_MAIN 33 | { 34 | FloatBuffer buf(65); 35 | dspu::Convolver cv; 36 | dspu::Sample vox, conv, out, dir; 37 | 38 | MTEST_ASSERT(vox.load("tmp/convolver/vox.wav") == STATUS_OK); 39 | MTEST_ASSERT(conv.load("tmp/convolver/mono-hall.wav") == STATUS_OK); 40 | 41 | MTEST_ASSERT(cv.init(conv.channel(0), conv.samples(), 13, 0.0f)); 42 | 43 | MTEST_ASSERT(out.resize(1, vox.samples() + conv.samples()) == STATUS_OK); 44 | MTEST_ASSERT(dir.resize(1, vox.samples() + conv.samples()) == STATUS_OK); 45 | out.set_sample_rate(vox.sample_rate()); 46 | dir.set_sample_rate(dir.sample_rate()); 47 | 48 | // Convolve using the convolver 49 | buf.fill_zero(); 50 | float *dst = out.channel(0); 51 | cv.process(dst, vox.channel(0), vox.samples()); 52 | dst += vox.samples(); 53 | for (size_t n=conv.samples(); n > 0; ) 54 | { 55 | size_t to_do = lsp_min(buf.size(), n); 56 | cv.process(dst, buf.data(), to_do); 57 | n -= to_do; 58 | dst += to_do; 59 | } 60 | 61 | // Perform direct convolution 62 | dsp::convolve(dir.channel(0), vox.channel(0), conv.channel(0), conv.samples(), vox.samples()); 63 | 64 | MTEST_ASSERT(out.save("tmp/convolver/processed.wav") == STATUS_OK); 65 | MTEST_ASSERT(dir.save("tmp/convolver/direct.wav") == STATUS_OK); 66 | } 67 | 68 | MTEST_END 69 | 70 | -------------------------------------------------------------------------------- /src/test/mtest/util/fft_crossover.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Linux Studio Plugins Project 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 10 авг. 2023 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | MTEST_BEGIN("dspu.util", fft_crossover) 30 | 31 | typedef struct band_t 32 | { 33 | size_t offset; 34 | dspu::Sample s; 35 | } band_t; 36 | 37 | static void crossover_func(void *object, void *subject, size_t band, const float *data, size_t first, size_t count) 38 | { 39 | band_t *b= static_cast(subject); 40 | float *dst = b->s.channel(0); 41 | 42 | dsp::copy(&dst[b->offset], data, count); 43 | b->offset += count; 44 | } 45 | 46 | float freq_to_index(float f, float sample_rate, size_t rank) 47 | { 48 | size_t n = 1 << rank; 49 | return (f * n) / sample_rate; 50 | } 51 | 52 | MTEST_MAIN 53 | { 54 | dspu::Sample src; 55 | io::Path path; 56 | 57 | MTEST_ASSERT(path.fmt("%s/util/noise.wav", resources()) > 0); 58 | MTEST_ASSERT(src.load(&path) == STATUS_OK); 59 | MTEST_ASSERT(src.channels() == 1); 60 | 61 | band_t bands[5]; 62 | 63 | constexpr size_t rank = 12; 64 | constexpr size_t xlength = 1 << rank; 65 | 66 | for (size_t i=0; i<5; ++i) 67 | { 68 | band_t *b = &bands[i]; 69 | 70 | b->offset = 0; 71 | b->s.init(src.channels(), src.length() + xlength, src.length() + xlength); 72 | b->s.set_sample_rate(src.sample_rate()); 73 | } 74 | 75 | dspu::FFTCrossover crossover; 76 | MTEST_ASSERT(crossover.init(rank, 5) == STATUS_OK); 77 | crossover.set_sample_rate(src.sample_rate()); 78 | 79 | // Band 0 80 | crossover.set_lpf(0, 50, 0.0f, true); 81 | crossover.set_flatten(0, dspu::db_to_gain(-3.0f)); 82 | crossover.enable_band(0, true); 83 | 84 | // Band 1 85 | crossover.set_hpf(1, 90, -32.0f, true); 86 | crossover.set_lpf(1, 425, -32.0f, true); 87 | crossover.set_flatten(1, dspu::db_to_gain(-3.0f)); 88 | crossover.enable_band(1, true); 89 | 90 | // Band 2 91 | crossover.set_hpf(2, 425, -32.0f, true); 92 | crossover.set_lpf(2, 1750, -32.0f, true); 93 | crossover.set_flatten(2, dspu::db_to_gain(-3.0f)); 94 | crossover.enable_band(2, true); 95 | 96 | // Band 3 97 | crossover.set_hpf(3, 1750, -32.0f, true); 98 | crossover.set_lpf(3, 7300, -32.0f, true); 99 | crossover.set_flatten(3, dspu::db_to_gain(-3.0f)); 100 | crossover.enable_band(3, true); 101 | 102 | // Band 4 103 | crossover.set_hpf(4, 7300, -64.0f, true); 104 | crossover.set_flatten(4, dspu::db_to_gain(-3.0f)); 105 | crossover.enable_band(4, true); 106 | 107 | for (size_t i=0; i<5; ++i) 108 | MTEST_ASSERT(crossover.set_handler(i, crossover_func, NULL, &bands[i])); 109 | 110 | 111 | crossover.process(src.channel(0), src.length()); 112 | crossover.process(NULL, xlength); 113 | 114 | for (size_t i=0; i<5; ++i) 115 | { 116 | band_t *b = &bands[i]; 117 | MTEST_ASSERT(path.fmt("%s/%s-xover-%d.wav", tempdir(), full_name(), int(i)) > 0); 118 | 119 | printf("Saving band %d to: %s\n", int(i), path.as_native()); 120 | 121 | MTEST_ASSERT(b->s.save(&path) > 0); 122 | } 123 | } 124 | 125 | MTEST_END 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/test/mtest/util/randomizer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 24 авг. 2018 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | MTEST_BEGIN("dspu.util", randomizer) 26 | 27 | MTEST_MAIN 28 | { 29 | size_t rows = 32; 30 | if (argc > 0) 31 | rows = atoi(argv[0]); 32 | if (rows < 4) 33 | rows = 32; 34 | 35 | dspu::Randomizer rnd; 36 | rnd.init(); 37 | 38 | int *counters = new int[rows * rows]; 39 | for (size_t i=0; i < rows*rows; ++i) 40 | counters[i] = 0; 41 | 42 | for (size_t i=0; i<(rows*rows*1024); ++i) 43 | { 44 | size_t idx = rows * rows * rnd.random(dspu::RND_TRIANGLE); 45 | counters[idx]++; 46 | } 47 | 48 | float max = 0; 49 | for (size_t i=0; i < rows*rows; ++i) 50 | if (max < counters[i]) 51 | max = counters[i]; 52 | max = 1.0f / max; 53 | 54 | for (size_t i=0; i 3 | * (C) 2023 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 6 авг. 2023 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | MTEST_BEGIN("dspu.util", spectral_splitter) 29 | 30 | typedef struct band_t 31 | { 32 | size_t imin; 33 | size_t imax; 34 | size_t offset; 35 | dspu::Sample s; 36 | } band_t; 37 | 38 | static void spectral_splitter_func( 39 | void *object, 40 | void *subject, 41 | float *out, 42 | const float *in, 43 | size_t rank) 44 | { 45 | band_t *band = static_cast(subject); 46 | size_t len = 1 << rank; 47 | size_t freq = len >> 1; 48 | 49 | // Keep only the specified range of frequencies 50 | size_t i=0; 51 | for (; iimin) || (idx >= band->imax)) 55 | { 56 | out[0] = 0.0f; 57 | out[1] = 0.0f; 58 | } 59 | else 60 | { 61 | out[0] = in[0]; 62 | out[1] = in[1]; 63 | } 64 | 65 | in += 2; 66 | out += 2; 67 | } 68 | for (; iimin) || (idx >= band->imax)) 72 | { 73 | out[0] = 0.0f; 74 | out[1] = 0.0f; 75 | } 76 | else 77 | { 78 | out[0] = in[0]; 79 | out[1] = in[1]; 80 | } 81 | 82 | in += 2; 83 | out += 2; 84 | } 85 | } 86 | 87 | static void spectral_splitter_sink(void *object, void *subject, const float *samples, size_t offset, size_t count) 88 | { 89 | band_t *band = static_cast(subject); 90 | float *dst = band->s.channel(0); 91 | 92 | dsp::copy(&dst[band->offset], samples, count); 93 | band->offset += count; 94 | } 95 | 96 | float freq_to_index(float f, float sample_rate, size_t rank) 97 | { 98 | size_t n = 1 << rank; 99 | return (f * n) / sample_rate; 100 | } 101 | 102 | MTEST_MAIN 103 | { 104 | dspu::Sample src; 105 | io::Path path; 106 | 107 | MTEST_ASSERT(path.fmt("%s/util/noise.wav", resources()) > 0); 108 | MTEST_ASSERT(src.load(&path) == STATUS_OK); 109 | MTEST_ASSERT(src.channels() == 1); 110 | 111 | band_t bands[4]; 112 | float max_f = src.sample_rate() * 0.5f; 113 | 114 | constexpr size_t rank = 12; 115 | constexpr size_t xlength = 1 << rank; 116 | 117 | const float flist[] = { 0.0f, 100.0f, 1000.0f, 10000.0f, max_f }; 118 | 119 | for (size_t i=0; i<4; ++i) 120 | { 121 | band_t *b = &bands[i]; 122 | 123 | b->imin = freq_to_index(flist[i], src.sample_rate(), rank); 124 | b->imax = freq_to_index(flist[i+1], src.sample_rate(), rank); 125 | b->offset = 0; 126 | b->s.init(src.channels(), src.length() + xlength, src.length() + xlength); 127 | b->s.set_sample_rate(src.sample_rate()); 128 | } 129 | 130 | dspu::SpectralSplitter split; 131 | MTEST_ASSERT(split.init(rank, 6) == STATUS_OK); 132 | split.set_rank(rank); 133 | split.set_chunk_rank(rank - 2); 134 | split.set_phase(0); 135 | for (size_t i=0; i<4; ++i) 136 | MTEST_ASSERT(split.bind(i, NULL, &bands[i], spectral_splitter_func, spectral_splitter_sink) == STATUS_OK); 137 | 138 | split.process(src.channel(0), src.length()); 139 | split.process(NULL, xlength); 140 | 141 | for (size_t i=0; i<4; ++i) 142 | { 143 | band_t *b = &bands[i]; 144 | MTEST_ASSERT(path.fmt("%s/%s-split-%d.wav", tempdir(), full_name(), int(i)) > 0); 145 | 146 | printf("Saving band %d to: %s\n", int(i), path.as_native()); 147 | 148 | MTEST_ASSERT(b->s.save(&path) > 0); 149 | } 150 | } 151 | 152 | MTEST_END 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /src/test/utest/3d/scene_load.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 10 авг. 2021 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | UTEST_BEGIN("dspu.3d", scene_load) 27 | 28 | void test_load_from_obj() 29 | { 30 | dspu::Scene3D s; 31 | dspu::Object3D *o; 32 | 33 | static const char *data = 34 | "# Quad test\n" 35 | "# (C) Linux Studio Plugins Project\n" 36 | "o Quad 1\n" 37 | "v -2 -2 -1\n" 38 | "v 2 -2 -1\n" 39 | "v 2 2 -1\n" 40 | "v -2 2 -1\n" 41 | "vn 0 0 1\n" 42 | "f 1//1 2//1 3//1 4//1\n" 43 | "\n" 44 | "o Quad 2\n" 45 | "v -2 -2 -2\n" 46 | "v 2 -2 -2\n" 47 | "v 2 2 -2\n" 48 | "v -2 2 -2\n" 49 | "vn 0 0 1\n" 50 | "f 5//2 6//2 7//2 8//2\n"; 51 | 52 | io::InStringSequence is; 53 | UTEST_ASSERT(is.wrap(data, "UTF-8") == STATUS_OK); 54 | UTEST_ASSERT(s.load(&is, WRAP_CLOSE) == STATUS_OK); 55 | 56 | // Validate scene 57 | UTEST_ASSERT(s.num_objects() == 2); 58 | UTEST_ASSERT(s.num_vertexes() == 8); 59 | UTEST_ASSERT(s.num_edges() == 10); 60 | UTEST_ASSERT(s.num_triangles() == 4); 61 | UTEST_ASSERT(s.num_normals() == 2); 62 | 63 | // Validate object 1 64 | o = s.object(0); 65 | UTEST_ASSERT(o != NULL); 66 | UTEST_ASSERT(o->get_name() != NULL); 67 | UTEST_ASSERT(strcmp(o->get_name(), "Quad 1") == 0); 68 | UTEST_ASSERT(o->num_triangles() == 2); 69 | 70 | // Validate object 2 71 | o = s.object(1); 72 | UTEST_ASSERT(o != NULL); 73 | UTEST_ASSERT(o->get_name() != NULL); 74 | UTEST_ASSERT(strcmp(o->get_name(), "Quad 2") == 0); 75 | UTEST_ASSERT(o->num_triangles() == 2); 76 | } 77 | 78 | UTEST_MAIN 79 | { 80 | test_load_from_obj(); 81 | } 82 | 83 | UTEST_END 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/test/utest/filters/equalizer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 26 дек. 2020 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace lsp; 29 | 30 | #define FFT_RANK 13 31 | #define BUF_SIZE (1 << (FFT_RANK + 2)) 32 | 33 | UTEST_BEGIN("dspu.filters", equalizer) 34 | 35 | void test_latency(const char *label, dspu::equalizer_mode_t mode) 36 | { 37 | dspu::Equalizer eq; 38 | dspu::filter_params_t fp; 39 | 40 | printf("Testing equalizer latency report for %s mode\n", label); 41 | 42 | // Configure the equalizer 43 | eq.init(1, FFT_RANK); 44 | eq.set_mode(mode); 45 | eq.set_sample_rate(48000); 46 | 47 | fp.nType = dspu::FLT_BT_LRX_HIPASS; 48 | fp.fFreq = 100.0f; 49 | fp.fFreq2 = 100.0f; 50 | fp.fGain = 1.0f; 51 | fp.nSlope = 2; 52 | fp.fQuality = 0.0f; 53 | eq.set_params(0, &fp); 54 | 55 | // Obtain it's impulse response 56 | FloatBuffer src(BUF_SIZE); 57 | FloatBuffer dst(BUF_SIZE); 58 | 59 | src.fill_zero(); 60 | src[0] = 1.0f; 61 | dst.fill_zero(); 62 | eq.process(dst, src, BUF_SIZE); 63 | 64 | // Save result 65 | io::Path path; 66 | UTEST_ASSERT(path.fmt("%s/%s-%s.csv", tempdir(), full_name(), label) > 0); 67 | printf(" output results: %s\n", path.as_utf8()); 68 | FILE *out = fopen(path.as_native(), "w"); 69 | UTEST_ASSERT(out != NULL); 70 | fprintf(out, "samples;in;out\n"); 71 | for (size_t i=0; i 3 | * (C) 2024 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 8 мар. 2024 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | #define MAX_N_BITS 32u 29 | 30 | using namespace lsp; 31 | 32 | UTEST_BEGIN("dspu.meters", correlometer) 33 | 34 | void process_file(const char *out, const char *in, size_t step, float duration) 35 | { 36 | io::Path ifn, ofn; 37 | 38 | UTEST_ASSERT(ifn.fmt("%s/%s", resources(), in) > 0); 39 | UTEST_ASSERT(ofn.fmt("%s/%s-%s.wav", tempdir(), full_name(), out) > 0); 40 | 41 | printf("Processing '%s' -> '%s'\n", ifn.as_native(), ofn.as_native()); 42 | 43 | // Initialize audio files 44 | dspu::Sample is, os; 45 | 46 | UTEST_ASSERT(is.load(&ifn) == STATUS_OK); 47 | UTEST_ASSERT(is.channels() >= 2); 48 | 49 | const size_t range = dspu::millis_to_samples(is.sample_rate(), duration); 50 | 51 | UTEST_ASSERT(is.append(range) == STATUS_OK); 52 | UTEST_ASSERT(os.init(1, is.length())); 53 | os.set_sample_rate(is.sample_rate()); 54 | 55 | // Initialize corellometer 56 | dspu::Correlometer xc; 57 | UTEST_ASSERT(xc.init(range) == STATUS_OK); 58 | xc.set_period(range); 59 | 60 | // Apply processing 61 | const float *a = is.channel(0); 62 | const float *b = is.channel(1); 63 | float *dst = os.channel(0); 64 | 65 | for (size_t offset=0; offset < is.length(); offset += step) 66 | { 67 | const size_t samples = lsp_min(is.length() - offset, step); 68 | xc.process(dst, a, b, samples); 69 | 70 | dst += step; 71 | a += step; 72 | b += step; 73 | } 74 | 75 | UTEST_ASSERT(os.remove(0, range) == STATUS_OK); 76 | 77 | // Save the result 78 | UTEST_ASSERT(os.save(&ofn) == ssize_t(is.length() - range)); 79 | } 80 | 81 | UTEST_MAIN 82 | { 83 | process_file("guitar1-di", "corr/guitar1-di.wav", 113, 200.0f); 84 | process_file("guitar1-od", "corr/guitar1-od.wav", 127, 300.0f); 85 | process_file("guitar2-di", "corr/guitar2-di.wav", 131, 400.0f); 86 | process_file("guitar2-od", "corr/guitar2-od.wav", 149, 500.0f); 87 | process_file("mix-dirty", "corr/mix-dirty.wav", 151, 200.0f); 88 | } 89 | 90 | UTEST_END 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/test/utest/noise/MLS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Linux Studio Plugins Project 3 | * (C) 2021 Stefano Tronci 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 10 Oct 2021 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace lsp; 27 | 28 | // MAX_N_BITS set the maximum number of bits to set for. All bits from 2 to MAX_N_BITS will be tested. 29 | // MAX_N_BITS should not be higher than 18, or it will take way too much time. 30 | // MLS supports up to a max of 32 or 64 bits (depending on architecture). Unfortunately testing for more than 18 is not practical... 31 | #define MAX_N_BITS 16 32 | // Set the numerical tolerance for error here. 33 | #define NUM_TOL 1e-6f 34 | 35 | // The code below checks whether the MLS implementation is correct by checking whether the circular cross-corrleation of one period is correct. 36 | 37 | UTEST_BEGIN("dspu.noise", MLS) 38 | 39 | // Circular autocorrelation. Can be implemented with FFT (much faster), but needs arbitrary size FFT. 40 | void cautocorr(float *dst, float *src, size_t count) 41 | { 42 | for (size_t n = 0; n < count; ++n) 43 | { 44 | dst[n] = 0.0f; 45 | for (size_t m = 0; m < count; ++ m) 46 | { 47 | dst[n] += src[m] * src[(m + n) % count]; 48 | } 49 | dst[n] /= count; 50 | } 51 | } 52 | 53 | UTEST_MAIN 54 | { 55 | dspu::MLS mls; 56 | dspu::MLS::mls_t nState = 0; // Use 0 to force default state. 57 | uint8_t nMaxBits = mls.maximum_number_of_bits(); 58 | dspu::MLS::mls_t nBufSize; 59 | if (MAX_N_BITS >= nMaxBits) 60 | nBufSize = -1; 61 | else 62 | nBufSize = (dspu::MLS::mls_t(1) << MAX_N_BITS) - dspu::MLS::mls_t(1); 63 | 64 | float *vPeriod = new float[nBufSize]; 65 | float *vCautoX = new float[nBufSize]; 66 | 67 | for (uint8_t nBits = 2; nBits < MAX_N_BITS; ++nBits) 68 | { 69 | mls.set_n_bits(nBits); 70 | mls.set_state(nState); 71 | dspu::MLS::mls_t nPeriod = mls.get_period(); 72 | 73 | for (size_t n = 0; n < nPeriod; ++n) 74 | vPeriod[n] = mls.process_single(); 75 | 76 | cautocorr(vCautoX, vPeriod, nPeriod); 77 | float target = -1.0f / nPeriod; 78 | for (size_t n = 0; n < nPeriod; ++n) 79 | { 80 | if (n == 0) 81 | { 82 | UTEST_ASSERT_MSG(abs(1.0f - vCautoX[n]) <= NUM_TOL, "Value out of tolerance (sample 0)!"); 83 | } 84 | else 85 | { 86 | UTEST_ASSERT_MSG(abs(target - vCautoX[n]) <= NUM_TOL, "Value out of tolerance (other sample)!"); 87 | } 88 | } 89 | } 90 | 91 | delete [] vPeriod; 92 | delete [] vCautoX; 93 | 94 | mls.destroy(); 95 | } 96 | 97 | 98 | UTEST_END; 99 | -------------------------------------------------------------------------------- /src/test/utest/sampling/player.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 29 авг. 2018 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | #define SAMPLE_LENGTH 8 29 | 30 | static const float samples[4][SAMPLE_LENGTH] = 31 | { 32 | { 1, -1, 1, -1, 1, 1, -1, -1 }, 33 | { 1, 2, 3, 5, 7, 11, 13, 17 }, 34 | { 4, 3, 2, 1, 1, 2, 3, 4 }, 35 | { 1, 2, 3, 2, 2, 3, 2, 1 } 36 | }; 37 | 38 | UTEST_BEGIN("dspu.sampling", player) 39 | UTEST_MAIN 40 | { 41 | dspu::SamplePlayer sp; 42 | sp.init(4, 5); 43 | 44 | FloatBuffer src(0x100); 45 | src.fill_zero(); 46 | FloatBuffer dst1(src); 47 | FloatBuffer dst2(src.size()); 48 | 49 | // Initialize samples 50 | for (size_t i=0; i<4; ++i) 51 | { 52 | dspu::Sample *s = new dspu::Sample(); 53 | s->init(1, SAMPLE_LENGTH, SAMPLE_LENGTH); 54 | dsp::copy(s->channel(0), samples[i], SAMPLE_LENGTH); 55 | UTEST_ASSERT(sp.bind(i, s)); 56 | } 57 | 58 | // Trigger playing 59 | float *dptr = dst1; 60 | dsp::copy(dptr, src, src.size()); 61 | for (size_t i=0; i<4; ++i) 62 | { 63 | dsp::fmadd_k3(&dptr[(i+1) * 11], samples[i], (i+1)*1.1f, SAMPLE_LENGTH); 64 | UTEST_ASSERT(sp.play(i, 0, (i+1) * 1.1f, (i+1) * 11)); 65 | } 66 | 67 | // Call processing 68 | dptr = dst2; 69 | float *sptr = src; 70 | for (size_t processed = 0; processed <= src.size(); processed += 16) 71 | { 72 | size_t n = src.size() - processed; 73 | if (n > 16) 74 | n = 16; 75 | sp.process(&dptr[processed], &sptr[processed], n); 76 | } 77 | 78 | // Destroy player 79 | sp.stop(); 80 | sp.unbind_all(); 81 | dspu::Sample *gc = sp.gc(); 82 | UTEST_ASSERT(sp.gc() == NULL); 83 | sp.destroy(true); 84 | 85 | size_t num_gc = 0; 86 | while (gc != NULL) 87 | { 88 | dspu::Sample *next = gc->gc_next(); 89 | UTEST_ASSERT(gc->gc_references() == 0); 90 | gc->destroy(); 91 | delete gc; 92 | gc = next; 93 | ++num_gc; 94 | } 95 | UTEST_ASSERT(num_gc == 4); 96 | 97 | // Check state 98 | UTEST_ASSERT_MSG(src.valid(), "Source buffer corrupted"); 99 | UTEST_ASSERT_MSG(dst1.valid(), "Destination buffer 1 corrupted"); 100 | UTEST_ASSERT_MSG(dst2.valid(), "Destination buffer 2 corrupted"); 101 | 102 | // Compare buffers 103 | if (!dst1.equals_absolute(dst2, 1e-5)) 104 | { 105 | src.dump("src"); 106 | dst1.dump("dst1"); 107 | dst2.dump("dst2"); 108 | } 109 | } 110 | UTEST_END; 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/test/utest/util/counter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 27 нояб. 2018 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define SRATE 22000 28 | #define FREQ 100.0f 29 | #define INITIAL 200 30 | 31 | UTEST_BEGIN("dspu.util", counter) 32 | 33 | UTEST_MAIN 34 | { 35 | dspu::Counter c; 36 | 37 | size_t init = SRATE / FREQ; 38 | float freq = float(SRATE) / float(INITIAL); 39 | 40 | // Set sample rate and frequency 41 | c.set_sample_rate(SRATE, true); 42 | c.set_frequency(FREQ, false); 43 | 44 | // Check proper state 45 | UTEST_ASSERT(c.get_sample_rate() == SRATE); 46 | UTEST_ASSERT(c.pending() == SRATE); 47 | UTEST_ASSERT(c.get_frequency() == FREQ); 48 | UTEST_ASSERT(c.get_initial_value() == init); 49 | UTEST_ASSERT(!c.fired()); 50 | 51 | // Perform submit of number of pending samples and check state 52 | c.submit(SRATE); 53 | UTEST_ASSERT(c.fired()); 54 | UTEST_ASSERT(c.pending() == init); 55 | UTEST_ASSERT(c.commit()); 56 | UTEST_ASSERT(!c.fired()); 57 | 58 | // Perform submit more than number of pending samples and check state 59 | c.submit(init*2 + (init >> 1)); 60 | UTEST_ASSERT(c.fired()); 61 | UTEST_ASSERT(c.pending() == (init - (init >> 1))); 62 | UTEST_ASSERT(c.commit()); 63 | UTEST_ASSERT(!c.fired()); 64 | 65 | // Update initial value 66 | c.set_initial_value(INITIAL, true); 67 | UTEST_ASSERT(c.pending() == INITIAL); 68 | UTEST_ASSERT(float_equals_relative(freq, c.get_frequency(), 1e-4f)); 69 | UTEST_ASSERT(c.get_initial_value() == INITIAL); 70 | UTEST_ASSERT(!c.fired()); 71 | 72 | // Perform submit of number of pending samples and check state 73 | c.submit(INITIAL >> 1); 74 | UTEST_ASSERT(!c.fired()); 75 | UTEST_ASSERT(c.pending() == (INITIAL - (INITIAL >> 1))); 76 | c.submit(INITIAL); 77 | UTEST_ASSERT(c.fired()); 78 | UTEST_ASSERT(c.pending() == (INITIAL - (INITIAL >> 1))); 79 | UTEST_ASSERT(c.commit()); 80 | UTEST_ASSERT(!c.fired()); 81 | 82 | // Lower sample rate 83 | c.set_sample_rate(SRATE >> 1, true); 84 | UTEST_ASSERT(c.get_sample_rate() == (SRATE >> 1)); 85 | UTEST_ASSERT(c.pending() == INITIAL); 86 | UTEST_ASSERT(float_equals_relative(freq*0.5f, c.get_frequency(), 1e-4f)); 87 | UTEST_ASSERT(c.get_initial_value() == INITIAL); 88 | UTEST_ASSERT(!c.fired()); 89 | 90 | // Raise sample rate 91 | c.preserve_frequency(); 92 | c.set_sample_rate(SRATE, true); 93 | UTEST_ASSERT(c.get_sample_rate() == SRATE); 94 | UTEST_ASSERT(c.pending() == (INITIAL << 1)); 95 | UTEST_ASSERT(float_equals_relative(freq*0.5f, c.get_frequency(), 1e-4f)); 96 | UTEST_ASSERT(c.get_initial_value() == (INITIAL << 1)); 97 | UTEST_ASSERT(!c.fired()); 98 | } 99 | 100 | UTEST_END; 101 | -------------------------------------------------------------------------------- /src/test/utest/util/crossfade.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 22 янв. 2020 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define SRATE 64 28 | #define BUF_SIZE (SRATE * 3) 29 | #define BUF_STEP 8 30 | 31 | UTEST_BEGIN("dspu.util", crossfade) 32 | 33 | void process(dspu::Crossfade &cf, float *dst, float *out, float *in) 34 | { 35 | cf.reset(); 36 | for (size_t i=0; i SRATE) && (i < (SRATE * 2))) 44 | { 45 | UTEST_ASSERT(!cf.toggle()); 46 | } 47 | 48 | // Perform cross-fade 49 | cf.process(dst, out, in, BUF_STEP); 50 | 51 | dst += BUF_STEP; 52 | if (out != NULL) out += BUF_STEP; 53 | if (in != NULL) in += BUF_STEP; 54 | } 55 | } 56 | 57 | UTEST_MAIN 58 | { 59 | float dst[BUF_SIZE], in[BUF_SIZE], out[BUF_SIZE]; 60 | 61 | dspu::Crossfade cf; 62 | cf.init(SRATE * 2, 0.5); // 0.5 sec = SRATE samples 63 | 64 | // Initialize buffers 65 | dsp::fill(in, 0.5f, BUF_SIZE); 66 | dsp::fill(out, 1.0f, BUF_SIZE); 67 | process(cf, dst, out, in); 68 | UTEST_ASSERT(float_equals_absolute(dst[0], 1.0f)); 69 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE - 1], 0.5f)); 70 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE >> 1], 0.75f)); 71 | 72 | // Initialize buffers 73 | dsp::fill(in, 0.5f, BUF_SIZE); 74 | process(cf, dst, NULL, in); 75 | UTEST_ASSERT(float_equals_absolute(dst[0], 0.0f)); 76 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE - 1], 0.5f)); 77 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE >> 1], 0.25f)); 78 | 79 | // Initialize buffers 80 | dsp::fill(out, 0.5f, BUF_SIZE); 81 | process(cf, dst, out, NULL); 82 | UTEST_ASSERT(float_equals_absolute(dst[0], 0.5f)); 83 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE - 1], 0.0f)); 84 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE >> 1], 0.25f)); 85 | 86 | // Initialize buffers 87 | process(cf, dst, NULL, NULL); 88 | UTEST_ASSERT(float_equals_absolute(dst[0], 0.0f)); 89 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE - 1], 0.0f)); 90 | UTEST_ASSERT(float_equals_absolute(dst[BUF_SIZE >> 1], 0.0f)); 91 | } 92 | 93 | UTEST_END 94 | 95 | -------------------------------------------------------------------------------- /src/test/utest/util/sidechain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Linux Studio Plugins Project 3 | * (C) 2022 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-dsp-units 6 | * Created on: 7 нояб. 2022 г. 7 | * 8 | * lsp-dsp-units is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-dsp-units is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-dsp-units. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | #define SRATE 48000u 30 | #define BUF_SIZE (SRATE * 4) 31 | #define BLOCK_SIZE 511u 32 | 33 | UTEST_BEGIN("dspu.util", sidechain) 34 | 35 | UTEST_MAIN 36 | { 37 | static const dspu::sidechain_mode_t modes[] = 38 | { 39 | dspu::SCM_PEAK, 40 | dspu::SCM_LPF, 41 | dspu::SCM_RMS, 42 | dspu::SCM_UNIFORM 43 | }; 44 | static const dspu::sidechain_source_t sources[] = 45 | { 46 | dspu::SCS_MIDDLE, 47 | dspu::SCS_SIDE, 48 | dspu::SCS_LEFT, 49 | dspu::SCS_RIGHT, 50 | dspu::SCS_AMIN, 51 | dspu::SCS_AMAX 52 | }; 53 | 54 | static const dspu::sidechain_stereo_mode_t scmodes[] = 55 | { 56 | dspu::SCSM_STEREO, 57 | dspu::SCSM_MIDSIDE 58 | }; 59 | 60 | FloatBuffer out(BUF_SIZE), a(BUF_SIZE), b(BUF_SIZE); 61 | out.randomize_sign(); 62 | a.randomize_sign(); 63 | b.randomize_sign(); 64 | 65 | dspu::Sidechain sc; 66 | 67 | for (size_t channels = 1; channels <= 2; ++channels) 68 | { 69 | UTEST_ASSERT(sc.init(channels, 50.0f)); 70 | sc.set_sample_rate(SRATE); 71 | 72 | for (size_t mode=0; mode < sizeof(modes)/sizeof(modes[0]); ++mode) 73 | { 74 | sc.set_mode(modes[mode]); 75 | 76 | for (size_t source=0; source < sizeof(sources)/sizeof(sources[0]); ++source) 77 | { 78 | sc.set_source(sources[source]); 79 | 80 | for (size_t scmode=0; scmode < sizeof(scmodes)/sizeof(scmodes[0]); ++scmode) 81 | { 82 | sc.set_stereo_mode(scmodes[scmode]); 83 | 84 | float *src[2], *dst; 85 | src[0] = a.data(); 86 | src[1] = b.data(); 87 | dst = out.data(); 88 | 89 | for (size_t i=0; i(src), count); 93 | 94 | dst += count; 95 | src[0] += count; 96 | src[1] += count; 97 | i += count; 98 | } 99 | 100 | // Validate buffers 101 | if (out.corrupted()) 102 | { 103 | UTEST_FAIL_MSG( 104 | "Output buffer corrupted channels=%d, mode=%d, source=%d, scmode=%d", 105 | int(channels), int(mode), int(source), int(scmode)); 106 | } 107 | if (a.corrupted()) 108 | { 109 | UTEST_FAIL_MSG( 110 | "First buffer corrupted channels=%d, mode=%d, source=%d, scmode=%d", 111 | int(channels), int(mode), int(source), int(scmode)); 112 | } 113 | if (b.corrupted()) 114 | { 115 | UTEST_FAIL_MSG( 116 | "First buffer corrupted channels=%d, mode=%d, source=%d, scmode=%d", 117 | int(channels), int(mode), int(source), int(scmode)); 118 | } 119 | } /* scmode */ 120 | } /* source */ 121 | } /* mode */ 122 | } /* channels */ 123 | 124 | sc.destroy(); 125 | } 126 | 127 | UTEST_END 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /src/test/utest/util/spectral_proc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Linux Studio Plugins Project 3 | * (C) 2020 Vladimir Sadovnikov 4 | * 5 | * This file is part of lsp-plugins 6 | * Created on: 2 июл. 2020 г. 7 | * 8 | * lsp-plugins is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * any later version. 12 | * 13 | * lsp-plugins is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with lsp-plugins. If not, see . 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace lsp; 30 | 31 | #define SRATE 48000.0f 32 | #define TEST_FREQ 440.0f 33 | #define SAMPLES 8192 34 | 35 | UTEST_BEGIN("dspu.util", spectral_proc) 36 | 37 | void test_simple() 38 | { 39 | FloatBuffer in(SAMPLES); 40 | FloatBuffer out(SAMPLES); 41 | 42 | // Generate input data 43 | float *src = in.data(); 44 | float w = 2 * M_PI * TEST_FREQ / SRATE; 45 | for (size_t i=0; i<8192; ++i) 46 | src[i] = sinf(w * i); 47 | 48 | // Generate output data 49 | out.fill_zero(); 50 | 51 | // Create processor 52 | dspu::SpectralProcessor sp; 53 | sp.init(14); 54 | sp.set_phase(0.0f); 55 | sp.set_rank(8); 56 | 57 | float *dst = out.data(); 58 | sp.process(dst, src, SAMPLES); 59 | 60 | UTEST_ASSERT(in.valid()); 61 | UTEST_ASSERT(out.valid()); 62 | 63 | // Compare data 64 | size_t latency = sp.latency(); 65 | for (size_t i=0; i