| 1 | /* FormantGrid.cpp |
| 2 | * |
| 3 | * Copyright (C) 2008,2009,2011,2012,2014-2020,2023,2025 Paul Boersma & 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. |
| 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 "FormantGrid.h"cxx . . $ `<file>/fon/FormantGrid.h`/ |
| 20 | #include "PitchTier_to_Sound.h"cxx . . $ `<file>/fon/PitchTier_to_Sound.h`/ |
| 21 | #include "Formula.h"cxx . . $ `<file>/sys/Formula.h`/ |
| 22 | |
| 23 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 24 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 25 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 26 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 27 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 28 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 29 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 30 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 31 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 32 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 33 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 34 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 35 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 36 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 37 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 38 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 39 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 40 | #include "FormantGrid_def.h"cxx . . $ `<file>/fon/FormantGrid_def.h`/ |
| 41 | |
| 42 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (FormantGrid, Function, 0); |
| 43 | |
| 44 | double structFormantGrid :: v_getVector ( |
| 45 | const integercxx . . $ integer# irow, |
| 46 | const integercxx . . $ integer# icol |
| 47 | ) const { |
| 48 | const constRealTiercxx . . $ constRealTier# tier = ourcxx . . $ `melder/melder.h:42:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).irow]; |
| 49 | return RealTier_getValueAtIndexcxx . . $ RealTier_getValueAtIndex(ed98425824ac647a). (tier, icol); |
| 50 | } |
| 51 | |
| 52 | double structFormantGrid :: v_getFunction1 ( |
| 53 | const integercxx . . $ integer# irow, |
| 54 | const double x |
| 55 | ) const { |
| 56 | const constRealTiercxx . . $ constRealTier# tier = ourcxx . . $ `melder/melder.h:42:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).irow]; |
| 57 | return RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (tier, x); |
| 58 | } |
| 59 | |
| 60 | void structFormantGrid :: v_shiftX ( |
| 61 | const double xfrom, |
| 62 | const double xto |
| 63 | ) /* mutable */ { |
| 64 | FormantGrid_Parent :: v_shiftXcxx . . $ structFunction#v_shiftX(bc12c9ec15586e6a). (xfrom, xto); |
| 65 | for (integercxx . . $ integer# i = 1; i <= ourcxx . . $ `melder/melder.h:42:9`! formants.sizecxx . . $ CollectionOf#size.; i ++) { |
| 66 | const mutableRealTiercxx . . $ mutableRealTier# tier = ourcxx . . $ `melder/melder.h:42:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 67 | tier -> v_shiftXcxx . . $ structRealTier#v_shiftX(bc12c9ec15586e6a). (xfrom, xto); |
| 68 | } |
| 69 | for (integercxx . . $ integer# i = 1; i <= ourcxx . . $ `melder/melder.h:42:9`! bandwidths.sizecxx . . $ CollectionOf#size.; i ++) { |
| 70 | const mutableRealTiercxx . . $ mutableRealTier# tier = ourcxx . . $ `melder/melder.h:42:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 71 | tier -> v_shiftXcxx . . $ structRealTier#v_shiftX(bc12c9ec15586e6a). (xfrom, xto); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void structFormantGrid :: v_scaleX ( |
| 76 | const double xminfrom, |
| 77 | const double xmaxfrom, |
| 78 | const double xminto, |
| 79 | const double xmaxto |
| 80 | ) /* mutable */ { |
| 81 | FormantGrid_Parent :: v_scaleXcxx . . $ structFunction#v_scaleX(52a61fa14d44b641). (xminfrom, xmaxfrom, xminto, xmaxto); |
| 82 | for (integercxx . . $ integer# i = 1; i <= ourcxx . . $ `melder/melder.h:42:9`! formants.sizecxx . . $ CollectionOf#size.; i ++) { |
| 83 | const mutableRealTiercxx . . $ mutableRealTier# tier = ourcxx . . $ `melder/melder.h:42:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 84 | tier -> v_scaleXcxx . . $ structRealTier#v_scaleX(52a61fa14d44b641). (xminfrom, xmaxfrom, xminto, xmaxto); |
| 85 | } |
| 86 | for (integercxx . . $ integer# i = 1; i <= ourcxx . . $ `melder/melder.h:42:9`! bandwidths.sizecxx . . $ CollectionOf#size.; i ++) { |
| 87 | const mutableRealTiercxx . . $ mutableRealTier# tier = ourcxx . . $ `melder/melder.h:42:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 88 | tier -> v_scaleXcxx . . $ structRealTier#v_scaleX(52a61fa14d44b641). (xminfrom, xmaxfrom, xminto, xmaxto); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void FormantGrid_initcxx . . $ FormantGrid_init(b9222a94efd1f8ed). ( |
| 93 | const mutableFormantGrid me, |
| 94 | const double tmin, |
| 95 | const double tmax, |
| 96 | const integercxx . . $ integer# numberOfFormants |
| 97 | ) { |
| 98 | for (integercxx . . $ integer# iformant = 1; iformant <= numberOfFormants; iformant ++) { |
| 99 | autoRealTiercxx . . $ autoRealTier# formant = RealTier_createcxx . . $ RealTier_create(8e3ec305798a9b8e). (tmin, tmax); |
| 100 | mycxx . . $ `melder/melder.h:44:9`! formants. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (formantcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 101 | autoRealTiercxx . . $ autoRealTier# bandwidth = RealTier_createcxx . . $ RealTier_create(8e3ec305798a9b8e). (tmin, tmax); |
| 102 | mycxx . . $ `melder/melder.h:44:9`! bandwidths. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (bandwidthcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 103 | } |
| 104 | mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. = tmin; |
| 105 | mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. = tmax; |
| 106 | } |
| 107 | |
| 108 | autoFormantGrid FormantGrid_createEmptycxx . . $ FormantGrid_createEmpty(73275a7b30af7b50). ( |
| 109 | const double tmin, |
| 110 | const double tmax, |
| 111 | const integercxx . . $ integer# numberOfFormants |
| 112 | ) { |
| 113 | try { |
| 114 | autoFormantGrid me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (FormantGrid); |
| 115 | FormantGrid_initcxx . . $ FormantGrid_init(b9222a94efd1f8ed). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, numberOfFormants); |
| 116 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 117 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 118 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Empty FormantGrid not created."); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | autoFormantGrid FormantGrid_createcxx . . $ FormantGrid_create(8dccade83a8cf46e). ( |
| 123 | const double tmin, |
| 124 | const double tmax, |
| 125 | const integercxx . . $ integer# numberOfFormants, |
| 126 | const double initialFirstFormant, |
| 127 | const double initialFormantSpacing, |
| 128 | const double initialFirstBandwidth, |
| 129 | const double initialBandwidthSpacing |
| 130 | ) { |
| 131 | try { |
| 132 | autoFormantGrid me = FormantGrid_createEmptycxx . . $ FormantGrid_createEmpty(73275a7b30af7b50). (tmin, tmax, numberOfFormants); |
| 133 | for (integercxx . . $ integer# iformant = 1; iformant <= numberOfFormants; iformant ++) { |
| 134 | FormantGrid_addFormantPointcxx . . $ FormantGrid_addFormantPoint(a8593809562a6688). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iformant, 0.5 * (tmin + tmax), |
| 135 | initialFirstFormant + (iformant - 1) * initialFormantSpacing); |
| 136 | FormantGrid_addBandwidthPointcxx . . $ FormantGrid_addBandwidthPoint(a8593809562a6688). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iformant, 0.5 * (tmin + tmax), |
| 137 | initialFirstBandwidth + (iformant - 1) * initialBandwidthSpacing); |
| 138 | } |
| 139 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 140 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 141 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"FormantGrid not created."); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void FormantGrid_addFormantPointcxx . . $ FormantGrid_addFormantPoint(a8593809562a6688). ( |
| 146 | const mutableFormantGrid me, |
| 147 | const integercxx . . $ integer# iformant, |
| 148 | const double time, |
| 149 | const double value |
| 150 | ) { |
| 151 | try { |
| 152 | if (iformant < 1 || iformant > mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.) |
| 153 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No such formant number."); |
| 154 | RealTiercxx . . $ RealTier# formantTier = mycxx . . $ `melder/melder.h:44:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]; |
| 155 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (formantTier, time, value); |
| 156 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 157 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": formant point not added."); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void FormantGrid_addBandwidthPointcxx . . $ FormantGrid_addBandwidthPoint(a8593809562a6688). ( |
| 162 | const mutableFormantGrid me, |
| 163 | const integercxx . . $ integer# iformant, |
| 164 | const double time, |
| 165 | const double value |
| 166 | ) { |
| 167 | try { |
| 168 | if (iformant < 1 || iformant > mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.) |
| 169 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No such formant number."); |
| 170 | RealTiercxx . . $ RealTier# bandwidthTier = mycxx . . $ `melder/melder.h:44:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]; |
| 171 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (bandwidthTier, time, value); |
| 172 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 173 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": bandwidth point not added."); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | double FormantGrid_getFormantAtTimecxx . . $ FormantGrid_getFormantAtTime(175baec10880f703). ( |
| 178 | const constFormantGrid me, |
| 179 | const integercxx . . $ integer# iformant, |
| 180 | const double time |
| 181 | ) { |
| 182 | if (iformant < 1 || iformant > mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.) |
| 183 | return undefinedcxx . . $ undefined.; |
| 184 | return RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (mycxx . . $ `melder/melder.h:44:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant], time); |
| 185 | } |
| 186 | |
| 187 | double FormantGrid_getBandwidthAtTimecxx . . $ FormantGrid_getBandwidthAtTime(175baec10880f703). ( |
| 188 | const constFormantGrid me, |
| 189 | const integercxx . . $ integer# iformant, |
| 190 | const double time |
| 191 | ) { |
| 192 | if (iformant < 1 || iformant > mycxx . . $ `melder/melder.h:44:9`! bandwidths.sizecxx . . $ CollectionOf#size.) |
| 193 | return undefinedcxx . . $ undefined.; |
| 194 | return RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (mycxx . . $ `melder/melder.h:44:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant], time); |
| 195 | } |
| 196 | |
| 197 | void FormantGrid_removeFormantPointsBetweencxx . . $ FormantGrid_removeFormantPointsBetween(a8593809562a6688). ( |
| 198 | const mutableFormantGrid me, |
| 199 | const integercxx . . $ integer# iformant, |
| 200 | const double tmin, |
| 201 | const double tmax |
| 202 | ) { |
| 203 | if (iformant < 1 || iformant > mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.) |
| 204 | return; |
| 205 | AnyTier_removePointsBetweencxx . . $ AnyTier_removePointsBetween(15327dad64b67f1a). (mycxx . . $ `melder/melder.h:44:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]->asAnyTiercxx . . $ structRealTier#asAnyTier(2fecc017ee6dfbab).(), tmin, tmax); |
| 206 | } |
| 207 | |
| 208 | void FormantGrid_removeBandwidthPointsBetweencxx . . $ FormantGrid_removeBandwidthPointsBetween(a8593809562a6688). ( |
| 209 | const mutableFormantGrid me, |
| 210 | const integercxx . . $ integer# iformant, |
| 211 | const double tmin, |
| 212 | const double tmax |
| 213 | ) { |
| 214 | if (iformant < 1 || iformant > mycxx . . $ `melder/melder.h:44:9`! bandwidths.sizecxx . . $ CollectionOf#size.) |
| 215 | return; |
| 216 | AnyTier_removePointsBetweencxx . . $ AnyTier_removePointsBetween(15327dad64b67f1a). (mycxx . . $ `melder/melder.h:44:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]->asAnyTiercxx . . $ structRealTier#asAnyTier(2fecc017ee6dfbab).(), tmin, tmax); |
| 217 | } |
| 218 | |
| 219 | void Sound_FormantGrid_filter_inplacecxx . . $ Sound_FormantGrid_filter_inplace(c894ca9e037130f5). ( |
| 220 | const mutableSoundcxx . . $ mutableSound# me, |
| 221 | const constFormantGrid formantGrid |
| 222 | ) { |
| 223 | const double dt = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 224 | if (formantGrid -> formants.sizecxx . . $ CollectionOf#size. > 0 && formantGrid -> bandwidths.sizecxx . . $ CollectionOf#size. > 0) { |
| 225 | for (integercxx . . $ integer# iformant = 1; iformant <= formantGrid -> formants.sizecxx . . $ CollectionOf#size.; iformant ++) { |
| 226 | const constRealTiercxx . . $ constRealTier# formantTier = formantGrid -> formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]; |
| 227 | const constRealTiercxx . . $ constRealTier# bandwidthTier = formantGrid -> bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant]; |
| 228 | for (integercxx . . $ integer# isamp = 1; isamp <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; isamp ++) { |
| 229 | const double t = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (isamp - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 230 | /* |
| 231 | Compute LP coefficients. |
| 232 | */ |
| 233 | const double formant = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (formantTier, t); |
| 234 | const double bandwidth = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (bandwidthTier, t); |
| 235 | if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (formant) && isdefinedcxx . . $ isdefined(f8197d536af80c96). (bandwidth)) { |
| 236 | const double cosomdt = coscxx . . $ cos(fee4f1d22bc8e617). (2 * NUMpicxx . . $ NUMpi. * formant * dt); |
| 237 | const double r = expcxx . . $ exp(fee4f1d22bc8e617). (- NUMpicxx . . $ NUMpi. * bandwidth * dt); |
| 238 | /* Formants at 0 Hz or the Nyquist are single poles, others are double poles. */ |
| 239 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (cosomdt) > 0.999999) { /* Allow for round-off errors. */ |
| 240 | /* single pole: D(z) = 1 - r z^-1 */ |
| 241 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) |
| 242 | if (isamp > 1) |
| 243 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp] += r * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp - 1]; |
| 244 | } else { |
| 245 | /* double pole: D(z) = 1 + p z^-1 + q z^-2 */ |
| 246 | const double p = - 2 * r * cosomdt; |
| 247 | const double q = r * r; |
| 248 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 249 | if (isamp > 1) |
| 250 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp] -= p * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp - 1]; |
| 251 | if (isamp > 2) |
| 252 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp] -= q * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp - 2]; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | autoSoundcxx . . $ autoSound# Sound_FormantGrid_filtercxx . . $ Sound_FormantGrid_filter(aea610c363f1f102). ( |
| 262 | const constSoundcxx . . $ constSound# me, |
| 263 | const constFormantGrid formantGrid |
| 264 | ) { |
| 265 | try { |
| 266 | autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 267 | Sound_FormantGrid_filter_inplacecxx . . $ Sound_FormantGrid_filter_inplace(c894ca9e037130f5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), formantGrid); |
| 268 | Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 269 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 270 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 271 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered with ", formantGrid, U"."); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | autoSoundcxx . . $ autoSound# Sound_FormantGrid_filter_noscalecxx . . $ Sound_FormantGrid_filter_noscale(aea610c363f1f102). ( |
| 276 | const constSoundcxx . . $ constSound# me, |
| 277 | const constFormantGrid formantGrid |
| 278 | ) { |
| 279 | try { |
| 280 | autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 281 | Sound_FormantGrid_filter_inplacecxx . . $ Sound_FormantGrid_filter_inplace(c894ca9e037130f5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), formantGrid); |
| 282 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 283 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 284 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered with ", formantGrid, U"."); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | autoSoundcxx . . $ autoSound# FormantGrid_to_Soundcxx . . $ FormantGrid_to_Sound(d788281f49b8a3b8). ( |
| 289 | const constFormantGrid me, |
| 290 | const double samplingFrequency, |
| 291 | const double tStart, const double f0Start, |
| 292 | const double tMid, const double f0Mid, |
| 293 | const double tEnd, const double f0End, |
| 294 | const double adaptFactor, const double maximumPeriod, |
| 295 | const double openPhase, const double collisionPhase, const double power1, const double power2 |
| 296 | ) { |
| 297 | try { |
| 298 | autoPitchTiercxx . . $ autoPitchTier# pitch = PitchTier_createcxx . . $ PitchTier_create(6e304f2c8cc67c9c). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 299 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (pitch.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + tStart * (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.), f0Start); |
| 300 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (pitch.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + tMid * (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.), f0Mid); |
| 301 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (pitch.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - (1.0 - tEnd) * (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.), f0End); |
| 302 | autoSoundcxx . . $ autoSound# thee = PitchTier_to_Sound_phonationcxx . . $ PitchTier_to_Sound_phonation(6a8eb2d6c3ac684d). (pitch.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), samplingFrequency, |
| 303 | adaptFactor, maximumPeriod, openPhase, collisionPhase, power1, power2, false); |
| 304 | Sound_FormantGrid_filter_inplacecxx . . $ Sound_FormantGrid_filter_inplace(c894ca9e037130f5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), me); |
| 305 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 306 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 307 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Sound."); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | void FormantGrid_playPartcxx . . $ FormantGrid_playPart(ac04658399c42f9c). ( |
| 312 | const constFormantGrid me, |
| 313 | const double tmin, const double tmax, |
| 314 | const double samplingFrequency, |
| 315 | const double tStart, const double f0Start, |
| 316 | const double tMid, const double f0Mid, |
| 317 | const double tEnd, const double f0End, |
| 318 | const double adaptFactor, const double maximumPeriod, |
| 319 | const double openPhase, const double collisionPhase, const double power1, const double power2, |
| 320 | const Sound_PlayCallbackcxx . . $ Sound_PlayCallback# playCallback, const mutableThingcxx . . $ mutableThing# playBoss |
| 321 | ) { |
| 322 | try { |
| 323 | autoSoundcxx . . $ autoSound# sound = FormantGrid_to_Soundcxx . . $ FormantGrid_to_Sound(d788281f49b8a3b8). (me, samplingFrequency, |
| 324 | tStart, f0Start, tMid, f0Mid, tEnd, f0End, |
| 325 | adaptFactor, maximumPeriod, openPhase, collisionPhase, power1, power2 |
| 326 | ); |
| 327 | Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (sound.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 328 | Sound_playPartcxx . . $ Sound_playPart(4a8b47ed00757136). (sound.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, playCallback, playBoss); |
| 329 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 330 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not played."); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void FormantGrid_formula_frequenciescxx . . $ FormantGrid_formula_frequencies(e82ad802bc23bc8c). ( |
| 335 | const mutableFormantGrid me, |
| 336 | const conststring32cxx . . $ conststring32# expression, |
| 337 | const Interpretercxx . . $ Interpreter# interpreter, |
| 338 | /* mutable assign if null */ mutableFormantGrid thee |
| 339 | ) { |
| 340 | try { |
| 341 | Formula_compilecxx . . $ Formula_compile(3f9bc12732facfd). (interpreter, me, expression, kFormula_EXPRESSION_TYPE_NUMERICcxx . . $ `sys/Formula.h:24:9`!, true); |
| 342 | Formula_Resultcxx . . $ Formula_Result# resultcxx . . $ Formula_Result#Formula_Result(49f6e7a06ebc5aa8).; |
| 343 | if (! thee) |
| 344 | thee = me; |
| 345 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.; irow ++) { |
| 346 | const RealTiercxx . . $ RealTier# formant = thycxx . . $ `melder/melder.h:45:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).irow]; |
| 347 | for (integercxx . . $ integer# icol = 1; icol <= formant -> pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size.; icol ++) { |
| 348 | Formula_runcxx . . $ Formula_run(4cd939002183d562). (irow, icol, & result); |
| 349 | if (isundefcxx . . $ isundef(f8197d536af80c96). (result. numericResultcxx . . $ Formula_Result#numericResult.)) |
| 350 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot put an undefined value into the tier.\nFormula not finished."); |
| 351 | formant -> pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).icol] -> valuecxx . . $ structRealPoint#value. = result. numericResultcxx . . $ Formula_Result#numericResult.; |
| 352 | } |
| 353 | } |
| 354 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 355 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": frequency formula not completed."); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | void FormantGrid_formula_bandwidthscxx . . $ FormantGrid_formula_bandwidths(e82ad802bc23bc8c). ( |
| 360 | const mutableFormantGrid me, |
| 361 | const conststring32cxx . . $ conststring32# expression, |
| 362 | const Interpretercxx . . $ Interpreter# interpreter, |
| 363 | /* mutable assign if null */ mutableFormantGrid thee |
| 364 | ) { |
| 365 | try { |
| 366 | Formula_compilecxx . . $ Formula_compile(3f9bc12732facfd). (interpreter, me, expression, kFormula_EXPRESSION_TYPE_NUMERICcxx . . $ `sys/Formula.h:24:9`!, true); |
| 367 | Formula_Resultcxx . . $ Formula_Result# resultcxx . . $ Formula_Result#Formula_Result(49f6e7a06ebc5aa8).; |
| 368 | if (! thee) |
| 369 | thee = me; |
| 370 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.; irow ++) { |
| 371 | const RealTiercxx . . $ RealTier# bandwidth = thycxx . . $ `melder/melder.h:45:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).irow]; |
| 372 | for (integercxx . . $ integer# icol = 1; icol <= bandwidth -> pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size.; icol ++) { |
| 373 | Formula_runcxx . . $ Formula_run(4cd939002183d562). (irow, icol, & result); |
| 374 | if (isundefcxx . . $ isundef(f8197d536af80c96). (result. numericResultcxx . . $ Formula_Result#numericResult.)) |
| 375 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot put an undefined value into the tier.\nFormula not finished."); |
| 376 | bandwidth -> pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).icol] -> valuecxx . . $ structRealPoint#value. = result. numericResultcxx . . $ Formula_Result#numericResult.; |
| 377 | } |
| 378 | } |
| 379 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 380 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": bandwidth formula not completed."); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | autoFormantGrid Formant_downto_FormantGridcxx . . $ Formant_downto_FormantGrid(e5fbb1b24a0773f9). (const constFormantcxx . . $ constFormant# me) { |
| 385 | try { |
| 386 | autoFormantGrid thee = FormantGrid_createEmptycxx . . $ FormantGrid_createEmpty(73275a7b30af7b50). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! maxnFormantscxx . . $ structFormant#maxnFormants.); |
| 387 | for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) { |
| 388 | const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 389 | const double t = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe); |
| 390 | for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.; iformant ++) { |
| 391 | Formant_Formantcxx . . $ Formant_Formant# pair = & frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]; |
| 392 | FormantGrid_addFormantPointcxx . . $ FormantGrid_addFormantPoint(a8593809562a6688). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iformant, t, pair -> frequencycxx . . $ structFormant_Formant#frequency.); |
| 393 | FormantGrid_addBandwidthPointcxx . . $ FormantGrid_addBandwidthPoint(a8593809562a6688). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iformant, t, pair -> bandwidthcxx . . $ structFormant_Formant#bandwidth.); |
| 394 | } |
| 395 | } |
| 396 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 397 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 398 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to FormantGrid."); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | autoFormantcxx . . $ autoFormant# FormantGrid_to_Formantcxx . . $ FormantGrid_to_Formant(672bf9422707277). (const constFormantGrid me, const double dt, const double intensity) { |
| 403 | try { |
| 404 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (dt > 0.0); |
| 405 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (intensity >= 0.0); |
| 406 | const integercxx . . $ integer# nt = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) / dt) + 1; |
| 407 | const double t1 = 0.5 * (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - (nt - 1) * dt); |
| 408 | autoFormantcxx . . $ autoFormant# thee = Formant_createcxx . . $ Formant_create(c4f62f8fc805b821). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., nt, dt, t1, mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.); |
| 409 | for (integercxx . . $ integer# iframe = 1; iframe <= nt; iframe ++) { |
| 410 | const Formant_Framecxx . . $ Formant_Frame# frame = & thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 411 | frame -> intensitycxx . . $ structFormant_Frame#intensity. = intensity; |
| 412 | frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants. = mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.; |
| 413 | frame -> formantcxx . . $ structFormant_Frame#formant. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structFormant_Formantcxx . . $ structFormant_Formant#> (mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.); |
| 414 | const double time = t1 + (iframe - 1) * dt; |
| 415 | for (integercxx . . $ integer# iformant = 1; iformant <= mycxx . . $ `melder/melder.h:44:9`! formants.sizecxx . . $ CollectionOf#size.; iformant ++) { |
| 416 | const Formant_Formantcxx . . $ Formant_Formant# formant = & frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]; |
| 417 | formant -> frequencycxx . . $ structFormant_Formant#frequency. = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (mycxx . . $ `melder/melder.h:44:9`! formants.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant], time); |
| 418 | formant -> bandwidthcxx . . $ structFormant_Formant#bandwidth. = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (mycxx . . $ `melder/melder.h:44:9`! bandwidths.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant], time); |
| 419 | } |
| 420 | } |
| 421 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 422 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 423 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Formant."); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | autoSoundcxx . . $ autoSound# Sound_Formant_filtercxx . . $ Sound_Formant_filter(138f167c247d8bc6). (const constSoundcxx . . $ constSound# me, const constFormantcxx . . $ constFormant# formant) { |
| 428 | try { |
| 429 | autoFormantGrid grid = Formant_downto_FormantGridcxx . . $ Formant_downto_FormantGrid(e5fbb1b24a0773f9). (formant); |
| 430 | autoSoundcxx . . $ autoSound# thee = Sound_FormantGrid_filtercxx . . $ Sound_FormantGrid_filter(aea610c363f1f102). (me, grid.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 431 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 432 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 433 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered with ", formant, U"."); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | autoSoundcxx . . $ autoSound# Sound_Formant_filter_noscalecxx . . $ Sound_Formant_filter_noscale(138f167c247d8bc6). (const constSoundcxx . . $ constSound# me, const constFormantcxx . . $ constFormant# formant) { |
| 438 | try { |
| 439 | autoFormantGrid grid = Formant_downto_FormantGridcxx . . $ Formant_downto_FormantGrid(e5fbb1b24a0773f9). (formant); |
| 440 | autoSoundcxx . . $ autoSound# thee = Sound_FormantGrid_filter_noscalecxx . . $ Sound_FormantGrid_filter_noscale(aea610c363f1f102). (me, grid.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 441 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 442 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 443 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered with ", formant, U"."); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | /* End of file FormantGrid.cpp */ |