DTW.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef _DTW_h_
  2. #define _DTW_h_
  3. /* DTW.h
  4. *
  5. * Copyright (C) 1993-2017 David Weenink
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. djmw 20020813 GPL header
  22. djmw 20110306 Latest modification.
  23. */
  24. #include "Spectrogram.h"
  25. #include "Polygon_extensions.h"
  26. #include "Pitch.h"
  27. #include "DurationTier.h"
  28. #include "Sound.h"
  29. #include "DTW_def.h"
  30. #define DTW_SAKOECHIBA 1
  31. #define DTW_SLOPES 2
  32. #define DTW_UNREACHABLE -1
  33. #define DTW_FORBIDDEN -2
  34. #define DTW_START 3
  35. #define DTW_XANDY 2
  36. #define DTW_X 4
  37. #define DTW_Y 6
  38. void DTW_Path_Query_init (DTW_Path_Query me, integer ny, integer nx);
  39. /* Prototype on y-axis and test on x-axis */
  40. autoDTW DTW_create (double tminp, double tmaxp, integer ntp, double dtp, double t1p,
  41. double tminc, double tmaxc, integer ntc, double dtc, double t1c);
  42. void DTW_setWeights (DTW me, double wx, double wy, double wd);
  43. autoDTW DTW_swapAxes (DTW me);
  44. void DTW_findPath_bandAndSlope (DTW me, double sakoeChibaBand, int localSlope, autoMatrix *cumulativeDists);
  45. void DTW_findPath (DTW me, bool matchStart, bool matchEnd, int slope); // deprecated
  46. /* Obsolete
  47. Function:
  48. Calculate the minimum path (through a distance matrix).
  49. Possible constraints:
  50. matchStart: path starts at position (1,1) (bottom-left)
  51. matchEnd: path ends at (I,J) (top-right)
  52. slope: 1 no constraints
  53. 2 1/3 < slope < 3
  54. 3 1/2 < slope < 2
  55. 4 2/3 < slope < 3/2
  56. For algorithm and DP-equations see the article (& especially table I) in:
  57. Sakoe, H. & Chiba, S. (1978), Dynamic Programming Algorithm Optimization
  58. for Spoken Word recognition, IEEE Trans. on ASSP, vol 26, 43-49.
  59. */
  60. void DTW_Path_recode (DTW me);
  61. double DTW_getYTimeFromXTime (DTW me, double tx);
  62. double DTW_getXTimeFromYTime (DTW me, double ty);
  63. double DTW_getPathY (DTW me, double tx);
  64. integer DTW_getMaximumConsecutiveSteps (DTW me, int direction);
  65. void DTW_paintDistances (DTW me, Graphics g, double xmin, double xmax, double ymin,
  66. double ymax, double minimum, double maximum, bool garnish);
  67. void DTW_drawPath (DTW me, Graphics g, double xmin, double xmax, double ymin,
  68. double ymax, bool garnish);
  69. void DTW_drawWarpX (DTW me, Graphics g, double xmin, double xmax, double ymin, double ymax, double tx, bool garnish);
  70. void DTW_drawWarpY (DTW me, Graphics g, double xmin, double xmax, double ymin, double ymax, double ty, bool garnish);
  71. void DTW_pathRemoveRedundantNodes (DTW me);
  72. void DTW_pathQueryRecode (DTW me);
  73. void DTW_drawDistancesAlongPath (DTW me, Graphics g, double xmin, double xmax, double dmin, double dmax, bool garnish);
  74. void DTW_Sounds_draw (DTW me, Sound yy, Sound xx, Graphics g, double xmin, double xmax,
  75. double ymin, double ymax, bool garnish);
  76. void DTW_Sounds_drawWarpX (DTW me, Sound yy, Sound xx, Graphics g, double xmin, double xmax,
  77. double ymin, double ymax, double tx, bool garnish);
  78. autoPolygon DTW_to_Polygon (DTW me, double band, int slope);
  79. void DTW_Polygon_findPathInside (DTW me, Polygon thee, int localSlope, autoMatrix *cumulativeDists);
  80. autoMatrix DTW_to_Matrix_distances (DTW me);
  81. autoMatrix DTW_to_Matrix_cumulativeDistances (DTW me, double sakoeChibaBand, int slope);
  82. autoMatrix DTW_Polygon_to_Matrix_cumulativeDistances (DTW me, Polygon thee, int localSlope);
  83. autoDTW Matrices_to_DTW (Matrix me, Matrix thee, bool matchStart, bool matchEnd, int slope, double metric);
  84. autoDTW Spectrograms_to_DTW (Spectrogram me, Spectrogram thee, bool matchStart, bool matchEnd, int slope, double metric);
  85. autoDTW Pitches_to_DTW (Pitch me, Pitch thee, double vuv_costs, double time_weight, bool matchStart, bool matchEnd, int slope);
  86. autoDurationTier DTW_to_DurationTier (DTW me);
  87. void DTW_Matrix_replace (DTW me, Matrix thee);
  88. #endif /* _DTW_h_ */