├── modules ├── libltfat │ ├── testing │ │ ├── cUnit │ │ │ ├── README │ │ │ ├── test_typeindependent.c │ │ │ ├── test_typecomplexindependent.c │ │ │ ├── runner_template.c │ │ │ ├── Makefile │ │ │ ├── multiinclude.h │ │ │ ├── runner_multiinclude.h │ │ │ ├── test_fftshift.c │ │ │ ├── test_ifftshift.c │ │ │ ├── test_firwin.c │ │ │ ├── test_fftfftshift.c │ │ │ ├── test_fftifftshift.c │ │ │ ├── test_fftrealfftshift.c │ │ │ ├── test_fftrealifftshift.c │ │ │ ├── test_circshift.c │ │ │ ├── test_long2fir.c │ │ │ ├── test_fir2long.c │ │ │ ├── test_all_libltfat.c │ │ │ ├── test_fftcircshift.c │ │ │ ├── test_fftrealcircshift.c │ │ │ ├── test_normalize.c │ │ │ ├── test_maxtree.c │ │ │ └── test_pgauss.c │ │ ├── mUnit │ │ │ ├── ltfatstatusstring.m │ │ │ ├── complex2interleaved.m │ │ │ ├── makelibraryname.m │ │ │ ├── interleaved2complex.m │ │ │ ├── test_gabframediag.m │ │ │ ├── ltfatdiditfail.m │ │ │ ├── test_libltfat_heap.m │ │ │ ├── test_fifo.m │ │ │ ├── test_libltfat_solvehermitiansystem.m │ │ │ ├── test_libltfat_pgauss.m │ │ │ ├── oldtest_libltfat_maxtree.m │ │ │ ├── loadlibltfat.m │ │ │ ├── test_libltfat_fftshift.m │ │ │ ├── test_libltfat_ifftshift.m │ │ │ ├── test_libltfat_fftifftshift.m │ │ │ ├── test_libltfat_fftfftshift.m │ │ │ ├── test_libltfat_firwin.m │ │ │ ├── test_libltfat_circshift.m │ │ │ ├── test_libltfat_long2fir.m │ │ │ ├── test_all_libltfat.m │ │ │ ├── test_libltfat_fold.m │ │ │ └── test_libltfat_fir2long.m │ │ └── pyUnit │ │ │ ├── testhelper.py │ │ │ └── test_libltfat_fftshift.py │ ├── doc │ │ ├── dgt.md │ │ ├── mathjaxinclude │ │ │ └── macros.js │ │ ├── htmltemplate │ │ │ ├── footer.html │ │ │ └── header.html │ │ └── texinclude │ │ │ └── macros.tex │ ├── include │ │ └── ltfat │ │ │ ├── ci_memalloc.h │ │ │ ├── linalg.h │ │ │ ├── reassign_typeconstant.h │ │ │ ├── heap.h │ │ │ ├── dct.h │ │ │ ├── dst.h │ │ │ ├── basicmacros.h │ │ │ ├── blaslapack.h │ │ │ ├── dgt_common.h │ │ │ ├── maxtree.h │ │ │ ├── dgt_shear.h │ │ │ ├── version.h │ │ │ ├── dgt_multi.h │ │ │ ├── ti_windows.h │ │ │ ├── errno.h │ │ │ ├── slidgtrealmp.h │ │ │ ├── typeconstant.h │ │ │ ├── dgtwrapper_typeconstant.h │ │ │ ├── goertzel.h │ │ │ └── heapint_private.h │ ├── src │ │ ├── argchecks.c │ │ ├── slidgtrealmp_private.h │ │ ├── slicingbuf_private.h │ │ ├── dgtreal_long_private.h │ │ ├── ci_memalloc.c │ │ ├── spread.c │ │ ├── dgtrealwrapper_private.h │ │ ├── dgtwrapper_private.h │ │ ├── dgt_long_private.h │ │ ├── version.c │ │ ├── dgt.c │ │ ├── wavelets_typeconstant.c │ │ ├── reassign_typeconstant.c │ │ ├── circularbuf_private.h │ │ ├── fbheapint_private.h │ │ ├── error.c │ │ ├── filedefs.mk │ │ ├── reassign_ti.c │ │ ├── firwin_typeconstant.c │ │ ├── wfacreal.c │ │ ├── iwfacreal.c │ │ └── heapint_private.h │ └── thirdparty │ │ └── kissfft │ │ ├── COPYING │ │ ├── Makefile │ │ ├── TIPS │ │ └── README.simd └── libphaseret │ ├── doc │ ├── gla.md │ ├── spsi.md │ ├── rtisila.md │ ├── mathjaxinclude │ │ └── macros.js │ ├── legla.md │ ├── doxymain.md │ ├── pghi.md │ ├── htmltemplate │ │ ├── footer.html │ │ └── header.html │ ├── texinclude │ │ └── macros.tex │ └── rtpghi.md │ ├── include │ ├── phaseret │ │ ├── api.h │ │ ├── basicmacros.h │ │ ├── types.h │ │ ├── utils.h │ │ └── gsrtisilapghi.h │ └── phaseret.h │ ├── src │ ├── filedefs.mk │ ├── legla_private.h │ ├── rtpghi_private.h │ ├── gsrtisila_private.h │ ├── pghi_typeconstant.c │ ├── legla_typeconstant.c │ └── CMakeLists.txt │ ├── testing │ └── mUnit │ │ ├── complex2interleaved.m │ │ ├── interleaved2complex.m │ │ ├── test_libphaseret_pghi.m │ │ ├── test_libphaseret_spsi.m │ │ ├── test_libphaseret_gla.m │ │ ├── test_libphaseret_rtisila.m │ │ ├── test_libphaseret_legla.m │ │ ├── test_libphaseret_gsrtisila.m │ │ ├── test_libphaseret_rtpghi.m │ │ ├── test_libphaseret_overlaynthframe.m │ │ ├── test_libphaseret_gsrtisilapghi.m │ │ ├── loadlibphaseret.m │ │ └── test_all_libphaseret.m │ ├── README.md │ └── CMakeLists.txt ├── examples ├── multigabormp │ ├── CMakeLists.txt │ └── Makefile ├── Makefile ├── utils │ └── ltfathelper.h ├── CMakeLists.txt ├── example_dgtprocessor.cpp └── example_gabanasyn.c ├── .gitignore ├── .gitattributes ├── comptarget.mk ├── ostools.mk ├── copyrightplate ├── README.md └── CMakeLists.txt /modules/libltfat/testing/cUnit/README: -------------------------------------------------------------------------------- 1 | The structure 2 | -------------------------------------------------------------------------------- /examples/multigabormp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(multigabormpd multigabormpd.cpp) 2 | target_link_libraries(multigabormpd ltfat) 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | cmakebuild 2 | */CMakeFiles/* 3 | CMakeFiles/* 4 | obj 5 | build 6 | html 7 | latex 8 | *.mex* 9 | *.o 10 | *.so 11 | *.a 12 | .ycm_* 13 | 14 | -------------------------------------------------------------------------------- /modules/libltfat/doc/dgt.md: -------------------------------------------------------------------------------- 1 | \page dgttheory Discrete Gabor transform (also called STFT) 2 | 3 | 4 | 5 | For more details please see 6 | \cite ltfatnote003 7 | \cite ltfatnote006 8 | \cite ltfatnote011 9 | 10 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/gla.md: -------------------------------------------------------------------------------- 1 | \defgroup gla Griffin-Lim Algorithm 2 | \addtogroup gla 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows papers \cite griflim84 \cite pebaso13 8 | 9 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/spsi.md: -------------------------------------------------------------------------------- 1 | \defgroup spsi Single Pass Spectrogram Inversion 2 | \addtogroup spsi 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows papers \cite be15 . 8 | 9 | 10 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/rtisila.md: -------------------------------------------------------------------------------- 1 | \defgroup rtisila Real-Time Spectrogram Inversion with Look Ahead 2 | \addtogroup rtisila 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows paper \cite zhbewy07. 8 | 9 | 10 | -------------------------------------------------------------------------------- /modules/libltfat/doc/mathjaxinclude/macros.js: -------------------------------------------------------------------------------- 1 | MathJax.Hub.Config({ 2 | TeX: { 3 | Macros: { 4 | stime: "t", 5 | sfreq: "\\omega", 6 | sfreqarg: "\\xi", 7 | stimearg: "\\tau", 8 | me: "\\mathrm{e}", 9 | mi: "\\mathrm{i}", 10 | } 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/mathjaxinclude/macros.js: -------------------------------------------------------------------------------- 1 | MathJax.Hub.Config({ 2 | TeX: { 3 | Macros: { 4 | stime: "t", 5 | sfreq: "\\omega", 6 | sfreqarg: "\\xi", 7 | stimearg: "\\tau", 8 | me: "\\mathrm{e}", 9 | mi: "\\mathrm{i}", 10 | } 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/ltfatstatusstring.m: -------------------------------------------------------------------------------- 1 | function sstring=ltfatstatusstring(status) 2 | 3 | [~,~,enuminfo]=libltfatprotofile; 4 | 5 | map = structfun(@(a) a==status ,enuminfo.ltfaterr_status); 6 | names = fieldnames(enuminfo.ltfaterr_status); 7 | sstring = names{map}; 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /modules/libphaseret/include/phaseret/api.h: -------------------------------------------------------------------------------- 1 | //#include "dgtrealwrapper.h" 2 | #include "gla.h" 3 | #include "legla.h" 4 | #include "pghi.h" 5 | #include "spsi.h" 6 | #include "rtpghi.h" 7 | #include "rtisila.h" 8 | #include "gsrtisila.h" 9 | #include "gsrtisilapghi.h" 10 | #include "utils.h" 11 | 12 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS+=-g -Wall -Wextra -std=c++11 2 | 3 | SRC=$(wildcard *.c) 4 | PROGS = $(patsubst %.c,%,$(SRC)) 5 | 6 | all: $(PROGS) 7 | 8 | %: %.c 9 | $(CXX) $(CFLAGS) -g -Ofast -I.. $< -o $@ ../build/libltfat.a -lblas -llapack -lfftw3 -lc -lm -lsndfile 10 | 11 | clean: 12 | -rm $(PROGS) 13 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/legla.md: -------------------------------------------------------------------------------- 1 | \defgroup legla Le Roux's Modifications of the Griffin-Lim Algorithm 2 | \addtogroup legla 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows papers \cite leroux08 \cite leroux10. 8 | 9 | Algorithm Acceleration 10 | ---------------------- 11 | 12 | \cite pebaso13 13 | -------------------------------------------------------------------------------- /modules/libphaseret/src/filedefs.mk: -------------------------------------------------------------------------------- 1 | files += gla.c legla.c gsrtisila.c gsrtisilapghi.c pghi.c rtisila.c rtpghi.c spsi.c utils.c 2 | files_notypechange += pghi_typeconstant.c legla_typeconstant.c 3 | 4 | DSLFLAGS = -lltfat 5 | DLFLAGS = -lltfatd 6 | SLFLAGS = -lltfatf 7 | CFLAGS+=-Imodules/libltfat/include 8 | extradepincludes:=\#include \"ltfat.h\"\n 9 | 10 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/ci_memalloc.h: -------------------------------------------------------------------------------- 1 | LTFAT_API LTFAT_TYPE* 2 | LTFAT_NAME(malloc)(size_t n); 3 | 4 | LTFAT_API LTFAT_TYPE* 5 | LTFAT_NAME(calloc)(size_t n); 6 | 7 | LTFAT_API LTFAT_TYPE* 8 | LTFAT_NAME(realloc)(LTFAT_TYPE *ptr, size_t nold, size_t nnew); 9 | 10 | LTFAT_API LTFAT_TYPE* 11 | LTFAT_NAME(postpad) (LTFAT_TYPE* ptr, size_t nold, size_t nnew); 12 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/complex2interleaved.m: -------------------------------------------------------------------------------- 1 | function fi = complex2interleaved(fc) 2 | 3 | if ~isnumeric(fc) 4 | error('%s: Input must be numeric.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fc); 8 | fsize(1)=fsize(1)*2; 9 | 10 | fi = zeros(fsize,'like',fc); 11 | 12 | fi(1:2:end,:,:) = real(fc); 13 | 14 | if ~isreal(fc) 15 | fi(2:2:end,:,:) = imag(fc); 16 | end -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/makelibraryname.m: -------------------------------------------------------------------------------- 1 | function lname = makelibraryname(fname,complexity,is_complex) 2 | 3 | suffix = ''; 4 | 5 | if strcmp(complexity,'double') 6 | suffix = [suffix,'_d']; 7 | elseif strcmp(complexity,'single') 8 | suffix = [suffix,'_s']; 9 | end 10 | 11 | if is_complex 12 | suffix = [suffix,'c']; 13 | end 14 | 15 | lname = ['ltfat_',fname,suffix]; -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/complex2interleaved.m: -------------------------------------------------------------------------------- 1 | function fi = complex2interleaved(fc) 2 | 3 | if ~isnumeric(fc) 4 | error('%s: Input must be numeric.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fc); 8 | fsize(1)=fsize(1)*2; 9 | 10 | fi = zeros(fsize,class(fc)); 11 | 12 | fi(1:2:end,:,:) = real(fc); 13 | 14 | if ~isreal(fc) 15 | fi(2:2:end,:,:) = imag(fc); 16 | end -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/interleaved2complex.m: -------------------------------------------------------------------------------- 1 | function fc = interleaved2complex(fi) 2 | 3 | if ~isreal(fi) 4 | error('%s: Input must be real.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fi); 8 | fsize(1)=fsize(1)/2; 9 | 10 | if rem(fsize(1),1)~=0 11 | error('%s: Wrong dimension.',upper(mfilename)) 12 | end 13 | 14 | 15 | fc=fi(1:2:end,:,:) + 1i*fi(2:2:end,:,:); 16 | 17 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/interleaved2complex.m: -------------------------------------------------------------------------------- 1 | function fc = interleaved2complex(fi) 2 | 3 | if ~isreal(fi) 4 | error('%s: Input must be real.',upper(mfilename)) 5 | end 6 | 7 | fsize = size(fi); 8 | fsize(1)=fsize(1)/2; 9 | 10 | if rem(fsize(1),1)~=0 11 | error('%s: Wrong dimension.',upper(mfilename)) 12 | end 13 | 14 | 15 | fc=fi(1:2:end,:,:) + 1i*fi(2:2:end,:,:); 16 | 17 | -------------------------------------------------------------------------------- /examples/utils/ltfathelper.h: -------------------------------------------------------------------------------- 1 | #if !(defined(LTFAT_DOUBLE) || defined(LTFAT_SINGLE)) 2 | #define LTFAT_DOUBLE 3 | #endif 4 | 5 | #include "ltfat.h" 6 | #include "ltfat/types.h" 7 | #include "ltfat/macros.h" 8 | 9 | #ifdef __cplusplus 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using Clock = std::chrono::high_resolution_clock; 16 | using namespace std; 17 | #else 18 | #endif 19 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_typeindependent.c: -------------------------------------------------------------------------------- 1 | #include "test_fftcircshift.c" 2 | #include "test_fftfftshift.c" 3 | #include "test_fftifftshift.c" 4 | #include "test_fftrealcircshift.c" 5 | #include "test_fftrealfftshift.c" 6 | #include "test_fftrealifftshift.c" 7 | #include "test_pgauss.c" 8 | #include "test_dgtreal_fb.c" 9 | #include "test_idgtreal_fb.c" 10 | #include "test_dgtreal_long.c" 11 | #include "test_idgtreal_long.c" 12 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/doxymain.md: -------------------------------------------------------------------------------- 1 | \mainpage Phase Retrieval Toolbox Library 2 | 3 | 4 | Algorithms 5 | ---------- 6 | 7 | #### Offline # 8 | - \ref gla 9 | - \ref legla 10 | - \ref pghi 11 | 12 | #### Real-time # 13 | - \ref rtisila 14 | - \ref rtpghi 15 | - \ref spsi 16 | 17 | Conventions 18 | ----------- 19 | 20 | The library follows the same conventions as the 21 | [libltfat](http://ltfat.github.io/libltfat). 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /modules/libltfat/src/argchecks.c: -------------------------------------------------------------------------------- 1 | #include "ltfat/dgt_common.h" 2 | #include "ltfat/thirdparty/fftw3.h" 3 | 4 | LTFAT_API int 5 | ltfat_phaseconvention_is_valid(ltfat_phaseconvention in) 6 | { 7 | int isvalid = 0; 8 | 9 | switch (in) 10 | { 11 | case LTFAT_TIMEINV: 12 | case LTFAT_FREQINV: 13 | isvalid = 1; break; 14 | default: 15 | isvalid = 0; 16 | } 17 | 18 | return isvalid; 19 | } 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_typecomplexindependent.c: -------------------------------------------------------------------------------- 1 | #include "test_circshift.c" 2 | #include "test_dgt_fb.c" 3 | #include "test_idgt_fb.c" 4 | #include "test_dgt_long.c" 5 | #include "test_idgt_long.c" 6 | #include "test_fftshift.c" 7 | #include "test_ifftshift.c" 8 | #include "test_fir2long.c" 9 | #include "test_long2fir.c" 10 | #include "test_normalize.c" 11 | #include "test_firwin.c" 12 | #include "test_gabdual_painless.c" 13 | #include "test_gabdual_long.c" 14 | 15 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/pghi.md: -------------------------------------------------------------------------------- 1 | \defgroup pghi Phase Gradient Heap Integration 2 | \addtogroup pghi 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows paper \cite ltfatnote040. 8 | 9 | Please note that the gollowing relation holds between 10 | \f$\lambda\f$ used in the paper and \f$\gamma\f$ used in this 11 | implementation 12 | \f[ 13 | \gamma = \lambda L, 14 | \f] 15 | where \f$L\f$ is the transform length. 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /modules/libltfat/testing/pyUnit/testhelper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | import os 5 | import subprocess 6 | from cffi import FFI 7 | 8 | ffi = FFI() 9 | filedir = os.path.dirname(os.path.abspath(__file__)) 10 | libpath = os.path.join(filedir, '..', '..', 'build') 11 | libltfat = os.path.join(libpath, 'libltfat.so') 12 | header = os.path.join(libpath, 'ltfat_flat.h') 13 | 14 | with open(header) as f_header: 15 | ffi.cdef(f_header.read()) 16 | 17 | lib = ffi.dlopen(libltfat) 18 | 19 | -------------------------------------------------------------------------------- /modules/libltfat/src/slidgtrealmp_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_SLIDGTREALMP_PRIVATE_H 2 | #define _LTFAT_SLIDGTREALMP_PRIVATE_H 3 | 4 | 5 | #endif 6 | 7 | struct LTFAT_NAME(slidgtrealmp_state) 8 | { 9 | LTFAT_NAME(dgtrealmp_state)* mpstate; 10 | int owning_mpstate; 11 | LTFAT_NAME(slicing_processor_state)* slistate; 12 | int owning_slistate; 13 | LTFAT_COMPLEX** couttmp; 14 | ltfat_int P; 15 | void* userdata; 16 | LTFAT_NAME(slidgtrealmp_processor_callback)* callback; 17 | }; 18 | 19 | 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behaviour, in case users don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files we want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.mk text 7 | *.m text 8 | *.c text 9 | *.h text 10 | *.cc text 11 | *.txt text 12 | # 13 | *.sh text eol=lf 14 | *.py text eol=lf 15 | Makefile* text 16 | 17 | # Denote all files that are truly binary and should not be modified. 18 | *.png binary 19 | *.jpg binary 20 | *.wav binary 21 | *.pdf binary -------------------------------------------------------------------------------- /modules/libltfat/testing/pyUnit/test_libltfat_fftshift.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | # encoding: utf-8 3 | 4 | from testhelper import lib, ffi 5 | import numpy as np 6 | 7 | 8 | def test_fftshift(): 9 | inArr = np.array([1, 2, 3, 4, 5, 6, 7], dtype=np.float64) 10 | res = np.array([5, 6, 7, 1, 2, 3, 4], dtype=np.float64) 11 | status = getattr(lib, 'ltfat_fftshift_d')( 12 | ffi.cast("double *",inArr.ctypes.data), 7, ffi.cast("double *",res.ctypes.data)) 13 | print(inArr) 14 | print(res) 15 | assert all(inArr == res) 16 | -------------------------------------------------------------------------------- /comptarget.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(COMPTARGET),debug) 2 | # Do debug stuff here 3 | CFLAGS +=-O0 -g 4 | CXXFLAGS +=-O0 -g 5 | endif 6 | 7 | ifeq ($(COMPTARGET),release) 8 | CFLAGS +=-O2 -DNDEBUG 9 | CXXFLAGS +=-O2 -DNDEBUG 10 | endif 11 | 12 | ifeq ($(COMPTARGET),highoptim) 13 | CFLAGS +=-O3 -DNDEBUG 14 | CXXFLAGS +=-O3 -DNDEBUG 15 | endif 16 | 17 | ifeq ($(COMPTARGET),profiling) 18 | CFLAGS +=-O2 -DNDEBUG -g 19 | CXXFLAGS +=-O2 -DNDEBUG -g 20 | endif 21 | 22 | ifeq ($(COMPTARGET),fulloptim) 23 | CFLAGS +=-Ofast -DNDEBUG 24 | CXXFLAGS +=-Ofast -DNDEBUG 25 | endif 26 | 27 | -------------------------------------------------------------------------------- /modules/libltfat/src/slicingbuf_private.h: -------------------------------------------------------------------------------- 1 | struct LTFAT_NAME(slicing_processor_state) 2 | { 3 | LTFAT_NAME(slicing_processor_callback)* 4 | processorCallback; //!< Custom processor callback 5 | void* userdata; //!< Callback data 6 | LTFAT_NAME(block_processor_state)* block_processor; 7 | LTFAT_REAL* bufIn; 8 | LTFAT_REAL* bufOut; 9 | LTFAT_REAL* bufIn_start; 10 | LTFAT_REAL* bufOut_start; 11 | ltfat_int winLen; 12 | ltfat_int taperLen; 13 | ltfat_int zpadLen; 14 | LTFAT_REAL* ga; 15 | LTFAT_REAL* gs; 16 | 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_gabframediag.m: -------------------------------------------------------------------------------- 1 | function test_libltfat_gabframediag 2 | [~,~,enuminfo]=libltfatprotofile; 3 | LTFAT_FIRWIN = enuminfo.LTFAT_FIRWIN; 4 | 5 | a = 14; 6 | gl = 34; 7 | M = 64; 8 | g = zeros(gl,1); 9 | d = zeros(a,1); 10 | gPtr = libpointer('doublePtr',g); 11 | dPtr = libpointer('doublePtr',d); 12 | 13 | calllib('libltfat','ltfat_firwin_d',LTFAT_FIRWIN.LTFAT_HANN,gl,gPtr); 14 | 15 | 16 | calllib('libltfat','ltfat_gabframediag_d',gPtr,gl,a,M,a,dPtr); 17 | 18 | 19 | d =gabframediag(gPtr.Value,a,M,lcm(a,M)); 20 | d(1:a)-dPtr.Value 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/ltfatdiditfail.m: -------------------------------------------------------------------------------- 1 | function [test_failed,fail]=ltfatdiditfail(res,test_failed,tolerance); 2 | %LTFATDIDITFAIL Did a test fail 3 | % 4 | % [test_fail,fail]=LTFATDIDITFAIL(res,test_fail) updates test_fail if 5 | % res is above threshhold and outputs the word FAIL in the variable 6 | % fail. Use only in testing scripts. 7 | if nargin<3 8 | tolerance=1e-10; 9 | if isa(res,'single') 10 | tolerance=5e-4; 11 | end 12 | end; 13 | 14 | fail=''; 15 | if (abs(res)>tolerance) || isnan(res) 16 | fail='FAILED'; 17 | test_failed=test_failed+1; 18 | end; 19 | 20 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/linalg.h: -------------------------------------------------------------------------------- 1 | typedef struct LTFAT_NAME_COMPLEX(hermsystemsolver_plan) LTFAT_NAME_COMPLEX(hermsystemsolver_plan); 2 | 3 | LTFAT_API int 4 | LTFAT_NAME_COMPLEX(hermsystemsolver_init)(ltfat_int M, 5 | LTFAT_NAME_COMPLEX(hermsystemsolver_plan)** p); 6 | 7 | 8 | LTFAT_API int 9 | LTFAT_NAME_COMPLEX(hermsystemsolver_execute)( 10 | LTFAT_NAME_COMPLEX(hermsystemsolver_plan)* p, 11 | const LTFAT_COMPLEX* A, ltfat_int M, LTFAT_COMPLEX* b); 12 | 13 | LTFAT_API int 14 | LTFAT_NAME_COMPLEX(hermsystemsolver_done)( 15 | LTFAT_NAME_COMPLEX(hermsystemsolver_plan)** p); 16 | -------------------------------------------------------------------------------- /ostools.mk: -------------------------------------------------------------------------------- 1 | #This file produces system and environment dependent tools for working with files 2 | #It sets the following variables 3 | # 4 | # RM 5 | # CP 6 | 7 | ifeq ($(OS),Windows_NT) 8 | $(info Windows detected) 9 | MINGW = 1 10 | RM = del /Q /F 11 | CP = copy /Y 12 | MKDIR = md 13 | RMDIR = rmdir /S /Q 14 | PS2 = \\ 15 | PS = $(strip $(PS2)) 16 | CC = gcc 17 | ifndef SHELL 18 | ifdef ComSpec 19 | SHELL := $(ComSpec) 20 | endif 21 | ifdef COMSPEC 22 | SHELL := $(COMSPEC) 23 | endif 24 | endif 25 | else 26 | #If not on Windows 27 | RM = rm -rf 28 | CP = cp -f 29 | PS = / 30 | MKDIR = mkdir -p 31 | RMDIR = $(RM) 32 | endif 33 | 34 | #CC=gcc 35 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.1) 2 | project (examples CXX C) 3 | 4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils) 5 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../modules/libltfat/include) 6 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../modules/libphaseret/include) 7 | 8 | set (CMAKE_CXX_STANDARD 14) 9 | set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) 10 | set(CMAKE_C_FLAGS ${OLD_CMAKE_C_FLAGS}) 11 | 12 | 13 | if(CMAKE_CROSSCOMPILING) 14 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") 15 | endif(CMAKE_CROSSCOMPILING) 16 | 17 | add_subdirectory(multigabormp) 18 | -------------------------------------------------------------------------------- /examples/multigabormp/Makefile: -------------------------------------------------------------------------------- 1 | CXXFLAGS+=-Ofast -Wall -Wextra -std=c++1z 2 | 3 | ifeq ($(TYPE),single) 4 | CXXFLAGS+=-DLTFAT_SINGLE 5 | else 6 | CXXFLAGS+=-DLTFAT_DOUBLE 7 | endif 8 | 9 | SRC=$(wildcard *.cpp) 10 | PROGS = $(patsubst %.cpp,%,$(SRC)) 11 | libltfat=../../build/libltfat.a 12 | 13 | all: $(PROGS) 14 | 15 | $(PROGS): %: %.cpp $(libltfat) 16 | $(CXX) $(CXXFLAGS) -I../utils -I../../modules/libltfat/include $< -o $@ $(libltfat) -lfftw3 -lfftw3f -lc -lm 17 | 18 | $(libltfat): 19 | make -C ../.. -j12 MODULE=libltfat NOBLASLAPACK=1 COMPTARGET=fulloptim static 20 | 21 | clean: cleanlib cleanexe 22 | 23 | cleanlib: 24 | make -C ../.. clean 25 | 26 | cleanexe: 27 | -rm $(PROGS) 28 | 29 | -------------------------------------------------------------------------------- /modules/libphaseret/src/legla_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _phaseret_legla_private_h 2 | #define _phaseret_legla_private_h 3 | //#include "dgtrealwrapper_private.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | struct phaseret_legla_params 10 | { 11 | double relthr; ///< Relative threshold for automatic determination of kernel size, default 1e-3 12 | phaseret_size ksize; ///< Maximum allowed kernel size (default 2*ceil(M/a) -1) or kernel size directly if relthr==0.0 13 | unsigned leglaflags; ///< LEGLA algorithm flags, default MOD_COEFFICIENTWISE | MOD_MODIFIEDUPDATE 14 | ltfat_dgt_params* dparams; 15 | }; 16 | 17 | 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /modules/libltfat/src/dgtreal_long_private.h: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | struct LTFAT_NAME(dgtreal_long_plan) 8 | { 9 | ltfat_int a; 10 | ltfat_int M; 11 | ltfat_int L; 12 | ltfat_int W; 13 | ltfat_int c; 14 | ltfat_int h_a; 15 | ltfat_phaseconvention ptype; 16 | LTFAT_NAME(fftreal_plan)* p_before; 17 | LTFAT_NAME(ifftreal_plan)* p_after; 18 | LTFAT_NAME(fftreal_plan)* p_veryend; 19 | LTFAT_REAL* sbuf; 20 | LTFAT_COMPLEX* cbuf; 21 | const LTFAT_REAL* f; 22 | LTFAT_COMPLEX* gf; 23 | LTFAT_REAL* cwork; 24 | LTFAT_COMPLEX* cout; 25 | LTFAT_REAL* ff, *cf; 26 | }; 27 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/reassign_typeconstant.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_REASSIGN_TYPECONSTANT_H 2 | #define _LTFAT_REASSIGN_TYPECONSTANT_H 3 | 4 | #define fbreassOptOut_EXPANDRAT 2 5 | 6 | typedef enum 7 | { 8 | REASS_DEFAULT = 0, 9 | REASS_NOTIMEWRAPAROUND = 1 10 | } fbreassHints; 11 | 12 | typedef struct { 13 | ltfat_int** repos; 14 | ltfat_int* reposl; 15 | ltfat_int* reposlmax; 16 | ltfat_int l; 17 | } fbreassOptOut; 18 | 19 | LTFAT_API fbreassOptOut* 20 | fbreassOptOut_init(ltfat_int l,ltfat_int inital); 21 | 22 | LTFAT_API void 23 | fbreassOptOut_expand(fbreassOptOut* oo,ltfat_int ii); 24 | 25 | LTFAT_API void 26 | fbreassOptOut_destroy(fbreassOptOut* oo); 27 | 28 | 29 | #endif /* end of include guard: _REASSIGN_H */ 30 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_pghi.m: -------------------------------------------------------------------------------- 1 | 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | 12 | 13 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 14 | s = abs(corig); 15 | cout = zeros(2*M2,N); 16 | coutPtr = libpointer('doublePtr',cout); 17 | gamma = gl^2*0.25645; 18 | calllib('libphaseret','phaseret_pghi_d',s,L,1,a,M,gamma,coutPtr); 19 | 20 | cout2 = interleaved2complex(coutPtr.Value); 21 | %cout2 = pghi(s,gamma,a,M,'timeinv'); 22 | 23 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 24 | 25 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 26 | magnitudeerrdb(s,s2) 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/heap.h: -------------------------------------------------------------------------------- 1 | typedef struct LTFAT_NAME(heap) LTFAT_NAME(heap); 2 | 3 | LTFAT_API LTFAT_NAME(heap)* 4 | LTFAT_NAME(heap_init)(ltfat_int initmaxsize, const LTFAT_REAL* s); 5 | 6 | LTFAT_API const LTFAT_REAL* 7 | LTFAT_NAME(heap_getdataptr)(LTFAT_NAME(heap)* h); 8 | 9 | LTFAT_API void 10 | LTFAT_NAME(heap_done)(LTFAT_NAME(heap)* h); 11 | 12 | LTFAT_API void 13 | LTFAT_NAME(heap_grow)(LTFAT_NAME(heap)* h, int factor); 14 | 15 | LTFAT_API void 16 | LTFAT_NAME(heap_reset)(LTFAT_NAME(heap)* h, const LTFAT_REAL* news); 17 | 18 | LTFAT_API ltfat_int 19 | LTFAT_NAME(heap_get)(LTFAT_NAME(heap) *h); 20 | 21 | LTFAT_API ltfat_int 22 | LTFAT_NAME(heap_delete)(LTFAT_NAME(heap) *h); 23 | 24 | LTFAT_API void 25 | LTFAT_NAME(heap_insert)(LTFAT_NAME(heap) *h, ltfat_int key); 26 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_spsi.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | f = gspi; 3 | a = 256; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('blackman',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | 12 | 13 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 14 | s = abs(corig); 15 | cout = zeros(2*M2,N); 16 | cout(1:numel(s)) = s(:); 17 | coutPtr = libpointer('doublePtr',cout); 18 | calllib('libphaseret','phaseret_spsi_d',coutPtr,L,1,a,M,libpointer(),coutPtr); 19 | 20 | %cout2 = interleaved2complex(coutPtr.Value); 21 | cout2 = spsi(s,a,M,'timeinv'); 22 | 23 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 24 | 25 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 26 | magnitudeerrdb(s,s2) 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /modules/libltfat/src/ci_memalloc.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | 4 | LTFAT_API LTFAT_TYPE* 5 | LTFAT_NAME(malloc) (size_t n) 6 | { 7 | return (LTFAT_TYPE*)ltfat_malloc(n * sizeof(LTFAT_TYPE)); 8 | } 9 | 10 | LTFAT_API LTFAT_TYPE* 11 | LTFAT_NAME(realloc) (LTFAT_TYPE* ptr, size_t nold, size_t nnew) 12 | { 13 | return (LTFAT_TYPE*)ltfat_realloc(ptr, nold * sizeof(LTFAT_TYPE), nnew * sizeof(LTFAT_TYPE)); 14 | } 15 | 16 | LTFAT_API LTFAT_TYPE* 17 | LTFAT_NAME(postpad) (LTFAT_TYPE* ptr, size_t nold, size_t nnew) 18 | { 19 | return (LTFAT_TYPE*)ltfat_postpad(ptr, nold * sizeof(LTFAT_TYPE), nnew * sizeof(LTFAT_TYPE)); 20 | } 21 | 22 | LTFAT_API LTFAT_TYPE* 23 | LTFAT_NAME(calloc) (size_t n) 24 | { 25 | return (LTFAT_TYPE*) ltfat_calloc( n, sizeof(LTFAT_TYPE)); 26 | } 27 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/runner_template.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/errno.h" 3 | #include "ltfat/macros.h" 4 | #include "minunit.h" 5 | #include "runner_multiinclude.h" 6 | 7 | void all_tests() 8 | { 9 | mu_suite_start(); 10 | 11 | mu_run_test_singledouble(%FUNCTIONNAME%); 12 | 13 | mu_suite_stop(); 14 | } 15 | 16 | 17 | int main() 18 | { 19 | all_tests(); 20 | 21 | 22 | if (ft.noOfFailedTests > 0) 23 | { 24 | printf("\n----------------\nFAILED TESTS %d: \n\n", ft.noOfFailedTests); 25 | for (int ii = 0; ii < ft.noOfFailedTests; ii++) { printf(" %s\n", ft.failedTests[ii]); } 26 | ltfat_free(ft.failedTests); 27 | } 28 | else 29 | { 30 | printf("\n----------------\nALL TESTS PASSED\n"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_gla.m: -------------------------------------------------------------------------------- 1 | 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = M; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('blackman',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | maxit = 100; 12 | 13 | corig = dgtreal(f,{'blackman',gl},a,M); 14 | s = abs(corig) + 1i*zeros(size(corig)); 15 | 16 | cinPtr = libpointer('doublePtr',complex2interleaved(s)); 17 | cout = zeros(2*M2,N); 18 | coutPtr = libpointer('doublePtr',cout); 19 | 20 | calllib('libphaseret','phaseret_gla_d',cinPtr,libpointer(),g,L,gl,1,a,M,maxit,coutPtr); 21 | 22 | cout2 = interleaved2complex(coutPtr.Value); 23 | 24 | frec = idgtreal(cout2,{'dual',{'blackman',gl}},a,M); 25 | 26 | s2 = dgtreal(frec,{'blackman',gl},a,M); 27 | magnitudeerrdb(s,s2) 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /modules/libltfat/src/spread.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | LTFAT_API void 6 | LTFAT_NAME(col2diag)(const LTFAT_TYPE *cin, ltfat_int L, 7 | LTFAT_TYPE *cout) 8 | { 9 | ltfat_int ii; 10 | 11 | LTFAT_TYPE *pcout; 12 | const LTFAT_TYPE *pcin; 13 | 14 | pcout=cout; 15 | ltfat_int Lp1=L+1; 16 | for (ltfat_int jj=0; jj. 18 | */ 19 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_heap.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_heap(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | L = 1025; 7 | f = rand(L,1); 8 | fPtr = libpointer('doublePtr',f); 9 | idxArr = randperm(L); 10 | 11 | heap = calllib('libltfat','ltfat_heap_init_d', L, fPtr); 12 | 13 | for w = idxArr 14 | calllib('libltfat','ltfat_heap_insert_d', heap, w-1); 15 | end 16 | 17 | sortedIdxArr = zeros(L,1); 18 | 19 | for w = 1:L 20 | sortedIdxArr(w) = calllib('libltfat','ltfat_heap_delete_d', heap); 21 | end 22 | 23 | calllib('libltfat','ltfat_heap_done_d',heap); 24 | 25 | res = norm(f(sortedIdxArr+1) - sort(f,'descend')); 26 | 27 | plot([f,f(sortedIdxArr+1),sort(f,'descend')]) 28 | 29 | if res>0 30 | test_failed=1; 31 | end 32 | 33 | 34 | 35 | 36 | 37 | %plot(sort(f,'descend')) 38 | 39 | -------------------------------------------------------------------------------- /modules/libphaseret/src/rtpghi_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_RTPGHI_PRIVATE_H 2 | #define _PHASERET_RTPGHI_PRIVATE_H 3 | 4 | 5 | struct PHASERET_NAME(rtpghi_state) 6 | { 7 | PHASERET_NAME(rtpghiupdate_plan)* p; 8 | ltfat_int M; 9 | ltfat_int a; 10 | ltfat_int W; 11 | int do_causal; 12 | LTFAT_REAL* slog; 13 | LTFAT_REAL* s; 14 | LTFAT_REAL* tgrad; //!< Time gradient buffer 15 | LTFAT_REAL* fgrad; //!< Frequency gradient buffer 16 | LTFAT_REAL* phase; //!< Buffer for keeping previously computed frame 17 | double gamma; 18 | }; 19 | 20 | struct PHASERET_NAME(rtpghiupdate_plan) 21 | { 22 | LTFAT_NAME(heap)* h; 23 | int* donemask; 24 | double logtol; 25 | double tol; 26 | ltfat_int M; 27 | LTFAT_REAL* randphase; //!< Precomputed array of random phase 28 | ltfat_int randphaseLen; 29 | ltfat_int randphaseId; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /modules/libltfat/src/dgtrealwrapper_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_dgtrealwrapper_private_h 2 | #define _ltfat_dgtrealwrapper_private_h 3 | #include "dgtwrapper_private.h" 4 | 5 | typedef int LTFAT_NAME(complextorealtransform)(void* userdata, const LTFAT_COMPLEX* c, ltfat_int L, ltfat_int W, LTFAT_REAL* f); 6 | typedef int LTFAT_NAME(realtocomplextransform)(void* userdata, const LTFAT_REAL* f, ltfat_int L, ltfat_int W, LTFAT_COMPLEX* c); 7 | 8 | struct LTFAT_NAME(dgtreal_plan) 9 | { 10 | ltfat_int L; 11 | ltfat_int W; 12 | ltfat_int a; 13 | ltfat_int M; 14 | LTFAT_REAL* f; 15 | LTFAT_COMPLEX* c; 16 | ltfat_phaseconvention ptype; 17 | LTFAT_NAME(complextorealtransform)* backtra; 18 | void* backtra_userdata; 19 | LTFAT_NAME(donefunc)* backdonefunc; 20 | LTFAT_NAME(realtocomplextransform)* fwdtra; 21 | void* fwdtra_userdata; 22 | LTFAT_NAME(donefunc)* fwddonefunc; 23 | }; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /modules/libphaseret/src/gsrtisila_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_GSRTISILA_PRIVATE_H 2 | #define _PHASERET_GSRTISILA_PRIVATE_H 3 | 4 | 5 | struct PHASERET_NAME(gsrtisilaupdate_plan) 6 | { 7 | PHASERET_NAME(rtisilaupdate_plan)* p2; 8 | const LTFAT_REAL* g; 9 | // const LTFAT_REAL* gd; 10 | ltfat_int gl; 11 | ltfat_int M; 12 | ltfat_int a; 13 | ltfat_int gNo; 14 | int do_skipinitialization; 15 | }; 16 | 17 | struct PHASERET_NAME(gsrtisila_state) 18 | { 19 | PHASERET_NAME(gsrtisilaupdate_plan)* uplan; 20 | ltfat_int maxLookahead; 21 | ltfat_int lookahead; 22 | ltfat_int lookback; 23 | ltfat_int maxit; 24 | ltfat_int W; 25 | LTFAT_REAL* frames; //!< Buffer for time-domain frames 26 | LTFAT_COMPLEX* cframes; //!< Buffer for frequency-domain frames 27 | LTFAT_REAL* s; //!< Buffer for target magnitude 28 | void** garbageBin; 29 | ltfat_int garbageBinSize; 30 | }; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /modules/libphaseret/include/phaseret/basicmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _PHASERET_BASICMACROS_H 2 | #define _PHASERET_BASICMACROS_H 3 | 4 | #ifndef PHASERET_API 5 | #if defined(_WIN32) || defined(__WIN32__) 6 | # if defined(LTFAT_BUILD_SHARED) 7 | # define PHASERET_API __declspec(dllexport) 8 | # elif !defined(LTFAT_BUILD_STATIC) 9 | # define PHASERET_API __declspec(dllimport) 10 | # else 11 | # define PHASERET_API 12 | # endif 13 | #else 14 | // # if __GNUC__ >= 4 15 | // # define PHASERET_API __attribute__((visibility("default"))) 16 | // # else 17 | # define PHASERET_API 18 | // # endif 19 | #endif 20 | #endif 21 | 22 | #define PHASERET_NAME_DOUBLE(name) LTFAT_MAKENAME(phaseret,name,_d) 23 | #define PHASERET_NAME_SINGLE(name) LTFAT_MAKENAME(phaseret,name,_s) 24 | #define PHASERET_NAME_COMPLEXDOUBLE(name) LTFAT_MAKENAME(phaseret,name,_dc) 25 | #define PHASERET_NAME_COMPLEXSINGLE(name) LTFAT_MAKENAME(phaseret,name,_sc) 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/basicmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_BASICMACROS_H 2 | #define _LTFAT_BASICMACROS_H 3 | 4 | #ifndef LTFAT_API 5 | #if defined(_WIN32) || defined(__WIN32__) 6 | # if defined(LTFAT_BUILD_SHARED) 7 | # define LTFAT_API __declspec(dllexport) 8 | # elif !defined(LTFAT_BUILD_STATIC) 9 | # define LTFAT_API __declspec(dllimport) 10 | # else 11 | # define LTFAT_API 12 | # endif 13 | #else 14 | // # if __GNUC__ >= 4 15 | // # define LTFAT_API __attribute__((visibility("default"))) 16 | // # else 17 | # define LTFAT_API 18 | // # endif 19 | #endif 20 | #endif 21 | 22 | #define LTFAT_MAKENAME(prefix,name,suffix) prefix ## _ ## name ## suffix 23 | 24 | #define LTFAT_NAME_DOUBLE(name) LTFAT_MAKENAME(ltfat,name,_d) 25 | #define LTFAT_NAME_SINGLE(name) LTFAT_MAKENAME(ltfat,name,_s) 26 | #define LTFAT_NAME_COMPLEXDOUBLE(name) LTFAT_MAKENAME(ltfat,name,_dc) 27 | #define LTFAT_NAME_COMPLEXSINGLE(name) LTFAT_MAKENAME(ltfat,name,_sc) 28 | 29 | 30 | 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_rtisila.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | lookahead = 0; 12 | maxit = 10; 13 | 14 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 15 | s = abs(corig); 16 | 17 | cout = zeros(2*M2,N); 18 | coutPtr = libpointer('doublePtr',cout); 19 | 20 | calllib('libphaseret','phaseret_rtisilaoffline_d',s,g,L,gl,1,a,M,lookahead,maxit,coutPtr); 21 | 22 | cout2 = interleaved2complex(coutPtr.Value); 23 | 24 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 25 | 26 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 27 | magnitudeerrdb(s,s2) 28 | 29 | 30 | 31 | c=rtisila(s,g,a,M,'lookahead',lookahead,'maxit',maxit,'timeinv'); 32 | frec = idgtreal(c,{'dual',{'hann',gl}},a,M,'timeinv'); 33 | magnitudeerrdb(s,dgtreal(frec,{'hann',gl},a,M,'timeinv')) 34 | 35 | plotdgtreal(abs(c-cout2),a,M,'linabs') 36 | 37 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/htmltemplate/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /modules/libphaseret/README.md: -------------------------------------------------------------------------------- 1 | #libPhaseReT 2 | libPhaseReT is a C99 and C++11 library collecting implementations of phase 3 | reconstruction algorithms for complex time-frequency representations (like STFT). 4 | 5 | ## Requirements 6 | 7 | The library depends on [libltfat](http://github.com/ltfat/libltfat). 8 | 9 | ## Instalation and usage 10 | 11 | The following installs the library to /usr/local/lib and phaseret.h to /usr/local/include/ 12 | 13 | ``` 14 | make 15 | sudo make install 16 | ``` 17 | 18 | The path can be changed by calling 19 | 20 | ``` 21 | sudo make install PREFIX=/custom/path 22 | ``` 23 | 24 | ## Documentation 25 | 26 | Doxygen-generated documentation [webpage](http://ltfat.github.io/libphaseret). 27 | 28 | # References 29 | 30 | If you use this toolbox/library in your research, please cite 31 | 32 | > Zdenek Prusa, Peter Soendergaard: TBD. 33 | 34 | and/or relevant references found in help of the individual files. 35 | 36 | # License 37 | PhaseReT is distributed under terms of 38 | [GPL3](http://www.gnu.org/licenses/gpl-3.0.en.html) 39 | -------------------------------------------------------------------------------- /modules/libphaseret/include/phaseret/types.h: -------------------------------------------------------------------------------- 1 | #include "basicmacros.h" 2 | #include "ltfat/types.h" 3 | 4 | #ifdef PHASERET_NAME_REAL 5 | #undef PHASERET_NAME_REAL 6 | #endif 7 | 8 | #ifdef PHASERET_NAME_COMPLEX 9 | #undef PHASERET_NAME_COMPLEX 10 | #endif 11 | 12 | #ifdef PHASERET_NAME 13 | #undef PHASERET_NAME 14 | #endif 15 | 16 | #ifdef LTFAT_DOUBLE 17 | # define PHASERET_NAME_REAL(name) PHASERET_NAME_DOUBLE(name) 18 | # define PHASERET_NAME_COMPLEX(name) PHASERET_NAME_COMPLEXDOUBLE(name) 19 | # if defined(LTFAT_COMPLEXTYPE) 20 | # define PHASERET_NAME(name) PHASERET_NAME_COMPLEXDOUBLE(name) 21 | # else 22 | # define PHASERET_NAME(name) PHASERET_NAME_DOUBLE(name) 23 | # endif 24 | #endif 25 | 26 | #ifdef LTFAT_SINGLE 27 | #define PHASERET_NAME_REAL(name) PHASERET_NAME_SINGLE(name) 28 | #define PHASERET_NAME_COMPLEX(name) PHASERET_NAME_COMPLEXSINGLE(name) 29 | # if defined(LTFAT_COMPLEXTYPE) 30 | # define PHASERET_NAME(name) PHASERET_NAME_COMPLEXSINGLE(name) 31 | # else 32 | # define PHASERET_NAME(name) PHASERET_NAME_SINGLE(name) 33 | # endif 34 | #endif 35 | -------------------------------------------------------------------------------- /modules/libltfat/doc/htmltemplate/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /modules/libltfat/src/dgtwrapper_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_dgtwrapper_private_h 2 | #define _ltfat_dgtwrapper_private_h 3 | 4 | 5 | struct ltfat_dgt_params 6 | { 7 | ltfat_phaseconvention ptype; 8 | unsigned fftw_flags; 9 | ltfat_dgt_hint hint; 10 | int do_synoverwrites; 11 | }; 12 | 13 | typedef int LTFAT_NAME(donefunc)(void** pla); 14 | 15 | typedef int LTFAT_NAME(complextocomplextransform)(void* userdata, const LTFAT_COMPLEX* c, ltfat_int L, ltfat_int W, LTFAT_COMPLEX* f); 16 | typedef int LTFAT_NAME(typetocomplextransform)(void* userdata, const LTFAT_TYPE* f, ltfat_int L, ltfat_int W, LTFAT_COMPLEX* c); 17 | 18 | struct LTFAT_NAME(dgt_plan) 19 | { 20 | ltfat_int L; 21 | ltfat_int W; 22 | ltfat_int a; 23 | ltfat_int M; 24 | LTFAT_COMPLEX* f; 25 | LTFAT_COMPLEX* c; 26 | ltfat_phaseconvention ptype; 27 | LTFAT_NAME(complextocomplextransform)* backtra; 28 | void* backtra_userdata; 29 | LTFAT_NAME(donefunc)* backdonefunc; 30 | LTFAT_NAME(typetocomplextransform)* fwdtra; 31 | void* fwdtra_userdata; 32 | LTFAT_NAME(donefunc)* fwddonefunc; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /modules/libltfat/src/dgt_long_private.h: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | struct LTFAT_NAME_REAL(dgt_long_plan) 8 | { 9 | ltfat_int a; 10 | ltfat_int M; 11 | ltfat_int L; 12 | ltfat_int W; 13 | ltfat_int c; 14 | ltfat_int h_a; 15 | ltfat_phaseconvention ptype; 16 | LTFAT_NAME_REAL(fft_plan)* p_before; 17 | LTFAT_NAME_REAL(ifft_plan)* p_after; 18 | LTFAT_NAME_REAL(fft_plan)* p_veryend; 19 | LTFAT_REAL* sbuf; 20 | const LTFAT_REAL* f; 21 | LTFAT_COMPLEX* gf; 22 | LTFAT_COMPLEX* cout; 23 | LTFAT_REAL* ff, *cf; 24 | }; 25 | 26 | struct LTFAT_NAME_COMPLEX(dgt_long_plan) 27 | { 28 | ltfat_int a; 29 | ltfat_int M; 30 | ltfat_int L; 31 | ltfat_int W; 32 | ltfat_int c; 33 | ltfat_int h_a; 34 | ltfat_phaseconvention ptype; 35 | LTFAT_NAME_REAL(fft_plan)* p_before; 36 | LTFAT_NAME_REAL(ifft_plan)* p_after; 37 | LTFAT_NAME_REAL(fft_plan)* p_veryend; 38 | LTFAT_REAL* sbuf; 39 | const LTFAT_COMPLEX* f; 40 | LTFAT_COMPLEX* gf; 41 | LTFAT_COMPLEX* cout; 42 | LTFAT_REAL* ff, *cf; 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /modules/libltfat/src/version.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/macros.h" 3 | 4 | #define LTFAT_MAKEVESRIONSTRING(major,minor,patch) #major "." #minor "." #patch 5 | #define LTFAT_VERSIONSTRING(major,minor,patch) LTFAT_MAKEVESRIONSTRING(major,minor,patch) 6 | 7 | 8 | static const ltfat_library_version ltfat_version = 9 | { 10 | LTFAT_VERSIONSTRING(LTFAT_VERSION_MAJOR,LTFAT_VERSION_MINOR,LTFAT_VERSION_PATCH), 11 | __DATE__ " " __TIME__, 12 | LTFAT_VERSION_MAJOR, LTFAT_VERSION_MINOR , LTFAT_VERSION_MICRO, sizeof(ltfat_int) 13 | }; 14 | 15 | LTFAT_API const ltfat_library_version* 16 | ltfat_get_version() 17 | { 18 | return <fat_version; 19 | } 20 | 21 | LTFAT_API int 22 | ltfat_is_compatible_version(unsigned int your_major, 23 | unsigned int UNUSED(your_minor), 24 | unsigned int UNUSED(your_micro)) 25 | { 26 | const ltfat_library_version* dll_version = ltfat_get_version(); 27 | return (int) ( dll_version->major == your_major); 28 | } 29 | 30 | LTFAT_API int 31 | ltfat_int_size() 32 | { 33 | return sizeof(ltfat_int); 34 | } 35 | 36 | LTFAT_API int 37 | ltfat_int_is_compatible(int sizeofyourint) 38 | { 39 | return ltfat_int_size() == sizeofyourint; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_legla.m: -------------------------------------------------------------------------------- 1 | [~,structs]=libphaseretprotofile; 2 | 3 | 4 | S = libstruct('phaseret_legla_init_params',struct()); 5 | calllib('libphaseret','phaseret_legla_init_params_defaults',S); 6 | 7 | 8 | f = greasy; 9 | a = 256; 10 | M = 2*1024; 11 | M2 = floor(M/2) + 1; 12 | gl = M; 13 | L = dgtlength(size(f,1),a,M); 14 | g = firwin('blackman',gl); 15 | gd = long2fir(gabdual(g,a,M),gl); 16 | N = L/a; 17 | maxit = 200; 18 | 19 | corig = dgtreal(f,{'blackman',gl},a,M); 20 | s = abs(corig) + 1i*zeros(size(corig)); 21 | cinitPtr = libpointer('doublePtr',complex2interleaved(s)); 22 | 23 | cout = zeros(2*M2,N); 24 | coutPtr = libpointer('doublePtr',cout); 25 | 26 | tic; 27 | calllib('libphaseret','phaseret_legla_d',cinitPtr,g,L,gl,1,a,M,maxit,coutPtr); 28 | toc; 29 | cout2 = interleaved2complex(coutPtr.Value); 30 | %cout2 = phaselockreal(cout2,a,M); 31 | 32 | 33 | frec = idgtreal(cout2,{'dual',{'blackman',gl}},a,M); 34 | s2 = dgtreal(frec,{'blackman',gl},a,M); 35 | magnitudeerrdb(s,s2) 36 | 37 | tic; 38 | cout2 = legla(s,g,a,M,'modtrunc','onthefly','flegla','maxit',maxit); 39 | toc; 40 | 41 | frec = idgtreal(cout2,{'dual',{'blackman',gl}},a,M); 42 | 43 | s2 = dgtreal(frec,{'blackman',gl},a,M); 44 | magnitudeerrdb(s,s2) 45 | 46 | clear S; 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /modules/libltfat/src/dgt.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | LTFAT_API void 8 | LTFAT_NAME(dgt_ola)(const LTFAT_COMPLEX* f, const LTFAT_COMPLEX* g, 9 | ltfat_int L, ltfat_int gl, 10 | ltfat_int W, ltfat_int a, ltfat_int M, 11 | ltfat_int bl, const ltfat_phaseconvention ptype, 12 | LTFAT_COMPLEX* cout) 13 | { 14 | LTFAT_NAME(dgt_ola_plan) plan = 15 | LTFAT_NAME(dgt_ola_init)(g, gl, W, a, M, bl, ptype, FFTW_ESTIMATE); 16 | 17 | LTFAT_NAME(dgt_ola_execute)(plan, f, L, cout); 18 | 19 | LTFAT_NAME(dgt_ola_done)(plan); 20 | 21 | } 22 | 23 | 24 | LTFAT_API void 25 | LTFAT_NAME(dgtreal_ola)(const LTFAT_REAL* f, const LTFAT_REAL* g, 26 | ltfat_int L, ltfat_int gl, 27 | ltfat_int W, ltfat_int a, ltfat_int M, 28 | ltfat_int bl, const ltfat_phaseconvention ptype, 29 | LTFAT_COMPLEX* cout) 30 | { 31 | LTFAT_NAME(dgtreal_ola_plan) plan = 32 | LTFAT_NAME(dgtreal_ola_init)(g, gl, W, a, M, bl, ptype, FFTW_ESTIMATE); 33 | 34 | LTFAT_NAME(dgtreal_ola_execute)(plan, f, L, cout); 35 | 36 | LTFAT_NAME(dgtreal_ola_done)(plan); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /modules/libphaseret/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | project (libphaseret C CXX) 3 | 4 | option(NOBLASLAPACK 5 | "Disable BLAS and LAPACK dependency. Must be used if LTFAT was compiled without BLAS 6 | and LAPACK dependency" OFF) 7 | 8 | if (MSVC) 9 | set(USECPP 1) 10 | else (MSVC) 11 | option(USECPP 12 | "Use C++ compiler instead of C compiler" OFF) 13 | endif (MSVC) 14 | 15 | 16 | # FIND_LIBRARY(FFTW3_LIB NAMES fftw3 libfftw3) 17 | # FIND_LIBRARY(FFTW3F_LIB NAMES fftw3f libfftw3f) 18 | 19 | FIND_LIBRARY(LTFAT_LIB NAMES ltfat libltfat) 20 | FIND_LIBRARY(LTFATF_LIB NAMES ltfatf libltfatf) 21 | FIND_LIBRARY(LTFATD_LIB NAMES ltfatd libltfatd) 22 | 23 | FIND_PATH(LTFAT_INCLUDE NAMES ltfat.h) 24 | 25 | # if (NOT NOBLASLAPACK) 26 | # FIND_LIBRARY(BLAS_LIB NAMES blas libblas) 27 | # FIND_LIBRARY(LAPACK_LIB NAMES lapack liblapack) 28 | # endif (NOT NOBLASLAPACK) 29 | 30 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 31 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 32 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 33 | 34 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 35 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty) 36 | include_directories(${LTFAT_INCLUDE}) 37 | 38 | add_subdirectory(src) 39 | 40 | -------------------------------------------------------------------------------- /modules/libltfat/src/wavelets_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | 3 | LTFAT_API ltfatExtType 4 | ltfatExtStringToEnum(const char* extType) 5 | { 6 | if (strcmp(extType, "per") == 0) 7 | { 8 | return PER; 9 | } 10 | else if (strcmp(extType, "perdec") == 0) 11 | { 12 | return PERDEC; 13 | } 14 | else if (strcmp(extType, "ppd") == 0) 15 | { 16 | return PPD; 17 | } 18 | else if (strcmp(extType, "sym") == 0) 19 | { 20 | return SYM; 21 | } 22 | else if (strcmp(extType, "even") == 0) 23 | { 24 | return EVEN; 25 | } 26 | else if (strcmp(extType, "symw") == 0) 27 | { 28 | return SYMW; 29 | } 30 | else if (strcmp(extType, "odd") == 0) 31 | { 32 | return ODD; 33 | } 34 | else if (strcmp(extType, "asymw") == 0) 35 | { 36 | return ASYMW; 37 | } 38 | else if (strcmp(extType, "sp0") == 0) 39 | { 40 | return SP0; 41 | } 42 | else if (strcmp(extType, "zpd") == 0) 43 | { 44 | return ZPD; 45 | } 46 | else if (strcmp(extType, "zero") == 0) 47 | { 48 | return ZERO; 49 | } 50 | else if (strcmp(extType, "valid") == 0) 51 | { 52 | return VALID; 53 | } 54 | else 55 | { 56 | return BAD_TYPE; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/Makefile: -------------------------------------------------------------------------------- 1 | CFILES = $(shell ls test_*.c) 2 | 3 | run_all: test_all_libltfat 4 | LD_LIBRARY_PATH=../../build ./test_all_libltfat 5 | 6 | test_all_libltfat: Makefile ../../build/libltfat.so $(CFILES) 7 | $(CC) -Wall -Wextra -pedantic -std=gnu99 -O0 -g -I../../include -I../../thirdparty test_all_libltfat.c -o test_all_libltfat -L../../build -lltfat -lfftw3 -lfftw3f -lm 8 | 9 | mem: test_all_libltfat 10 | LD_LIBRARY_PATH=../../build valgrind --leak-check=yes ./test_all_libltfat 11 | 12 | clean: 13 | -rm -f *.o 14 | find . -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print | xargs rm -f 15 | 16 | test_%: test_%.c Makefile 17 | $(shell truncate -s 0 runner_test_typecomplexindependent.c) 18 | $(shell truncate -s 0 runner_test_typeindependent.c) 19 | $(shell echo 'int TEST_NAME($@)(){' >> runner_test_typeindependent.c) 20 | $(shell echo '#include "$<"' >> runner_test_typeindependent.c) 21 | $(shell echo 'return 0;}' >> runner_test_typeindependent.c) 22 | $(shell sed 's/%FUNCTIONNAME%/$@/g' runner_template.c > runner.c) 23 | $(CC) -Wall -Wextra -pedantic -std=c99 -O0 -g -I../../include -I../../thirdparty runner.c -o $@ -L../../build -lltfat -lfftw3 -lfftw3f -lm 24 | LD_LIBRARY_PATH=../../build ./$@ 25 | -rm -f ./$@ 26 | 27 | .PHONY: run_all 28 | 29 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_gsrtisila.m: -------------------------------------------------------------------------------- 1 | ; 2 | f = gspi; 3 | a = 256; 4 | M = 2048; 5 | M2 = floor(M/2) + 1; 6 | gl = 2048; 7 | L = dgtlength(numel(f),a,M); 8 | win = 'hann'; 9 | g = firwin(win,gl); 10 | gd = long2fir(gabdual(g,a,M),gl); 11 | N = L/a; 12 | lookahead = 0; 13 | maxit = 16; 14 | 15 | corig = dgtreal(f,{win,gl},a,M,'timeinv'); 16 | s = abs(corig); 17 | 18 | cout = zeros(2*M2,N); 19 | coutPtr = libpointer('doublePtr',cout); 20 | 21 | calllib('libphaseret','phaseret_gsrtisilaoffline_d',s,g,L,gl,1,a,M,lookahead,maxit,coutPtr); 22 | 23 | coutsingle = zeros(2*M2,N,'single'); 24 | coutsinglePtr = libpointer('singlePtr',coutsingle); 25 | ssingle = cast(s,'single'); 26 | gsingle = cast(g,'single'); 27 | calllib('libphaseret','phaseret_gsrtisilaoffline_s',ssingle,gsingle,L,gl,1,a,M,lookahead,maxit,coutsinglePtr); 28 | 29 | 30 | coutsingle2 = interleaved2complex(coutsinglePtr.Value); 31 | cout2 = interleaved2complex(coutPtr.Value); 32 | 33 | 34 | frec = idgtreal(coutsingle2,{'dual',{win,gl}},a,M,'timeinv'); 35 | 36 | s2 = dgtreal(frec,{win,gl},a,M,'timeinv'); 37 | magnitudeerrdb(s,s2) 38 | 39 | 40 | 41 | c=gsrtisila(s,g,a,M,'lookahead',lookahead,'maxit',maxit,'timeinv'); 42 | frec = idgtreal(c,{'dual',{win,gl}},a,M,'timeinv'); 43 | magnitudeerrdb(s,dgtreal(frec,{win,gl},a,M,'timeinv')) 44 | 45 | 46 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/multiinclude.h: -------------------------------------------------------------------------------- 1 | #define LTFAT_DOUBLE 2 | #include "ltfat/types.h" 3 | #define TEST_NAME(name) name##_d 4 | #define TEST_NAME_COMPLEX(name) name##_dc 5 | 6 | #include "test_typecomplexindependent.c" 7 | #include "test_typeindependent.c" 8 | 9 | #undef TEST_NAME 10 | #undef TEST_NAME_COMPLEX 11 | #undef LTFAT_DOUBLE 12 | 13 | #define LTFAT_SINGLE 14 | #include "ltfat/types.h" 15 | #define TEST_NAME(name) name##_s 16 | #define TEST_NAME_COMPLEX(name) name##_sc 17 | 18 | #include "test_typecomplexindependent.c" 19 | #include "test_typeindependent.c" 20 | 21 | 22 | #undef TEST_NAME 23 | #undef TEST_NAME_COMPLEX 24 | #undef LTFAT_SINGLE 25 | 26 | #define LTFAT_COMPLEXTYPE 27 | 28 | #define LTFAT_DOUBLE 29 | #include "ltfat/types.h" 30 | #define TEST_NAME(name) name##_dc 31 | #define TEST_NAME_COMPLEX(name) name##_dc 32 | 33 | #include "test_typecomplexindependent.c" 34 | 35 | #undef TEST_NAME 36 | #undef TEST_NAME_COMPLEX 37 | #undef LTFAT_DOUBLE 38 | 39 | #define LTFAT_SINGLE 40 | #include "ltfat/types.h" 41 | #define TEST_NAME(name) name##_sc 42 | #define TEST_NAME_COMPLEX(name) name##_sc 43 | 44 | 45 | #include "test_typecomplexindependent.c" 46 | 47 | #undef TEST_NAME 48 | #undef TEST_NAME_COMPLEX 49 | #undef LTFAT_SINGLE 50 | #undef LTFAT_COMPLEXTYPE 51 | 52 | // Unsets all the macros 53 | #include "ltfat/types.h" 54 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_rtpghi.m: -------------------------------------------------------------------------------- 1 | clear all; 2 | f = cocktailparty; 3 | a = 128; 4 | M = 2048; 5 | M2 = floor(M/2) + 1; 6 | gl = 2048; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | 12 | 13 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 14 | s = abs(corig); 15 | cout = zeros(2*M2,N); 16 | coutPtr = libpointer('doublePtr',cout); 17 | gamma = gl^2*0.25645; 18 | 19 | tic 20 | calllib('libphaseret','phaseret_rtpghioffline_d',s,L,1,a,M,gamma,1e-6,1,coutPtr); 21 | t = toc; 22 | t/N*1000 23 | 24 | coutsingle = zeros(2*M2,N,'single'); 25 | coutsinglePtr = libpointer('singlePtr',coutsingle); 26 | 27 | ssingle = cast(s,'single'); 28 | 29 | tic 30 | calllib('libphaseret','phaseret_rtpghioffline_s',ssingle,L,1,a,M,gamma,1e-6,1,coutsinglePtr); 31 | t =toc; 32 | t/N*1000 33 | 34 | coutsingle2 = interleaved2complex(coutsinglePtr.Value); 35 | cout2 = interleaved2complex(coutPtr.Value); 36 | 37 | 38 | frec = idgtreal(coutsingle2,{'dual',{'hann',gl}},a,M,'timeinv'); 39 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 40 | magnitudeerrdb(s,s2) 41 | 42 | 43 | cout2 = rtpghi(s,gamma,a,M,'timeinv','tol',1e-6,'causal'); 44 | 45 | frec = idgtreal(cout2,{'dual',{'hann',gl}},a,M,'timeinv'); 46 | s2 = dgtreal(frec,{'hann',gl},a,M,'timeinv'); 47 | magnitudeerrdb(s,s2) 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_overlaynthframe.m: -------------------------------------------------------------------------------- 1 | function test_libphaseret_overlaynthframe 2 | f = greasy; 3 | a = 128; 4 | M = 1024; 5 | M2 = floor(M/2) + 1; 6 | gl = 1024; 7 | L = dgtlength(numel(f),a,M); 8 | g = firwin('hann',gl); 9 | gamma = 0.25645*gl^2; 10 | gd = long2fir(gabdual(g,a,M),gl); 11 | gshift = fftshift(g); 12 | N = 10; 13 | idx = 9; 14 | g2 = repmat(g.*gd,1,N); 15 | g1 = repmat(fftshift(g.*gd),1,N); 16 | cout = zeros(gl,1); 17 | coutPtr = libpointer('doublePtr',cout); 18 | 19 | calllib('libphaseret','phaseret_overlaynthframe_d',g1,gl,N,a,idx,coutPtr); 20 | 21 | [~,out2] = comp_overlayframes(g2,a,gl,idx); 22 | [~,out3orig] = overlayframes(g2,a,gl,idx); 23 | out1orig = M*coutPtr.Value; 24 | out3orig = out3orig*M; 25 | 26 | out1 = out1orig; 27 | out3 = out3orig; 28 | out1(out1orig==0) = 1; 29 | out1(out1<1e-6) = 1e-6; 30 | out3(out3orig==0) = 1; 31 | out3(out3<1e-6) = 1e-6; 32 | 33 | figure(1); plot([gshift./out1,gshift./out3]) 34 | 35 | 36 | 37 | function [partrec,frame] = overlayframes(cframes,a,M,n) 38 | 39 | N = size(cframes,2); 40 | bufLen = N*a - (a-1) + M-1; 41 | partrec = zeros(bufLen,1); 42 | 43 | startidx = ceil(M/2)-1; 44 | idxrange = startidx + [0:floor(M/2),-ceil(M/2)+1:-1]; 45 | for ii=0:N-1 46 | idx = ii*a + idxrange + 1; 47 | partrec(idx) = partrec(idx) + cframes(:,ii+1); 48 | end 49 | 50 | frame = partrec(a*n+1:a*n + M); 51 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/blaslapack.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_blaslapack 2 | #define _ltfat_blaslapack 3 | #include "ltfat.h" 4 | #include "ltfat/types.h" 5 | #include "ltfat/thirdparty/cblas.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | 13 | // LAPACK overwrites the input argument. 14 | ltfat_int 15 | LTFAT_NAME(posv)(const ptrdiff_t N, const ptrdiff_t NRHS, 16 | LTFAT_COMPLEX *A, const ptrdiff_t lda, 17 | LTFAT_COMPLEX *B, const ptrdiff_t ldb); 18 | 19 | // LAPACK overwrites the input argument. 20 | ltfat_int 21 | LTFAT_NAME(gesvd)(const ptrdiff_t M, const ptrdiff_t N, 22 | LTFAT_COMPLEX *A, const ptrdiff_t lda, 23 | LTFAT_REAL *S, LTFAT_COMPLEX *U, const ptrdiff_t ldu, 24 | LTFAT_COMPLEX *VT, const ptrdiff_t ldvt); 25 | 26 | void 27 | LTFAT_NAME(gemm)(const enum CBLAS_TRANSPOSE TransA, 28 | const enum CBLAS_TRANSPOSE TransB, 29 | const ptrdiff_t M, const ptrdiff_t N, const ptrdiff_t K, 30 | const LTFAT_COMPLEX *alpha, 31 | const LTFAT_COMPLEX *A, const ptrdiff_t lda, 32 | const LTFAT_COMPLEX *B, const ptrdiff_t ldb, 33 | const LTFAT_COMPLEX *beta, 34 | LTFAT_COMPLEX *C, const ptrdiff_t ldc); 35 | 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/runner_multiinclude.h: -------------------------------------------------------------------------------- 1 | #define LTFAT_DOUBLE 2 | #include "ltfat/types.h" 3 | #define TEST_NAME(name) name##_d 4 | #define TEST_NAME_COMPLEX(name) name##_dc 5 | 6 | #include "runner_test_typecomplexindependent.c" 7 | #include "runner_test_typeindependent.c" 8 | 9 | #undef TEST_NAME 10 | #undef TEST_NAME_COMPLEX 11 | #undef LTFAT_DOUBLE 12 | 13 | #define LTFAT_SINGLE 14 | #include "ltfat/types.h" 15 | #define TEST_NAME(name) name##_s 16 | #define TEST_NAME_COMPLEX(name) name##_sc 17 | 18 | #include "runner_test_typecomplexindependent.c" 19 | #include "runner_test_typeindependent.c" 20 | 21 | 22 | #undef TEST_NAME 23 | #undef TEST_NAME_COMPLEX 24 | #undef LTFAT_SINGLE 25 | 26 | #define LTFAT_COMPLEXTYPE 27 | 28 | #define LTFAT_DOUBLE 29 | #include "ltfat/types.h" 30 | #define TEST_NAME(name) name##_dc 31 | #define TEST_NAME_COMPLEX(name) name##_dc 32 | 33 | #include "runner_test_typecomplexindependent.c" 34 | 35 | #undef TEST_NAME 36 | #undef TEST_NAME_COMPLEX 37 | #undef LTFAT_DOUBLE 38 | 39 | #define LTFAT_SINGLE 40 | #include "ltfat/types.h" 41 | #define TEST_NAME(name) name##_sc 42 | #define TEST_NAME_COMPLEX(name) name##_sc 43 | 44 | 45 | #include "runner_test_typecomplexindependent.c" 46 | 47 | #undef TEST_NAME 48 | #undef TEST_NAME_COMPLEX 49 | #undef LTFAT_SINGLE 50 | #undef LTFAT_COMPLEXTYPE 51 | 52 | // Unsets all the macros 53 | #include "ltfat/types.h" 54 | -------------------------------------------------------------------------------- /modules/libphaseret/include/phaseret/utils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef LTFAT_NOSYSTEMHEADERS 3 | #include "ltfat.h" 4 | #include "ltfat/types.h" 5 | #endif 6 | #include "phaseret/types.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** Shifts cols of height x N matrix by one to the left 13 | * 14 | * \param[in,o] cols Input/output matrix 15 | * \param[in] height Height 16 | * \param[in] N No. of cols 17 | * \param[in] newcol (optional) Length height vector to be used as the last col. 18 | * If it is NULL, it is set to zeros. 19 | */ 20 | int 21 | PHASERET_NAME(shiftcolsleft)(LTFAT_REAL cols[], ltfat_int height, ltfat_int N, const LTFAT_REAL newcol[]); 22 | 23 | int 24 | PHASERET_NAME_COMPLEX(shiftcolsleft)(LTFAT_COMPLEX cols[], ltfat_int height, ltfat_int N, const LTFAT_COMPLEX newcol[]); 25 | 26 | int 27 | PHASERET_NAME(force_magnitude)(LTFAT_COMPLEX cin[], const LTFAT_REAL s[], ltfat_int L, LTFAT_COMPLEX cout[]); 28 | 29 | void 30 | PHASERET_NAME(realimag2absangle)(const LTFAT_COMPLEX cin[], ltfat_int L, LTFAT_COMPLEX c[]); 31 | 32 | void 33 | PHASERET_NAME(absangle2realimag)(const LTFAT_COMPLEX cin[], ltfat_int L, LTFAT_COMPLEX c[]); 34 | 35 | PHASERET_API void 36 | PHASERET_NAME(absangle2realimag_split2inter)(const LTFAT_REAL s[], 37 | const LTFAT_REAL phase[], ltfat_int L, LTFAT_COMPLEX c[]); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | 44 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/dgt_common.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_DGT_COMMON_H 2 | #define _LTFAT_DGT_COMMON_H 3 | #include "ltfat/basicmacros.h" 4 | /** \addtogroup dgt 5 | * @{ 6 | */ 7 | 8 | /** \name Phase convention 9 | * @{ */ 10 | 11 | /** Discrete Gabor Transform Phase convention 12 | * 13 | * There are two commonly used phase conventions. 14 | * 15 | * Frequency invariant: 16 | * \anchor dgtfreqinv 17 | * \f[ 18 | * c(m,n) 19 | * = \sum_{l=0}^{L-1}\! f(l) 20 | * \overline{g(l-na)} \me^{-\mi 2\pi l m/M } \, 21 | * \f] 22 | * This is commonly used by mathematicans. Effectivelly, each 23 | * frequency channel is demodulated to the baseband. 24 | * 25 | * Time invatiant: 26 | * \anchor dgttimeinv 27 | * \f[ 28 | * c(m,n) 29 | * = \sum_{l=0}^{L-1}\! f(l) 30 | * \overline{g(l-na)} \me^{-\mi 2\pi (l-na) m/M } \, 31 | * \f] 32 | * This is commonly used by engineers. This is equivalent to 33 | * a filterbank. 34 | * 35 | * \see dgt_phaselock dgtreal_phaselock dgt_phaseunlock dgtreal_phaseunlock 36 | * 37 | */ 38 | typedef enum 39 | { 40 | LTFAT_TIMEINV = 0, 41 | LTFAT_FREQINV = 1, 42 | LTFAT_POPULAR = 2 43 | } ltfat_phaseconvention; 44 | 45 | /** @}*/ 46 | /** @}*/ 47 | 48 | #ifdef __cplusplus 49 | extern "C" 50 | { 51 | #endif 52 | 53 | LTFAT_API int 54 | ltfat_phaseconvention_is_valid(ltfat_phaseconvention in); 55 | 56 | #ifdef __cplusplus 57 | } // extern "C" 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /modules/libltfat/doc/texinclude/macros.tex: -------------------------------------------------------------------------------- 1 | 2 | \DeclareMathOperator*{\argmax}{arg\,max} 3 | \DeclareMathOperator*{\supp}{supp} 4 | 5 | \newcommand{\stime}{t} 6 | \newcommand{\stimearg}{\tau} 7 | \newcommand{\sfreq}{\omega} 8 | \newcommand{\sfreqarg}{\xi} 9 | 10 | 11 | \newcommand{\Lspacen}[1]{\ensuremath{L^2\left\mathcal{R}^{#1}\right}} 12 | \newcommand{\Lspace}{\Lspacen{}} 13 | \newcommand{\Lspacetwod}{\Lspacen{2}} 14 | 15 | \newcommand{\barg}{\ensuremath{\mathcal{B}}} 16 | \newcommand{\dstimearg}{\ensuremath{\, \mathrm{d}\stimearg}} 17 | 18 | \newcommand{\modop}{\ensuremath{\mathcal{E}}} 19 | \newcommand{\tranop}{\ensuremath{\mathcal{T}}} 20 | \newcommand{\dilop}{\ensuremath{\mathcal{D}}} 21 | 22 | \newcommand{\modoparg}[1]{\ensuremath{\modop_{#1}}} 23 | \newcommand{\tranoparg}[1]{\ensuremath{\tranop_{#1}}} 24 | \newcommand{\diloparg}[1]{\ensuremath{\dilop_{#1}}} 25 | 26 | \newcommand{\modopsfreq}{\modoparg{\sfreq}} 27 | \newcommand{\tranopstime}{\tranoparg{\stime}} 28 | \newcommand{\diloplambda}{\diloparg{\lambda}} 29 | 30 | \newcommand{\stftphase}[2]{\ensuremath{\Phi_{#1}^{#2}}} 31 | \newcommand{\stftmodulus}[2]{\ensuremath{M_{#1}^{#2}}} 32 | 33 | \newcommand{\stftphasefvarphi}{\stftphase{\varphi}{f}} 34 | \newcommand{\stftmodulusfvarphi}{\stftmodulus{\varphi}{f}} 35 | 36 | \newcommand{\stftphasefg}{\stftphase{g}{f}} 37 | \newcommand{\stftmodulusfg}{\stftmodulus{g}{f}} 38 | 39 | \newcommand{\me}{\mathrm{e}} 40 | \newcommand{\mi}{\mathrm{i}} 41 | 42 | % \newcommand{\normm}[1]{\left\lVert#1\right\rVert} 43 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/texinclude/macros.tex: -------------------------------------------------------------------------------- 1 | 2 | \DeclareMathOperator*{\argmax}{arg\,max} 3 | \DeclareMathOperator*{\supp}{supp} 4 | 5 | \newcommand{\stime}{t} 6 | \newcommand{\stimearg}{\tau} 7 | \newcommand{\sfreq}{\omega} 8 | \newcommand{\sfreqarg}{\xi} 9 | 10 | 11 | \newcommand{\Lspacen}[1]{\ensuremath{L^2\left\mathcal{R}^{#1}\right}} 12 | \newcommand{\Lspace}{\Lspacen{}} 13 | \newcommand{\Lspacetwod}{\Lspacen{2}} 14 | 15 | \newcommand{\barg}{\ensuremath{\mathcal{B}}} 16 | \newcommand{\dstimearg}{\ensuremath{\, \mathrm{d}\stimearg}} 17 | 18 | \newcommand{\modop}{\ensuremath{\mathcal{E}}} 19 | \newcommand{\tranop}{\ensuremath{\mathcal{T}}} 20 | \newcommand{\dilop}{\ensuremath{\mathcal{D}}} 21 | 22 | \newcommand{\modoparg}[1]{\ensuremath{\modop_{#1}}} 23 | \newcommand{\tranoparg}[1]{\ensuremath{\tranop_{#1}}} 24 | \newcommand{\diloparg}[1]{\ensuremath{\dilop_{#1}}} 25 | 26 | \newcommand{\modopsfreq}{\modoparg{\sfreq}} 27 | \newcommand{\tranopstime}{\tranoparg{\stime}} 28 | \newcommand{\diloplambda}{\diloparg{\lambda}} 29 | 30 | \newcommand{\stftphase}[2]{\ensuremath{\Phi_{#1}^{#2}}} 31 | \newcommand{\stftmodulus}[2]{\ensuremath{M_{#1}^{#2}}} 32 | 33 | \newcommand{\stftphasefvarphi}{\stftphase{\varphi}{f}} 34 | \newcommand{\stftmodulusfvarphi}{\stftmodulus{\varphi}{f}} 35 | 36 | \newcommand{\stftphasefg}{\stftphase{g}{f}} 37 | \newcommand{\stftmodulusfg}{\stftmodulus{g}{f}} 38 | 39 | \newcommand{\me}{\mathrm{e}} 40 | \newcommand{\mi}{\mathrm{i}} 41 | 42 | % \newcommand{\normm}[1]{\left\lVert#1\right\rVert} 43 | -------------------------------------------------------------------------------- /modules/libltfat/thirdparty/kissfft/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003-2010 Mark Borgerding 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /modules/libltfat/thirdparty/kissfft/Makefile: -------------------------------------------------------------------------------- 1 | KFVER=130 2 | 3 | doc: 4 | @echo "Start by reading the README file. If you want to build and test lots of stuff, do a 'make testall'" 5 | @echo "but be aware that 'make testall' has dependencies that the basic kissfft software does not." 6 | @echo "It is generally unneeded to run these tests yourself, unless you plan on changing the inner workings" 7 | @echo "of kissfft and would like to make use of its regression tests." 8 | 9 | testall: 10 | # The simd and int32_t types may or may not work on your machine 11 | make -C test DATATYPE=simd CFLAGADD="$(CFLAGADD)" test 12 | make -C test DATATYPE=int32_t CFLAGADD="$(CFLAGADD)" test 13 | make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test 14 | make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test 15 | make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test 16 | echo "all tests passed" 17 | 18 | tarball: clean 19 | hg archive -r v$(KFVER) -t tgz kiss_fft$(KFVER).tar.gz 20 | hg archive -r v$(KFVER) -t zip kiss_fft$(KFVER).zip 21 | 22 | clean: 23 | cd test && make clean 24 | cd tools && make clean 25 | rm -f kiss_fft*.tar.gz *~ *.pyc kiss_fft*.zip 26 | 27 | asm: kiss_fft.s 28 | 29 | kiss_fft.s: kiss_fft.c kiss_fft.h _kiss_fft_guts.h 30 | [ -e kiss_fft.s ] && mv kiss_fft.s kiss_fft.s~ || true 31 | gcc -S kiss_fft.c -O3 -mtune=native -ffast-math -fomit-frame-pointer -unroll-loops -dA -fverbose-asm 32 | gcc -o kiss_fft_short.s -S kiss_fft.c -O3 -mtune=native -ffast-math -fomit-frame-pointer -dA -fverbose-asm -DFIXED_POINT 33 | [ -e kiss_fft.s~ ] && diff kiss_fft.s~ kiss_fft.s || true 34 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/maxtree.h: -------------------------------------------------------------------------------- 1 | // maxtree 2 | 3 | typedef struct LTFAT_NAME(maxtree) LTFAT_NAME(maxtree); 4 | typedef LTFAT_REAL 5 | LTFAT_NAME(maxtree_complexinput_callback)(void* userdata, LTFAT_COMPLEX cval, ltfat_int pos); 6 | 7 | LTFAT_API int 8 | LTFAT_NAME(maxtree_setcallback)(LTFAT_NAME(maxtree)* p, 9 | LTFAT_NAME(maxtree_complexinput_callback)* callback, 10 | void* userdata); 11 | 12 | LTFAT_API int 13 | LTFAT_NAME(maxtree_init)( 14 | ltfat_int L, ltfat_int Lstep, ltfat_int depth, 15 | LTFAT_NAME(maxtree)** p); 16 | 17 | 18 | LTFAT_API int 19 | LTFAT_NAME(maxtree_initwitharray)( 20 | ltfat_int L, ltfat_int depth, const LTFAT_REAL inarray[], 21 | LTFAT_NAME(maxtree)** p); 22 | 23 | LTFAT_API int 24 | LTFAT_NAME(maxtree_reset)( 25 | LTFAT_NAME(maxtree)* p, const LTFAT_REAL inarray[]); 26 | 27 | LTFAT_API int 28 | LTFAT_NAME(maxtree_reset_complex)( 29 | LTFAT_NAME(maxtree)* p, const LTFAT_COMPLEX inarray[]); 30 | 31 | LTFAT_API int 32 | LTFAT_NAME(maxtree_setdirty)( 33 | LTFAT_NAME(maxtree)* p, ltfat_int start, ltfat_int end); 34 | 35 | LTFAT_API int 36 | LTFAT_NAME(maxtree_getdirty)( 37 | LTFAT_NAME(maxtree)* p, ltfat_int* start, ltfat_int* end); 38 | 39 | LTFAT_API int 40 | LTFAT_NAME(maxtree_findmax)( 41 | LTFAT_NAME(maxtree)* p, LTFAT_REAL* max, ltfat_int* maxPos); 42 | 43 | LTFAT_API int 44 | LTFAT_NAME(maxtree_done)(LTFAT_NAME(maxtree)** p); 45 | 46 | int 47 | LTFAT_NAME(maxtree_updatedirty)(LTFAT_NAME(maxtree)* p); 48 | 49 | int 50 | LTFAT_NAME(maxtree_updaterange)( 51 | LTFAT_NAME(maxtree)* p, ltfat_int start, ltfat_int stop); 52 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_fifo.m: -------------------------------------------------------------------------------- 1 | function test_libltfat_fifo 2 | gl = 20; 3 | fifoLen = 120; % Must be at least as big as gl + max expected bufLen 4 | M = gl; 5 | a = 7; 6 | g = firwin('hann',gl); 7 | gd = gabdual(g,a,M); 8 | gg = fftshift(g.*gd)*M; 9 | 10 | fifoPtr = calllib('libltfat','rtdgtreal_fifo_init_d',fifoLen,gl,a,1); 11 | fifoPtr.Value.buf.setdatatype('doublePtr',fifoLen+1) 12 | ififoPtr = calllib('libltfat','rtidgtreal_fifo_init_d',fifoLen,gl,a,1); 13 | ififoPtr.Value.buf.setdatatype('doublePtr',fifoLen+gl+1) 14 | 15 | bufIn = (1:1000)'; 16 | %bufIn = ones(1,1000); 17 | bufOut = zeros(size(bufIn)); 18 | bufLen = 100; 19 | bufOutPtr = libpointer('doublePtr',zeros(gl,1)); 20 | 21 | for ii=1:length(bufIn)/bufLen 22 | slice = (ii-1)*bufLen + 1 : ii*bufLen; 23 | buf = bufIn(slice); 24 | bufInPtr = libpointer('doublePtr',buf); 25 | bufInPtrTmp = libpointer('doublePtr',zeros(size(buf))); 26 | 27 | written = calllib('libltfat','rtdgtreal_fifo_write_d',fifoPtr,bufLen,bufInPtr); 28 | 29 | while calllib('libltfat','rtdgtreal_fifo_read_d',fifoPtr,bufOutPtr) > 0 30 | bufOutPtr.Value = bufOutPtr.Value.*gg; 31 | written = calllib('libltfat','rtidgtreal_fifo_write_d',ififoPtr,bufOutPtr) 32 | end 33 | 34 | read = calllib('libltfat','rtidgtreal_fifo_read_d',ififoPtr,bufLen,bufInPtrTmp) 35 | 36 | bufOut(slice) = bufInPtrTmp.Value; 37 | 38 | end 39 | 40 | inshift = circshift(bufIn,(gl-1)); 41 | inshift(1:(gl-1)) = 0; 42 | stem([bufOut, inshift]);shg; 43 | 44 | 45 | 46 | 47 | calllib('libltfat','rtdgtreal_fifo_done_d',fifoPtr); 48 | calllib('libltfat','rtidgtreal_fifo_done_d',ififoPtr); 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 8 | TEST_NAME(fillRand)(fin, L[lId]); 9 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 10 | TEST_NAME(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME(fftshift)(fin, L[lId], fout) == 0, 13 | "fftshift"); 14 | mu_assert( LTFAT_NAME(fftshift)(fin, L[lId], fin) == 0, 15 | "fftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 22 | TEST_NAME(fillRand)(fin, L[0]); 23 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 24 | TEST_NAME(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME(fftshift)(NULL, L[0], fin) == LTFATERR_NULLPOINTER, 29 | "First is null"); 30 | mu_assert( LTFAT_NAME(fftshift)(fin, L[0], NULL) == LTFATERR_NULLPOINTER, 31 | "Last is null"); 32 | mu_assert( LTFAT_NAME(fftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME(fftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | 37 | mu_assert( LTFAT_NAME(fftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 38 | "Multiple wrong inputs"); 39 | 40 | 41 | ltfat_free(fin); 42 | ltfat_free(fout); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_libphaseret_gsrtisilapghi.m: -------------------------------------------------------------------------------- 1 | f = gspi; 2 | a = 128; 3 | M = 2048; 4 | M2 = floor(M/2) + 1; 5 | gl = 2048; 6 | L = dgtlength(numel(f),a,M); 7 | g = firwin('hann',gl); 8 | gamma = 0.25645*gl^2; 9 | gd = long2fir(gabdual(g,a,M),gl); 10 | N = L/a; 11 | lookahead = 7; 12 | maxit = 1; 13 | 14 | corig = dgtreal(f,{'hann',gl},a,M,'timeinv'); 15 | s = abs(corig); 16 | 17 | cout = zeros(2*M2,N); 18 | coutPtr = libpointer('doublePtr',cout); 19 | 20 | coutsingle = zeros(2*M2,N,'single'); 21 | coutsinglePtr = libpointer('singlePtr',coutsingle); 22 | 23 | tic 24 | calllib('libphaseret','phaseret_gsrtisilapghioffline_d',s,g,L,gl,0,a,M,lookahead,maxit,... 25 | gamma, 1e-6, 0, coutPtr); 26 | toc 27 | 28 | coutsingle = zeros(2*M2,N,'single'); 29 | coutsinglePtr = libpointer('singlePtr',coutsingle); 30 | ssingle = cast(s,'single'); 31 | 32 | tic 33 | calllib('libphaseret','phaseret_gsrtisilapghioffline_s',ssingle,cast(g,'single'),L,gl,1,a,M,lookahead,maxit,... 34 | gamma, 1e-6, 0, coutsinglePtr); 35 | toc 36 | 37 | coutsingle2 = interleaved2complex(coutsinglePtr.Value); 38 | cout2 = interleaved2complex(coutPtr.Value); 39 | 40 | frec = idgtreal(coutsingle2,{'dual',{'hann',gl}},a,M,'timeinv'); 41 | 42 | s2 = abs(dgtreal(frec,{'hann',gl},a,M,'timeinv')); 43 | magnitudeerrdb(s,s2) 44 | 45 | 46 | 47 | c=gsrtisila(s,g,a,M,'lookahead',lookahead,'maxit',maxit,'timeinv','rtpghi',{gamma}); 48 | 49 | frec = idgtreal(c,{'dual',{'hann',gl}},a,M,'timeinv'); 50 | s3 = abs(dgtreal(frec,{'hann',gl},a,M,'timeinv')); 51 | magnitudeerrdb(s,s3) 52 | 53 | 54 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_ifftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_ifftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 8 | TEST_NAME(fillRand)(fin, L[lId]); 9 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 10 | TEST_NAME(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME(ifftshift)(fin, L[lId], fout) == 0, 13 | "fftshift"); 14 | mu_assert( LTFAT_NAME(ifftshift)(fin, L[lId], fin) == 0, 15 | "fftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 22 | TEST_NAME(fillRand)(fin, L[0]); 23 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 24 | TEST_NAME(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME(ifftshift)(NULL, L[0], fin) == LTFATERR_NULLPOINTER, 29 | "First is null"); 30 | mu_assert( LTFAT_NAME(ifftshift)(fin, L[0], NULL) == LTFATERR_NULLPOINTER, 31 | "Last is null"); 32 | mu_assert( LTFAT_NAME(ifftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME(ifftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | 37 | mu_assert( LTFAT_NAME(ifftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 38 | "Multiple wrong inputs"); 39 | 40 | 41 | ltfat_free(fin); 42 | ltfat_free(fout); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/dgt_shear.h: -------------------------------------------------------------------------------- 1 | typedef struct 2 | { 3 | ltfat_int a; 4 | ltfat_int M; 5 | ltfat_int L; 6 | ltfat_int W; 7 | ltfat_int s0; 8 | ltfat_int s1; 9 | ltfat_int br; 10 | 11 | LTFAT_COMPLEX *p0; 12 | LTFAT_COMPLEX *p1; 13 | 14 | LTFAT_COMPLEX *fwork; 15 | LTFAT_COMPLEX *gwork; 16 | LTFAT_COMPLEX *c_rect; 17 | 18 | LTFAT_COMPLEX *finalmod; 19 | 20 | // LTFAT_FFTW(plan) f_plan; 21 | // LTFAT_FFTW(plan) g_plan; 22 | LTFAT_NAME_REAL(fft_plan)* f_plan; 23 | LTFAT_NAME_REAL(fft_plan)* g_plan; 24 | 25 | 26 | LTFAT_NAME_COMPLEX(dgt_long_plan)* rect_plan; 27 | 28 | const LTFAT_COMPLEX *f; 29 | LTFAT_COMPLEX *cout; 30 | 31 | } LTFAT_NAME(dgt_shear_plan); 32 | 33 | 34 | LTFAT_API LTFAT_NAME(dgt_shear_plan) 35 | LTFAT_NAME(dgt_shear_init)( 36 | const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 37 | ltfat_int L, ltfat_int W, ltfat_int a, 38 | ltfat_int M, ltfat_int s0, ltfat_int s1, ltfat_int br, 39 | LTFAT_COMPLEX *cout, 40 | unsigned flags); 41 | 42 | LTFAT_API void 43 | LTFAT_NAME(dgt_shear_execute)(const LTFAT_NAME(dgt_shear_plan) plan); 44 | 45 | LTFAT_API void 46 | LTFAT_NAME(dgt_shear_done)(LTFAT_NAME(dgt_shear_plan) plan); 47 | 48 | LTFAT_API void 49 | LTFAT_NAME(dgt_shear)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 50 | ltfat_int L, ltfat_int W, ltfat_int a, ltfat_int M, 51 | ltfat_int s0, ltfat_int s1, ltfat_int br, 52 | LTFAT_COMPLEX *c); 53 | 54 | LTFAT_API void 55 | LTFAT_NAME(pchirp)(const long long L, const long long n, LTFAT_COMPLEX *g); 56 | -------------------------------------------------------------------------------- /modules/libltfat/src/reassign_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/macros.h" 3 | 4 | LTFAT_API fbreassOptOut* 5 | fbreassOptOut_init(ltfat_int l, ltfat_int inital) 6 | { 7 | fbreassOptOut* ret = (fbreassOptOut*) ltfat_calloc( 1, sizeof * ret); 8 | ret->l = l; 9 | // This is an array of pointers. 10 | ret->repos = (ltfat_int**) ltfat_malloc(l * sizeof * ret->repos); 11 | ret->reposl = (ltfat_int*) ltfat_calloc(l , sizeof * ret->reposl); 12 | ret->reposlmax = (ltfat_int*) ltfat_malloc(l * sizeof * ret->reposlmax); 13 | ltfat_int inital2 = ltfat_imax(1, inital); 14 | for (ltfat_int ii = 0; ii < l; ii++) 15 | { 16 | ret->repos[ii] = (ltfat_int*) ltfat_malloc( inital2 * sizeof * ret->repos[ii]); 17 | ret->reposlmax[ii] = inital2; 18 | } 19 | 20 | return ret; 21 | } 22 | 23 | LTFAT_API void 24 | fbreassOptOut_destroy(fbreassOptOut* oo) 25 | { 26 | 27 | for (ltfat_int ii = 0; ii < oo->l; ii++) 28 | { 29 | if (oo->repos[ii] && oo->reposlmax[ii] > 0) 30 | { 31 | ltfat_free(oo->repos[ii]); 32 | } 33 | } 34 | 35 | LTFAT_SAFEFREEALL(oo->repos, oo->reposl, oo->reposlmax, oo); 36 | oo = NULL; 37 | } 38 | 39 | LTFAT_API void 40 | fbreassOptOut_expand(fbreassOptOut* oo, ltfat_int ii) 41 | { 42 | ltfat_int explmax = (ltfat_int) (fbreassOptOut_EXPANDRAT * oo->reposlmax[ii]); 43 | oo->repos[ii] = (ltfat_int*) ltfat_realloc( (void*) oo->repos[ii], 44 | oo->reposlmax[ii] * sizeof * oo->repos[ii], 45 | explmax * sizeof * oo->repos[ii]); 46 | oo->reposlmax[ii] = explmax; 47 | } 48 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/rtpghi.md: -------------------------------------------------------------------------------- 1 | \defgroup rtpghi Real-Time Phase Gradient Heap Integration 2 | \addtogroup rtpghi 3 | 4 | Algorithm Description 5 | --------------------- 6 | 7 | The implementation follows paper \cite ltfatnote043 8 | 9 | The \a gamma parameter for a window \f$ g\f$ can be computed as 10 | \f[ 11 | \gamma = C_g (\mathit{gl})^2 12 | \f] 13 | where \a gl is a window length. 14 | 15 | FIR window | \f$ C_g \f$ 16 | ---------------------------------------------|-------------- 17 | LTFAT_HANN, LTFAT_HANNING, NUTTALL10 | 0.25645 18 | LTFAT_SQRTHANN, LTFAT_COSINE, LTFAT_SINE | 0.41532 19 | LTFAT_HAMMING | 0.29794 20 | LTFAT_NUTTALL01 | 0.29610 21 | LTFAT_TRIA, LTFAT_TRIANGULAR, LTFAT_BARTLETT | 0.27561 22 | LTFAT_SQRTTRIA | 0.48068 23 | LTFAT_BLACKMAN | 0.17954 24 | LTFAT_BLACKMAN2 | 0.18465 25 | LTFAT_NUTTALL, LTFAT_NUTTALL12 | 0.12807 26 | LTFAT_OGG, LTFAT_ITERSINE | 0.35744 27 | LTFAT_NUTTALL20 | 0.14315 28 | LTFAT_NUTTALL11 | 0.17001 29 | LTFAT_NUTTALL02 | 0.18284 30 | LTFAT_NUTTALL30 | 0.09895 31 | LTFAT_NUTTALL21 | 0.11636 32 | LTFAT_NUTTALL03 | 0.13369 33 | 34 | For \gamma for a Gaussian window please see \cite ltfatnote043 35 | 36 | The Gaussian window will give the best result. 37 | LTFAT_BLACKMAN is also a good choice. 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /modules/libltfat/src/circularbuf_private.h: -------------------------------------------------------------------------------- 1 | #ifndef _circularbuf_private_h 2 | #define _circularbuf_private_h 3 | 4 | struct LTFAT_NAME(analysis_fifo_state) 5 | { 6 | ltfat_int winLen; //!< Window length 7 | ltfat_int readchanstride; //!< Window length 8 | ltfat_int hop; //!< Hop size 9 | LTFAT_REAL* buf; //!< Ring buffer array 10 | ltfat_int bufLen; //!< Length of the previous 11 | ltfat_int readIdx; //!< Read pos. 12 | ltfat_int writeIdx; //!< Write pos. 13 | ltfat_int numChans; 14 | }; 15 | 16 | struct LTFAT_NAME(synthesis_fifo_state) 17 | { 18 | ltfat_int winLen; //!< Window length 19 | ltfat_int writechanstride; //!< Window length 20 | ltfat_int hop; //!< Hop size 21 | LTFAT_REAL* buf; //!< Ring buffer array 22 | ltfat_int bufLen; //!< Length of the previous 23 | ltfat_int readIdx; //!< Read pos. 24 | ltfat_int writeIdx; //!< Write pos. 25 | ltfat_int numChans; 26 | }; 27 | 28 | struct LTFAT_NAME(block_processor_state) 29 | { 30 | LTFAT_NAME(block_processor_callback)* 31 | processorCallback; //!< Custom processor callback 32 | void* userdata; //!< Callback data 33 | LTFAT_NAME(analysis_fifo_state)* fwdfifo; 34 | LTFAT_NAME(synthesis_fifo_state)* backfifo; 35 | ltfat_int bufLenMax; 36 | LTFAT_REAL* prebuf; 37 | LTFAT_REAL* postbuf; 38 | LTFAT_REAL* prewin; 39 | LTFAT_REAL* postwin; 40 | int freeBuffers; 41 | const LTFAT_REAL** inTmp; 42 | LTFAT_REAL** outTmp; 43 | size_t in_pos; 44 | size_t out_pos; 45 | double in_in_out_offset; 46 | double out_in_in_offset; 47 | ltfat_int prehop; 48 | ltfat_int posthop; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LIBLTFAT -- Backend library of LTFAT 2 | ------------------------------------ 3 | 4 | This is a standalone backend library of LTFAT. 5 | 6 | Dependencies 7 | ------------ 8 | 9 | The library depends on FFTW, BLAS and LAPACK. On Ubuntu, just run 10 | ``` 11 | sudo apt-get install libfftw3-dev libblas-dev liblapack-dev 12 | ``` 13 | followed by 14 | ``` 15 | make 16 | sudo make install PREFIX=/usr/local 17 | ``` 18 | 19 | You might also need to run 20 | ``` 21 | sudo ldconfig 22 | ``` 23 | to make the just installed library accesible. 24 | 25 | Building with MAKE (Linux) 26 | -------------------------- 27 | 28 | There are three target libraries (static and shared versions) 29 | * build/libltfat.a(.so) Contains double and single prec. versions of the functions 30 | * build/libltfatd.a(.so) Just double prec. versions of the functions 31 | * build/libltfatf.a(.so) Just single prec. versions of the functions 32 | 33 | The dependency on BLAS and LAPACK can be disabled by calling 34 | ``` 35 | make NOBLASLAPACK=1 36 | ``` 37 | 38 | The dependency on FFTW can be disabled by calling 39 | ``` 40 | make FFTBACKEND=KISS 41 | ``` 42 | The internal [KISS FFT](http://kissfft.sourceforge.net/) implementation will be used. 43 | 44 | Building with CMAKE (Linux, Windows) 45 | ------------------------------------ 46 | 47 | By default, cmake is configured as if `NOBLASLAPACK=1` and `FFTBACKEND=KISS` were set such 48 | that libltfat is standalone (except for the libm dependency). 49 | 50 | Documentation 51 | ------------- 52 | 53 | Doxygen generated documentation is available [here](http://ltfat.github.io/libltfat). 54 | 55 | Contacts 56 | -------- 57 | 58 | libltfat was written by Peter L. Søndergaard and Zdeněk Průša. 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_firwin.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_firwin)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | LTFAT_FIRWIN win[] = { LTFAT_HANN, LTFAT_HANNING, LTFAT_NUTTALL10, LTFAT_SQRTHANN, 5 | LTFAT_COSINE, LTFAT_SINE, LTFAT_HAMMING, LTFAT_NUTTALL01, 6 | LTFAT_SQUARE, LTFAT_RECT, LTFAT_TRIA, LTFAT_TRIANGULAR, 7 | LTFAT_BARTLETT, LTFAT_SQRTTRIA, LTFAT_BLACKMAN, LTFAT_BLACKMAN2, 8 | LTFAT_NUTTALL, LTFAT_NUTTALL12, LTFAT_OGG, LTFAT_ITERSINE, 9 | LTFAT_NUTTALL20, LTFAT_NUTTALL11, LTFAT_NUTTALL02, LTFAT_NUTTALL30, 10 | LTFAT_NUTTALL21, LTFAT_NUTTALL03 11 | }; 12 | 13 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 14 | { 15 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 16 | TEST_NAME(fillRand)(fin, L[lId]); 17 | 18 | 19 | for (unsigned int nId = 0; nId < ARRAYLEN(win); nId++) 20 | { 21 | mu_assert( LTFAT_NAME(firwin)( win[nId], L[lId], fin) == LTFATERR_SUCCESS, 22 | "firwin"); 23 | } 24 | 25 | ltfat_free(fin); 26 | } 27 | 28 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 29 | TEST_NAME(fillRand)(fin, L[0]); 30 | 31 | mu_assert( LTFAT_NAME(firwin)( win[0], L[0], NULL) == LTFATERR_NULLPOINTER, 32 | "Array is null"); 33 | 34 | mu_assert( LTFAT_NAME(firwin)( win[0], 0, fin) == LTFATERR_BADSIZE, 35 | "gl is wrong"); 36 | 37 | mu_assert( LTFAT_NAME(firwin)( 9999, L[0], fin) == LTFATERR_CANNOTHAPPEN, 38 | "Wrong enum value"); 39 | 40 | ltfat_free(fin); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/version.h: -------------------------------------------------------------------------------- 1 | /** \defgroup version Version 2 | * 3 | * Utility functions and constants for checking compatibility 4 | * of the library and the header. 5 | * 6 | * \addtogroup version 7 | * @{ 8 | */ 9 | #ifndef _LTFAT_VERSION_H 10 | #define _LTFAT_VERSION_H 11 | 12 | #define LTFAT_VERSION_MAJOR 0 13 | #define LTFAT_VERSION_MINOR 1 14 | #define LTFAT_VERSION_MICRO 0 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | typedef struct 22 | { 23 | const char* version; 24 | const char* build_date; 25 | const unsigned int major; 26 | const unsigned int minor; 27 | const unsigned int micro; 28 | const int ltfat_int_size; 29 | } ltfat_library_version; 30 | 31 | /** \returns Pointer to an internal library version struct 32 | * (no memory allocation occurs). 33 | */ 34 | LTFAT_API const ltfat_library_version* 35 | ltfat_get_version(); 36 | 37 | /** \returns 0 if passed version number is not compatible with 38 | * the binary version. 39 | * To check the compatibility of your version of ltfat.h with the library 40 | * pass LTFAT_VERSION_MAJOR, LTFAT_VERSION_MINOR and LTFAT_VERSION_MICRO. 41 | */ 42 | LTFAT_API int 43 | ltfat_is_compatible_version(unsigned int your_major, 44 | unsigned int your_minor, 45 | unsigned int your_micro); 46 | 47 | /** \returns Size of ltfat_int used in compilation 48 | */ 49 | LTFAT_API int 50 | ltfat_int_size(); 51 | 52 | /** \returns 0 if \t sizeofyour_ltfat_int is not equal to 53 | * sizeof(ltfat_int) used in compilation. 54 | */ 55 | LTFAT_API int 56 | ltfat_int_is_compatible(int sizeofyour_ltfat_int); 57 | 58 | /** @} */ 59 | 60 | #ifdef __cplusplus 61 | } // extern "C" 62 | #endif 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftfftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftfftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, L[lId], fout) == 0, 13 | "fftfftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, L[lId], fin) == 0, 15 | "fftfftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftfftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftifftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftifftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, L[lId], fout) == 0, 13 | "fftifftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, L[lId], fin) == 0, 15 | "fftifftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftifftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftrealfftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftrealfftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, L[lId], fout) == 0, 13 | "fftrealfftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, L[lId], fin) == 0, 15 | "fftrealfftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftrealfftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftrealifftshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftrealifftshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 8 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 9 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 10 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 11 | 12 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, L[lId], fout) == 0, 13 | "fftrealifftshift"); 14 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, L[lId], fin) == 0, 15 | "fftrealifftshift inplace"); 16 | 17 | ltfat_free(fin); 18 | ltfat_free(fout); 19 | } 20 | 21 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 22 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 23 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 24 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 25 | 26 | 27 | // Inputs can be checked only once 28 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(NULL, L[0], 29 | fin) == LTFATERR_NULLPOINTER, "First is null"); 30 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, L[0], 31 | NULL) == LTFATERR_NULLPOINTER, "Last is null"); 32 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, 0, fout) == LTFATERR_BADSIZE, 33 | "Zero length"); 34 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(fin, -1, fout) == LTFATERR_BADSIZE, 35 | "Negative length"); 36 | mu_assert( LTFAT_NAME_COMPLEX(fftrealifftshift)(NULL, -1, fout) < LTFATERR_SUCCESS, 37 | "Multiple wrong inputs"); 38 | 39 | 40 | ltfat_free(fin); 41 | ltfat_free(fout); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /modules/libltfat/src/fbheapint_private.h: -------------------------------------------------------------------------------- 1 | void 2 | LTFAT_NAME(borderstoheapneighs)(struct LTFAT_NAME(heap)* h, 3 | ltfat_int Nsum, const ltfat_int neighs[], int* donemask); 4 | /* Filter bank heap integration (uniform case)*/ 5 | inline void 6 | LTFAT_NAME(trapezheap_ufb)(const struct LTFAT_NAME(heapinttask) *heaptask, 7 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 8 | const LTFAT_REAL* cfreq, 9 | ltfat_int w, LTFAT_REAL* phase); 10 | inline void 11 | LTFAT_NAME(trapezheapreal_ufb)(const struct LTFAT_NAME(heapinttask) *heaptask, 12 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 13 | const LTFAT_REAL* cfreq, 14 | ltfat_int w, LTFAT_REAL* phase); 15 | void 16 | LTFAT_NAME(gradsamptorad_ufb)(const LTFAT_REAL* tgrad, const LTFAT_REAL* fgrad, 17 | const LTFAT_REAL* cfreq, 18 | ltfat_int a, ltfat_int M, ltfat_int L, ltfat_int W, 19 | LTFAT_REAL* tgradw, LTFAT_REAL* fgradw); 20 | /* Filter bank heap integration (general case)*/ 21 | void LTFAT_NAME(trapezheap_fb)(const struct LTFAT_NAME(heapinttask_fb) *fbhit, 22 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 23 | ltfat_int w, LTFAT_REAL* phase); 24 | void 25 | LTFAT_NAME(gradsamptorad_fb)(const LTFAT_REAL* tgrad, const LTFAT_REAL* fgrad, 26 | const LTFAT_REAL* cfreq, 27 | ltfat_int M, 28 | const ltfat_int N[], ltfat_int Nsum, 29 | ltfat_int W, 30 | LTFAT_REAL* tgradw, LTFAT_REAL* fgradw); 31 | -------------------------------------------------------------------------------- /modules/libphaseret/src/pghi_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "phaseret/rtpghi.h" 2 | 3 | PHASERET_API double 4 | phaseret_firwin2gamma(LTFAT_FIRWIN win, ltfat_int gl) 5 | { 6 | double gamma; 7 | if ( gl <= 0) return NAN; 8 | 9 | switch (win) 10 | { 11 | case LTFAT_HANN: 12 | /* case LTFAT_HANNING: */ 13 | /* case LTFAT_NUTTALL10: */ 14 | gamma = 0.25645; break; 15 | case LTFAT_SQRTHANN: 16 | /* case LTFAT_COSINE: */ 17 | /* case LTFAT_SINE: */ 18 | gamma = 0.41532; break; 19 | case LTFAT_HAMMING: 20 | gamma = 0.29794; break; 21 | case LTFAT_NUTTALL01: 22 | gamma = 0.29610; break; 23 | case LTFAT_SQUARE: 24 | /* case LTFAT_RECT: */ 25 | gamma = 0.85732; break; 26 | case LTFAT_TRIA: 27 | /* case LTFAT_TRIANGULAR: */ 28 | /* case LTFAT_BARTLETT: */ 29 | gamma = 0.27561; break; 30 | case LTFAT_SQRTTRIA: 31 | gamma = 0.48068; break; 32 | case LTFAT_BLACKMAN: 33 | gamma = 0.17954; break; 34 | case LTFAT_BLACKMAN2: 35 | gamma = 0.18465; break; 36 | case LTFAT_NUTTALL: 37 | /* case LTFAT_NUTTALL12: */ 38 | gamma = 0.12807; break; 39 | case LTFAT_OGG: 40 | /* case LTFAT_ITERSINE: */ 41 | gamma = 0.35744; break; 42 | case LTFAT_NUTTALL20: 43 | gamma = 0.14315; break; 44 | case LTFAT_NUTTALL11: 45 | gamma = 0.17001; break; 46 | case LTFAT_NUTTALL02: 47 | gamma = 0.18284; break; 48 | case LTFAT_NUTTALL30: 49 | gamma = 0.09895; break; 50 | case LTFAT_NUTTALL21: 51 | gamma = 0.11636; break; 52 | case LTFAT_NUTTALL03: 53 | gamma = 0.13369; break; 54 | case LTFAT_TRUNCGAUSS01: 55 | gamma = 0.17054704423023; break; 56 | default: 57 | return NAN; 58 | }; 59 | 60 | gamma *= gl * gl; 61 | 62 | return gamma; 63 | } 64 | -------------------------------------------------------------------------------- /modules/libltfat/src/error.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/errno.h" 3 | #include "ltfat/macros.h" 4 | #include "stdarg.h" 5 | 6 | /* Global custom error handler */ 7 | ltfat_error_handler_t* ltfat_error_handler = NULL; 8 | 9 | static void 10 | no_error_handler ( int UNUSED(ltfat_errno), const char* UNUSED(file), 11 | int UNUSED(line), const char* UNUSED(funcname), 12 | const char* UNUSED(reason) ) {} 13 | 14 | LTFAT_API void 15 | ltfat_error (int ltfat_errno, const char* file, int line, 16 | const char* funcname, const char* format, ...) 17 | { 18 | // Shortcut when no_error_handler is used 19 | if (ltfat_error_handler && ltfat_error_handler == no_error_handler ) 20 | return; 21 | 22 | // Print to a string 23 | char reason[500] = {0}; 24 | 25 | va_list ap; 26 | va_start (ap, format); 27 | vsnprintf(reason, 500, format, ap ); 28 | va_end(ap); 29 | 30 | // Call the registered error handler or do the default behavior 31 | if (ltfat_error_handler) 32 | { 33 | (*ltfat_error_handler) (ltfat_errno, file, line, funcname, reason ); 34 | } 35 | else 36 | { 37 | fprintf (stderr, "[ERROR %d]: (%s:%d): [%s]: %s\n", -ltfat_errno, file, line, 38 | funcname, reason); 39 | 40 | fflush (stderr); 41 | } 42 | } 43 | 44 | LTFAT_API ltfat_error_handler_t* 45 | ltfat_set_error_handler (ltfat_error_handler_t* new_handler) 46 | { 47 | ltfat_error_handler_t* previous_handler = ltfat_error_handler; 48 | ltfat_error_handler = new_handler; 49 | return previous_handler; 50 | } 51 | 52 | LTFAT_API ltfat_error_handler_t* 53 | ltfat_set_error_handler_off (void) 54 | { 55 | ltfat_error_handler_t* previous_handler = ltfat_error_handler; 56 | ltfat_error_handler = no_error_handler; 57 | return previous_handler; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /modules/libltfat/src/filedefs.mk: -------------------------------------------------------------------------------- 1 | files = dgt.c dgtreal_fb.c dgt_multi.c dgt_ola.c dgt_shear.c \ 2 | dgtreal_long.c dwilt.c idwilt.c wmdct.c iwmdct.c \ 3 | filterbank.c ifilterbank.c heapint.c heap.c wfacreal.c \ 4 | idgtreal_long.c idgtreal_fb.c iwfacreal.c pfilt.c reassign_ti.c \ 5 | windows.c \ 6 | dgt_shearola.c utils.c rtdgtreal.c circularbuf.c slicingbuf.c \ 7 | dgtrealwrapper.c dgtrealmp.c dgtrealmp_parbuf.c dgtrealmp_kernel.c dgtrealmp_guts.c maxtree.c \ 8 | slidgtrealmp.c \ 9 | filterbankphaseret.c fbheapint.c 10 | 11 | files_complextransp =\ 12 | ci_utils.c ci_windows.c spread.c wavelets.c goertzel.c \ 13 | reassign.c gabdual_painless.c wfac.c iwfac.c \ 14 | dgt_long.c idgt_long.c dgt_fb.c idgt_fb.c ci_memalloc.c \ 15 | dgtwrapper.c 16 | 17 | files_blaslapack = ltfat_blaslapack.c gabdual_fac.c gabtight_fac.c 18 | 19 | files_blaslapack_complextransp = gabdual.c gabtight.c 20 | 21 | files_fftw_complextransp = dct.c dst.c 22 | 23 | files_notypechange = memalloc.c error.c version.c argchecks.c \ 24 | dgtwrapper_typeconstant.c dgtrealmp_typeconstant.c \ 25 | reassign_typeconstant.c wavelets_typeconstant.c \ 26 | integer_manip.c firwin_typeconstant.c 27 | 28 | FFTBACKEND ?= FFTW 29 | 30 | ifneq ($(FFTBACKEND),FFTW) 31 | ifneq ($(FFTBACKEND),KISS) 32 | $(error FFTBACKEND must be either FFTW or KISS) 33 | endif 34 | endif 35 | 36 | ifeq ($(FFTBACKEND),FFTW) 37 | files += fftw_wrappers.c 38 | files_complextransp += $(files_fftw_complextransp) 39 | LFLAGS+= $(FFTWLIBS) 40 | CFLAGS+=-DFFTW 41 | endif 42 | 43 | ifeq ($(FFTBACKEND),KISS) 44 | files += kissfft_wrappers.c kiss_fft.c 45 | CFLAGS+=-DKISS 46 | endif 47 | 48 | ifndef NOBLASLAPACK 49 | files += $(files_blaslapack) 50 | files_complextransp += $(files_blaslapack_complextransp) 51 | LFLAGS+=$(BLASLAPACKLIBS) 52 | endif 53 | 54 | extradepincludes:=\#include \n 55 | 56 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_circshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_circshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 7 | { 8 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 9 | TEST_NAME(fillRand)(fin, L[lId]); 10 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 11 | TEST_NAME(fillRand)(fout, L[lId]); 12 | 13 | for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) 14 | { 15 | mu_assert( LTFAT_NAME(circshift)(fin, L[lId], shift[shiftId], fout) == 0, 16 | "circshift"); 17 | mu_assert( LTFAT_NAME(circshift)(fin, L[lId], shift[shiftId], fin) == 0, 18 | "circshift inplace"); 19 | } 20 | ltfat_free(fin); 21 | ltfat_free(fout); 22 | } 23 | 24 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 25 | TEST_NAME(fillRand)(fin, L[0]); 26 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 27 | TEST_NAME(fillRand)(fout, L[0]); 28 | 29 | 30 | // Inputs can be checked only once 31 | mu_assert( LTFAT_NAME(circshift)(NULL, L[0], shift[0], fin) == LTFATERR_NULLPOINTER, 32 | "First is null"); 33 | mu_assert( LTFAT_NAME(circshift)(fin, L[0], shift[0], NULL) == LTFATERR_NULLPOINTER, 34 | "Last is null"); 35 | mu_assert( LTFAT_NAME(circshift)(fin, 0, shift[0], fout) == LTFATERR_BADSIZE, 36 | "Zero length"); 37 | mu_assert( LTFAT_NAME(circshift)(fin, -1, shift[0], fout) == LTFATERR_BADSIZE, 38 | "Negative length"); 39 | 40 | mu_assert( LTFAT_NAME(circshift)(NULL, -1, shift[0], fout) < LTFATERR_SUCCESS, 41 | "Multiple wrong inputs"); 42 | 43 | 44 | ltfat_free(fin); 45 | ltfat_free(fout); 46 | return 0; 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_solvehermitiansystem.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_solvehermitiansystem(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [301, 9,11,110, 9, 8, 11, 10, 301]; 11 | 12 | 13 | complexstring = 'complex'; 14 | funname_init = makelibraryname('hermsystemsolver_init',flags.complexity,1); 15 | funname_execute = makelibraryname('hermsystemsolver_execute',flags.complexity,1); 16 | funname_done = makelibraryname('hermsystemsolver_done',flags.complexity,1); 17 | 18 | p = libpointer(); 19 | calllib('libltfat',funname_init,max(Larr),p); 20 | 21 | for Lidx = 1:numel(Larr) 22 | L = Larr(Lidx); 23 | 24 | 25 | 26 | 27 | 28 | D = randn(L,flags.complexity)+1i*randn(L,flags.complexity); 29 | % D(:,1) = D(:,end); 30 | A = D*D'; 31 | Amessedup = A; 32 | for n=2:size(A,2) 33 | for m=1:n-1 34 | Amessedup(m,n) = randn(1); 35 | end 36 | end 37 | Aint = complex2interleaved(Amessedup); 38 | APtr = libpointer(dataPtr,Aint); 39 | 40 | b = randn(L,1,flags.complexity)+ 1i*randn(L,1,flags.complexity); 41 | bint = complex2interleaved(b); 42 | bPtr = libpointer(dataPtr,bint); 43 | 44 | tic 45 | trueres = A\b; 46 | toc 47 | 48 | tic 49 | status = calllib('libltfat',funname_execute,p,APtr,L,bPtr); 50 | toc 51 | 52 | 53 | res = norm(trueres - interleaved2complex(bPtr.Value)); 54 | 55 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,1e-8); 56 | fprintf(['SOLVEHERM L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 57 | 58 | end 59 | 60 | calllib('libltfat',funname_done,p); 61 | 62 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_pgauss.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_pgauss(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1 ,9, 11, 110, 1, 9, 11, 110]; 11 | tfratarr = [1, 2, 0.1, 100, 1, 2, 0.1, 100]; 12 | ctarr = [0, 0, 0, 0, 0.1, -0.1, 1.0, 0.2]; 13 | cfarr = [0, 0.1, 0, 0,-0.1, 0, 1, 0]; 14 | 15 | 16 | for L = Larr 17 | for tfrId = 1:numel(tfratarr) 18 | tfr = tfratarr(tfrId); 19 | ct = ctarr(tfrId); 20 | cf = cfarr(tfrId); 21 | 22 | z = cast((1:L)',flags.complexity); 23 | zi = z; 24 | ziPtr = libpointer(dataPtr,zi); 25 | 26 | trueres = pgauss(L,tfr,'delay',-ct); 27 | 28 | status = calllib('libltfat',makelibraryname('pgauss',flags.complexity,0),... 29 | L,tfr,ct,ziPtr); 30 | 31 | res = norm(trueres - ziPtr.Value); 32 | 33 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 34 | fprintf(['PGAUSS L:%3i, tfr:%3.3f c_t:%3.3f %s %s %s\n'],L,tfr,ct,flags.complexity,ltfatstatusstring(status),fail); 35 | 36 | 37 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 38 | zi = complex2interleaved(z); 39 | ziPtr = libpointer(dataPtr,zi); 40 | 41 | trueres = pgauss(L,tfr,'delay',-ct,'cf',cf); 42 | 43 | status = calllib('libltfat',makelibraryname('pgauss',flags.complexity,1),... 44 | L,tfr,ct,cf,ziPtr); 45 | 46 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 47 | 48 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 49 | fprintf(['PGAUSS CMPLX L:%3i, tfr:%3.3f c_t:%3.3f c_f:%3.3f %s %s %s\n'],L,tfr,ct,cf,flags.complexity,ltfatstatusstring(status),fail); 50 | 51 | end 52 | end 53 | 54 | 55 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_long2fir.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_long2fir)() 2 | { 3 | ltfatInt Lfir[] = {111, 1, 100}; 4 | ltfatInt Llong[] = {111, 2, 102}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(Lfir); lId++) 7 | { 8 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Llong[lId]); 9 | TEST_NAME(fillRand)(fin, Llong[lId]); 10 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Lfir[lId]); 11 | TEST_NAME(fillRand)(fout, Lfir[lId]); 12 | 13 | mu_assert( LTFAT_NAME(long2fir)(fin, Llong[lId], Lfir[lId], fout) == 0, 14 | "long2fir"); 15 | mu_assert( LTFAT_NAME(long2fir)(fin, Llong[lId], Lfir[lId], fin) == 0, 16 | "long2fir inplace"); 17 | 18 | ltfat_free(fin); 19 | ltfat_free(fout); 20 | } 21 | 22 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Llong[0]); 23 | TEST_NAME(fillRand)(fin, Llong[0]); 24 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Lfir[0]); 25 | TEST_NAME(fillRand)(fout, Lfir[0]); 26 | 27 | 28 | // Inputs can be checked only once 29 | mu_assert( LTFAT_NAME(long2fir)(NULL, Llong[0], Lfir[0], 30 | fin) == LTFATERR_NULLPOINTER, 31 | "First is null"); 32 | mu_assert( LTFAT_NAME(long2fir)(fin, Llong[0], Lfir[0], 33 | NULL) == LTFATERR_NULLPOINTER, 34 | "Last is null"); 35 | mu_assert( LTFAT_NAME(long2fir)(fin, 0, Lfir[0], fout) == LTFATERR_BADSIZE, 36 | "Zero length"); 37 | mu_assert( LTFAT_NAME(long2fir)(fin, -1, Lfir[0], fout) == LTFATERR_BADSIZE, 38 | "Negative length"); 39 | 40 | mu_assert( LTFAT_NAME(long2fir)(fin, 9, 10 , fout) == LTFATERR_BADREQSIZE, 41 | "Output longer than input"); 42 | 43 | mu_assert( LTFAT_NAME(long2fir)(NULL, -1, Lfir[0], fout) < LTFATERR_SUCCESS, 44 | "Multiple wrong inputs"); 45 | 46 | 47 | ltfat_free(fin); 48 | ltfat_free(fout); 49 | return 0; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fir2long.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fir2long)() 2 | { 3 | ltfatInt Lfir[] = {111, 1, 100}; 4 | ltfatInt Llong[] = {111, 2, 102}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(Lfir); lId++) 7 | { 8 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Lfir[lId]); 9 | TEST_NAME(fillRand)(fin, Lfir[lId]); 10 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Llong[lId]); 11 | TEST_NAME(fillRand)(fout, Llong[lId]); 12 | 13 | mu_assert( LTFAT_NAME(fir2long)(fin, Lfir[lId], Llong[lId], fout) == 0, 14 | "fir2long"); 15 | mu_assert( LTFAT_NAME(fir2long)(fout, Lfir[lId], Llong[lId], fout) == 0, 16 | "fir2long inplace"); 17 | 18 | ltfat_free(fin); 19 | ltfat_free(fout); 20 | } 21 | 22 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(Lfir[0]); 23 | TEST_NAME(fillRand)(fin, Lfir[0]); 24 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(Llong[0]); 25 | TEST_NAME(fillRand)(fout, Llong[0]); 26 | 27 | 28 | // Inputs can be checked only once 29 | mu_assert( LTFAT_NAME(fir2long)(NULL, Lfir[0], Llong[0], 30 | fin) == LTFATERR_NULLPOINTER, 31 | "First is null"); 32 | mu_assert( LTFAT_NAME(fir2long)(fin, Lfir[0], Llong[0], 33 | NULL) == LTFATERR_NULLPOINTER, 34 | "Last is null"); 35 | mu_assert( LTFAT_NAME(fir2long)(fin, 0, Llong[0], fout) == LTFATERR_BADSIZE, 36 | "Zero length"); 37 | mu_assert( LTFAT_NAME(fir2long)(fin, -1, Llong[0], fout) == LTFATERR_BADSIZE, 38 | "Negative length"); 39 | 40 | mu_assert( LTFAT_NAME(fir2long)(fin, 10, 9 , fout) == LTFATERR_BADREQSIZE, 41 | "Output shorter than input"); 42 | 43 | mu_assert( LTFAT_NAME(fir2long)(NULL, -1, Llong[0], fout) < LTFATERR_SUCCESS, 44 | "Multiple wrong inputs"); 45 | 46 | 47 | ltfat_free(fin); 48 | ltfat_free(fout); 49 | return 0; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_all_libltfat.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/errno.h" 3 | #include "ltfat/macros.h" 4 | #include "minunit.h" 5 | 6 | 7 | void all_tests() 8 | { 9 | mu_suite_start(); 10 | 11 | mu_run_test_singledoublecomplex(test_circshift); 12 | mu_run_test_singledoublecomplex(test_fftshift); 13 | mu_run_test_singledoublecomplex(test_ifftshift); 14 | mu_run_test_singledoublecomplex(test_fir2long); 15 | mu_run_test_singledoublecomplex(test_long2fir); 16 | mu_run_test_singledoublecomplex(test_normalize); 17 | mu_run_test_singledoublecomplex(test_firwin); 18 | mu_run_test_singledoublecomplex(test_gabdual_painless); 19 | mu_run_test_singledoublecomplex(test_gabdual_long); 20 | mu_run_test_singledoublecomplex(test_dgt_fb); 21 | mu_run_test_singledoublecomplex(test_idgt_fb); 22 | mu_run_test_singledoublecomplex(test_dgt_long); 23 | mu_run_test_singledoublecomplex(test_idgt_long); 24 | mu_run_test_singledouble(test_dgtreal_fb); 25 | mu_run_test_singledouble(test_idgtreal_fb); 26 | mu_run_test_singledouble(test_dgtreal_long); 27 | mu_run_test_singledouble(test_idgtreal_long); 28 | mu_run_test_singledouble(test_pgauss); 29 | mu_run_test_singledouble(test_fftcircshift); 30 | mu_run_test_singledouble(test_fftfftshift); 31 | mu_run_test_singledouble(test_fftifftshift); 32 | mu_run_test_singledouble(test_fftrealcircshift); 33 | mu_run_test_singledouble(test_fftrealfftshift); 34 | mu_run_test_singledouble(test_fftrealifftshift); 35 | 36 | mu_suite_stop(); 37 | } 38 | 39 | 40 | int main() 41 | { 42 | all_tests(); 43 | 44 | 45 | if (ft.noOfFailedTests > 0) 46 | { 47 | printf("\n----------------\nFAILED TESTS %d: \n\n", ft.noOfFailedTests); 48 | for (int ii = 0; ii < ft.noOfFailedTests; ii++) { printf(" %s\n", ft.failedTests[ii]); } 49 | ltfat_free(ft.failedTests); 50 | } 51 | else 52 | { 53 | printf("\n----------------\nALL TESTS PASSED\n"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /modules/libltfat/src/reassign_ti.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | 6 | 7 | LTFAT_API void 8 | LTFAT_NAME(filterbankphasegrad)(const LTFAT_COMPLEX* c [], 9 | const LTFAT_COMPLEX* ch[], 10 | const LTFAT_COMPLEX* cd[], 11 | ltfat_int M, 12 | ltfat_int N[], 13 | ltfat_int L, 14 | const LTFAT_REAL minlvl, 15 | LTFAT_REAL* tgrad[], 16 | LTFAT_REAL* fgrad[], 17 | LTFAT_REAL* cs[]) 18 | { 19 | #define FOREACHCOEF \ 20 | for(ltfat_int m=0;m minlvlAlt) 34 | minlvlAlt = en; 35 | ENDFOREACHCOEF 36 | 37 | // Adjust minlvl 38 | minlvlAlt *= minlvl; 39 | 40 | // Force spectrogram values less tha minLvlAlt to minlvlAlt 41 | FOREACHCOEF 42 | LTFAT_REAL csEl = ARRAYEL(cs); 43 | if (csEl < minlvlAlt) 44 | ARRAYEL(cs) = minlvlAlt; 45 | ENDFOREACHCOEF 46 | 47 | // Instantaneous frequency 48 | FOREACHCOEF 49 | LTFAT_REAL tgradEl = ltfat_real( ARRAYEL(cd) * conj(ARRAYEL(c)) / ARRAYEL(cs) 50 | ) / L * 2; 51 | ARRAYEL(tgrad) = fabs(tgradEl) <= 2 ? tgradEl : 0.0f; 52 | ENDFOREACHCOEF 53 | 54 | 55 | FOREACHCOEF 56 | ARRAYEL(fgrad) = ltfat_imag( ARRAYEL(ch) * conj(ARRAYEL(c)) / ARRAYEL(cs)); 57 | ENDFOREACHCOEF 58 | 59 | #undef FOREACHCOEF 60 | #undef ENDFOREACHCOEF 61 | #undef ARRAYEL 62 | } 63 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/oldtest_libltfat_maxtree.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_maxtree(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [100,101,500,501,1025]; 11 | darr = 0; 12 | 13 | for repeat = 1:1 14 | for depth = darr 15 | 16 | for Lidx = 1:numel(Larr) 17 | 18 | L = Larr(Lidx); 19 | 20 | 21 | f = cast(randn(L,1)',flags.complexity); 22 | 23 | fPtr = libpointer(dataPtr,f); 24 | 25 | funname = makelibraryname('maxtree_initwitharray',flags.complexity,0); 26 | 27 | p = libpointer(); 28 | 29 | calllib('libltfat',funname,L,depth,fPtr,p); 30 | 31 | maxPtr = libpointer(dataPtr,5); 32 | maxposPtr = libpointer('int64Ptr',cast(5,'int64')); 33 | 34 | 35 | funname = makelibraryname('maxtree_findmax',flags.complexity,0); 36 | status=calllib('libltfat',funname,p,maxPtr,maxposPtr); 37 | 38 | fprintf('max=%.3f, maxPos=%d\n',maxPtr.value, maxposPtr.value); 39 | 40 | fPtr.value(1) = 1000; 41 | 42 | funname = makelibraryname('maxtree_setdirty',flags.complexity,0); 43 | status=calllib('libltfat',funname,p,0,1); 44 | 45 | funname = makelibraryname('maxtree_findmax',flags.complexity,0); 46 | status=calllib('libltfat',funname,p,maxPtr,maxposPtr); 47 | 48 | fprintf('max=%.3f, maxPos=%d\n',maxPtr.value, maxposPtr.value); 49 | 50 | 51 | [fmax,fIdx] = max(fPtr.value); 52 | 53 | fprintf('max=%.3f, maxPos=%d\n', fmax, fIdx -1); 54 | fprintf('max=%.3f, maxPos=%d\n',maxPtr.value, maxposPtr.value); 55 | 56 | [test_failed,fail]=ltfatdiditfail(maxPtr.value-fmax + maxposPtr.value - (fIdx -1) ,test_failed,0); 57 | fprintf(['MAXTREE L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 58 | 59 | funname = makelibraryname('maxtree_done',flags.complexity,0); 60 | calllib('libltfat',funname,p); 61 | 62 | end 63 | end 64 | end 65 | 66 | 67 | -------------------------------------------------------------------------------- /examples/example_dgtprocessor.cpp: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | 3 | class DGTProcessor 4 | { 5 | public: 6 | class Callback 7 | { 8 | public: 9 | virtual int callback(const std::complex in[], 10 | const int M2, const int W, 11 | std::complex out[]) noexcept = 0; 12 | }; 13 | 14 | DGTProcessor(LTFAT_FIRWIN win, int gl, int a, int M, int Wmax) 15 | { 16 | processor_struct = rtdgtreal_processor_wininit_s( g, gl, a, M, Wmax, nullptr, nullptr); 17 | if (!processor_struct) 18 | throw std::invalid_argument(); 19 | } 20 | 21 | DGTProcessor(LTFAT_FIRWIN win, int gl, int a, int M, int Wmax, DGTProcessor::Callback callback): 22 | DGTProcessor(win, gl, a, M, Wmax) 23 | { 24 | registerCallback(callback); 25 | } 26 | 27 | 28 | virtual ~DGTProcessor() 29 | { 30 | if (processor_struct) 31 | rtdgtreal_processor_done_s(processor_struct); 32 | } 33 | 34 | void registerCallback(DGTProcessor::Callback* callback) 35 | { 36 | rtdgtreal_processor_setcallback_s( processor_struct, DGTProcessor::callbackWrapper, static_cast(callback)); 37 | } 38 | 39 | int process(const float in[], int bufLen, float out[]) noexcept 40 | { 41 | rtdgtreal_processor_execute_s(processor_struct, in, bufLen, out); 42 | } 43 | 44 | private: 45 | rtdgtreal_processor_s* processor_struct{ nullptr }; 46 | 47 | static void callbackWrapper( 48 | void* userdata, const float in[][2], const int M2, const int W, float out[][2]) 49 | { 50 | static_cast(userdata)->callback( 51 | reinterpret_cast*>(in), M2, W, 52 | reinterpret_cast*>(out)); 53 | } 54 | }; 55 | 56 | class SimpleDGTProcessorCallback : public DGTProcessor::Callback 57 | { 58 | public: 59 | int callback( 60 | const std::complex in[], 61 | const int M2, const int W, 62 | std::complex out[]) noexcept 63 | { 64 | std::copy_n(in, M2 * W, out); 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/loadlibltfat.m: -------------------------------------------------------------------------------- 1 | function loadlibltfat(varargin) 2 | global libltfat_intptrstr; 3 | 4 | definput.keyvals.lib='libltfat.so'; 5 | definput.flags.phase={'load','reload','recompile'}; 6 | definput.flags.comptarget={'fulloptim','release','debug'}; 7 | definput.flags.verbosity={'quiet','verbose'}; 8 | definput.flags.corcpp={'c','cpp'}; 9 | definput.keyvals.compiler = []; 10 | 11 | [flags,kv,lib]=ltfatarghelper({'lib'},definput,varargin); 12 | 13 | [~,libname]=fileparts(lib); 14 | currdir = fileparts(mfilename('fullpath')); 15 | libltfatpath = [currdir, filesep, '..', filesep,'..',filesep,'..',filesep,'..',filesep]; 16 | libpath = [libltfatpath, filesep,'build',filesep,lib]; 17 | iscompiled = exist(libpath,'file'); 18 | 19 | makecmd = ['make -C ',libltfatpath]; 20 | if ~iscompiled || flags.do_recompile 21 | [status,result] = system([makecmd, ' clean']); 22 | if status ~=0, error(result); end 23 | 24 | makecmd = [makecmd, ' MODULE=libltfat']; 25 | makecmd = [makecmd, ' munit -j12']; 26 | makecmd = [makecmd, ' MATLABROOT=', matlabroot]; 27 | makecmd = [makecmd, sprintf(' COMPTARGET=%s',flags.comptarget)]; 28 | 29 | if flags.do_cpp 30 | makecmd = [makecmd, ' USECPP=1']; 31 | end 32 | 33 | if kv.compiler 34 | makecmd = [makecmd, sprintf(' CC=%s',kv.compiler)]; 35 | end 36 | 37 | if flags.do_verbose 38 | disp(makecmd); 39 | system(makecmd); 40 | else 41 | [status,result] = system(makecmd); 42 | if status ~=0, error(result); end 43 | end 44 | end 45 | 46 | if libisloaded(libname) 47 | if flags.do_reload || flags.do_recompile 48 | unloadlibrary(libname); 49 | else 50 | error('%s: libltfat is already loaded. Use ''reload'' to force reload.',upper(mfilename)); 51 | end 52 | end 53 | 54 | warning('off'); 55 | headerpath = [libltfatpath,'build',filesep,'ltfat.h']; 56 | loadlibrary(libpath,headerpath,'mfilename','libltfatprotofile.m'); 57 | warning('on'); 58 | 59 | intbitsize = 8*calllib('libltfat','ltfat_int_size'); 60 | libltfat_intptrstr = sprintf('int%dPtr',intbitsize); 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/dgt_multi.h: -------------------------------------------------------------------------------- 1 | typedef struct LTFAT_NAME(dgt_multi_plan) LTFAT_NAME(dgt_multi_plan); 2 | 3 | // { 4 | // ltfat_int a; 5 | // ltfat_int M; 6 | // ltfat_int L; 7 | // ltfat_int Lg; 8 | // ltfat_int W; 9 | // ltfat_int lt1; 10 | // ltfat_int lt2; 11 | // 12 | // LTFAT_COMPLEX *f; 13 | // LTFAT_COMPLEX *c_scratch; 14 | // LTFAT_COMPLEX *cout; 15 | // 16 | // LTFAT_COMPLEX *mwin; 17 | // LTFAT_COMPLEX *c_rect; 18 | // 19 | // LTFAT_COMPLEX *mod; 20 | // 21 | // LTFAT_NAME(dgt_long_plan) *rect_plan_array; 22 | // 23 | // } LTFAT_NAME(dgt_multi_plan); 24 | 25 | struct LTFAT_NAME(dgt_multi_plan) 26 | { 27 | ltfat_int a; 28 | ltfat_int M; 29 | ltfat_int L; 30 | ltfat_int Lg; 31 | ltfat_int W; 32 | ltfat_int lt1; 33 | ltfat_int lt2; 34 | 35 | LTFAT_COMPLEX *f; 36 | LTFAT_COMPLEX *c_scratch; 37 | LTFAT_COMPLEX *cout; 38 | 39 | LTFAT_COMPLEX *mwin; 40 | LTFAT_COMPLEX *c_rect; 41 | 42 | LTFAT_COMPLEX *mod; 43 | 44 | LTFAT_NAME_COMPLEX(dgt_long_plan)** rect_plan_array; 45 | }; 46 | 47 | LTFAT_API LTFAT_NAME(dgt_multi_plan) 48 | LTFAT_NAME(dgt_multi_init)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 49 | ltfat_int L, ltfat_int Lg, ltfat_int W, ltfat_int a, ltfat_int M, 50 | ltfat_int lt1, ltfat_int lt2, 51 | LTFAT_COMPLEX *c,unsigned flags); 52 | 53 | LTFAT_API void 54 | LTFAT_NAME(dgt_multi_execute)(const LTFAT_NAME(dgt_multi_plan) plan); 55 | 56 | LTFAT_API void 57 | LTFAT_NAME(dgt_multi_done)(LTFAT_NAME(dgt_multi_plan) plan); 58 | 59 | LTFAT_API void 60 | LTFAT_NAME(nonsepwin2multi)(const LTFAT_COMPLEX *g, 61 | ltfat_int L, ltfat_int Lg, ltfat_int a, ltfat_int M, 62 | ltfat_int lt1, ltfat_int lt2, 63 | LTFAT_COMPLEX *mwin); 64 | 65 | LTFAT_API void 66 | LTFAT_NAME(dgt_multi)(const LTFAT_COMPLEX *f, const LTFAT_COMPLEX *g, 67 | ltfat_int L, ltfat_int Lg, ltfat_int W, ltfat_int a, ltfat_int M, 68 | ltfat_int lt1, ltfat_int lt2, 69 | LTFAT_COMPLEX *c); 70 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/ti_windows.h: -------------------------------------------------------------------------------- 1 | /** \addtogroup windows 2 | * @{ 3 | */ 4 | 5 | /** Compute real, periodized Gaussian window 6 | * 7 | * \param[in] L Window length 8 | * \param[in] w Time-freqency support ratio 9 | * \param[in] c_t Time center offset 10 | * \param[out] g Window 11 | * 12 | * #### Function versions # 13 | * 14 | * ltfat_pgauss_d(ltfat_int L,const double w, const double c_t, double* g); 15 | * 16 | * ltfat_pgauss_s(ltfat_int L,const double w, const double c_t, float* g); 17 | * 18 | * \returns 19 | * Status code | Description 20 | * ----------------------|------------ 21 | * LTFATERR_SUCCESS | Indicates no error 22 | * LTFATERR_NULLPOINTER | The output array is NULL. 23 | * LTFATERR_BADSIZE | Window length is less or equal to 0. 24 | * LTFATERR_NOTPOSARG | \a w is less or equal to zero. 25 | */ 26 | LTFAT_API int 27 | LTFAT_NAME(pgauss)(ltfat_int L, const double w, const double c_t, 28 | LTFAT_REAL *g); 29 | 30 | /** Compute complex, periodized Gaussian window 31 | * 32 | * \param[in] L Window length 33 | * \param[in] w Time-freqency support ratio 34 | * \param[in] c_t Time center offset 35 | * \param[in] c_f Frequency center offset 36 | * \param[out] g Window 37 | * 38 | * #### Function versions # 39 | * 40 | * 41 | * ltfat_pgauss_cd(ltfat_int L, const double w, const double c_t, 42 | * const double c_f, ltfat_complex_d* g); 43 | * 44 | * ltfat_pgauss_cs(ltfat_int L, const double w, const double c_t, 45 | * const double c_f, ltfat_complex_s* g); 46 | * 47 | * \returns 48 | * Status code | Description 49 | * ----------------------|------------ 50 | * LTFATERR_SUCCESS | Indicates no error 51 | * LTFATERR_NULLPOINTER | The output array is NULL. 52 | * LTFATERR_BADSIZE | Window length is less or equal to 0. 53 | * LTFATERR_NOTPOSARG | \a w is less or equal to zero. 54 | */ 55 | LTFAT_API int 56 | LTFAT_NAME_COMPLEX(pgauss)(ltfat_int L, const double w, const double c_t, 57 | const double c_f, LTFAT_COMPLEX *g); 58 | 59 | /** @} */ 60 | -------------------------------------------------------------------------------- /modules/libltfat/src/firwin_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/macros.h" 3 | 4 | LTFAT_API int 5 | ltfat_str2firwin(const char* win) 6 | { 7 | if( !strcmp("hann",win) || !strcmp("hanning",win) || !strcmp("nuttall10",win)) 8 | return LTFAT_HANN; 9 | if( !strcmp("hamming",win)) return LTFAT_HAMMING; 10 | else if( !strcmp("sqrthann",win) || !strcmp("cosine",win) || !strcmp("sine",win)) 11 | return LTFAT_SQRTHANN; 12 | else if( !strcmp("nuttall01",win)) return LTFAT_NUTTALL01; 13 | else if( !strcmp("square",win) || !strcmp("rect",win)) return LTFAT_SQUARE; 14 | else if( !strcmp("tria",win) || !strcmp("triangular",win) || !strcmp("bartlett",win)) 15 | return LTFAT_TRIA; 16 | else if( !strcmp("sqrttria",win)) return LTFAT_SQRTTRIA; 17 | else if( !strcmp("blackman",win)) return LTFAT_BLACKMAN; 18 | else if( !strcmp("blackman2",win)) return LTFAT_BLACKMAN2; 19 | else if( !strcmp("nuttall",win) || !strcmp("nuttall12",win)) return LTFAT_NUTTALL; 20 | else if( !strcmp("ogg",win) || !strcmp("itersine",win)) return LTFAT_OGG; 21 | else if( !strcmp("nuttall20",win)) return LTFAT_NUTTALL20; 22 | else if( !strcmp("nuttall11",win)) return LTFAT_NUTTALL11; 23 | else if( !strcmp("nuttall02",win)) return LTFAT_NUTTALL02; 24 | else if( !strcmp("nuttall30",win)) return LTFAT_NUTTALL30; 25 | else if( !strcmp("nuttall21",win)) return LTFAT_NUTTALL21; 26 | else if( !strcmp("nuttall03",win)) return LTFAT_NUTTALL03; 27 | else if( !strcmp("truncgauss01",win)) return LTFAT_TRUNCGAUSS01; 28 | else if( !strcmp("truncgauss005",win)) return LTFAT_TRUNCGAUSS005; 29 | 30 | return LTFATERR_BADARG; 31 | } 32 | 33 | LTFAT_API ltfat_int 34 | ltfat_mtgausslength(ltfat_int a, ltfat_int M, double thr) 35 | { 36 | int status = LTFATERR_FAILED; 37 | CHECK(LTFATERR_NOTPOSARG, a > 0, "a must be greater than 0 (passed %td)", a); 38 | CHECK(LTFATERR_NOTPOSARG, M > 0, "M must be greater than 0 (passed %td)", M); 39 | CHECK(LTFATERR_NOTPOSARG, thr > 0 && thr <= 1.0, "Thr must be in the range ]0,1]"); 40 | 41 | return 2*(ltfat_int) ltfat_round(sqrt(-a*M*log(thr)/M_PI)); 42 | error: 43 | return status; 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftcircshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftcircshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 7 | { 8 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 9 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 10 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 11 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 12 | 13 | for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) 14 | { 15 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, L[lId], shift[shiftId], 16 | fout) == 0, 17 | "fftcirschift"); 18 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, L[lId], shift[shiftId], 19 | fin) == 0, 20 | "fftcirschift inplace"); 21 | } 22 | 23 | ltfat_free(fin); 24 | ltfat_free(fout); 25 | } 26 | 27 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 28 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 29 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 30 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 31 | 32 | 33 | // Inputs can be checked only once 34 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(NULL, L[0], shift[0], 35 | fin) == LTFATERR_NULLPOINTER, 36 | "First is null"); 37 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, L[0], shift[0], 38 | NULL) == LTFATERR_NULLPOINTER, 39 | "Last is null"); 40 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, 0, shift[0], 41 | fout) == LTFATERR_BADSIZE, 42 | "Zero length"); 43 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(fin, -1, shift[0], 44 | fout) == LTFATERR_BADSIZE, 45 | "Negative length"); 46 | 47 | mu_assert( LTFAT_NAME_COMPLEX(fftcircshift)(NULL, -1, shift[0], 48 | fout) < LTFATERR_SUCCESS, 49 | "Multiple wrong inputs"); 50 | 51 | 52 | ltfat_free(fin); 53 | ltfat_free(fout); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /examples/example_gabanasyn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "ltfat.h" 6 | 7 | int main() 8 | { 9 | // Number of frequency channels 10 | ltfatInt M = 2048; 11 | // Hop factor 12 | ltfatInt a = 256; 13 | // Length of the signal. Must be an integer multiple of both a and M 14 | ltfatInt L = 100*2048; 15 | // Length of the window, I use a Gauss window here which is possibly 16 | // fully supported 17 | ltfatInt gl = L; 18 | // Number of channels 19 | ltfatInt W = 1; 20 | 21 | // Number of unique channels when the input is a real signal 22 | ltfatInt M2 = M / 2 + 1; 23 | // Number of time hops 24 | ltfatInt N = L / a; 25 | 26 | // Allocate space for a window 27 | double* g = ltfat_malloc(gl * sizeof * g); 28 | // Alocate space for the dual window 29 | double* gd = ltfat_malloc(gl * sizeof * gd); 30 | // Space for input signal 31 | double* f = ltfat_malloc(W * L * sizeof * f); 32 | // Space for reconstructed signal 33 | double* frec = ltfat_malloc(W * L * sizeof * f); 34 | // Space for coefficients 35 | double _Complex* c = ltfat_malloc(W * M2 * N * sizeof * c); 36 | 37 | // Generate some input 38 | srand(time(NULL)); 39 | for (ltfatInt l = 0; l < W * L; ++l) 40 | { 41 | f[l] = ((double)rand()) / RAND_MAX; 42 | } 43 | 44 | // Compute window. Using a*M/L for w makes the time-frequency support of the 45 | // Gaussion window to best fit the time-frequency sampling grid 46 | pgauss_d(L, a * M / L, 0, g); 47 | 48 | // Compute the dual window 49 | gabdual_long_d(g,L,1,a,M,gd); 50 | 51 | // Do the transform 52 | dgtreal_long_d(f, g, L, W, a, M, TIMEINV, c); 53 | 54 | // Do inverse transform 55 | idgtreal_long_d(c, gd, L, W, a, M, TIMEINV, frec); 56 | 57 | 58 | // Comute error of the reconstruction 59 | double err = 0.0; 60 | 61 | for (ltfatInt l = 0; l < L * W; ++l) 62 | { 63 | double dif = fabs( f[l] - frec[l] ); 64 | err += dif * dif; 65 | } 66 | 67 | printf("Error of the reconstruction is %e\n", err); 68 | 69 | LTFAT_SAFEFREEALL(g, gd, f, frec, c); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /modules/libphaseret/src/legla_typeconstant.c: -------------------------------------------------------------------------------- 1 | #include "phaseret/legla.h" 2 | #include "legla_private.h" 3 | #include "ltfat/macros.h" 4 | 5 | 6 | int 7 | phaseret_legla_params_defaults(phaseret_legla_params* params) 8 | { 9 | int status = LTFATERR_SUCCESS; 10 | CHECKNULL(params); 11 | 12 | params->relthr = 1e-3; 13 | params->ksize.width = 0; 14 | params->ksize.height = 0; 15 | params->leglaflags = MOD_COEFFICIENTWISE | MOD_MODIFIEDUPDATE; 16 | CHECKMEM( params->dparams = ltfat_dgt_params_allocdef()); 17 | error: 18 | return status; 19 | } 20 | 21 | 22 | PHASERET_API phaseret_legla_params* 23 | phaseret_legla_params_allocdef() 24 | { 25 | phaseret_legla_params* params = 26 | (phaseret_legla_params*) ltfat_calloc(1, sizeof * params); 27 | 28 | phaseret_legla_params_defaults(params); 29 | 30 | return params; 31 | } 32 | 33 | PHASERET_API int 34 | phaseret_legla_params_set_relthr(phaseret_legla_params* params, double relthr) 35 | { 36 | int status = LTFATERR_SUCCESS; 37 | CHECKNULL(params); 38 | params->relthr = relthr; 39 | error: 40 | return status; 41 | } 42 | 43 | 44 | PHASERET_API int 45 | phaseret_legla_params_set_kernelsize(phaseret_legla_params* params, 46 | phaseret_size ksize) 47 | { 48 | int status = LTFATERR_SUCCESS; 49 | CHECKNULL(params); 50 | params->ksize = ksize; 51 | error: 52 | return status; 53 | } 54 | 55 | PHASERET_API int 56 | phaseret_legla_params_set_leglaflags(phaseret_legla_params* params, 57 | unsigned leglaflags) 58 | { 59 | int status = LTFATERR_SUCCESS; 60 | CHECKNULL(params); 61 | params->leglaflags = leglaflags; 62 | error: 63 | return status; 64 | } 65 | 66 | PHASERET_API ltfat_dgt_params* 67 | phaseret_legla_params_get_dgtreal_params(phaseret_legla_params* params) 68 | { 69 | if (params) 70 | return params->dparams; 71 | else 72 | return NULL; 73 | } 74 | 75 | PHASERET_API int 76 | phaseret_legla_params_free(phaseret_legla_params* params) 77 | { 78 | int status = LTFATERR_SUCCESS; 79 | CHECKNULL(params); 80 | ltfat_dgt_params_free(params->dparams); 81 | ltfat_free(params); 82 | error: 83 | return status; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_fftrealcircshift.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_fftrealcircshift)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfatInt shift[] = { -5, 0, 1, -1000, 10540, 5660}; 5 | 6 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 7 | { 8 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 9 | TEST_NAME_COMPLEX(fillRand)(fin, L[lId]); 10 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[lId]); 11 | TEST_NAME_COMPLEX(fillRand)(fout, L[lId]); 12 | 13 | for (unsigned int shiftId = 0; shiftId < ARRAYLEN(shift); shiftId++) 14 | { 15 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[lId], shift[shiftId], 16 | fout) == 0, 17 | "fftrealcirschift"); 18 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[lId], shift[shiftId], 19 | fin) == 0, 20 | "fftrealcirschift inplace"); 21 | } 22 | 23 | ltfat_free(fin); 24 | ltfat_free(fout); 25 | } 26 | 27 | LTFAT_COMPLEX* fin = LTFAT_NAME_COMPLEX(malloc)(L[0]); 28 | TEST_NAME_COMPLEX(fillRand)(fin, L[0]); 29 | LTFAT_COMPLEX* fout = LTFAT_NAME_COMPLEX(malloc)(L[0]); 30 | TEST_NAME_COMPLEX(fillRand)(fout, L[0]); 31 | 32 | 33 | // Inputs can be checked only once 34 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(NULL, L[0], shift[0], 35 | fin) == LTFATERR_NULLPOINTER, 36 | "First is null"); 37 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, L[0], shift[0], 38 | NULL) == LTFATERR_NULLPOINTER, 39 | "Last is null"); 40 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, 0, shift[0], 41 | fout) == LTFATERR_BADSIZE, 42 | "Zero length"); 43 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(fin, -1, shift[0], 44 | fout) == LTFATERR_BADSIZE, 45 | "Negative length"); 46 | 47 | mu_assert( LTFAT_NAME_COMPLEX(fftrealcircshift)(NULL, -1, shift[0], 48 | fout) < LTFATERR_SUCCESS, 49 | "Multiple wrong inputs"); 50 | 51 | 52 | ltfat_free(fin); 53 | ltfat_free(fout); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /modules/libltfat/thirdparty/kissfft/TIPS: -------------------------------------------------------------------------------- 1 | Speed: 2 | * If you want to use multiple cores, then compile with -openmp or -fopenmp (see your compiler docs). 3 | Realize that larger FFTs will reap more benefit than smaller FFTs. This generally uses more CPU time, but 4 | less wall time. 5 | 6 | * experiment with compiler flags 7 | Special thanks to Oscar Lesta. He suggested some compiler flags 8 | for gcc that make a big difference. They shave 10-15% off 9 | execution time on some systems. Try some combination of: 10 | -march=pentiumpro 11 | -ffast-math 12 | -fomit-frame-pointer 13 | 14 | * If the input data has no imaginary component, use the kiss_fftr code under tools/. 15 | Real ffts are roughly twice as fast as complex. 16 | 17 | * If you can rearrange your code to do 4 FFTs in parallel and you are on a recent Intel or AMD machine, 18 | then you might want to experiment with the USE_SIMD code. See README.simd 19 | 20 | 21 | Reducing code size: 22 | * remove some of the butterflies. There are currently butterflies optimized for radices 23 | 2,3,4,5. It is worth mentioning that you can still use FFT sizes that contain 24 | other factors, they just won't be quite as fast. You can decide for yourself 25 | whether to keep radix 2 or 4. If you do some work in this area, let me 26 | know what you find. 27 | 28 | * For platforms where ROM/code space is more plentiful than RAM, 29 | consider creating a hardcoded kiss_fft_state. In other words, decide which 30 | FFT size(s) you want and make a structure with the correct factors and twiddles. 31 | 32 | * Frank van der Hulst offered numerous suggestions for smaller code size and correct operation 33 | on embedded targets. "I'm happy to help anyone who is trying to implement KISSFFT on a micro" 34 | 35 | Some of these were rolled into the mainline code base: 36 | - using long casts to promote intermediate results of short*short multiplication 37 | - delaying allocation of buffers that are sometimes unused. 38 | In some cases, it may be desirable to limit capability in order to better suit the target: 39 | - predefining the twiddle tables for the desired fft size. 40 | -------------------------------------------------------------------------------- /modules/libltfat/doc/htmltemplate/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |  $projectnumber --> 34 | 35 |
$projectbrief
--> 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
$searchbox
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /modules/libphaseret/doc/htmltemplate/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |  $projectnumber --> 34 | 35 |
$projectbrief
--> 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
$searchbox
53 |
54 | 55 | 56 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_normalize.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_normalize)() 2 | { 3 | ltfatInt L[] = {111, 1, 100}; 4 | ltfat_normalize_t norm[] = { LTFAT_NORM_NULL, LTFAT_NORM_AREA, 5 | LTFAT_NORM_1, LTFAT_NORM_ENERGY, 6 | LTFAT_NORM_2, LTFAT_NORM_INF, LTFAT_NORM_PEAK 7 | }; 8 | 9 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 10 | { 11 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 12 | TEST_NAME(fillRand)(fin, L[lId]); 13 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[lId]); 14 | TEST_NAME(fillRand)(fout, L[lId]); 15 | 16 | 17 | for (unsigned int nId = 0; nId < ARRAYLEN(norm); nId++) 18 | { 19 | 20 | mu_assert( LTFAT_NAME(normalize)(fin, L[lId], norm[nId], fout) == 0, 21 | "normalize"); 22 | mu_assert( LTFAT_NAME(normalize)(fin, L[lId], norm[nId], fin) == 0, 23 | "normalize inplace"); 24 | } 25 | 26 | ltfat_free(fin); 27 | ltfat_free(fout); 28 | } 29 | 30 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 31 | TEST_NAME(fillRand)(fin, L[0]); 32 | LTFAT_TYPE* fout = LTFAT_NAME(malloc)(L[0]); 33 | TEST_NAME(fillRand)(fout, L[0]); 34 | 35 | 36 | // Inputs can be checked only once 37 | mu_assert( LTFAT_NAME(normalize)(NULL, L[0], norm[0], 38 | fin) == LTFATERR_NULLPOINTER, 39 | "First is null"); 40 | mu_assert( LTFAT_NAME(normalize)(fin, L[0], norm[0], 41 | NULL) == LTFATERR_NULLPOINTER, 42 | "Last is null"); 43 | mu_assert( LTFAT_NAME(normalize)(fin, 0, norm[0], fout) == LTFATERR_BADSIZE, 44 | "Zero length"); 45 | mu_assert( LTFAT_NAME(normalize)(fin, -1, norm[0], fout) == LTFATERR_BADSIZE, 46 | "Negative length"); 47 | 48 | mu_assert( LTFAT_NAME(normalize)(NULL, -1, norm[0], fout) < LTFATERR_SUCCESS, 49 | "Multiple wrong inputs"); 50 | 51 | mu_assert( LTFAT_NAME(normalize)(fin, L[0], 10000, 52 | fout) == LTFATERR_CANNOTHAPPEN, 53 | "Wrong flag"); 54 | 55 | 56 | ltfat_free(fin); 57 | ltfat_free(fout); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_maxtree.c: -------------------------------------------------------------------------------- 1 | ltfat_int L[] = { 9 , 10, 100, 101 }; 2 | ltfat_int depth[] = { 1, 2, 3, 4, 5 }; 3 | ltfat_int rLen[] = { 1, 2, 3, 4, 7, 8, 10, 19, 21}; 4 | 5 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 6 | { 7 | LTFAT_REAL* fin = LTFAT_NAME_REAL(malloc)(L[lId]); 8 | TEST_NAME(fillRand)(fin, L[lId]); 9 | 10 | for (unsigned int dId = 0; dId < ARRAYLEN(depth); dId++) 11 | { 12 | ltfat_int maxPos; 13 | LTFAT_REAL max; 14 | ltfat_int maxPos2; 15 | LTFAT_REAL max2; 16 | /* fin[L[lId]-1] = 100; */ 17 | LTFAT_NAME(findmaxinarray)(fin, L[lId], &max, &maxPos); 18 | printf("max=%.2f, maxPos=%td\n", max, maxPos); 19 | 20 | LTFAT_NAME(maxtree)* p = NULL; 21 | LTFAT_NAME(maxtree_initwitharray)(L[lId], depth[dId], fin, &p); 22 | LTFAT_NAME(maxtree_findmax)(p, &max2, &maxPos2); 23 | printf("max=%.2f, maxPos=%td\n", max2, maxPos2); 24 | 25 | for (unsigned int idx = 0; idx < L[lId]; idx++) 26 | { 27 | for (unsigned int rIdx = 0; rIdx < ARRAYLEN(rLen); rIdx++) 28 | { 29 | 30 | max = -100; max2 = -101; maxPos = -1; maxPos2 = -1; 31 | TEST_NAME(fillRand)(fin, L[lId]); 32 | LTFAT_NAME(maxtree_reset)(p, fin); 33 | 34 | for (unsigned int ii = 0; ii < rLen[rIdx]; ii++) 35 | { 36 | ltfat_int pos = idx + ii; 37 | if (pos >= L[lId]) 38 | pos = pos%L[lId]; 39 | 40 | fin[pos] = 100 + ii; 41 | } 42 | 43 | LTFAT_NAME(findmaxinarray)(fin, L[lId], &max, &maxPos); 44 | /* printf("max=%.2f, maxPos=%td\n",max,maxPos); */ 45 | 46 | LTFAT_NAME(maxtree_setdirty)(p, idx, idx + rLen[rIdx]); 47 | LTFAT_NAME(maxtree_findmax)(p, &max2, &maxPos2); 48 | 49 | /* printf("max=%.2f, maxPos=%td\n",max2,maxPos2); */ 50 | mu_assert( max == max2 && maxPos == maxPos2 , 51 | "TREEMAX L=%td, d=%td, idx=%d, r=%td", 52 | L[lId], depth[dId], idx, rLen[rIdx] ); 53 | } 54 | } 55 | 56 | 57 | LTFAT_NAME(maxtree_done)(&p); 58 | } 59 | 60 | ltfat_free(fin); 61 | } 62 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_fftshift.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_fftshift(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1,9,11,110]; 11 | 12 | for do_complex = 0:1 13 | complexstring = ''; 14 | if do_complex, complexstring = 'complex'; end 15 | funname = makelibraryname('fftshift',flags.complexity,do_complex); 16 | 17 | for L = Larr 18 | 19 | if do_complex 20 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 21 | zi = complex2interleaved(z); 22 | zout = randn(size(zi),flags.complexity); 23 | 24 | ziPtr = libpointer(dataPtr,zi); 25 | zoutPtr = libpointer(dataPtr,zout); 26 | else 27 | z = cast((1:L)',flags.complexity); 28 | zi = z; 29 | zout = randn(size(zi),flags.complexity); 30 | 31 | ziPtr = libpointer(dataPtr,zi); 32 | zoutPtr = libpointer(dataPtr,zout); 33 | end 34 | 35 | trueres = fftshift(z); 36 | 37 | 38 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 39 | 40 | if do_complex 41 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 42 | else 43 | res = norm(trueres - zoutPtr.Value); 44 | end 45 | 46 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 47 | fprintf(['FFTSHIFT OP L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 48 | 49 | status = calllib('libltfat',funname,ziPtr,L,ziPtr); 50 | 51 | if do_complex 52 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 53 | else 54 | res = norm(trueres - ziPtr.Value); 55 | end 56 | 57 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 58 | fprintf(['FFTSHIFT IP L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 59 | end 60 | end 61 | 62 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_ifftshift.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_ifftshift(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1,9,11,110]; 11 | 12 | for do_complex = 0:1 13 | complexstring = ''; 14 | if do_complex, complexstring = 'complex'; end 15 | funname = makelibraryname('ifftshift',flags.complexity,do_complex); 16 | 17 | for L = Larr 18 | 19 | if do_complex 20 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 21 | zi = complex2interleaved(z); 22 | zout = randn(size(zi),flags.complexity); 23 | 24 | ziPtr = libpointer(dataPtr,zi); 25 | zoutPtr = libpointer(dataPtr,zout); 26 | else 27 | z = cast((1:L)',flags.complexity); 28 | zi = z; 29 | zout = randn(size(zi),flags.complexity); 30 | 31 | ziPtr = libpointer(dataPtr,zi); 32 | zoutPtr = libpointer(dataPtr,zout); 33 | end 34 | 35 | trueres = ifftshift(z); 36 | 37 | 38 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 39 | 40 | if do_complex 41 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 42 | else 43 | res = norm(trueres - zoutPtr.Value); 44 | end 45 | 46 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 47 | fprintf(['FFTSHIFT OP L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 48 | 49 | status = calllib('libltfat',funname,ziPtr,L,ziPtr); 50 | 51 | if do_complex 52 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 53 | else 54 | res = norm(trueres - ziPtr.Value); 55 | end 56 | 57 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 58 | fprintf(['FFTSHIFT IP L:%3i, %s %s %s %s\n'],L,flags.complexity,complexstring,ltfatstatusstring(status),fail); 59 | end 60 | end 61 | 62 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/errno.h: -------------------------------------------------------------------------------- 1 | /** \defgroup error Error handling 2 | * 3 | * Errors are negative numbers. Positive numbers are reserved for 4 | * other purposes (like returning number of samples written) 5 | * 6 | * \addtogroup error 7 | * @{ 8 | */ 9 | 10 | #ifndef _LTFAT_ERRNO_H 11 | #define _LTFAT_ERRNO_H 12 | #include "basicmacros.h" 13 | 14 | enum ltfaterr_status 15 | { 16 | // General 17 | LTFATERR_SUCCESS = 0, 18 | LTFATERR_FAILED = -1, 19 | LTFATERR_NOMEM = -2, 20 | LTFATERR_INITFAILED = -3, 21 | LTFATERR_NULLPOINTER = -4, 22 | LTFATERR_EMPTY = -5, 23 | LTFATERR_BADARG = -6, 24 | LTFATERR_NOTPOSARG = -7, 25 | LTFATERR_NOTINRANGE = -8, 26 | LTFATERR_OVERFLOW = -9, 27 | LTFATERR_UNDERFLOW = -10, 28 | LTFATERR_CANNOTHAPPEN = -11, 29 | LTFATERR_BADSIZE = -12, // Array size is wrong 30 | LTFATERR_BADREQSIZE = -13, // Output array size is wrong 31 | LTFATERR_NOTSUPPORTED = -14, 32 | // Specific 33 | LTFATERR_BADTRALEN = -99, 34 | LTFATERR_NOTAFRAME = -100, 35 | LTFATERR_NOTPAINLESS = -101, 36 | LTFATERR_NOTPOSDEFMATRIX= -102, 37 | // Missing components 38 | LTFATERR_NOBLASLAPACK = -200 39 | }; 40 | 41 | 42 | /** Function signature for a custom error handler 43 | * 44 | * \param[in] ltfat_errno Status code of the error 45 | * \param[in] file Filename 46 | * \param[in] line Line 47 | * \param[in] funcname Function name 48 | * \param[out] reason Error message 49 | */ 50 | typedef void ltfat_error_handler_t (int ltfat_errno, const char* file, int line, 51 | const char* funcname, const char* reason); 52 | 53 | 54 | /** Register a new error handler 55 | * 56 | * Default error handling behavior can be recovered by passing NULL. 57 | * \returns Old error handler 58 | */ 59 | LTFAT_API ltfat_error_handler_t* 60 | ltfat_set_error_handler (ltfat_error_handler_t* new_handler); 61 | 62 | /** Disable error handling 63 | * \returns Old error handler 64 | */ 65 | LTFAT_API ltfat_error_handler_t* 66 | ltfat_set_error_handler_off (void); 67 | 68 | /** @} */ 69 | 70 | LTFAT_API void 71 | ltfat_error (int ltfat_errno, const char * file, int line, 72 | const char* funcname, const char * format, ...); 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/slidgtrealmp.h: -------------------------------------------------------------------------------- 1 | /* \defgroup slidgtrealmp Sliding Matching Pursuit with Multi-Gabor Dictionaries 2 | */ 3 | #ifndef _LTFAT_SLIDGTREALMP_H 4 | #define _LTFAT_SLIDGTREALMP_H 5 | 6 | 7 | #endif 8 | 9 | typedef struct LTFAT_NAME(slidgtrealmp_state) LTFAT_NAME(slidgtrealmp_state); 10 | 11 | typedef int LTFAT_NAME(slidgtrealmp_niter_callback)(void* userdata, 12 | const LTFAT_REAL in[], int winLen, int taperLen, int zpadLen, int W, LTFAT_REAL out[]); 13 | 14 | /* \addtogroup slidgtrealmp 15 | * @{ */ 16 | 17 | /** 18 | */ 19 | typedef int LTFAT_NAME(slidgtrealmp_processor_callback)( 20 | void* userdata, LTFAT_NAME(dgtrealmp_state)* mpstate, 21 | LTFAT_COMPLEX* cres[], LTFAT_COMPLEX* c[], int P, int M2[], int N[], int L, LTFAT_REAL f[]); 22 | 23 | /** \name Basic interface 24 | * @{ */ 25 | LTFAT_API int 26 | LTFAT_NAME(slidgtrealmp_init)( 27 | LTFAT_NAME(dgtrealmp_parbuf)* pb, ltfat_int L, 28 | ltfat_int numChans, ltfat_int bufLenMax, 29 | LTFAT_NAME(slidgtrealmp_state)** pout); 30 | 31 | LTFAT_API int 32 | LTFAT_NAME(slidgtrealmp_execute)( 33 | LTFAT_NAME(slidgtrealmp_state)* p, 34 | const LTFAT_REAL* in[], ltfat_int inLen, ltfat_int chanNo, 35 | LTFAT_REAL* fout[]); 36 | 37 | LTFAT_API int 38 | LTFAT_NAME(slidgtrealmp_done)(LTFAT_NAME(slidgtrealmp_state)** p); 39 | 40 | LTFAT_API int 41 | LTFAT_NAME(slidgtrealmp_reset)( 42 | LTFAT_NAME(slidgtrealmp_state)* p); 43 | 44 | LTFAT_API int 45 | LTFAT_NAME(slidgtrealmp_setcallback)(LTFAT_NAME(slidgtrealmp_state)* p, 46 | LTFAT_NAME(slidgtrealmp_processor_callback)* callback, 47 | void* userdata); 48 | /** @} */ 49 | 50 | /** \name Advanced interface 51 | * @{ */ 52 | LTFAT_API int 53 | LTFAT_NAME(slidgtrealmp_init_fromstates)( 54 | LTFAT_NAME(dgtrealmp_state)* mpstate, 55 | LTFAT_NAME(slicing_processor_state)* slistate, 56 | LTFAT_NAME(slidgtrealmp_state)** pout); 57 | 58 | LTFAT_API int 59 | LTFAT_NAME(slidgtrealmp_execute_compact)( 60 | LTFAT_NAME(slidgtrealmp_state)* p, 61 | const LTFAT_REAL in[], ltfat_int inLen, ltfat_int chanNo, 62 | LTFAT_REAL fout[]); 63 | 64 | LTFAT_API ltfat_int 65 | LTFAT_NAME(slidgtrealmp_getprocdelay)( LTFAT_NAME(slidgtrealmp_state)* p); 66 | /** @} */ 67 | /** @} */ 68 | 69 | /* PRIVATE */ 70 | 71 | int 72 | LTFAT_NAME(slidgtrealmp_execute_callback)(void* userdata, 73 | const LTFAT_REAL in[], int winLen, int taperLen, 74 | int zpadLen, int W, LTFAT_REAL out[]); 75 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/loadlibphaseret.m: -------------------------------------------------------------------------------- 1 | function loadlibphaseret(varargin) 2 | 3 | definput.keyvals.lib='libphaseret.so'; 4 | definput.flags.phase={'load','reload','recompile'}; 5 | definput.flags.comptarget={'fulloptim','release','debug'}; 6 | definput.flags.verbosity={'quiet','verbose'}; 7 | definput.flags.corcpp={'c','cpp'}; 8 | definput.keyvals.compiler = []; 9 | 10 | [flags,kv,lib]=ltfatarghelper({'lib'},definput,varargin); 11 | 12 | [~,libname]=fileparts(lib); 13 | currdir = fileparts(mfilename('fullpath')); 14 | libltfatpath = [currdir, filesep, '..', filesep,'..',filesep,'..',filesep,'..',filesep]; 15 | libpath = [libltfatpath, filesep,'build',filesep,lib]; 16 | iscompiled = exist(libpath,'file'); 17 | 18 | makecmd = ['make -C ',libltfatpath]; 19 | if ~iscompiled || flags.do_recompile 20 | [status,result] = system([makecmd, ' clean']); 21 | if status ~=0, error(result); end 22 | 23 | makecmd = [makecmd, ' MODULE=%s']; 24 | makecmd = [makecmd, ' munit -j12']; 25 | makecmd = [makecmd, ' MATLABROOT=', matlabroot]; 26 | makecmd = [makecmd, sprintf(' COMPTARGET=%s',flags.comptarget)]; 27 | 28 | if flags.do_cpp 29 | makecmd = [makecmd, ' USECPP=1']; 30 | end 31 | 32 | if kv.compiler 33 | makecmd = [makecmd, sprintf(' CC=%s',kv.compiler)]; 34 | end 35 | 36 | makecmd_libltfat = sprintf(makecmd,'libltfat'); 37 | if flags.do_verbose 38 | disp(makecmd_libltfat); 39 | system(makecmd_libltfat); 40 | else 41 | [status,result] = system(makecmd_libltfat); 42 | if status ~=0, error(result); end 43 | end 44 | 45 | makecmd_libphaseret = sprintf(makecmd,'libphaseret'); 46 | if flags.do_verbose 47 | disp(makecmd_libphaseret); 48 | system(makecmd_libphaseret); 49 | else 50 | [status,result] = system(makecmd_libphaseret); 51 | if status ~=0, error(result); end 52 | end 53 | end 54 | 55 | if libisloaded(libname) 56 | if flags.do_reload || flags.do_recompile 57 | unloadlibrary(libname); 58 | else 59 | error('%s: libphaseret is already loaded. Use ''reload'' to force reload.',upper(mfilename)); 60 | end 61 | end 62 | 63 | warning('off'); 64 | headerpath = [libltfatpath,'build',filesep,'phaseret.h']; 65 | headerpath_libltfat = [libltfatpath,'build',filesep,'ltfat.h']; 66 | loadlibrary(libpath,headerpath,'mfilename','libphaseretprotofile.m','addheader',headerpath_libltfat); 67 | warning('on'); 68 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/typeconstant.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_TYPECONSTANT_H 2 | #define _LTFAT_TYPECONSTANT_H 3 | // #include "ltfat.h" 4 | #include "memalloc.h" 5 | #include "dgt_common.h" 6 | #include "dgtwrapper_typeconstant.h" 7 | 8 | typedef struct 9 | { 10 | ltfat_int quot; 11 | ltfat_int rem; 12 | } ltfat_div_t; 13 | 14 | /* -------- Define routines that do not change between single/double-- */ 15 | LTFAT_API ltfat_div_t 16 | ltfat_idiv(ltfat_int a, ltfat_int b); 17 | 18 | LTFAT_API ltfat_int 19 | ltfat_idivceil(ltfat_int a, ltfat_int b); 20 | 21 | LTFAT_API ltfat_int 22 | ltfat_gcd(ltfat_int a, ltfat_int b, ltfat_int *r, ltfat_int *s ); 23 | 24 | LTFAT_API void 25 | ltfat_fftindex(ltfat_int N, ltfat_int *indexout); 26 | 27 | LTFAT_API 28 | ltfat_int makelarger(ltfat_int L, ltfat_int K); 29 | 30 | LTFAT_API 31 | ltfat_int ltfat_imax(ltfat_int a, ltfat_int b); 32 | 33 | LTFAT_API 34 | ltfat_int ltfat_imin(ltfat_int a, ltfat_int b); 35 | 36 | /** \addtogroup utils 37 | * @{ 38 | */ 39 | /** Find least common multiple of a and b 40 | */ 41 | LTFAT_API 42 | ltfat_int ltfat_lcm(ltfat_int a, ltfat_int b); 43 | 44 | /** Find next suitable L for signal length Ls and Gabor lattice parameters a and M 45 | */ 46 | LTFAT_API ltfat_int 47 | ltfat_dgtlength(ltfat_int Ls, ltfat_int a, ltfat_int M); 48 | /** @}*/ 49 | 50 | LTFAT_API ltfat_int 51 | ltfat_pow2base(ltfat_int x); 52 | 53 | LTFAT_API int 54 | ltfat_ispow2(ltfat_int x); 55 | 56 | LTFAT_API ltfat_int 57 | ltfat_dgtlengthmulti(ltfat_int Ls, ltfat_int P, ltfat_int a[], ltfat_int M[]); 58 | 59 | LTFAT_API 60 | void gabimagepars(ltfat_int Ls, ltfat_int x, ltfat_int y, 61 | ltfat_int *a, ltfat_int *M, ltfat_int *L, ltfat_int *N, ltfat_int *Ngood); 62 | 63 | LTFAT_API 64 | ltfat_int wfacreal_size(ltfat_int L, ltfat_int a, ltfat_int M); 65 | 66 | LTFAT_API ltfat_int 67 | ltfat_nextfastfft(ltfat_int x); 68 | 69 | LTFAT_API ltfat_int 70 | ltfat_pow2(ltfat_int x); 71 | 72 | LTFAT_API ltfat_int 73 | ltfat_nextpow2(ltfat_int x); 74 | 75 | LTFAT_API ltfat_int 76 | ltfat_modpow2(ltfat_int x, ltfat_int pow2var); 77 | 78 | LTFAT_API ltfat_int 79 | ltfat_round(const double x); 80 | 81 | LTFAT_API ltfat_int 82 | ltfat_positiverem(ltfat_int a, ltfat_int b); 83 | 84 | 85 | LTFAT_API ltfat_int 86 | ltfat_posnumfastmod(ltfat_int a, ltfat_int b); 87 | 88 | LTFAT_API ltfat_int 89 | ltfat_rangelimit(ltfat_int a, ltfat_int amin, ltfat_int amax); 90 | 91 | // Custom headers are down here 92 | #include "reassign_typeconstant.h" 93 | 94 | #endif /* _LTFAT_TYPECONSTANT */ 95 | -------------------------------------------------------------------------------- /modules/libphaseret/include/phaseret/gsrtisilapghi.h: -------------------------------------------------------------------------------- 1 | #ifndef LTFAT_NOSYSTEMHEADERS 2 | #include "ltfat.h" 3 | #include "ltfat/types.h" 4 | #include "rtpghi.h" 5 | #include "rtisila.h" 6 | #include "gsrtisila.h" 7 | #endif 8 | 9 | #ifndef _phaseret_gsrtisilapghi_h 10 | #define _phaseret_gsrtisilapghi_h 11 | // place for non-templated structs, enums, functions etc. 12 | #endif /* _gsrtisila_h */ 13 | 14 | #include "phaseret/types.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | typedef struct PHASERET_NAME(gsrtisilapghi_state) PHASERET_NAME(gsrtisilapghi_state); 21 | 22 | PHASERET_API int 23 | PHASERET_NAME(gsrtisilapghi_init_win)(LTFAT_FIRWIN win, ltfat_int gl, ltfat_int W, 24 | ltfat_int a, ltfat_int M, ltfat_int lookahead, 25 | ltfat_int maxit, double tol, int do_causalrtpghi, 26 | PHASERET_NAME(gsrtisilapghi_state)** pout); 27 | 28 | PHASERET_API int 29 | PHASERET_NAME(gsrtisilapghi_init)(const LTFAT_REAL* g, ltfat_int gl, 30 | ltfat_int W, ltfat_int a, ltfat_int M, ltfat_int lookahead, 31 | ltfat_int maxit, double gamma, double tol, int do_causalrtpghi, 32 | PHASERET_NAME(gsrtisilapghi_state)** pout); 33 | 34 | PHASERET_API int 35 | PHASERET_NAME(gsrtisilapghi_execute)(PHASERET_NAME(gsrtisilapghi_state)* p, 36 | const LTFAT_REAL s[], LTFAT_COMPLEX c[]); 37 | 38 | PHASERET_API int 39 | PHASERET_NAME(gsrtisilapghi_done)(PHASERET_NAME(gsrtisilapghi_state)** p); 40 | 41 | PHASERET_API int 42 | PHASERET_NAME(gsrtisilapghi_reset)(PHASERET_NAME(gsrtisilapghi_state)* p, 43 | const LTFAT_REAL** sinit); 44 | 45 | PHASERET_API int 46 | PHASERET_NAME(gsrtisilapghioffline)(const LTFAT_REAL s[], const LTFAT_REAL g[], 47 | ltfat_int L, ltfat_int gl, ltfat_int W, ltfat_int a, ltfat_int M, 48 | ltfat_int lookahead, ltfat_int maxit, 49 | double gamma, double tol, int do_causalrtpghi, LTFAT_COMPLEX c[]); 50 | 51 | PHASERET_API PHASERET_NAME(gsrtisila_state)* 52 | PHASERET_NAME(gsrtisilapghi_get_gsrtisila_state)( PHASERET_NAME(gsrtisilapghi_state)* p); 53 | 54 | PHASERET_API PHASERET_NAME(rtpghi_state)* 55 | PHASERET_NAME(gsrtisilapghi_get_rtpghi_state)( PHASERET_NAME(gsrtisilapghi_state)* p); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_fftifftshift.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_fftifftshift(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1,9,11,110,111]; 11 | 12 | for L = Larr 13 | 14 | z = cast((1:L)',flags.complexity); 15 | zi = complex2interleaved(fft(z)); 16 | zout = randn(size(zi),flags.complexity); 17 | 18 | ziPtr = libpointer(dataPtr,zi); 19 | zoutPtr = libpointer(dataPtr,zout); 20 | 21 | trueres = ifftshift(z); 22 | 23 | funname = makelibraryname('fftifftshift',flags.complexity,1); 24 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 25 | 26 | res = norm(trueres - real(ifft(interleaved2complex(zoutPtr.Value)))); 27 | 28 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 29 | fprintf(['FFTIFFTSHIFT OP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 30 | 31 | status = calllib('libltfat', funname, ziPtr,L,ziPtr); 32 | 33 | res = norm(trueres - real(ifft(interleaved2complex(ziPtr.Value)))); 34 | 35 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 36 | fprintf(['FFTIFFTSHIFT IP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 37 | 38 | z = cast((1:L)',flags.complexity); 39 | zi = complex2interleaved(fftreal(z)); 40 | zout = randn(size(zi),flags.complexity); 41 | 42 | ziPtr = libpointer(dataPtr,zi); 43 | zoutPtr = libpointer(dataPtr,zout); 44 | 45 | trueres = ifftshift(z); 46 | 47 | funname = makelibraryname('fftrealifftshift',flags.complexity,1); 48 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 49 | 50 | res = norm(trueres - ifftreal(interleaved2complex(zoutPtr.Value),L)); 51 | 52 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 53 | fprintf(['FFTREALIFFTSHIFT OP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 54 | 55 | status = calllib('libltfat', funname, ziPtr,L,ziPtr); 56 | 57 | res = norm(trueres - ifftreal(interleaved2complex(ziPtr.Value),L)); 58 | 59 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 60 | fprintf(['FFTREALIFFTSHIFT IP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 61 | 62 | end 63 | 64 | 65 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/dgtwrapper_typeconstant.h: -------------------------------------------------------------------------------- 1 | #ifndef _ltfat_dgtwrapper_typeconstant_h 2 | #define _ltfat_dgtwrapper_typeconstant_h 3 | 4 | /** \defgroup dgtwrapper Discrete Gabor Transform analysis-synthesis 5 | */ 6 | typedef struct ltfat_dgt_params ltfat_dgt_params; 7 | 8 | /** \addtogroup dgtwrapper 9 | * @{ */ 10 | typedef enum 11 | { 12 | ltfat_dgt_auto, 13 | ltfat_dgt_long, 14 | ltfat_dgt_fb 15 | } ltfat_dgt_hint; 16 | 17 | /** \name Parameter setup struct 18 | * @{ */ 19 | 20 | /** Allocate dgt_params structure and initialize to default values 21 | * 22 | * \warning The structure must be freed using ltfat_dgt_params_free() 23 | * 24 | * \returns Allocated struct (or NULL if the memory allocation failed 25 | * \see ltfat_dgt_params_free 26 | */ 27 | LTFAT_API ltfat_dgt_params* 28 | ltfat_dgt_params_allocdef(); 29 | 30 | /** Set DGT phase convention 31 | * 32 | * \returns 33 | * Status code | Description 34 | * ---------------------|---------------- 35 | * LTFATERR_SUCESS | No error occured 36 | * LTFATERR_NULLPOINTER | \a params was NULL 37 | */ 38 | LTFAT_API int 39 | ltfat_dgt_setpar_phaseconv(ltfat_dgt_params* params, ltfat_phaseconvention ptype); 40 | 41 | LTFAT_API int 42 | ltfat_dgt_getpar_phaseconv(ltfat_dgt_params* params); 43 | 44 | /** Set FFTW flags 45 | * 46 | * \returns 47 | * Status code | Description 48 | * ---------------------|---------------- 49 | * LTFATERR_SUCESS | No error occured 50 | * LTFATERR_NULLPOINTER | \a params was NULL 51 | */ 52 | LTFAT_API int 53 | ltfat_dgt_setpar_fftwflags(ltfat_dgt_params* params, unsigned fftw_flags); 54 | 55 | /** Set algorithm hint 56 | * 57 | * \returns 58 | * Status code | Description 59 | * ---------------------|---------------- 60 | * LTFATERR_SUCESS | No error occured 61 | * LTFATERR_NULLPOINTER | \a params was NULL 62 | */ 63 | LTFAT_API int 64 | ltfat_dgt_setpar_hint(ltfat_dgt_params* params, ltfat_dgt_hint hint); 65 | 66 | LTFAT_API int 67 | ltfat_dgt_setpar_synoverwrites(ltfat_dgt_params* params, int do_synoverwrites); 68 | 69 | /** Destroy struct 70 | * 71 | * \returns 72 | * Status code | Description 73 | * ---------------------|---------------- 74 | * LTFATERR_SUCESS | No error occured 75 | * LTFATERR_NULLPOINTER | \a params was NULL 76 | */ 77 | LTFAT_API int 78 | ltfat_dgt_params_free(ltfat_dgt_params* params); 79 | 80 | /** @} */ 81 | /** @} */ 82 | 83 | // The following function is not part of API 84 | int 85 | ltfat_dgt_params_defaults(ltfat_dgt_params* params); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_fftfftshift.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_fftfftshift(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1,9,11,110,111]; 11 | 12 | for L = Larr 13 | 14 | z = cast((1:L)' + i*(L:-1:1)',flags.complexity); 15 | zi = complex2interleaved(fft(z)); 16 | zout = randn(size(zi),flags.complexity); 17 | 18 | ziPtr = libpointer(dataPtr,zi); 19 | zoutPtr = libpointer(dataPtr,zout); 20 | 21 | trueres = fftshift(z); 22 | 23 | funname = makelibraryname('fftfftshift',flags.complexity,1); 24 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 25 | 26 | res = norm(trueres - ifft(interleaved2complex(zoutPtr.Value))); 27 | 28 | 29 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 30 | fprintf(['FFTFFTSHIFT OP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 31 | 32 | status = calllib('libltfat', funname, ziPtr,L,ziPtr); 33 | 34 | res = norm(trueres - (ifft(interleaved2complex(ziPtr.Value)))); 35 | 36 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 37 | fprintf(['FFTFFTSHIFT IP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 38 | 39 | z = cast((1:L)',flags.complexity); 40 | zi = complex2interleaved(fftreal(z)); 41 | zout = randn(size(zi),flags.complexity); 42 | 43 | ziPtr = libpointer(dataPtr,zi); 44 | zoutPtr = libpointer(dataPtr,zout); 45 | 46 | funname = makelibraryname('fftrealfftshift',flags.complexity,1); 47 | status = calllib('libltfat',funname,ziPtr,L,zoutPtr); 48 | 49 | trueres = fftshift(z); 50 | res = norm(trueres - real(ifftreal(interleaved2complex(zoutPtr.Value),L))); 51 | 52 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 53 | fprintf(['FFTREALFFTSHIFT OP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 54 | 55 | status = calllib('libltfat', funname, ziPtr,L,ziPtr); 56 | 57 | res = norm(trueres - real(ifftreal(interleaved2complex(ziPtr.Value),L))); 58 | 59 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 60 | fprintf(['FFTREALFFTSHIFT IP L:%3i, %s %s %s\n'],L,flags.complexity,ltfatstatusstring(status),fail); 61 | 62 | end 63 | 64 | 65 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/goertzel.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTFAT_GOERTZEL_H 2 | #define _LTFAT_GOERTZEL_H 3 | 4 | typedef enum 5 | { 6 | CZT_NEXTFASTFFT, 7 | CZT_NEXTPOW2 8 | } czt_ffthint; 9 | 10 | #endif 11 | 12 | 13 | /* 14 | Goertzel algorithm 15 | */ 16 | // This is opaque pointer 17 | typedef struct LTFAT_NAME(gga_plan_struct) *LTFAT_NAME(gga_plan); 18 | 19 | LTFAT_API LTFAT_NAME(gga_plan) 20 | LTFAT_NAME(gga_init)(const LTFAT_REAL *indVecPtr, 21 | ltfat_int M, ltfat_int L); 22 | 23 | LTFAT_API void 24 | LTFAT_NAME(gga_done)(LTFAT_NAME(gga_plan) plan); 25 | 26 | 27 | LTFAT_API 28 | void LTFAT_NAME(gga)(const LTFAT_TYPE *fPtr, const LTFAT_REAL *indVecPtr, 29 | ltfat_int L, ltfat_int W, ltfat_int M, 30 | LTFAT_COMPLEX *cPtr); 31 | 32 | LTFAT_API void 33 | LTFAT_NAME(gga_execute)(LTFAT_NAME(gga_plan) p, 34 | const LTFAT_TYPE *fPtr, 35 | ltfat_int W, 36 | LTFAT_COMPLEX *cPtr); 37 | 38 | 39 | /* 40 | Chirped Z transform 41 | */ 42 | // This is opaque pointer 43 | typedef struct LTFAT_NAME(chzt_plan_struct) *LTFAT_NAME(chzt_plan); 44 | 45 | LTFAT_API void 46 | LTFAT_NAME(chzt)(const LTFAT_TYPE *fPtr, ltfat_int L, 47 | ltfat_int W, ltfat_int K, 48 | const LTFAT_REAL deltao, const LTFAT_REAL o, 49 | LTFAT_COMPLEX *cPtr); 50 | 51 | LTFAT_API void 52 | LTFAT_NAME(chzt_execute)(LTFAT_NAME(chzt_plan) p, const LTFAT_TYPE *fPtr, 53 | ltfat_int W, LTFAT_COMPLEX *cPtr); 54 | 55 | LTFAT_API LTFAT_NAME(chzt_plan) 56 | LTFAT_NAME(chzt_init)(ltfat_int K, ltfat_int L, 57 | const LTFAT_REAL deltao, const LTFAT_REAL o, 58 | const unsigned fftw_flags, czt_ffthint hint); 59 | 60 | LTFAT_API 61 | void LTFAT_NAME(chzt_done)(LTFAT_NAME(chzt_plan) p); 62 | 63 | 64 | 65 | 66 | LTFAT_API void 67 | LTFAT_NAME(chzt_fac)(const LTFAT_TYPE *fPtr, ltfat_int L, 68 | ltfat_int W, ltfat_int K, 69 | const LTFAT_REAL deltao, const LTFAT_REAL o, 70 | LTFAT_COMPLEX *cPtr); 71 | 72 | LTFAT_API void 73 | LTFAT_NAME(chzt_fac_execute)(LTFAT_NAME(chzt_plan) p, const LTFAT_TYPE *fPtr, 74 | ltfat_int W, LTFAT_COMPLEX *cPtr); 75 | 76 | LTFAT_API LTFAT_NAME(chzt_plan) 77 | LTFAT_NAME(chzt_fac_init)(ltfat_int K, ltfat_int L, 78 | const LTFAT_REAL deltao, const LTFAT_REAL o, 79 | const unsigned fftw_flags, czt_ffthint hint); 80 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_firwin.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_firwin(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | [~,~,enuminfo]=libltfatprotofile; 11 | Cenumnorms = enuminfo.LTFAT_FIRWIN; 12 | 13 | d = arg_firwin; 14 | wins = d.flags.wintype; 15 | wins(strcmp('truncgauss',wins)) = []; 16 | 17 | wins = [wins 'truncgauss01']; 18 | 19 | names =fieldnames(Cenumnorms); 20 | 21 | libwins = {}; 22 | for nameId = 1:numel(wins) 23 | libwins{end+1} = Cenumnorms.(names{strcmpi(['ltfat_', wins{nameId}],names)}); 24 | end 25 | 26 | Larr = [1,9,10,11,110,111]; 27 | 28 | for do_complex = 0:1 29 | complexstring = ''; 30 | if do_complex, complexstring = 'complex'; end 31 | funname = makelibraryname('firwin',flags.complexity,do_complex); 32 | for L = Larr 33 | for nId = 1:numel(wins) 34 | win = wins{nId}; 35 | lwin = libwins{nId}; 36 | 37 | if do_complex 38 | z = cast((1:L)' + i*(1:L)',flags.complexity); 39 | zi = complex2interleaved(z); 40 | ziPtr = libpointer(dataPtr,zi); 41 | else 42 | z = cast((1:L)',flags.complexity); 43 | zi = z; 44 | ziPtr = libpointer(dataPtr,zi); 45 | end 46 | 47 | status = calllib('libltfat',funname,lwin,L,ziPtr); 48 | 49 | startswith = 'truncgauss'; 50 | if regexpi(win,['^',startswith]) 51 | percent = 1; 52 | if numel(win) > numel(startswith) 53 | percent = str2double(win(numel(startswith)+1:end)); 54 | end 55 | 56 | trueres = long2fir(pgauss(10*L,'width',L,'atheight',percent/100,'inf'),L); 57 | if rem(L,2) == 0 58 | trueres(end/2+1) = 0; % 59 | end 60 | else 61 | trueres = firwin(win,L); 62 | end 63 | 64 | if do_complex 65 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 66 | else 67 | res = norm(trueres - ziPtr.Value); 68 | end 69 | 70 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed); 71 | fprintf(['FIRWIN L:%3i, %s %s %s %s %s\n'],L,win,flags.complexity,complexstring,ltfatstatusstring(status),fail); 72 | end 73 | end 74 | end 75 | 76 | 77 | -------------------------------------------------------------------------------- /modules/libltfat/src/wfacreal.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | /* wfac for real valued input. Produces only half the output coefficients of wfac_r */ 8 | LTFAT_API void 9 | LTFAT_NAME(wfacreal)(const LTFAT_REAL* g, ltfat_int L, ltfat_int R, 10 | ltfat_int a, ltfat_int M, 11 | LTFAT_COMPLEX* gf) 12 | { 13 | 14 | ltfat_int h_a, h_m; 15 | 16 | //LTFAT_REAL *gfp; 17 | LTFAT_COMPLEX* gfp = gf; 18 | 19 | ltfat_int s; 20 | ltfat_int rem, negrem; 21 | 22 | /* LTFAT_FFTW(plan) p_before; */ 23 | LTFAT_NAME(fftreal_plan)* p_before; 24 | 25 | ltfat_int b = L / M; 26 | ltfat_int c = ltfat_gcd(a, M, &h_a, &h_m); 27 | ltfat_int p = a / c; 28 | ltfat_int q = M / c; 29 | ltfat_int d = b / p; 30 | 31 | /* This is a floor operation. */ 32 | ltfat_int d2 = d / 2 + 1; 33 | 34 | const LTFAT_REAL sqrtM = (LTFAT_REAL) sqrt((double)M); 35 | 36 | LTFAT_REAL* sbuf = LTFAT_NAME_REAL(malloc)(d); 37 | LTFAT_COMPLEX* cbuf = LTFAT_NAME_COMPLEX(malloc)(d2); 38 | 39 | /* Create plan. In-place. */ 40 | /* p_before = LTFAT_FFTW(plan_dft_r2c_1d)((int) d, sbuf, */ 41 | /* (LTFAT_FFTW(complex)*) cbuf, FFTW_MEASURE); */ 42 | LTFAT_NAME(fftreal_init)(d, 1, sbuf, cbuf, FFTW_MEASURE, &p_before); 43 | 44 | 45 | // ltfat_int ld3=2*c*p*q*R; 46 | ltfat_int ld3 = c * p * q * R; 47 | //gfp=(LTFAT_REAL*)gf; 48 | for (ltfat_int r = 0; r < c; r++) 49 | { 50 | for (ltfat_int w = 0; w < R; w++) 51 | { 52 | for (ltfat_int l = 0; l < q; l++) 53 | { 54 | for (ltfat_int k = 0; k < p; k++) 55 | { 56 | negrem = ltfat_positiverem(k * M - l * a, L); 57 | for (s = 0; s < d; s++) 58 | { 59 | rem = (negrem + s * p * M) % L; 60 | sbuf[s] = sqrtM * g[r + rem + L * w]; 61 | } 62 | 63 | /* LTFAT_FFTW(execute)(p_before); */ 64 | LTFAT_NAME(fftreal_execute)(p_before); 65 | 66 | for (s = 0; s < d2; s++) 67 | { 68 | gfp[s * ld3] = cbuf[s]; 69 | } 70 | gfp++; 71 | } 72 | } 73 | } 74 | } 75 | 76 | LTFAT_SAFEFREEALL(sbuf, cbuf); 77 | /* LTFAT_FFTW(destroy_plan)(p_before); */ 78 | LTFAT_NAME(fftreal_done)(&p_before); 79 | } 80 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_circshift.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_circshift(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1,9,11,110]; 11 | shiftarr = [-10, 100, 0, -1, 1, 3]; 12 | 13 | for do_complex = 0:1 14 | complexstring = ''; 15 | if do_complex, complexstring = 'complex'; end 16 | for L = Larr 17 | for shift = shiftarr 18 | 19 | if do_complex 20 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 21 | zi = complex2interleaved(z); 22 | zout = randn(size(zi),flags.complexity); 23 | 24 | ziPtr = libpointer(dataPtr,zi); 25 | zoutPtr = libpointer(dataPtr,zout); 26 | else 27 | z = cast((1:L)',flags.complexity); 28 | zi = z; 29 | zout = randn(size(zi),flags.complexity); 30 | 31 | ziPtr = libpointer(dataPtr,zi); 32 | zoutPtr = libpointer(dataPtr,zout); 33 | end 34 | 35 | trueres = circshift(z,shift); 36 | 37 | 38 | status = calllib('libltfat',makelibraryname('circshift',flags.complexity,do_complex),... 39 | ziPtr,L,shift,zoutPtr); 40 | 41 | if do_complex 42 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 43 | else 44 | res = norm(trueres - zoutPtr.Value); 45 | end 46 | 47 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 48 | fprintf(['CIRCSHIFT OP L:%3i, shift:%3i %s %s %s %s\n'],L,shift,flags.complexity,complexstring,ltfatstatusstring(status),fail); 49 | 50 | status = calllib('libltfat',makelibraryname('circshift',flags.complexity,do_complex),... 51 | ziPtr,L,shift,ziPtr); 52 | 53 | if do_complex 54 | res = norm(trueres - interleaved2complex(ziPtr.Value)); 55 | else 56 | res = norm(trueres - ziPtr.Value); 57 | end 58 | 59 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 60 | fprintf(['CIRCSHIFT IP L:%3i, shift:%3i %s %s %s %s\n'],L,shift,flags.complexity,complexstring,ltfatstatusstring(status),fail); 61 | end 62 | end 63 | end 64 | 65 | -------------------------------------------------------------------------------- /modules/libltfat/src/iwfacreal.c: -------------------------------------------------------------------------------- 1 | #include "ltfat.h" 2 | #include "ltfat/types.h" 3 | #include "ltfat/macros.h" 4 | 5 | #include "ltfat/thirdparty/fftw3.h" 6 | 7 | LTFAT_API void 8 | LTFAT_NAME(iwfacreal)(const LTFAT_COMPLEX* gf, ltfat_int L, 9 | ltfat_int R, 10 | ltfat_int a, ltfat_int M, LTFAT_REAL* g) 11 | { 12 | 13 | ltfat_int h_a, h_m; 14 | 15 | /* LTFAT_FFTW(plan) p_before; */ 16 | LTFAT_NAME_REAL(ifftreal_plan)* p_before; 17 | 18 | ltfat_int b = L / M; 19 | ltfat_int c = ltfat_gcd(a, M, &h_a, &h_m); 20 | ltfat_int p = a / c; 21 | ltfat_int q = M / c; 22 | ltfat_int d = b / p; 23 | 24 | /* This is a floor operation. */ 25 | ltfat_int d2 = d / 2 + 1; 26 | 27 | /* division by d is because of the way FFTW normalizes the transform. */ 28 | LTFAT_REAL scaling = (LTFAT_REAL) ( 1.0 / sqrt((double)M) / d ); 29 | 30 | LTFAT_REAL* sbuf = LTFAT_NAME_REAL(malloc)( d); 31 | LTFAT_COMPLEX* cbuf = LTFAT_NAME_COMPLEX(malloc)( d2); 32 | 33 | /* Create plan. In-place. */ 34 | /* p_before = LTFAT_FFTW(plan_dft_c2r_1d)((int)d, (LTFAT_FFTW(complex)*) cbuf, sbuf, */ 35 | /* FFTW_MEASURE); */ 36 | LTFAT_NAME_REAL(ifftreal_init)(d, 1, cbuf, sbuf, FFTW_MEASURE, &p_before); 37 | 38 | ltfat_int ld3 = c * p * q * R; 39 | 40 | /* Advancing pointer: Runs through array pointing out the base for the strided operations. */ 41 | const LTFAT_COMPLEX* gfp = gf; 42 | 43 | for (ltfat_int r = 0; r < c; r++) 44 | { 45 | for (ltfat_int w = 0; w < R; w++) 46 | { 47 | for (ltfat_int l = 0; l < q; l++) 48 | { 49 | for (ltfat_int k = 0; k < p; k++) 50 | { 51 | ltfat_int negrem = ltfat_positiverem(k * M - l * a, L); 52 | for (ltfat_int s = 0; s < d2; s++) 53 | { 54 | cbuf[s] = gfp[s * ld3] * scaling; 55 | } 56 | 57 | /* LTFAT_FFTW(execute)(p_before); */ 58 | LTFAT_NAME_REAL(ifftreal_execute)(p_before); 59 | 60 | for (ltfat_int s = 0; s < d; s++) 61 | { 62 | g[r + (negrem + s * p * M) % L + L * w] = sbuf[s]; 63 | } 64 | gfp++; 65 | } 66 | } 67 | } 68 | } 69 | 70 | /* Clear the work-arrays. */ 71 | LTFAT_SAFEFREEALL(cbuf, sbuf); 72 | 73 | /* LTFAT_FFTW(destroy_plan)(p_before); */ 74 | LTFAT_NAME_REAL(ifftreal_done)(&p_before); 75 | } 76 | -------------------------------------------------------------------------------- /modules/libltfat/src/heapint_private.h: -------------------------------------------------------------------------------- 1 | #define NORTHFROMW(w,M,N) ((((w) + 1) % (M)) + (w) - (w) % (M)) 2 | #define SOUTHFROMW(w,M,N) (((w) - 1 + (M)) % (M) + (w) - (w) % (M)) 3 | #define EASTFROMW(w,M,N) (((w) + (M)) % ((M) * (N))) 4 | #define WESTFROMW(w,M,N) (((w) - (M) + (M) * (N)) % ((M) * (N))) 5 | 6 | #ifndef _ltfat_mask_element_defined 7 | #define _ltfat_mask_element_defined 8 | 9 | enum ltfat_mask_element 10 | { 11 | LTFAT_MASK_BELOWTOL = -1, // Do not compute phase, the coefficient is too small 12 | LTFAT_MASK_UNKNOWN = 0, // Will compute phase for these 13 | LTFAT_MASK_KNOWN = 1, // The phase was already known 14 | LTFAT_MASK_WENTNORTH = 2, // Phase was spread from the south neighbor 15 | LTFAT_MASK_WENTSOUTH = 3, // Phase was spread from the north neighbor 16 | LTFAT_MASK_WENTEAST = 4, // Phase was spread from the west neighbor 17 | LTFAT_MASK_WENTWEST = 5, // Phase was spread from the east neighbor 18 | LTFAT_MASK_STARTPOINT = 6, // This is the initial point of integration. It gets zero phase 19 | LTFAT_MASK_BORDERPOINT = 7, // This is candidate border coefficient with known phase 20 | }; 21 | 22 | #endif 23 | 24 | struct LTFAT_NAME(heapinttask) 25 | { 26 | ltfat_int height; 27 | ltfat_int N; 28 | int do_real; 29 | int* donemask; 30 | void (*intfun)(const LTFAT_NAME(heapinttask)*, 31 | const LTFAT_REAL*, const LTFAT_REAL*, 32 | ltfat_int, LTFAT_REAL* ); 33 | LTFAT_NAME(heap)* heap; 34 | }; 35 | 36 | 37 | void 38 | LTFAT_NAME(trapezheap)(const LTFAT_NAME(heapinttask) *heaptask, 39 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 40 | ltfat_int w, LTFAT_REAL* phase); 41 | 42 | void 43 | LTFAT_NAME(trapezheapreal)(const LTFAT_NAME(heapinttask) *heaptask, 44 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 45 | ltfat_int w, LTFAT_REAL* phase); 46 | 47 | void 48 | LTFAT_NAME(gradsamptorad)(const LTFAT_REAL* tgrad, const LTFAT_REAL* fgrad, 49 | ltfat_int a, ltfat_int M, ltfat_int L, ltfat_int W, 50 | ltfat_phaseconvention phasetype, int do_real, 51 | LTFAT_REAL* tgradw, LTFAT_REAL* fgradw); 52 | 53 | void 54 | LTFAT_NAME(borderstoheap)(LTFAT_NAME(heap)* h, 55 | ltfat_int height, ltfat_int N, 56 | int * donemask); 57 | 58 | void 59 | LTFAT_NAME(borderstoheapreal)(LTFAT_NAME(heap)* h, 60 | ltfat_int height, ltfat_int N, 61 | int * donemask); 62 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_long2fir.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_long2fir(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1, 9,11,110,1, 9, 8, 8, 11, 11, 10]; 11 | Loutarr = [11,9,12,221,1,10, 10, 11, 15, 16, 1000]; 12 | 13 | for do_complex = 0:1 14 | complexstring = ''; 15 | if do_complex, complexstring = 'complex'; end 16 | funname = makelibraryname('long2fir',flags.complexity,do_complex); 17 | 18 | for Lidx = 1:numel(Larr) 19 | Lout = Larr(Lidx); 20 | L = Loutarr(Lidx); 21 | 22 | if do_complex 23 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 24 | zi = complex2interleaved(z); 25 | zout = randn(2*Lout,1,flags.complexity); 26 | 27 | ziPtr = libpointer(dataPtr,zi); 28 | zoutPtr = libpointer(dataPtr,zout); 29 | else 30 | z = cast((1:L)',flags.complexity); 31 | zi = z; 32 | zout = randn(Lout,1,flags.complexity); 33 | 34 | ziPtr = libpointer(dataPtr,zi); 35 | zoutPtr = libpointer(dataPtr,zout); 36 | end 37 | 38 | trueres = long2fir(z,Lout); 39 | 40 | status = calllib('libltfat',funname,ziPtr,L,Lout,zoutPtr); 41 | 42 | if do_complex 43 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 44 | else 45 | res = norm(trueres - zoutPtr.Value); 46 | end 47 | 48 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 49 | fprintf(['FIR2LONG OP L:%3i, Lout:%3i, %s %s %s %s\n'],L,Lout,flags.complexity,complexstring,ltfatstatusstring(status),fail); 50 | 51 | status = calllib('libltfat',funname,ziPtr,L,Lout,ziPtr); 52 | 53 | if do_complex 54 | res = norm(trueres - postpad(interleaved2complex(ziPtr.Value),numel(trueres))); 55 | else 56 | res = norm(trueres - postpad(ziPtr.Value,numel(trueres))); 57 | end 58 | 59 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 60 | fprintf(['FIR2LONG IP L:%3i, Lout:%3i, %s %s %s %s\n'],L,Lout,flags.complexity,complexstring,ltfatstatusstring(status),fail); 61 | end 62 | end 63 | 64 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.1) 2 | project (libltfat C CXX) 3 | 4 | set(CMAKE_BUILD_TYPE Release) 5 | 6 | option(BUILD_SHARED_LIBS 7 | "Build .so/.dll" ON) 8 | 9 | option(NOBLASLAPACK 10 | "Disable BLAS and LAPACK dependency" ON) 11 | 12 | option(NOFFTW 13 | "Disable FFTW dependency" ON) 14 | 15 | if (MSVC) 16 | set(USECPP 1) 17 | else (MSVC) 18 | option(USECPP 19 | "Use C++ compiler" OFF) 20 | endif (MSVC) 21 | 22 | if (NOT NOFFTW) 23 | FIND_LIBRARY(FFTW3_LIB NAMES fftw3 libfftw3) 24 | FIND_LIBRARY(FFTW3F_LIB NAMES fftw3f libfftw3f) 25 | endif (NOT NOFFTW) 26 | 27 | if (NOT NOBLASLAPACK) 28 | FIND_LIBRARY(BLAS_LIB NAMES blas libblas) 29 | FIND_LIBRARY(LAPACK_LIB NAMES lapack liblapack) 30 | endif (NOT NOBLASLAPACK) 31 | 32 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 33 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 34 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 35 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 36 | 37 | 38 | if (NOBLASLAPACK) 39 | add_definitions(-DNOBLASLAPACK) 40 | endif (NOBLASLAPACK) 41 | 42 | if (NOFFTW) 43 | add_definitions(-DKISS) 44 | else (NOFFTW) 45 | add_definitions(-DFFTW) 46 | endif (NOFFTW) 47 | 48 | if (MSVC) 49 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /wd4706") 50 | else (MSVC) 51 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") 52 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") 53 | SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined -Wl,-rpath,$ORIGIN") 54 | SET(LIBS m) 55 | if(CMAKE_CROSSCOMPILING) 56 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc") 57 | endif(CMAKE_CROSSCOMPILING) 58 | endif(MSVC) 59 | 60 | set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 61 | set(OLD_CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) 62 | 63 | if(USECPP) 64 | set (CMAKE_CXX_STANDARD 11) 65 | else(USECPP) 66 | set (CMAKE_C_STANDARD 99) 67 | endif(USECPP) 68 | 69 | if (MSVC) 70 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_HAS_EXCEPTIONS=0 /EHsc") 71 | else (MSVC) 72 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") 73 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath,$ORIGIN") 74 | SET(LIBS m) 75 | endif(MSVC) 76 | 77 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/libltfat/include) 78 | 79 | add_subdirectory(modules/libltfat/src) 80 | 81 | option(DO_LIBPHASERET 82 | "Compile libphaseret module" OFF) 83 | 84 | if (DO_LIBPHASERET) 85 | add_subdirectory(modules/libphaseret/src) 86 | endif (DO_LIBPHASERET) 87 | 88 | add_subdirectory(examples EXCLUDE_FROM_ALL) 89 | 90 | -------------------------------------------------------------------------------- /modules/libltfat/include/ltfat/heapint_private.h: -------------------------------------------------------------------------------- 1 | #define NORTHFROMW(w,M,N) ((((w) + 1) % (M)) + (w) - (w) % (M)) 2 | #define SOUTHFROMW(w,M,N) (((w) - 1 + (M)) % (M) + (w) - (w) % (M)) 3 | #define EASTFROMW(w,M,N) (((w) + (M)) % ((M) * (N))) 4 | #define WESTFROMW(w,M,N) (((w) - (M) + (M) * (N)) % ((M) * (N))) 5 | 6 | #ifndef _ltfat_mask_element_defined 7 | #define _ltfat_mask_element_defined 8 | 9 | enum ltfat_mask_element 10 | { 11 | LTFAT_MASK_BELOWTOL = -1, // Do not compute phase, the coefficient is too small 12 | LTFAT_MASK_UNKNOWN = 0, // Will compute phase for these 13 | LTFAT_MASK_KNOWN = 1, // The phase was already known 14 | LTFAT_MASK_WENTNORTH = 2, // Phase was spread from the south neighbor 15 | LTFAT_MASK_WENTSOUTH = 3, // Phase was spread from the north neighbor 16 | LTFAT_MASK_WENTEAST = 4, // Phase was spread from the west neighbor 17 | LTFAT_MASK_WENTWEST = 5, // Phase was spread from the east neighbor 18 | LTFAT_MASK_STARTPOINT = 6, // This is the initial point of integration. It gets zero phase 19 | LTFAT_MASK_BORDERPOINT = 7, // This is candidate border coefficient with known phase 20 | }; 21 | 22 | #endif 23 | 24 | struct LTFAT_NAME(heapinttask) 25 | { 26 | ltfat_int height; 27 | ltfat_int N; 28 | int do_real; 29 | int* donemask; 30 | void (*intfun)(const LTFAT_NAME(heapinttask)*, 31 | const LTFAT_REAL*, const LTFAT_REAL*, 32 | ltfat_int, LTFAT_REAL* ); 33 | LTFAT_NAME(heap)* heap; 34 | }; 35 | 36 | 37 | void 38 | LTFAT_NAME(trapezheap)(const LTFAT_NAME(heapinttask) *heaptask, 39 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 40 | ltfat_int w, LTFAT_REAL* phase); 41 | 42 | void 43 | LTFAT_NAME(trapezheapreal)(const LTFAT_NAME(heapinttask) *heaptask, 44 | const LTFAT_REAL* tgradw, const LTFAT_REAL* fgradw, 45 | ltfat_int w, LTFAT_REAL* phase); 46 | 47 | void 48 | LTFAT_NAME(gradsamptorad)(const LTFAT_REAL* tgrad, const LTFAT_REAL* fgrad, 49 | ltfat_int a, ltfat_int M, ltfat_int L, ltfat_int W, 50 | ltfat_phaseconvention phasetype, int do_real, 51 | LTFAT_REAL* tgradw, LTFAT_REAL* fgradw); 52 | 53 | void 54 | LTFAT_NAME(borderstoheap)(LTFAT_NAME(heap)* h, 55 | ltfat_int height, ltfat_int N, 56 | int * donemask); 57 | 58 | void 59 | LTFAT_NAME(borderstoheapreal)(LTFAT_NAME(heap)* h, 60 | ltfat_int height, ltfat_int N, 61 | int * donemask); 62 | -------------------------------------------------------------------------------- /modules/libphaseret/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include) 2 | 3 | 4 | SET(sources 5 | gla.c legla.c pghi.c rtisila.c rtpghi.c spsi.c utils.c 6 | gsrtisila.c gsrtisilapghi.c) 7 | 8 | SET(sources_typeconstant 9 | legla_typeconstant.c pghi_typeconstant.c) 10 | 11 | if (USECPP) 12 | SET_SOURCE_FILES_PROPERTIES( ${sources} ${sources_typeconstant} 13 | PROPERTIES LANGUAGE CXX) 14 | endif (USECPP) 15 | 16 | add_library(libphaseret_commondouble OBJECT ${sources_typeconstant}) 17 | add_library(libphaseret_commonsingle OBJECT ${sources_typeconstant}) 18 | 19 | add_library(libphaseret_double OBJECT ${sources}) 20 | add_library(libphaseret_single OBJECT ${sources}) 21 | 22 | target_compile_definitions(libphaseret_commondouble PUBLIC LTFAT_DOUBLE) 23 | target_compile_definitions(libphaseret_commonsingle PUBLIC LTFAT_SINGLE) 24 | target_compile_definitions(libphaseret_double PUBLIC LTFAT_DOUBLE) 25 | target_compile_definitions(libphaseret_single PUBLIC LTFAT_SINGLE) 26 | 27 | if (WIN32) 28 | if(BUILD_SHARED_LIBS) 29 | target_compile_definitions(libphaseret_commondouble PUBLIC LTFAT_BUILD_SHARED) 30 | target_compile_definitions(libphaseret_commonsingle PUBLIC LTFAT_BUILD_SHARED) 31 | target_compile_definitions(libphaseret_double PUBLIC LTFAT_BUILD_SHARED) 32 | target_compile_definitions(libphaseret_single PUBLIC LTFAT_BUILD_SHARED) 33 | else(BUILD_SHARED_LIBS) 34 | target_compile_definitions(libphaseret_commondouble PUBLIC LTFAT_BUILD_STATIC) 35 | target_compile_definitions(libphaseret_commonsingle PUBLIC LTFAT_BUILD_STATIC) 36 | target_compile_definitions(libphaseret_double PUBLIC LTFAT_BUILD_STATIC) 37 | target_compile_definitions(libphaseret_single PUBLIC LTFAT_BUILD_STATIC) 38 | endif(BUILD_SHARED_LIBS) 39 | endif(WIN32) 40 | 41 | add_library(phaseret 42 | $ 43 | $ 44 | $) 45 | 46 | 47 | add_library(phaseretd 48 | $ 49 | $) 50 | 51 | add_library(phaseretf 52 | $ 53 | $) 54 | 55 | if (WIN32) 56 | if(BUILD_SHARED_LIBS) 57 | set_target_properties(phaseret PROPERTIES IMPORT_SUFFIX ".dll.lib") 58 | set_target_properties(phaseretf PROPERTIES IMPORT_SUFFIX ".dll.lib") 59 | set_target_properties(phaseretd PROPERTIES IMPORT_SUFFIX ".dll.lib") 60 | endif(BUILD_SHARED_LIBS) 61 | endif(WIN32) 62 | 63 | target_link_libraries(phaseret ltfat) 64 | target_link_libraries(phaseretf ltfatf) 65 | target_link_libraries(phaseretd ltfatd) 66 | 67 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_all_libltfat.m: -------------------------------------------------------------------------------- 1 | function [total_tests_failed,list_of_failed_tests]=test_all_libltfat(prec,varargin) 2 | 3 | definput.keyvals.tests=[]; 4 | definput.keyvals.ignore={}; 5 | [flags,kv]=ltfatarghelper({'tests'},definput,varargin); 6 | 7 | tests_todo = arrayfun(@(dEl) dEl.name(6:end-2),dir('./test_libltfat_*.m'),'UniformOutput',0); 8 | 9 | if ~isempty(kv.tests) 10 | if ischar(kv.tests) 11 | kv.tests = {kv.tests}; 12 | end 13 | tests_todo = kv.tests; 14 | end 15 | 16 | if ~isempty(kv.ignore) 17 | if ischar(kv.ignore) 18 | kv.ignore = {kv.ignore}; 19 | end 20 | if ~iscell(kv.ignore) 21 | error('%s: Ignored tests list is incorrect.',upper(mfilename)); 22 | end 23 | 24 | ignoreList = []; 25 | ignoreUsed = []; 26 | ignoreCell = kv.ignore; 27 | for ii=1:numel(tests_todo) 28 | res = cellfun(@(iEl) strcmpi(tests_todo{ii},iEl) , ignoreCell); 29 | if any(res) 30 | ignoreList(end+1) = ii; 31 | disp(sprintf('Ignoring test: %s',tests_todo{ii})) 32 | end 33 | [~,idx]=find(res>0); 34 | ignoreUsed(end+1:end+numel(idx)) = idx; 35 | end 36 | 37 | if ~isempty(ignoreList) 38 | tests_todo(ignoreList) = []; 39 | end 40 | 41 | if numel(ignoreUsed)~=numel(ignoreCell) 42 | ignoreCell(ignoreUsed) = []; 43 | strToPlot = cellfun(@(iEl) [iEl,', '],ignoreCell,'UniformOutput',0); 44 | strToPlot = cell2mat(strToPlot); 45 | 46 | error('%s: The following ignored tests were not found: %s',... 47 | upper(mfilename),strToPlot(1:end-2)); 48 | 49 | end 50 | end 51 | 52 | 53 | precarray={'double','single'}; 54 | if nargin >0 && ~strcmpi(prec,'all') 55 | if any(cellfun(@(pEl)strcmpi(pEl,prec),precarray)) 56 | precarray={prec}; 57 | else 58 | error('%s: Unknown data precision.',upper(mfilename)); 59 | end 60 | end 61 | 62 | total_tests_failed=0; 63 | list_of_failed_tests={}; 64 | 65 | for precidx=1:numel(precarray) 66 | prec=precarray{precidx}; 67 | 68 | for ii=1:length(tests_todo) 69 | test_failed=feval(['test_',tests_todo{ii}],prec); 70 | total_tests_failed=total_tests_failed+test_failed; 71 | if test_failed>0 72 | list_of_failed_tests{end+1}=['test_',tests_todo{ii},' ',prec]; 73 | end; 74 | end; 75 | end; 76 | 77 | disp(' '); 78 | if total_tests_failed==0 79 | disp('ALL TESTS PASSED'); 80 | else 81 | s=sprintf('%i TESTS FAILED',total_tests_failed); 82 | disp(s); 83 | disp('The following test scripts contained failed tests'); 84 | for ii=1:length(list_of_failed_tests) 85 | disp([' ',list_of_failed_tests{ii}]); 86 | end; 87 | end; 88 | 89 | -------------------------------------------------------------------------------- /modules/libltfat/testing/cUnit/test_pgauss.c: -------------------------------------------------------------------------------- 1 | int TEST_NAME(test_pgauss)() 2 | { 3 | ltfatInt L[] = { 111, 1, 100 }; 4 | double w[] = { 0.001, 0.1, 0.2 }; 5 | double c_t[] = { 0.0, 0.1, -0.2 }; 6 | double c_f[] = { 0.0, 0.1, -0.2 }; 7 | 8 | 9 | for (unsigned int lId = 0; lId < ARRAYLEN(L); lId++) 10 | { 11 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[lId]); 12 | TEST_NAME(fillRand)(fin, L[lId]); 13 | LTFAT_COMPLEX* fincmplx = LTFAT_NAME_COMPLEX(malloc)(L[0]); 14 | TEST_NAME_COMPLEX(fillRand)(fincmplx, L[0]); 15 | 16 | 17 | for (unsigned int wId = 0; wId < ARRAYLEN(w); wId++) 18 | { 19 | for (unsigned int ctId = 0; ctId < ARRAYLEN(c_t); ctId++) 20 | { 21 | 22 | mu_assert( 23 | LTFAT_NAME(pgauss)( L[lId], w[wId], c_t[ctId], fin) == LTFATERR_SUCCESS, 24 | "pgauss"); 25 | 26 | for (unsigned int cfId = 0; cfId < ARRAYLEN(c_f); cfId++) 27 | { 28 | mu_assert( 29 | LTFAT_NAME(pgauss_cmplx)( L[lId], w[wId], c_t[ctId], c_f[cfId], 30 | fincmplx) == LTFATERR_SUCCESS, 31 | "pgauss"); 32 | } 33 | } 34 | } 35 | 36 | ltfat_free(fin); 37 | ltfat_free(fincmplx); 38 | } 39 | 40 | LTFAT_TYPE* fin = LTFAT_NAME(malloc)(L[0]); 41 | TEST_NAME(fillRand)(fin, L[0]); 42 | 43 | LTFAT_COMPLEX* fincmplx = LTFAT_NAME_COMPLEX(malloc)(L[0]); 44 | TEST_NAME_COMPLEX(fillRand)(fincmplx, L[0]); 45 | 46 | mu_assert( 47 | LTFAT_NAME(pgauss)( L[0], w[0], c_t[0], NULL) == LTFATERR_NULLPOINTER, 48 | "pgauss Array is null"); 49 | 50 | mu_assert( 51 | LTFAT_NAME(pgauss)( 0, w[0], c_t[0], fin) == LTFATERR_BADSIZE, 52 | "pgauss L is wrong"); 53 | 54 | mu_assert( 55 | LTFAT_NAME(pgauss)( L[0], 0.0, c_t[0], fin) == LTFATERR_NOTPOSARG, 56 | "pgauss Wrong t-f ratio"); 57 | 58 | mu_assert( 59 | LTFAT_NAME(pgauss_cmplx)( L[0], w[0], c_t[0], c_f[0], 60 | NULL) == LTFATERR_NULLPOINTER, 61 | "pgauss cmplx Array is null"); 62 | 63 | mu_assert( 64 | LTFAT_NAME(pgauss_cmplx)( 0, w[0], c_t[0], c_f[0], 65 | fincmplx) == LTFATERR_BADSIZE, 66 | "pgauss cmplx L is wrong"); 67 | 68 | mu_assert( 69 | LTFAT_NAME(pgauss_cmplx)( L[0], 0.0, c_t[0], c_f[0], 70 | fincmplx) == LTFATERR_NOTPOSARG, 71 | "pgauss cmplx Wrong t-f ratio"); 72 | 73 | ltfat_free(fin); 74 | ltfat_free(fincmplx); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /modules/libphaseret/testing/mUnit/test_all_libphaseret.m: -------------------------------------------------------------------------------- 1 | function [total_tests_failed,list_of_failed_tests]=test_all_libphaseret(prec,varargin) 2 | 3 | definput.keyvals.tests=[]; 4 | definput.keyvals.ignore={}; 5 | [flags,kv]=ltfatarghelper({'tests'},definput,varargin); 6 | 7 | tests_todo = arrayfun(@(dEl) dEl.name(6:end-2),dir('./test_libphaseret_*.m'),'UniformOutput',0); 8 | 9 | if ~isempty(kv.tests) 10 | if ischar(kv.tests) 11 | kv.tests = {kv.tests}; 12 | end 13 | tests_todo = kv.tests; 14 | end 15 | 16 | if ~isempty(kv.ignore) 17 | if ischar(kv.ignore) 18 | kv.ignore = {kv.ignore}; 19 | end 20 | if ~iscell(kv.ignore) 21 | error('%s: Ignored tests list is incorrect.',upper(mfilename)); 22 | end 23 | 24 | ignoreList = []; 25 | ignoreUsed = []; 26 | ignoreCell = kv.ignore; 27 | for ii=1:numel(tests_todo) 28 | res = cellfun(@(iEl) strcmpi(tests_todo{ii},iEl) , ignoreCell); 29 | if any(res) 30 | ignoreList(end+1) = ii; 31 | disp(sprintf('Ignoring test: %s',tests_todo{ii})) 32 | end 33 | [~,idx]=find(res>0); 34 | ignoreUsed(end+1:end+numel(idx)) = idx; 35 | end 36 | 37 | if ~isempty(ignoreList) 38 | tests_todo(ignoreList) = []; 39 | end 40 | 41 | if numel(ignoreUsed)~=numel(ignoreCell) 42 | ignoreCell(ignoreUsed) = []; 43 | strToPlot = cellfun(@(iEl) [iEl,', '],ignoreCell,'UniformOutput',0); 44 | strToPlot = cell2mat(strToPlot); 45 | 46 | error('%s: The following ignored tests were not found: %s',... 47 | upper(mfilename),strToPlot(1:end-2)); 48 | 49 | end 50 | end 51 | 52 | 53 | precarray={'double','single'}; 54 | if nargin >0 && ~strcmpi(prec,'all') 55 | if any(cellfun(@(pEl)strcmpi(pEl,prec),precarray)) 56 | precarray={prec}; 57 | else 58 | error('%s: Unknown data precision.',upper(mfilename)); 59 | end 60 | end 61 | 62 | total_tests_failed=0; 63 | list_of_failed_tests={}; 64 | 65 | for precidx=1:numel(precarray) 66 | prec=precarray{precidx}; 67 | 68 | for ii=1:length(tests_todo) 69 | test_failed=feval(['test_',tests_todo{ii}],prec); 70 | total_tests_failed=total_tests_failed+test_failed; 71 | if test_failed>0 72 | list_of_failed_tests{end+1}=['test_',tests_todo{ii},' ',prec]; 73 | end; 74 | end; 75 | end; 76 | 77 | disp(' '); 78 | if total_tests_failed==0 79 | disp('ALL TESTS PASSED'); 80 | else 81 | s=sprintf('%i TESTS FAILED',total_tests_failed); 82 | disp(s); 83 | disp('The following test scripts contained failed tests'); 84 | for ii=1:length(list_of_failed_tests) 85 | disp([' ',list_of_failed_tests{ii}]); 86 | end; 87 | end; 88 | 89 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_fold.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_fold(varargin) 2 | 3 | test_failed = 0; 4 | 5 | fprintf(' =============== %s ================ \n',upper(mfilename)); 6 | 7 | definput.flags.complexity={'double','single'}; 8 | [flags]=ltfatarghelper({},definput,varargin); 9 | dataPtr = [flags.complexity, 'Ptr']; 10 | 11 | Larr = [10 11 10 10 101 101]; 12 | Lfoldarr = [3 16 3 3 1 2]; 13 | shiftarr = [0 0 -5 -101 -3 11]; 14 | 15 | for do_complex = 0:1 16 | complexstring = ''; 17 | if do_complex, complexstring = 'complex'; end 18 | funname = makelibraryname('fold_array',flags.complexity,do_complex); 19 | 20 | for lId = 1:numel(Larr) 21 | L = Larr(lId); 22 | Lfold = Lfoldarr(lId); 23 | shift = shiftarr(lId); 24 | 25 | if do_complex 26 | z = (1:max(L,Lfold)) + 1i*(max(L,Lfold):-1:1); 27 | z(L+1:end) = 0; 28 | zi = complex2interleaved(z); 29 | zout = complex2interleaved(randn(1,Lfold) + 1i*randn(1,Lfold)); 30 | else 31 | z = (1:max(L,Lfold)); 32 | z(L+1:end) = 0; 33 | zi = z; 34 | zout = randn(1,Lfold); 35 | end 36 | 37 | ziPtr = libpointer(dataPtr,zi); 38 | zoutPtr = libpointer(dataPtr,zout); 39 | 40 | periods = ceil(L/Lfold); 41 | fext = postpad(z,periods*Lfold); 42 | ffoldtrue = circshift(sum(reshape(fext, Lfold, periods),2).',[0,shift]); 43 | ffold2ndtrue = sum(reshape(circshift(fext,[0,shift]), Lfold, periods),2).'; 44 | 45 | errTrues = norm(ffoldtrue - ffold2ndtrue); 46 | 47 | 48 | status = calllib('libltfat',funname,ziPtr,L,shift,Lfold,zoutPtr); 49 | 50 | if do_complex 51 | res = norm(ffoldtrue - interleaved2complex(zoutPtr.Value)); 52 | else 53 | res = norm(ffoldtrue - zoutPtr.Value); 54 | end 55 | 56 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 57 | fprintf(['FOLD OP L:%3i, Lfold:%3i, shift:%3i, %s %s %s %s\n'],L,Lfold,shift,flags.complexity,complexstring,ltfatstatusstring(status),fail); 58 | 59 | status = calllib('libltfat',funname,ziPtr,L,shift,Lfold,ziPtr); 60 | 61 | if do_complex 62 | res = norm(ffoldtrue - postpad(interleaved2complex(ziPtr.Value),Lfold)); 63 | else 64 | res = norm(ffoldtrue - ziPtr.Value(1:Lfold)); 65 | end 66 | 67 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 68 | fprintf(['FOLD IP L:%3i, Lfold:%3i, shift:%3i, %s %s %s %s\n'],L,Lfold,shift,flags.complexity,complexstring,ltfatstatusstring(status),fail); 69 | end 70 | end 71 | 72 | %interleaved2complex(zoutPtr.Value) 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /modules/libltfat/testing/mUnit/test_libltfat_fir2long.m: -------------------------------------------------------------------------------- 1 | function test_failed = test_libltfat_fir2long(varargin) 2 | test_failed = 0; 3 | 4 | fprintf(' =============== %s ================ \n',upper(mfilename)); 5 | 6 | definput.flags.complexity={'double','single'}; 7 | [flags]=ltfatarghelper({},definput,varargin); 8 | dataPtr = [flags.complexity, 'Ptr']; 9 | 10 | Larr = [1, 9,11,110,1, 9, 8, 8, 11, 11, 10]; 11 | Loutarr = [11,9,12,221,1,10, 10, 11, 15, 16, 1000]; 12 | 13 | for do_complex = 0:1 14 | complexstring = ''; 15 | if do_complex, complexstring = 'complex'; end 16 | funname = makelibraryname('fir2long',flags.complexity,do_complex); 17 | 18 | for Lidx = 1:numel(Larr) 19 | L = Larr(Lidx); 20 | Lout = Loutarr(Lidx); 21 | 22 | if do_complex 23 | z = cast((1:L)'+1i*(L:-1:1)',flags.complexity); 24 | zi = complex2interleaved(z); 25 | zout = randn(2*Lout,1,flags.complexity); 26 | 27 | ziPtr = libpointer(dataPtr,zi); 28 | zoutPtr = libpointer(dataPtr,zout); 29 | else 30 | z = cast((1:L)',flags.complexity); 31 | zi = z; 32 | zout = randn(Lout,1,flags.complexity); 33 | 34 | ziPtr = libpointer(dataPtr,zi); 35 | zoutPtr = libpointer(dataPtr,zout); 36 | end 37 | 38 | trueres = fir2long(z,Lout); 39 | 40 | 41 | status = calllib('libltfat',funname,ziPtr,L,Lout,zoutPtr); 42 | 43 | if do_complex 44 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 45 | else 46 | res = norm(trueres - zoutPtr.Value); 47 | end 48 | 49 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 50 | fprintf(['FIR2LONG OP L:%3i, Lout:%3i, %s %s %s %s\n'],L,Lout,flags.complexity,complexstring,ltfatstatusstring(status),fail); 51 | 52 | zoutPtr.Value(:) = randn(size(zoutPtr.Value),flags.complexity); 53 | zoutPtr.Value(1:numel(ziPtr.Value)) = ziPtr.Value; 54 | status = calllib('libltfat',funname,zoutPtr,L,Lout,zoutPtr); 55 | 56 | if do_complex 57 | res = norm(trueres - interleaved2complex(zoutPtr.Value)); 58 | else 59 | res = norm(trueres - zoutPtr.Value); 60 | end 61 | 62 | [test_failed,fail]=ltfatdiditfail(res+status,test_failed,0); 63 | fprintf(['FIR2LONG IP L:%3i, Lout:%3i, %s %s %s %s\n'],L,Lout,flags.complexity,complexstring,ltfatstatusstring(status),fail); 64 | end 65 | end 66 | 67 | -------------------------------------------------------------------------------- /modules/libltfat/thirdparty/kissfft/README.simd: -------------------------------------------------------------------------------- 1 | If you are reading this, it means you think you may be interested in using the SIMD extensions in kissfft 2 | to do 4 *separate* FFTs at once. 3 | 4 | Beware! Beyond here there be dragons! 5 | 6 | This API is not easy to use, is not well documented, and breaks the KISS principle. 7 | 8 | 9 | Still reading? Okay, you may get rewarded for your patience with a considerable speedup 10 | (2-3x) on intel x86 machines with SSE if you are willing to jump through some hoops. 11 | 12 | The basic idea is to use the packed 4 float __m128 data type as a scalar element. 13 | This means that the format is pretty convoluted. It performs 4 FFTs per fft call on signals A,B,C,D. 14 | 15 | For complex data, the data is interlaced as follows: 16 | rA0,rB0,rC0,rD0, iA0,iB0,iC0,iD0, rA1,rB1,rC1,rD1, iA1,iB1,iC1,iD1 ... 17 | where "rA0" is the real part of the zeroth sample for signal A 18 | 19 | Real-only data is laid out: 20 | rA0,rB0,rC0,rD0, rA1,rB1,rC1,rD1, ... 21 | 22 | Compile with gcc flags something like 23 | -O3 -mpreferred-stack-boundary=4 -DUSE_SIMD=1 -msse 24 | 25 | Be aware of SIMD alignment. This is the most likely cause of segfaults. 26 | The code within kissfft uses scratch variables on the stack. 27 | With SIMD, these must have addresses on 16 byte boundaries. 28 | Search on "SIMD alignment" for more info. 29 | 30 | 31 | 32 | Robin at Divide Concept was kind enough to share his code for formatting to/from the SIMD kissfft. 33 | I have not run it -- use it at your own risk. It appears to do 4xN and Nx4 transpositions 34 | (out of place). 35 | 36 | void SSETools::pack128(float* target, float* source, unsigned long size128) 37 | { 38 | __m128* pDest = (__m128*)target; 39 | __m128* pDestEnd = pDest+size128; 40 | float* source0=source; 41 | float* source1=source0+size128; 42 | float* source2=source1+size128; 43 | float* source3=source2+size128; 44 | 45 | while(pDest