From 4e3f857cb84c2c2ba834d5ddd0c5e1d9375cd947 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 16 Mar 2021 01:20:31 +0000 Subject: initial --- include/dtw.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 include/dtw.h (limited to 'include') diff --git a/include/dtw.h b/include/dtw.h new file mode 100644 index 0000000..4c8064d --- /dev/null +++ b/include/dtw.h @@ -0,0 +1,79 @@ +/* +Copyright (c) 2014, Calder Phillips-Grafflin (calder.pg@gmail.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* 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. + +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 HOLDER 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. +*/ + +#include +#include +#include + +#ifndef DTW_H +#define DTW_H + +namespace DTW +{ + +class SimpleDTW +{ +private: + + double (*distance_fn_)(MYFLT* p1, MYFLT* p2, int bands); + MYFLT* data_; + size_t x_dim_; + size_t y_dim_; + int mfcc_bands; + + inline size_t GetDataIndex(size_t x, size_t y) + { + return (x * y_dim_) + y; + } + + inline double GetFromDTWMatrix(size_t x, size_t y) + { + return data_[GetDataIndex(x, y)]; + } + + inline void SetInDTWMatrix(size_t x, size_t y, MYFLT val) + { + data_[GetDataIndex(x, y)] = val; + } + +public: + + SimpleDTW (csnd::Csound* csound, size_t x_size, size_t y_size, int mfcc_bands, MYFLT (*distance_fn)(MYFLT* p1, MYFLT* p2, int bands)); + + ~SimpleDTW() {} + + double EvaluateWarpingCost( + MYFLT* sequence_1, + int seq1_items, + MYFLT* sequence_2, + int seq2_items + ); + +}; + +} + +#endif // DTW_H -- cgit v1.2.3