Excitations.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Excitations.cpp
  2. *
  3. * Copyright (C) 1993-2017 David Weenink, 2016 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "Excitations.h"
  19. Thing_implement (ExcitationList, Ordered, 0);
  20. void ExcitationList_addItem_copy (ExcitationList me, Excitation you) {
  21. try {
  22. if (my size > 0) {
  23. Melder_require (your nx == my at [1] -> nx, U"Dimension of ", you, U" should agree with the rest.");
  24. }
  25. autoExcitation newItem = Data_copy (you);
  26. my addItem_move (newItem.move());
  27. } catch (MelderError) {
  28. Melder_throw (me, U": item not added.");
  29. }
  30. }
  31. void ExcitationList_addItems (ExcitationList me, OrderedOf <structExcitation> * list) {
  32. for (integer i = 1; i <= list -> size; i ++) {
  33. ExcitationList_addItem_copy (me, list -> at [i]);
  34. }
  35. }
  36. autoExcitationList Excitations_to_ExcitationList (OrderedOf <structExcitation> * me) {
  37. try {
  38. autoExcitationList you = ExcitationList_create ();
  39. ExcitationList_addItems (you.get(), me);
  40. return you;
  41. } catch (MelderError) {
  42. Melder_throw (U"No ExcitationList created from Excitation(s).");
  43. }
  44. }
  45. autoPatternList ExcitationList_to_PatternList (ExcitationList me, integer join) {
  46. try {
  47. Melder_assert (my size > 0);
  48. Excitation excitation = my at [1];
  49. if (join < 1) {
  50. join = 1;
  51. }
  52. Melder_require (my size % join == 0, U"Number of rows should be a multiple of the join.");
  53. autoPatternList thee = PatternList_create (my size / join, join * excitation -> nx);
  54. integer r = 0, c = 1;
  55. for (integer i = 1; i <= my size; i ++) {
  56. double *z = my at [i] -> z [1];
  57. if ((i - 1) % join == 0) {
  58. r ++;
  59. c = 1;
  60. }
  61. for (integer j = 1; j <= excitation -> nx; j ++) {
  62. thy z [r] [c ++] = z [j];
  63. }
  64. }
  65. return thee;
  66. } catch (MelderError) {
  67. Melder_throw (me, U": no PatternList created.");
  68. }
  69. }
  70. autoTableOfReal ExcitationList_to_TableOfReal (ExcitationList me) {
  71. try {
  72. Melder_assert (my size > 0);
  73. Excitation excitation = my at [1];
  74. autoTableOfReal thee = TableOfReal_create (my size, excitation -> nx);
  75. for (integer i = 1; i <= my size; i ++) {
  76. double *z = my at [i] -> z [1];
  77. for (integer j = 1; j <= excitation -> nx; j ++) {
  78. thy data [i] [j] = z [j];
  79. }
  80. }
  81. return thee;
  82. } catch (MelderError) {
  83. Melder_throw (me, U": TableOfReal not created.");
  84. }
  85. }
  86. autoExcitation ExcitationList_extractItem (ExcitationList me, integer item) {
  87. try {
  88. Melder_require (item > 0 && item <= my size, U"Item number should be in the range [1, ", my size, U"].");
  89. autoExcitation thee = Data_copy (my at [item]);
  90. Thing_setName (thee.get(), Thing_getName (my at [item]));
  91. return thee;
  92. } catch (MelderError) {
  93. Melder_throw (me, U": Excitation not extracted.");
  94. }
  95. }
  96. /* End of file Excitations.cpp */