Tube.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Tube.cpp
  2. *
  3. * Copyright (C) 1994-2012, 2015-2016 David Weenink
  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. /*
  19. djmw 20030613 Creation
  20. djmw 20061212 Changed info to Melder_writeLine<x> format.
  21. djmw 20110304 Thing_new
  22. */
  23. #include "Tube.h"
  24. #include "NUM2.h"
  25. #include "oo_DESTROY.h"
  26. #include "Tube_def.h"
  27. #include "oo_COPY.h"
  28. #include "Tube_def.h"
  29. #include "oo_EQUAL.h"
  30. #include "Tube_def.h"
  31. #include "oo_CAN_WRITE_AS_ENCODING.h"
  32. #include "Tube_def.h"
  33. #include "oo_WRITE_TEXT.h"
  34. #include "Tube_def.h"
  35. #include "oo_WRITE_BINARY.h"
  36. #include "Tube_def.h"
  37. #include "oo_READ_TEXT.h"
  38. #include "Tube_def.h"
  39. #include "oo_READ_BINARY.h"
  40. #include "Tube_def.h"
  41. #include "oo_DESCRIPTION.h"
  42. #include "Tube_def.h"
  43. Thing_implement (Tube, Sampled, 0);
  44. void structTube :: v_info () {
  45. structDaata :: v_info ();
  46. MelderInfo_writeLine (U"Time domain: ", xmin, U" to ", xmax, U" seconds");
  47. MelderInfo_writeLine (U"Maximum number of segments: ", maxnSegments);
  48. MelderInfo_writeLine (U"Number of frames: ", nx);
  49. MelderInfo_writeLine (U"Time step: ", dx, U" seconds");
  50. MelderInfo_writeLine (U"First frame at: ", x1, U" seconds");
  51. }
  52. void Tube_Frame_init (Tube_Frame me, integer nSegments, double length) {
  53. my nSegments = nSegments;
  54. my length = length;
  55. if (nSegments <= 0) {
  56. Melder_throw (U"Number of segments should be a natural number.");
  57. }
  58. my c = NUMvector<double> (1, nSegments);
  59. }
  60. /* Gray & Markel (1979), LPTRN */
  61. void Tube_Frames_rc_into_area (Tube_Frame me, Tube_Frame thee) {
  62. if (my nSegments > thy nSegments) {
  63. Melder_throw (U"Number of segments to big.");
  64. }
  65. double s = 0.0001; /* 1.0 cm^2 at glottis */
  66. double *rc = my c, *area = thy c;
  67. for (integer i = my nSegments; i > 0; i --) {
  68. s *= (1.0 + rc [i]) / (1.0 - rc [i]);
  69. area [i] = s;
  70. }
  71. }
  72. static void Tube_setLengths (Tube me, double length) {
  73. for (integer i = 1; i <= my nx; i ++) {
  74. Tube_Frame f = & my frame [i];
  75. if (f) {
  76. f -> length = length;
  77. }
  78. }
  79. }
  80. void Tube_init (Tube me, double tmin, double tmax, integer nt, double dt, double t1, integer maxnSegments, double defaultLength) {
  81. my maxnSegments = maxnSegments;
  82. Sampled_init (me, tmin, tmax, nt, dt, t1);
  83. my frame = NUMvector<structTube_Frame> (1, nt);
  84. Tube_setLengths (me, defaultLength);
  85. }
  86. Thing_implement (Area, Tube, 0);
  87. void Area_init (Area me, double tmin, double tmax, integer nt, double dt, double t1, integer maxnSegments, double defaultLength) {
  88. Tube_init (me, tmin, tmax, nt, dt, t1, maxnSegments, defaultLength);
  89. }
  90. autoArea Area_create (double tmin, double tmax, integer nt, double dt, double t1, integer maxnSegments, double defaultLength) {
  91. try {
  92. autoArea me = Thing_new (Area);
  93. Area_init (me.get(), tmin, tmax, nt, dt, t1, maxnSegments, defaultLength);
  94. return me;
  95. } catch (MelderError) {
  96. Melder_throw (U"Area not crteated.");
  97. }
  98. }
  99. Thing_implement (RC, Tube, 0);
  100. void RC_init (RC me, double tmin, double tmax, integer nt, double dt, double t1, integer maxnSegments, double defaultLength) {
  101. Tube_init (me, tmin, tmax, nt, dt, t1, maxnSegments, defaultLength);
  102. }
  103. autoRC RC_create (double tmin, double tmax, integer nt, double dt, double t1, integer maxnCoefficients, double defaultLength) {
  104. try {
  105. autoRC me = Thing_new (RC);
  106. RC_init (me.get(), tmin, tmax, nt, dt, t1, maxnCoefficients, defaultLength);
  107. return me;
  108. } catch (MelderError) {
  109. Melder_throw (U"RC not crteated.");
  110. }
  111. }
  112. /* End of file Tube.cpp */