| 1 | /* Speaker_to_Delta.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2005,2006,2011,2015-2019,2021 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. |
| 13 | * See the GNU 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 | #include "Art_Speaker.h" |
| 20 | #include "Speaker_to_Delta.h" |
| 21 | #define SMOOTH_LUNGS true |
| 22 | #define FIRST_TUBE 7 |
| 23 | |
| 24 | autoDelta Speaker_to_Delta (Speaker me) { |
| 25 | double f = my relativeSize * 1e-3; // we shall use millimetres and grams |
| 26 | double xe [30], ye [30], xi [30], yi [30], xmm [30], ymm [30], dx, dy; |
| 27 | autoDelta thee = Delta_create (89); |
| 28 | Melder_assert (my cord.numberOfMasses == 1 || my cord.numberOfMasses == 2 || my cord.numberOfMasses == 10); |
| 29 | |
| 30 | /* Lungs: tubes 1..23. */ |
| 31 | |
| 32 | for (integer itube = 1; itube <= 23; itube ++) { |
| 33 | Delta_Tube t = & thy tubes [itube]; |
| 34 | t -> Dx = t -> Dxeq = 10.0 * f; |
| 35 | t -> Dy = t -> Dyeq = 100.0 * f; |
| 36 | t -> Dz = t -> Dzeq = 230.0 * f; |
| 37 | t -> mass = 10.0 * my relativeSize * t -> Dx * t -> Dz; // 80 * f; 35 * Dx * Dz |
| 38 | t -> k1 = 200.0; // 90000 * Dx * Dz; Newtons per metre |
| 39 | t -> k3 = 0.0; |
| 40 | t -> Brel = 0.8; |
| 41 | t -> parallel = 1000; |
| 42 | } |
| 43 | |
| 44 | /* Bronchi: tubes 24..29. */ |
| 45 | |
| 46 | for (integer itube = 24; itube <= 29; itube ++) { |
| 47 | Delta_Tube t = & thy tubes [itube]; |
| 48 | t -> Dx = t -> Dxeq = 10.0 * f; |
| 49 | t -> Dy = t -> Dyeq = 15.0 * f; |
| 50 | t -> Dz = t -> Dzeq = 30.0 * f; |
| 51 | t -> mass = 10.0 * f; |
| 52 | t -> k1 = 40.0; // 125000 * Dx * Dz; Newtons per metre |
| 53 | t -> k3 = 0.0; |
| 54 | t -> Brel = 0.8; |
| 55 | } |
| 56 | |
| 57 | /* Trachea: tubes 30..35; four of these may be replaced by conus elasticus (see below). */ |
| 58 | |
| 59 | for (integer itube = 30; itube <= 35; itube ++) { |
| 60 | Delta_Tube t = & thy tubes [itube]; |
| 61 | t -> Dx = t -> Dxeq = 10.0 * f; |
| 62 | t -> Dy = t -> Dyeq = 15.0 * f; |
| 63 | t -> Dz = t -> Dzeq = 16.0 * f; |
| 64 | t -> mass = 5.0 * f; |
| 65 | t -> k1 = 160.0; // 100000 * Dx * Dz; Newtons per metre |
| 66 | t -> k3 = 0.0; |
| 67 | t -> Brel = 0.8; |
| 68 | } |
| 69 | |
| 70 | if (SMOOTH_LUNGS) { |
| 71 | struct { integer itube; double Dy, Dz, parallel; } data [] = { |
| 72 | { 7, 120.0, 240.0, 5000.0 }, { 8, 120.0, 240.0, 5000.0 }, { 9, 120.0, 240.0, 5000.0 }, |
| 73 | { 10, 120.0, 240.0, 5000.0 }, { 11, 120.0, 240.0, 5000.0 }, { 12, 120.0, 240.0, 5000.0 }, |
| 74 | { 13, 120.0, 240.0, 2500.0 }, { 14, 120.0, 240.0, 1250.0 }, { 15, 120.0, 240.0, 640.0 }, |
| 75 | { 16, 120.0, 240.0, 320.0 }, { 17, 120.0, 240.0, 160.0 }, { 18, 120.0, 140.0, 80.0 }, |
| 76 | { 19, 70.0, 70.0, 40.0 }, { 20, 35.0, 35.0, 20.0 }, { 21, 18.0, 18.0, 10.0 }, |
| 77 | { 22, 12.0, 12.0, 5.0 }, { 23, 12.0, 12.0, 3.0 }, { 24, 18.0, 9.0, 2.0 }, |
| 78 | { 25, 18.0, 19.0, 2.0 }, { } }; |
| 79 | for (integer i = 0; data [i]. itube; i ++) { |
| 80 | Delta_Tube t = & thy tubes [data [i]. itube]; |
| 81 | t -> Dy = t -> Dyeq = data [i]. Dy * f; |
| 82 | t -> Dz = t -> Dzeq = data [i]. Dz * f; |
| 83 | t -> parallel = data [i]. parallel; |
| 84 | } |
| 85 | for (integer itube = 26; itube <= 35; itube ++) { |
| 86 | Delta_Tube t = & thy tubes [itube]; |
| 87 | t -> Dy = t -> Dyeq = 11.0 * f; |
| 88 | t -> Dz = t -> Dzeq = 14.0 * f; |
| 89 | t -> parallel = 1; |
| 90 | } |
| 91 | for (integer itube = FIRST_TUBE; itube <= 18; itube ++) { |
| 92 | Delta_Tube t = & thy tubes [itube]; |
| 93 | t -> Dx = t -> Dxeq = 10.0 * f; |
| 94 | t -> mass = 10.0 * my relativeSize * t -> Dx * t -> Dz; // 10 mm |
| 95 | t -> k1 = 1e5 * t -> Dx * t -> Dz; // elastic tissue: 1 mbar/mm |
| 96 | t -> k3 = 0.0; |
| 97 | t -> Brel = 1.0; |
| 98 | } |
| 99 | for (integer itube = 19; itube <= 35; itube ++) { |
| 100 | Delta_Tube t = & thy tubes [itube]; |
| 101 | t -> Dx = t -> Dxeq = 10.0 * f; |
| 102 | t -> mass = 3.0 * my relativeSize * t -> Dx * t -> Dz; // 3 mm |
| 103 | t -> k1 = 10e5 * t -> Dx * t -> Dz; // cartilage: 10 mbar/mm |
| 104 | t -> k3 = 0.0; |
| 105 | t -> Brel = 1.0; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /* Glottis: tubes 36 and 37; the last one may be disconnected (see below). */ |
| 110 | { |
| 111 | Delta_Tube t = & thy tubes [36]; |
| 112 | t -> Dx = t -> Dxeq = my lowerCord.thickness; |
| 113 | t -> Dy = t -> Dyeq = 0.0; |
| 114 | t -> Dz = t -> Dzeq = my cord.length; |
| 115 | t -> mass = my lowerCord.mass; |
| 116 | t -> k1 = my lowerCord.k1; |
| 117 | t -> k3 = t -> k1 * (20.0 / t -> Dz) * (20.0 / t -> Dz); |
| 118 | t -> Brel = 0.2; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Fill in the values for the upper part of the glottis (tube 37) only if there is no one-mass model. |
| 123 | */ |
| 124 | if (my cord.numberOfMasses >= 2) { |
| 125 | Delta_Tube t = & thy tubes [37]; |
| 126 | t -> Dx = t -> Dxeq = my upperCord.thickness; |
| 127 | t -> Dy = t -> Dyeq = 0.0; |
| 128 | t -> Dz = t -> Dzeq = my cord.length; |
| 129 | t -> mass = my upperCord.mass; |
| 130 | t -> k1 = my upperCord.k1; |
| 131 | t -> k3 = t -> k1 * (20.0 / t -> Dz) * (20.0 / t -> Dz); |
| 132 | t -> Brel = 0.2; |
| 133 | |
| 134 | /* Couple spring with lower cord. */ |
| 135 | t -> k1left1 = thy tubes [36]. k1right1 = 1.0; |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Fill in the values for the conus elasticus (tubes 79..86) only if we want to model it. |
| 140 | */ |
| 141 | if (my cord.numberOfMasses == 10) { |
| 142 | thy tubes [79]. Dx = thy tubes [79]. Dxeq = 8.0 * f; |
| 143 | thy tubes [80]. Dx = thy tubes [80]. Dxeq = 7.0 * f; |
| 144 | thy tubes [81]. Dx = thy tubes [81]. Dxeq = 6.0 * f; |
| 145 | thy tubes [82]. Dx = thy tubes [82]. Dxeq = 5.0 * f; |
| 146 | thy tubes [83]. Dx = thy tubes [83]. Dxeq = 4.0 * f; |
| 147 | thy tubes [84]. Dx = thy tubes [84]. Dxeq = 0.75 * 4.0 * f + 0.25 * my lowerCord.thickness; |
| 148 | thy tubes [85]. Dx = thy tubes [85]. Dxeq = 0.50 * 4.0 * f + 0.50 * my lowerCord.thickness; |
| 149 | thy tubes [86]. Dx = thy tubes [86]. Dxeq = 0.25 * 4.0 * f + 0.75 * my lowerCord.thickness; |
| 150 | |
| 151 | thy tubes [79]. Dy = thy tubes [79]. Dyeq = 11.0 * f; |
| 152 | thy tubes [80]. Dy = thy tubes [80]. Dyeq = 7.0 * f; |
| 153 | thy tubes [81]. Dy = thy tubes [81]. Dyeq = 4.0 * f; |
| 154 | thy tubes [82]. Dy = thy tubes [82]. Dyeq = 2.0 * f; |
| 155 | thy tubes [83]. Dy = thy tubes [83]. Dyeq = 1.0 * f; |
| 156 | thy tubes [84]. Dy = thy tubes [84]. Dyeq = 0.75 * f; |
| 157 | thy tubes [85]. Dy = thy tubes [85]. Dyeq = 0.50 * f; |
| 158 | thy tubes [86]. Dy = thy tubes [86]. Dyeq = 0.25 * f; |
| 159 | |
| 160 | thy tubes [79]. Dz = thy tubes [79]. Dzeq = 16.0 * f; |
| 161 | thy tubes [80]. Dz = thy tubes [80]. Dzeq = 16.0 * f; |
| 162 | thy tubes [81]. Dz = thy tubes [81]. Dzeq = 16.0 * f; |
| 163 | thy tubes [82]. Dz = thy tubes [82]. Dzeq = 16.0 * f; |
| 164 | thy tubes [83]. Dz = thy tubes [83]. Dzeq = 16.0 * f; |
| 165 | thy tubes [84]. Dz = thy tubes [84]. Dzeq = 0.75 * 16.0 * f + 0.25 * my cord.length; |
| 166 | thy tubes [85]. Dz = thy tubes [85]. Dzeq = 0.50 * 16.0 * f + 0.50 * my cord.length; |
| 167 | thy tubes [86]. Dz = thy tubes [86]. Dzeq = 0.25 * 16.0 * f + 0.75 * my cord.length; |
| 168 | |
| 169 | thy tubes [79]. k1 = 160.0; |
| 170 | thy tubes [80]. k1 = 160.0; |
| 171 | thy tubes [81]. k1 = 160.0; |
| 172 | thy tubes [82]. k1 = 160.0; |
| 173 | thy tubes [83]. k1 = 160.0; |
| 174 | thy tubes [84]. k1 = 0.75 * 160.0 * f + 0.25 * my lowerCord.k1; |
| 175 | thy tubes [85]. k1 = 0.50 * 160.0 * f + 0.50 * my lowerCord.k1; |
| 176 | thy tubes [86]. k1 = 0.25 * 160.0 * f + 0.75 * my lowerCord.k1; |
| 177 | |
| 178 | thy tubes [79]. Brel = 0.7; |
| 179 | thy tubes [80]. Brel = 0.6; |
| 180 | thy tubes [81]. Brel = 0.5; |
| 181 | thy tubes [82]. Brel = 0.4; |
| 182 | thy tubes [83]. Brel = 0.3; |
| 183 | thy tubes [84]. Brel = 0.2; |
| 184 | thy tubes [85]. Brel = 0.2; |
| 185 | thy tubes [86]. Brel = 0.2; |
| 186 | |
| 187 | for (integer itube = 79; itube <= 86; itube ++) { |
| 188 | Delta_Tube t = & thy tubes [itube]; |
| 189 | t -> mass = t -> Dx * t -> Dz / (30.0 * f); |
| 190 | t -> k3 = t -> k1 * (20.0 / t -> Dz) * (20.0 / t -> Dz); |
| 191 | t -> k1left1 = t -> k1right1 = 1.0; |
| 192 | } |
| 193 | thy tubes [79]. k1left1 = 0.0; |
| 194 | thy tubes [36]. k1left1 = 1.0; // the essence: couple spring with lower vocal cords |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Fill in the values of the glottal shunt only if we want to model it. |
| 199 | */ |
| 200 | if (my shunt.Dx != 0.0) { |
| 201 | for (integer itube = 87; itube <= 89; itube ++) { |
| 202 | Delta_Tube t = & thy tubes [itube]; |
| 203 | t -> Dx = t -> Dxeq = my shunt.Dx; |
| 204 | t -> Dy = t -> Dyeq = my shunt.Dy; |
| 205 | t -> Dz = t -> Dzeq = my shunt.Dz; |
| 206 | t -> mass = 3.0 * my upperCord.mass; // heavy... |
| 207 | t -> k1 = 3.0 * my upperCord.k1; // ...and stiff... |
| 208 | t -> k3 = t -> k1 * (20.0 / t -> Dz) * (20.0 / t -> Dz); |
| 209 | t -> Brel = 3.0; // ...and inelastic, so that the walls will not vibrate |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* Vocal tract from neutral articulation. */ |
| 214 | bool closed [40]; |
| 215 | { |
| 216 | autoArt art = Art_create (); |
| 217 | Art_Speaker_meshVocalTract (art.get(), me, xi, yi, xe, ye, xmm, ymm, closed); |
| 218 | } |
| 219 | |
| 220 | /* Pharynx and mouth: tubes 38..64. */ |
| 221 | |
| 222 | for (integer itube = 38; itube <= 64; itube ++) { |
| 223 | Delta_Tube t = & thy tubes [itube]; |
| 224 | integer i = itube - 37; |
| 225 | dx = xmm [i] - xmm [i + 1]; |
| 226 | dy = ymm [i] - ymm [i + 1]; |
| 227 | t -> Dx = t -> Dxeq = hypot (dx, dy); |
| 228 | dx = xe [i] - xi [i]; |
| 229 | dy = ye [i] - yi [i]; |
| 230 | t -> Dyeq = hypot (dx, dy); |
| 231 | if (closed [i]) |
| 232 | t -> Dyeq = - t -> Dyeq; |
| 233 | t -> Dy = t -> Dyeq; |
| 234 | t -> Dz = t -> Dzeq = 0.015; |
| 235 | t -> mass = 0.006; |
| 236 | t -> k1 = 30.0; |
| 237 | t -> k3 = 0.0; |
| 238 | t -> Brel = 1.0; |
| 239 | } |
| 240 | /* For tongue-tip vibration [r]: thy tube [60]. Brel = 0.1; thy tube [60]. k1 = 3; */ |
| 241 | |
| 242 | /* Nose: tubes 65..78. */ |
| 243 | |
| 244 | for (integer itube = 65; itube <= 78; itube ++) { |
| 245 | Delta_Tube t = & thy tubes [itube]; |
| 246 | t -> Dx = t -> Dxeq = my nose.Dx; |
| 247 | t -> Dy = t -> Dyeq = my nose.weq [itube - 64]; |
| 248 | t -> Dz = t -> Dzeq = my nose.Dz; |
| 249 | t -> mass = 0.006; |
| 250 | t -> k1 = 100.0; |
| 251 | t -> k3 = 0.0; |
| 252 | t -> Brel = 1.0; |
| 253 | } |
| 254 | thy tubes [65]. Dy = thy tubes [65]. Dyeq = 0.0; // override: nasopharyngeal port closed |
| 255 | |
| 256 | /* The default structure: |
| 257 | * every tube is connected on the left to the previous tube (index one lower). |
| 258 | * This corresponds to a two-mass model of the vocal cords without shunt. |
| 259 | */ |
| 260 | for (integer itube = SMOOTH_LUNGS ? FIRST_TUBE : 1; itube <= thy numberOfTubes; itube ++) { |
| 261 | Delta_Tube t = & thy tubes [itube]; |
| 262 | t -> s1 = 5e6 * t -> Dx * t -> Dz; |
| 263 | t -> s3 = t -> s1 / (0.9e-3 * 0.9e-3); |
| 264 | t -> dy = 1e-5; |
| 265 | t -> left1 = t - 1; // connect to the previous tube on the left |
| 266 | t -> right1 = t + 1; // connect to the next tube on the right |
| 267 | } |
| 268 | |
| 269 | /***** Connections: boundaries and interfaces. *****/ |
| 270 | |
| 271 | /* The leftmost boundary: the diaphragm (tube 1). |
| 272 | * Disconnect on the left. |
| 273 | */ |
| 274 | thy tubes [SMOOTH_LUNGS ? FIRST_TUBE : 1]. left1 = nullptr; // closed at diaphragm |
| 275 | |
| 276 | /* Optional one-mass model of the vocal cords. |
| 277 | * Short-circuit over tube 37 (upper glottis). |
| 278 | */ |
| 279 | if (my cord.numberOfMasses == 1) { |
| 280 | |
| 281 | /* Connect the right side of tube 36 to the left side of tube 38. */ |
| 282 | thy tubes [36]. right1 = & thy tubes [38]; |
| 283 | thy tubes [38]. left1 = & thy tubes [36]; |
| 284 | |
| 285 | /* Disconnect tube 37 on both sides. */ |
| 286 | thy tubes [37]. left1 = thy tubes [37]. right1 = nullptr; |
| 287 | } |
| 288 | |
| 289 | /* Optionally couple vocal cords with conus elasticus. |
| 290 | * Replace tubes 32..35 (upper trachea) by tubes 79..86 (conus elasticus). |
| 291 | */ |
| 292 | if (my cord.numberOfMasses == 10) { |
| 293 | |
| 294 | /* Connect the right side of tube 31 to the left side of tube 79. */ |
| 295 | thy tubes [31]. right1 = & thy tubes [79]; |
| 296 | thy tubes [79]. left1 = & thy tubes [31]; |
| 297 | |
| 298 | /* Connect the right side of tube 86 to the left side of tube 36. */ |
| 299 | thy tubes [86]. right1 = & thy tubes [36]; |
| 300 | thy tubes [36]. left1 = & thy tubes [86]; |
| 301 | |
| 302 | /* Disconnect tubes 32..35 on both sides. */ |
| 303 | thy tubes [32]. left1 = thy tubes [32]. right1 = nullptr; |
| 304 | thy tubes [33]. left1 = thy tubes [33]. right1 = nullptr; |
| 305 | thy tubes [34]. left1 = thy tubes [34]. right1 = nullptr; |
| 306 | thy tubes [35]. left1 = thy tubes [35]. right1 = nullptr; |
| 307 | } else { |
| 308 | |
| 309 | /* Disconnect tubes 79..86 on both sides. */ |
| 310 | for (integer itube = 79; itube <= 86; itube ++) |
| 311 | thy tubes [itube]. left1 = thy tubes [itube]. right1 = nullptr; |
| 312 | } |
| 313 | |
| 314 | /* Optionally add a shunt parallel to the glottis. |
| 315 | * Create a side branch from tube 34/35 (or 85/86) to tube 38/39 with tubes 87..89. |
| 316 | */ |
| 317 | if (my shunt.Dx != 0.0) { |
| 318 | integer topOfTrachea = ( my cord.numberOfMasses == 10 ? 86 : 35 ); |
| 319 | |
| 320 | /* Create a three-way interface below the shunt. |
| 321 | * Connect lowest shunt tube (87) with top of trachea (34/35 or 85/86). |
| 322 | */ |
| 323 | thy tubes [topOfTrachea - 1]. right2 = & thy tubes [87]; // trachea to shunt |
| 324 | thy tubes [87]. left1 = & thy tubes [topOfTrachea - 1]; // shunt to trachea |
| 325 | thy tubes [87]. Dxeq = thy tubes [topOfTrachea - 1]. Dxeq = thy tubes [topOfTrachea]. Dxeq; // equal length |
| 326 | thy tubes [87]. Dx = thy tubes [topOfTrachea - 1]. Dx = thy tubes [topOfTrachea]. Dx; |
| 327 | |
| 328 | /* Create a three-way interface above the shunt. |
| 329 | * Connect highest shunt tube (89) with bottom of pharynx (38/39). |
| 330 | */ |
| 331 | thy tubes [89]. right1 = & thy tubes [39]; // shunt to pharynx |
| 332 | thy tubes [39]. left2 = & thy tubes [89]; // pharynx to shunt |
| 333 | thy tubes [89]. Dxeq = thy tubes [39]. Dxeq = thy tubes [38]. Dxeq; // all three of equal length |
| 334 | thy tubes [89]. Dx = thy tubes [39]. Dx = thy tubes [38]. Dx; |
| 335 | } else { |
| 336 | |
| 337 | /* Disconnect tubes 87..89 on both sides. */ |
| 338 | for (integer itube = 87; itube <= 89; itube ++) |
| 339 | thy tubes [itube]. left1 = thy tubes [itube]. right1 = nullptr; |
| 340 | } |
| 341 | |
| 342 | /* Create a three-way interface at the nasopharyngeal port. |
| 343 | * Connect tubes 50 (pharynx), 51 (mouth), and 65 (nose). |
| 344 | */ |
| 345 | thy tubes [50]. right2 = & thy tubes [65]; // pharynx to nose |
| 346 | thy tubes [65]. left1 = & thy tubes [50]; // nose to pharynx |
| 347 | thy tubes [65]. Dxeq = thy tubes [51]. Dxeq = thy tubes [50]. Dxeq; // all three must be of equal length |
| 348 | thy tubes [65]. Dx = thy tubes [51]. Dx = thy tubes [50]. Dx; |
| 349 | |
| 350 | /* The rightmost boundaries: the lips (tube 64) and the nostrils (tube 78). |
| 351 | * Disconnect on the right. |
| 352 | */ |
| 353 | thy tubes [64]. right1 = nullptr; // radiation at the lips |
| 354 | thy tubes [78]. right1 = nullptr; // radiation at the nostrils |
| 355 | |
| 356 | for (integer itube = 1; itube <= thy numberOfTubes; itube ++) { |
| 357 | Delta_Tube t = & thy tubes [itube]; |
| 358 | Melder_assert (! t->left1 || t->left1->right1 == t || t->left1->right2 == t); |
| 359 | Melder_assert (! t->left2 || t->left2->right1 == t); |
| 360 | Melder_assert (! t->right1 || t->right1->left1 == t || t->right1->left2 == t); |
| 361 | Melder_assert (! t->right2 || t->right2->left1 == t); |
| 362 | } |
| 363 | return thee; |
| 364 | } |
| 365 | |
| 366 | /* End of file Speaker_to_Delta.cpp */ |