| 1 | /* Artword_Speaker_to_Sound.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2005,2007,2008,2011,2012,2015-2017,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 "Speaker_to_Delta.h" |
| 20 | #include "Art_Speaker_Delta.h" |
| 21 | #include "Artword_Speaker_to_Sound.h" |
| 22 | |
| 23 | #define Dymin 0.00001 |
| 24 | #define criticalVelocity 10.0 |
| 25 | |
| 26 | #define noiseFactor 0.1 |
| 27 | |
| 28 | #define MONITOR_SAMPLES 100 |
| 29 | |
| 30 | /* While debugging, some of these can be 1; otherwise, they are all 0: */ |
| 31 | #define EQUAL_TUBE_WIDTHS 0 |
| 32 | #define CONSTANT_TUBE_LENGTHS 1 |
| 33 | #define NO_MOVING_WALLS 0 |
| 34 | #define NO_TURBULENCE 0 |
| 35 | #define NO_RADIATION_DAMPING 0 |
| 36 | #define NO_BERNOULLI_EFFECT 0 |
| 37 | #define MASS_LEAPFROG 0 |
| 38 | #define B91 0 |
| 39 | |
| 40 | autoSound Artword_Speaker_to_Sound (Artword artword, Speaker speaker, |
| 41 | double fsamp, integer oversampling, |
| 42 | autoSound *out_w1, integer iw1, autoSound *out_w2, integer iw2, autoSound *out_w3, integer iw3, |
| 43 | autoSound *out_p1, integer ip1, autoSound *out_p2, integer ip2, autoSound *out_p3, integer ip3, |
| 44 | autoSound *out_v1, integer iv1, autoSound *out_v2, integer iv2, autoSound *out_v3, integer iv3) |
| 45 | { |
| 46 | try { |
| 47 | autoSound result = Sound_createSimple (1, artword -> totalTime, fsamp); |
| 48 | const integer numberOfSamples = result -> nx; |
| 49 | double minTract [1+78], maxTract [1+78]; // for drawing |
| 50 | const double Dt = 1.0 / fsamp / oversampling, |
| 51 | rho0 = 1.14, |
| 52 | c = 353.0, |
| 53 | onebyc2 = 1.0 / (c * c), |
| 54 | rho0c2 = rho0 * c * c, |
| 55 | halfDt = 0.5 * Dt, |
| 56 | twoDt = 2.0 * Dt, |
| 57 | halfc2Dt = 0.5 * c * c * Dt, |
| 58 | twoc2Dt = 2.0 * c * c * Dt, |
| 59 | onebytworho0 = 1.0 / (2.0 * rho0), |
| 60 | Dtbytworho0 = Dt / (2.0 * rho0); |
| 61 | double tension, rrad, onebygrad, totalVolume; |
| 62 | autoArt art = Art_create (); |
| 63 | autoDelta delta = Speaker_to_Delta (speaker); |
| 64 | autoMelderMonitor monitor (U"Articulatory synthesis"); |
| 65 | Artword_intoArt (artword, art.get(), 0.0); |
| 66 | Art_Speaker_intoDelta (art.get(), speaker, delta.get()); |
| 67 | const integer M = delta -> numberOfTubes; |
| 68 | autoSound w1, w2, w3, p1, p2, p3, v1, v2, v3; |
| 69 | if (iw1 > 0 && iw1 <= M) w1 = Sound_createSimple (1, artword -> totalTime, fsamp); else iw1 = 0; |
| 70 | if (iw2 > 0 && iw2 <= M) w2 = Sound_createSimple (1, artword -> totalTime, fsamp); else iw2 = 0; |
| 71 | if (iw3 > 0 && iw3 <= M) w3 = Sound_createSimple (1, artword -> totalTime, fsamp); else iw3 = 0; |
| 72 | if (ip1 > 0 && ip1 <= M) p1 = Sound_createSimple (1, artword -> totalTime, fsamp); else ip1 = 0; |
| 73 | if (ip2 > 0 && ip2 <= M) p2 = Sound_createSimple (1, artword -> totalTime, fsamp); else ip2 = 0; |
| 74 | if (ip3 > 0 && ip3 <= M) p3 = Sound_createSimple (1, artword -> totalTime, fsamp); else ip3 = 0; |
| 75 | if (iv1 > 0 && iv1 <= M) v1 = Sound_createSimple (1, artword -> totalTime, fsamp); else iv1 = 0; |
| 76 | if (iv2 > 0 && iv2 <= M) v2 = Sound_createSimple (1, artword -> totalTime, fsamp); else iv2 = 0; |
| 77 | if (iv3 > 0 && iv3 <= M) v3 = Sound_createSimple (1, artword -> totalTime, fsamp); else iv3 = 0; |
| 78 | /* Initialize drawing. */ |
| 79 | for (int i = 1; i <= 78; i ++) { |
| 80 | minTract [i] = 100.0; |
| 81 | maxTract [i] = -100.0; |
| 82 | } |
| 83 | totalVolume = 0.0; |
| 84 | for (integer m = 1; m <= M; m ++) { |
| 85 | Delta_Tube t = & delta->tubes [m]; |
| 86 | if (! t -> left1 && ! t -> right1) |
| 87 | continue; |
| 88 | t->Dx = t->Dxeq; t->dDxdt = 0.0; // 5.113 (numbers refer to equations in Boersma (1998) |
| 89 | t->Dy = t->Dyeq; t->dDydt = 0.0; // 5.113 |
| 90 | t->Dz = t->Dzeq; // 5.113 |
| 91 | t->A = t->Dz * ( t->Dy >= t->dy ? t->Dy + Dymin : |
| 92 | t->Dy <= - t->dy ? Dymin : |
| 93 | (t->dy + t->Dy) * (t->dy + t->Dy) / (4.0 * t->dy) + Dymin ); // 4.4, 4.5 |
| 94 | #if EQUAL_TUBE_WIDTHS |
| 95 | t->A = 0.0001; |
| 96 | #endif |
| 97 | t->Jleft = t->Jright = 0.0; // 5.113 |
| 98 | t->Qleft = t->Qright = rho0c2; // 5.113 |
| 99 | t->pleft = t->pright = 0.0; // 5.114 |
| 100 | t->Kleft = t->Kright = 0.0; // 5.114 |
| 101 | t->V = t->A * t->Dx; // 5.114 |
| 102 | totalVolume += t->V; |
| 103 | } |
| 104 | //Melder_casual (U"Starting volume: ", totalVolume * 1000, U" litres."); |
| 105 | for (integer sample = 1; sample <= numberOfSamples; sample ++) { |
| 106 | const double time = (sample - 1) / fsamp; |
| 107 | Artword_intoArt (artword, art.get(), time); |
| 108 | Art_Speaker_intoDelta (art.get(), speaker, delta.get()); |
| 109 | if (sample % MONITOR_SAMPLES == 0 && monitor.graphics()) { // because we can be in batch |
| 110 | Graphics graphics = monitor.graphics(); |
| 111 | double area [1+78]; |
| 112 | for (int i = 1; i <= 78; i ++) { |
| 113 | area [i] = delta -> tubes [i]. A; |
| 114 | if (area [i] < minTract [i]) |
| 115 | minTract [i] = area [i]; |
| 116 | if (area [i] > maxTract [i]) |
| 117 | maxTract [i] = area [i]; |
| 118 | } |
| 119 | Graphics_beginMovieFrame (graphics, & Melder_WHITE); |
| 120 | |
| 121 | Graphics_Viewport vp = Graphics_insetViewport (monitor.graphics(), 0.0, 0.5, 0.5, 1.0); |
| 122 | Graphics_setWindow (graphics, 0.0, 1.0, 0.0, 0.05); |
| 123 | Graphics_setColour (graphics, Melder_RED); |
| 124 | Graphics_function (graphics, minTract, 1, 35, 0.0, 0.9); |
| 125 | Graphics_function (graphics, maxTract, 1, 35, 0.0, 0.9); |
| 126 | Graphics_setColour (graphics, Melder_BLACK); |
| 127 | Graphics_function (graphics, area, 1, 35, 0.0, 0.9); |
| 128 | Graphics_setLineType (graphics, Graphics_DOTTED); |
| 129 | Graphics_line (graphics, 0.0, 0.0, 1.0, 0.0); |
| 130 | Graphics_setLineType (graphics, Graphics_DRAWN); |
| 131 | Graphics_resetViewport (graphics, vp); |
| 132 | |
| 133 | vp = Graphics_insetViewport (graphics, 0, 0.5, 0, 0.5); |
| 134 | Graphics_setWindow (graphics, 0.0, 1.0, -0.000003, 0.00001); |
| 135 | Graphics_setColour (graphics, Melder_RED); |
| 136 | Graphics_function (graphics, minTract, 36, 37, 0.2, 0.8); |
| 137 | Graphics_function (graphics, maxTract, 36, 37, 0.2, 0.8); |
| 138 | Graphics_setColour (graphics, Melder_BLACK); |
| 139 | Graphics_function (graphics, area, 36, 37, 0.2, 0.8); |
| 140 | Graphics_setLineType (graphics, Graphics_DOTTED); |
| 141 | Graphics_line (graphics, 0.0, 0.0, 1.0, 0.0); |
| 142 | Graphics_setLineType (graphics, Graphics_DRAWN); |
| 143 | Graphics_resetViewport (graphics, vp); |
| 144 | |
| 145 | vp = Graphics_insetViewport (graphics, 0.5, 1.0, 0.5, 1.0); |
| 146 | Graphics_setWindow (graphics, 0.0, 1.0, 0.0, 0.001); |
| 147 | Graphics_setColour (graphics, Melder_RED); |
| 148 | Graphics_function (graphics, minTract, 38, 64, 0.0, 1.0); |
| 149 | Graphics_function (graphics, maxTract, 38, 64, 0.0, 1.0); |
| 150 | Graphics_setColour (graphics, Melder_BLACK); |
| 151 | Graphics_function (graphics, area, 38, 64, 0.0, 1.0); |
| 152 | Graphics_setLineType (graphics, Graphics_DOTTED); |
| 153 | Graphics_line (graphics, 0.0, 0.0, 1.0, 0.0); |
| 154 | Graphics_setLineType (graphics, Graphics_DRAWN); |
| 155 | Graphics_resetViewport (graphics, vp); |
| 156 | |
| 157 | vp = Graphics_insetViewport (graphics, 0.5, 1.0, 0.0, 0.5); |
| 158 | Graphics_setWindow (graphics, 0.0, 1.0, 0.001, 0.0); |
| 159 | Graphics_setColour (graphics, Melder_RED); |
| 160 | Graphics_function (graphics, minTract, 65, 78, 0.5, 1.0); |
| 161 | Graphics_function (graphics, maxTract, 65, 78, 0.5, 1.0); |
| 162 | Graphics_setColour (graphics, Melder_BLACK); |
| 163 | Graphics_function (graphics, area, 65, 78, 0.5, 1.0); |
| 164 | Graphics_setLineType (graphics, Graphics_DRAWN); |
| 165 | Graphics_resetViewport (graphics, vp); |
| 166 | |
| 167 | Graphics_endMovieFrame (graphics, 0.0); |
| 168 | Melder_monitor ((double) sample / numberOfSamples, U"Articulatory synthesis: ", Melder_half (time), U" seconds"); |
| 169 | } |
| 170 | for (integer n = 1; n <= oversampling; n ++) { |
| 171 | for (integer m = 1; m <= M; m ++) { |
| 172 | Delta_Tube t = & delta -> tubes [m]; |
| 173 | if (! t -> left1 && ! t -> right1) |
| 174 | continue; |
| 175 | |
| 176 | /* New geometry. */ |
| 177 | |
| 178 | #if CONSTANT_TUBE_LENGTHS |
| 179 | t->Dxnew = t->Dx; |
| 180 | #else |
| 181 | t->dDxdtnew = (t->dDxdt + Dt * 10000.0 * (t->Dxeq - t->Dx)) / |
| 182 | (1.0 + 200.0 * Dt); // critical damping, 10 ms |
| 183 | t->Dxnew = t->Dx + t->dDxdtnew * Dt; |
| 184 | #endif |
| 185 | /* 3-way: equal lengths. */ |
| 186 | /* This requires left tubes to be processed before right tubes. */ |
| 187 | if (t->left1 && t->left1->right2) |
| 188 | t->Dxnew = t->left1->Dxnew; |
| 189 | t->Dz = t->Dzeq; /* immediate... */ |
| 190 | t->eleft = (t->Qleft - t->Kleft) * t->V; // 5.115 |
| 191 | t->eright = (t->Qright - t->Kright) * t->V; // 5.115 |
| 192 | t->e = 0.5 * (t->eleft + t->eright); // 5.116 |
| 193 | t->p = 0.5 * (t->pleft + t->pright); // 5.116 |
| 194 | t->DeltaP = t->e / t->V - rho0c2; // 5.117 |
| 195 | t->v = t->p / (rho0 + onebyc2 * t->DeltaP); // 5.118 |
| 196 | { |
| 197 | const double dDy = t->Dyeq - t->Dy; |
| 198 | const double cubic = t->k3 * dDy * dDy; |
| 199 | Delta_Tube l1 = t->left1, l2 = t->left2, r1 = t->right1, r2 = t->right2; |
| 200 | tension = dDy * (t->k1 + cubic); |
| 201 | t->B = 2.0 * t->Brel * sqrt (t->mass * (t->k1 + 3.0 * cubic)); |
| 202 | if (t->k1left1 != 0.0 && l1) |
| 203 | tension += t->k1left1 * t->k1 * (dDy - (l1->Dyeq - l1->Dy)); |
| 204 | if (t->k1left2 != 0.0 && l2) |
| 205 | tension += t->k1left2 * t->k1 * (dDy - (l2->Dyeq - l2->Dy)); |
| 206 | if (t->k1right1 != 0.0 && r1) |
| 207 | tension += t->k1right1 * t->k1 * (dDy - (r1->Dyeq - r1->Dy)); |
| 208 | if (t->k1right2 != 0.0 && r2) |
| 209 | tension += t->k1right2 * t->k1 * (dDy - (r2->Dyeq - r2->Dy)); |
| 210 | } |
| 211 | if (t->Dy < t->dy) { |
| 212 | if (t->Dy >= - t->dy) { |
| 213 | const double dDy = t->dy - t->Dy, dDy2 = dDy * dDy; |
| 214 | tension += dDy2 / (4.0 * t->dy) * (t->s1 + 0.5 * t->s3 * dDy2); |
| 215 | t->B += 2.0 * dDy / (2.0 * t->dy) * |
| 216 | sqrt (t->mass * (t->s1 + t->s3 * dDy2)); |
| 217 | } else { |
| 218 | tension -= t->Dy * (t->s1 + t->s3 * (t->Dy * t->Dy + t->dy * t->dy)); |
| 219 | t->B += 2.0 * sqrt (t->mass * (t->s1 + t->s3 * (3.0 * t->Dy * t->Dy + t->dy * t->dy))); |
| 220 | } |
| 221 | } |
| 222 | t->dDydtnew = (t->dDydt + Dt / t->mass * (tension + 2.0 * t->DeltaP * t->Dz * t->Dx)) / |
| 223 | (1.0 + t->B * Dt / t->mass); // 5.119 |
| 224 | t->Dynew = t->Dy + t->dDydtnew * Dt; // 5.119 |
| 225 | #if NO_MOVING_WALLS |
| 226 | t->Dynew = t->Dy; |
| 227 | #endif |
| 228 | t->Anew = t->Dz * ( t->Dynew >= t->dy ? t->Dynew + Dymin : |
| 229 | t->Dynew <= - t->dy ? Dymin : |
| 230 | (t->dy + t->Dynew) * (t->dy + t->Dynew) / (4.0 * t->dy) + Dymin ); // 4.4, 4.5 |
| 231 | #if EQUAL_TUBE_WIDTHS |
| 232 | t->Anew = 0.0001; |
| 233 | #endif |
| 234 | t->Ahalf = 0.5 * (t->A + t->Anew); // 5.120 |
| 235 | t->Dxhalf = 0.5 * (t->Dxnew + t->Dx); // 5.121 |
| 236 | t->Vnew = t->Anew * t->Dxnew; // 5.128 |
| 237 | {// |
| 238 | const double oneByDyav = t->Dz / t->A; |
| 239 | /*t->R = 12.0 * 1.86e-5 * t->parallel * t->parallel * oneByDyav * oneByDyav;*/ |
| 240 | if (t->Dy < 0.0) |
| 241 | t->R = 12.0 * 1.86e-5 / (Dymin * Dymin + t->dy * t->dy); |
| 242 | else |
| 243 | t->R = 12.0 * 1.86e-5 * t->parallel * t->parallel / |
| 244 | ((t->Dy + Dymin) * (t->Dy + Dymin) + t->dy * t->dy); |
| 245 | t->R += 0.3 * t->parallel * oneByDyav; /* 5.23 */ |
| 246 | } |
| 247 | t->r = (1.0 + t->R * Dt / rho0) * t->Dxhalf / t->Anew; // 5.122 |
| 248 | t->ehalf = t->e + halfc2Dt * (t->Jleft - t->Jright); // 5.123 |
| 249 | t->phalf = (t->p + halfDt * (t->Qleft - t->Qright) / t->Dx) / (1.0 + Dtbytworho0 * t->R); // 5.123 |
| 250 | #if MASS_LEAPFROG |
| 251 | t->ehalf = t->ehalfold + 2.0 * halfc2Dt * (t->Jleft - t->Jright); |
| 252 | #endif |
| 253 | t->Jhalf = t->phalf * t->Ahalf; // 5.124 |
| 254 | t->Qhalf = t->ehalf / (t->Ahalf * t->Dxhalf) + onebytworho0 * t->phalf * t->phalf; // 5.124 |
| 255 | #if NO_BERNOULLI_EFFECT |
| 256 | t->Qhalf = t->ehalf / (t->Ahalf * t->Dxhalf); |
| 257 | #endif |
| 258 | } |
| 259 | for (int m = 1; m <= M; m ++) { // compute Jleftnew and Qleftnew |
| 260 | const Delta_Tube l = & delta->tubes [m], r1 = l -> right1, r2 = l -> right2, r = r1; |
| 261 | const Delta_Tube l1 = l, l2 = r ? r -> left2 : nullptr; |
| 262 | if (! l->left1) { // closed boundary at the left side (diaphragm)? |
| 263 | if (! r) |
| 264 | continue; // tube not connected at all |
| 265 | l->Jleftnew = 0.0; // 5.132 |
| 266 | l->Qleftnew = (l->eleft - twoc2Dt * l->Jhalf) / l->Vnew; // 5.132 |
| 267 | } |
| 268 | else // left boundary open to another tube will be handled... |
| 269 | (void) 0; // ...together with the right boundary of the tube to the left |
| 270 | if (! r) { // open boundary at the right side (lips, nostrils)? |
| 271 | rrad = 1.0 - c * Dt / 0.02; // radiation resistance, 5.135 |
| 272 | onebygrad = 1.0 / (1.0 + c * Dt / 0.02); // radiation conductance, 5.135 |
| 273 | #if NO_RADIATION_DAMPING |
| 274 | rrad = 0.0; |
| 275 | onebygrad = 0.0; |
| 276 | #endif |
| 277 | l->prightnew = ((l->Dxhalf / Dt + c * onebygrad) * l->pright + |
| 278 | 2.0 * ((l->Qhalf - rho0c2) - (l->Qright - rho0c2) * onebygrad)) / |
| 279 | (l->r * l->Anew / Dt + c * onebygrad); // 5.136 |
| 280 | l->Jrightnew = l->prightnew * l->Anew; // 5.136 |
| 281 | l->Qrightnew = (rrad * (l->Qright - rho0c2) + |
| 282 | c * (l->prightnew - l->pright)) * onebygrad + rho0c2; // 5.136 |
| 283 | } else if (! l2 && ! r2) { // two-way boundary |
| 284 | if (l->v > criticalVelocity && l->A < r->A) { |
| 285 | l->Pturbrightnew = -0.5 * rho0 * (l->v - criticalVelocity) * |
| 286 | (1.0 - l->A / r->A) * (1.0 - l->A / r->A) * l->v; |
| 287 | if (l->Pturbrightnew != 0.0) |
| 288 | l->Pturbrightnew *= NUMrandomGauss (1.0, noiseFactor) /* * l->A */; |
| 289 | } |
| 290 | if (r->v < - criticalVelocity && r->A < l->A) { |
| 291 | l->Pturbrightnew = 0.5 * rho0 * (r->v + criticalVelocity) * |
| 292 | (1.0 - r->A / l->A) * (1.0 - r->A / l->A) * r->v; |
| 293 | if (l->Pturbrightnew != 0.0) |
| 294 | l->Pturbrightnew *= NUMrandomGauss (1.0, noiseFactor) /* * r->A */; |
| 295 | } |
| 296 | #if NO_TURBULENCE |
| 297 | l->Pturbrightnew = 0.0; |
| 298 | #endif |
| 299 | l->Jrightnew = r->Jleftnew = |
| 300 | (l->Dxhalf * l->pright + r->Dxhalf * r->pleft + |
| 301 | twoDt * (l->Qhalf - r->Qhalf + l->Pturbright)) / |
| 302 | (l->r + r->r); // 5.127 |
| 303 | #if B91 |
| 304 | l->Jrightnew = r->Jleftnew = |
| 305 | (l->pright + r->pleft + |
| 306 | 2.0 * twoDt * (l->Qhalf - r->Qhalf + l->Pturbright) / (l->Dxhalf + r->Dxhalf)) / |
| 307 | (l->r / l->Dxhalf + r->r / r->Dxhalf); |
| 308 | #endif |
| 309 | l->prightnew = l->Jrightnew / l->Anew; // 5.128 |
| 310 | r->pleftnew = r->Jleftnew / r->Anew; // 5.128 |
| 311 | l->Krightnew = onebytworho0 * l->prightnew * l->prightnew; // 5.128 |
| 312 | r->Kleftnew = onebytworho0 * r->pleftnew * r->pleftnew; // 5.128 |
| 313 | #if NO_BERNOULLI_EFFECT |
| 314 | l->Krightnew = r->Kleftnew = 0.0; |
| 315 | #endif |
| 316 | l->Qrightnew = |
| 317 | (l->eright + r->eleft + twoc2Dt * (l->Jhalf - r->Jhalf) |
| 318 | + l->Krightnew * l->Vnew + (r->Kleftnew - l->Pturbrightnew) * r->Vnew) / |
| 319 | (l->Vnew + r->Vnew); // 5.131 |
| 320 | r->Qleftnew = l->Qrightnew + l->Pturbrightnew; // 5.131 |
| 321 | } else if (r2) { // two adjacent tubes at the right side (velic) |
| 322 | r1->Jleftnew = |
| 323 | (r1->Jleft * r1->Dxhalf * (1.0 / (l->A + r2->A) + 1.0 / r1->A) + |
| 324 | twoDt * ((l->Ahalf * l->Qhalf + r2->Ahalf * r2->Qhalf ) / (l->Ahalf + r2->Ahalf) - r1->Qhalf)) / |
| 325 | (1.0 / (1.0 / l->r + 1.0 / r2->r) + r1->r); // 5.138 |
| 326 | r2->Jleftnew = |
| 327 | (r2->Jleft * r2->Dxhalf * (1.0 / (l->A + r1->A) + 1.0 / r2->A) + |
| 328 | twoDt * ((l->Ahalf * l->Qhalf + r1->Ahalf * r1->Qhalf ) / (l->Ahalf + r1->Ahalf) - r2->Qhalf)) / |
| 329 | (1.0 / (1.0 / l->r + 1.0 / r1->r) + r2->r); // 5.138 |
| 330 | l->Jrightnew = r1->Jleftnew + r2->Jleftnew; // 5.139 |
| 331 | l->prightnew = l->Jrightnew / l->Anew; // 5.128 |
| 332 | r1->pleftnew = r1->Jleftnew / r1->Anew; // 5.128 |
| 333 | r2->pleftnew = r2->Jleftnew / r2->Anew; // 5.128 |
| 334 | l->Krightnew = onebytworho0 * l->prightnew * l->prightnew; // 5.128 |
| 335 | r1->Kleftnew = onebytworho0 * r1->pleftnew * r1->pleftnew; // 5.128 |
| 336 | r2->Kleftnew = onebytworho0 * r2->pleftnew * r2->pleftnew; // 5.128 |
| 337 | #if NO_BERNOULLI_EFFECT |
| 338 | l->Krightnew = r1->Kleftnew = r2->Kleftnew = 0; |
| 339 | #endif |
| 340 | l->Qrightnew = r1->Qleftnew = r2->Qleftnew = |
| 341 | (l->eright + r1->eleft + r2->eleft + twoc2Dt * (l->Jhalf - r1->Jhalf - r2->Jhalf) + |
| 342 | l->Krightnew * l->Vnew + r1->Kleftnew * r1->Vnew + r2->Kleftnew * r2->Vnew) / |
| 343 | (l->Vnew + r1->Vnew + r2->Vnew); // 5.137 |
| 344 | } else { |
| 345 | Melder_assert (l2 != nullptr); |
| 346 | l1->Jrightnew = |
| 347 | (l1->Jright * l1->Dxhalf * (1.0 / (r->A + l2->A) + 1.0 / l1->A) - |
| 348 | twoDt * ((r->Ahalf * r->Qhalf + l2->Ahalf * l2->Qhalf ) / (r->Ahalf + l2->Ahalf) - l1->Qhalf)) / |
| 349 | (1.0 / (1.0 / r->r + 1.0 / l2->r) + l1->r); // 5.138 |
| 350 | l2->Jrightnew = |
| 351 | (l2->Jright * l2->Dxhalf * (1.0 / (r->A + l1->A) + 1.0 / l2->A) - |
| 352 | twoDt * ((r->Ahalf * r->Qhalf + l1->Ahalf * l1->Qhalf ) / (r->Ahalf + l1->Ahalf) - l2->Qhalf)) / |
| 353 | (1.0 / (1.0 / r->r + 1.0 / l1->r) + l2->r); // 5.138 |
| 354 | r->Jleftnew = l1->Jrightnew + l2->Jrightnew; // 5.139 |
| 355 | r->pleftnew = r->Jleftnew / r->Anew; // 5.128 |
| 356 | l1->prightnew = l1->Jrightnew / l1->Anew; // 5.128 |
| 357 | l2->prightnew = l2->Jrightnew / l2->Anew; // 5.128 |
| 358 | r->Kleftnew = onebytworho0 * r->pleftnew * r->pleftnew; // 5.128 |
| 359 | l1->Krightnew = onebytworho0 * l1->prightnew * l1->prightnew; // 5.128 |
| 360 | l2->Krightnew = onebytworho0 * l2->prightnew * l2->prightnew; // 5.128 |
| 361 | #if NO_BERNOULLI_EFFECT |
| 362 | r->Kleftnew = l1->Krightnew = l2->Krightnew = 0.0; |
| 363 | #endif |
| 364 | r->Qleftnew = l1->Qrightnew = l2->Qrightnew = |
| 365 | (r->eleft + l1->eright + l2->eright + twoc2Dt * (l1->Jhalf + l2->Jhalf - r->Jhalf) + |
| 366 | r->Kleftnew * r->Vnew + l1->Krightnew * l1->Vnew + l2->Krightnew * l2->Vnew) / |
| 367 | (r->Vnew + l1->Vnew + l2->Vnew); // 5.137 |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* Save some results. */ |
| 372 | |
| 373 | if (n == (oversampling + 1) / 2) { |
| 374 | double out = 0.0; |
| 375 | for (int m = 1; m <= M; m ++) { |
| 376 | Delta_Tube t = & delta->tubes [m]; |
| 377 | out += rho0 * t->Dx * t->Dz * t->dDydt * Dt * 1000.0; // radiation of wall movement, 5.140 |
| 378 | if (! t->right1) |
| 379 | out += t->Jrightnew - t->Jright; // radiation of open tube end |
| 380 | } |
| 381 | result -> z [1] [sample] = out /= 4.0 * NUMpi * 0.4 * Dt; // at 0.4 metres |
| 382 | if (iw1) w1 -> z [1] [sample] = delta->tubes [iw1]. Dy; |
| 383 | if (iw2) w2 -> z [1] [sample] = delta->tubes [iw2]. Dy; |
| 384 | if (iw3) w3 -> z [1] [sample] = delta->tubes [iw3]. Dy; |
| 385 | if (ip1) p1 -> z [1] [sample] = delta->tubes [ip1]. DeltaP; |
| 386 | if (ip2) p2 -> z [1] [sample] = delta->tubes [ip2]. DeltaP; |
| 387 | if (ip3) p3 -> z [1] [sample] = delta->tubes [ip3]. DeltaP; |
| 388 | if (iv1) v1 -> z [1] [sample] = delta->tubes [iv1]. v; |
| 389 | if (iv2) v2 -> z [1] [sample] = delta->tubes [iv2]. v; |
| 390 | if (iv3) v3 -> z [1] [sample] = delta->tubes [iv3]. v; |
| 391 | } |
| 392 | for (int m = 1; m <= M; m ++) { |
| 393 | Delta_Tube t = & delta->tubes [m]; |
| 394 | t->Jleft = t->Jleftnew; |
| 395 | t->Jright = t->Jrightnew; |
| 396 | t->Qleft = t->Qleftnew; |
| 397 | t->Qright = t->Qrightnew; |
| 398 | t->Dy = t->Dynew; |
| 399 | t->dDydt = t->dDydtnew; |
| 400 | t->A = t->Anew; |
| 401 | t->Dx = t->Dxnew; |
| 402 | t->dDxdt = t->dDxdtnew; |
| 403 | t->eleft = t->eleftnew; |
| 404 | t->eright = t->erightnew; |
| 405 | #if MASS_LEAPFROG |
| 406 | t->ehalfold = t->ehalf; |
| 407 | #endif |
| 408 | t->pleft = t->pleftnew; |
| 409 | t->pright = t->prightnew; |
| 410 | t->Kleft = t->Kleftnew; |
| 411 | t->Kright = t->Krightnew; |
| 412 | t->V = t->Vnew; |
| 413 | t->Pturbright = t->Pturbrightnew; |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | totalVolume = 0.0; |
| 418 | for (integer m = 1; m <= M; m ++) |
| 419 | totalVolume += delta->tubes [m]. V; |
| 420 | //Melder_casual (U"Ending volume: ", totalVolume * 1000, U" litres."); |
| 421 | if (out_w1) *out_w1 = w1.move(); |
| 422 | if (out_w2) *out_w2 = w2.move(); |
| 423 | if (out_w3) *out_w3 = w3.move(); |
| 424 | if (out_p1) *out_p1 = p1.move(); |
| 425 | if (out_p2) *out_p2 = p2.move(); |
| 426 | if (out_p3) *out_p3 = p3.move(); |
| 427 | if (out_v1) *out_v1 = v1.move(); |
| 428 | if (out_v2) *out_v2 = v2.move(); |
| 429 | if (out_v3) *out_v3 = v3.move(); |
| 430 | return result; |
| 431 | } catch (MelderError) { |
| 432 | Melder_throw (artword, U" & ", speaker, U": articulatory synthesis not performed."); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /* End of file Artword_Speaker_to_Sound.cpp */ |