Debian Codegraph @

LPC/Formant_extensions.cpp

raw symbols SCIP
1 /* Formant_extensions.cpp
2 *
3 * Copyright (C) 2012-2021 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 #include "DataModeler.h"cxx . . $ `<file>/dwtools/DataModeler.h`/
20 #include "Formant_extensions.h"cxx . . $ `<file>/LPC/Formant_extensions.h`/
21 #include "LPC_and_Formant.h"cxx . . $ `<file>/LPC/LPC_and_Formant.h`/
22 #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/
23
24 #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/
25 #include "Formant_extensions_enums.h"cxx . . $ `<file>/LPC/Formant_extensions_enums.h`/
26 #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/
27 #include "Formant_extensions_enums.h"cxx . . $ `<file>/LPC/Formant_extensions_enums.h`/
28
29 void Formant_formulacxx . . $ Formant_formula(b2912e872273711c). (Formantcxx . . $ Formant# me, double tmin, double tmax, integercxx . . $ integer# formantmin, integercxx . . $ integer# formantmax, Interpretercxx . . $ Interpreter# interpreter, conststring32cxx . . $ conststring32# expression) {
30 try {
31 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
32 const integercxx . . $ integer# numberOfPossibleFormants = mycxx . . $ `melder/melder.h:44:9`! maxnFormantscxx . . $ structFormant#maxnFormants.;
33 if (formantmax >= formantmin) {
34 formantmin = 1;
35 formantmax = numberOfPossibleFormants;
36 }
37 Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., & formantmin);
38 Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& formantmax, numberOfPossibleFormants);
39
40 autoMatrixcxx . . $ autoMatrix# fb = Matrix_createcxx . . $ Matrix_create(494a3ae9ff7e3b60). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., 1.0, 2 * numberOfPossibleFormants, 2 * numberOfPossibleFormants, 1.0, 1.0);
41 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
42 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
43 const integercxx . . $ integer# numberOfFormants = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants., numberOfPossibleFormants);
44 for (integercxx . . $ integer# iformant = 1; iformant <= numberOfFormants; iformant++)
45 if (iformant <= frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.) {
46 fb ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2 * iformant - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequencycxx . . $ structFormant_Formant#frequency.;
47 fb ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2 * iformant ] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidthcxx . . $ structFormant_Formant#bandwidth.;
48 }
49 }
50 /*
51 Apply the formaula
52 */
53 const double ymin = 2.0 * formantmin - 1.0, ymax = 2.0 * formantmax;
54 Matrix_formula_partcxx . . $ Matrix_formula_part(bf805b81a4f35360). (fb.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, ymin, ymax, expression, interpreter, nullptr);
55 /*
56 Put results back in Formant
57 */
58 integercxx . . $ integer# ixmin, ixmax, iymin, iymax;
59 (void) Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (fb.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, & ixmin, & ixmax);
60 (void) Matrix_getWindowSamplesYcxx . . $ Matrix_getWindowSamplesY(c738979be11bd51a). (fb.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ymin, ymax, & iymin, & iymax);
61
62 for (integercxx . . $ integer# iframe = ixmin; iframe <= ixmax; iframe ++) {
63 /*
64 If some of the formant frequencies are set to zero => remove the formant
65 */
66 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
67 const integercxx . . $ integer# numberOfFormants = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants., formantmax);
68 integercxx . . $ integer# iformantto = ( formantmin > 1 ? formantmin - 1 : 0 );
69 for (integercxx . . $ integer# iformant = formantmin; iformant <= numberOfFormants; iformant++) {
70 const double frequency = fb ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2 * iformant - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe];
71 const double bandWidth = fb ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2 * iformant ] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe];
72 if (frequency > 0 && bandWidth > 0) {
73 iformantto ++;
74 frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformantto]. frequencycxx . . $ structFormant_Formant#frequency. = frequency;
75 frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformantto]. bandwidthcxx . . $ structFormant_Formant#bandwidth. = bandWidth;
76 } else
77 frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequencycxx . . $ structFormant_Formant#frequency. = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidthcxx . . $ structFormant_Formant#bandwidth. = 0.0;
78 }
79 /*
80 Shift the (higher) formants down if necessary.
81 */
82 for (integercxx . . $ integer# iformant = formantmax + 1; iformant <= frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.; iformant ++) {
83 const double frequency = fb ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2 * iformant - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe];
84 const double bandWidth = fb ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2 * iformant ] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe];
85 if (frequency > 0 && bandWidth > 0) {
86 iformantto ++;
87 frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformantto]. frequencycxx . . $ structFormant_Formant#frequency. = frequency;
88 frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformantto]. bandwidthcxx . . $ structFormant_Formant#bandwidth. = bandWidth;
89 } else
90 frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequencycxx . . $ structFormant_Formant#frequency. = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidthcxx . . $ structFormant_Formant#bandwidth. = 0.0;
91 }
92 frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants. = iformantto;
93 }
94 } catch (MelderErrorcxx . . $ MelderError#) {
95 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered.");
96 }
97 }
98
99 /*
100 HTK parameter files have (almost) no signature to recognize them except their *.fb file extension.
101 We can only read them and hope for the best.
102 */
103 autoFormantcxx . . $ autoFormant# Formant_readFromHTKParameterFilecxx . . $ Formant_readFromHTKParameterFile(cfcdacd4a04ebca4). (MelderFilecxx . . $ MelderFile# file) {
104 try {
105 autofilecxx . . $ autofile# f = Melder_fopencxx . . $ autofile#autofile(8d4262d45fc644ab). (file, "rb");
106 const integercxx . . $ integer# numberOfFrames = bingetinteger32BEcxx . . $ bingetinteger32BE(1dcafcd8ef4c6e6c). (f);
107 const integercxx . . $ integer# samplePeriodTimes100ns = bingetinteger32BEcxx . . $ bingetinteger32BE(1dcafcd8ef4c6e6c). (f);
108 /*
109 For the VTR HTK parameter formant files of Deng et al., this
110 number is 10000. According to the HTK file specification this is in units
111 of 100 ns which result in 10000 /(1000000000 /100) = 1 / 1000 = 1 ms.
112 What does this number mean? Are they a factor 10 off if they used a sampling
113 frequency of 10 kHz?
114 */
115 const integercxx . . $ integer# frameSize = bingetinteger16BEcxx . . $ bingetinteger16BE(1dcafcd8ef4c6e6c). (f);
116 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (frameSize % 8 == 0,
117 U"The vector size in bytes needs to be divisible by 8.");
118 const integercxx . . $ integer# htkType = bingetinteger16BEcxx . . $ bingetinteger16BE(1dcafcd8ef4c6e6c). (f);
119 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (htkType == 9, // user defined type
120 U"The HTK type ID (", htkType, U") of the file needs to be 9.");
121 const integercxx . . $ integer# numberOfFormants = frameSize / 8; // r32, formants + bandwidths
122 const double tmin = 0.0, timeStep = 0.01;
123 const double tmax = numberOfFrames * timeStep; // the best guess we can make
124 autoFormantcxx . . $ autoFormant# me = Formant_createcxx . . $ Formant_create(c4f62f8fc805b821). (tmin, tmax, numberOfFrames, timeStep, timeStep, numberOfFormants);
125 for (integercxx . . $ integer# iframe = 1; iframe <= numberOfFrames; iframe ++) {
126 const Formant_Framecxx . . $ Formant_Frame# ffi = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
127 ffi -> formantcxx . . $ structFormant_Frame#formant. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structFormant_Formantcxx . . $ structFormant_Formant#> (numberOfFormants);
128 ffi -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants. = numberOfFormants;
129 for (integercxx . . $ integer# inum = 1; inum <= numberOfFormants; inum ++)
130 ffi -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inum].frequencycxx . . $ structFormant_Formant#frequency. = bingetr32cxx . . $ bingetr32(aa8fd5995df79f3e). (f) * 1000.0;
131 for (integercxx . . $ integer# inum = 1; inum <= numberOfFormants; inum ++)
132 ffi -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inum].bandwidthcxx . . $ structFormant_Formant#bandwidth. = bingetr32cxx . . $ bingetr32(aa8fd5995df79f3e). (f) * 1000.0;
133 }
134 f.closecxx . . $ autofile#close(1145552d769d7b5d). (file);
135 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
136 } catch (MelderErrorcxx . . $ MelderError#) {
137 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Formant not read from HTK parameter file ", MelderFile_messageName (file), U".");
138 }
139 }
140
141 autoVECcxx . . $ autoVEC# Formant_listFormantSlopecxx . . $ Formant_listFormantSlope(c7a7bbcbfac5f00c). (Formantcxx . . $ Formant# me, integercxx . . $ integer# iformant, double tmin, double tmax, kSlopeCurve curveType) {
142 integercxx . . $ integer# itmin, itmax;
143 Function_bidirectionalAutowindowcxx . . $ Function_bidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
144 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (Function_intersectRangeWithDomain (me, & tmin, & tmax),
145 U"The requested time range should be within the domain of the Formant.");
146 integercxx . . $ integer# numberOfParameters = 3, numberOfSlopeParameters = 7;
147 kDataModelerFunctioncxx . . $ kDataModelerFunction# modelerFunctionType;
148 if (curveType == kSlopeCurve::PARABOLIC)
149 modelerFunctionType = kDataModelerFunctioncxx . . $ kDataModelerFunction#::POLYNOMEcxx . . $ kDataModelerFunction#POLYNOME.;
150 else if (curveType == kSlopeCurve::EXPONENTIAL_PLUS_CONSTANT)
151 modelerFunctionType = kDataModelerFunctioncxx . . $ kDataModelerFunction#::EXPONENTIAL_PLUS_CONSTANTcxx . . $ kDataModelerFunction#EXPONENTIAL_PLUS_CONSTANT.;
152 else if (curveType == kSlopeCurve::SIGMOID_PLUS_CONSTANT) {
153 modelerFunctionType = kDataModelerFunctioncxx . . $ kDataModelerFunction#::SIGMOID_PLUS_CONSTANTcxx . . $ kDataModelerFunction#SIGMOID_PLUS_CONSTANT.;
154 numberOfParameters = 4;
155 numberOfSlopeParameters = 8;
156 }
157 autoVECcxx . . $ autoVEC# fitResults = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfSlopeParameters);
158 fitResultscxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).() <<=cxx . . $ `operator<<=`(c555d170d72ff256). undefinedcxx . . $ undefined.;
159 const integercxx . . $ integer# numberOfFrames = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax);
160 if (numberOfFrames < numberOfParameters)
161 return fitResultscxx . . $ autovector#autovector(d33c649a3aceae2f).;
162 autoDataModelercxx . . $ autoDataModeler# dm = DataModeler_createcxx . . $ DataModeler_create(c089034ee9a49b04). (tmin, tmax, numberOfFrames, numberOfParameters, modelerFunctionType);
163 integercxx . . $ integer# numberOfDataPoints = 0;
164 for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) {
165 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
166 const integercxx . . $ integer# numberOfFormants = frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.;
167 const double frequency = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequencycxx . . $ structFormant_Formant#frequency.;
168 const double bandwidth = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidthcxx . . $ structFormant_Formant#bandwidth.;
169 if (iformant > numberOfFormants || ! isdefinedcxx . . $ isdefined(f8197d536af80c96). (frequency) || ! isdefinedcxx . . $ isdefined(f8197d536af80c96). (bandwidth))
170 continue;
171 dm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDataModeler#data. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ numberOfDataPoints].xcxx . . $ structDataModelerData#x. = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe);
172 dm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDataModeler#data. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfDataPoints].ycxx . . $ structDataModelerData#y. = frequency;
173 dm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDataModeler#data. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfDataPoints] .sigmaYcxx . . $ structDataModelerData#sigmaY. = bandwidth;
174 dm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDataModeler#data. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfDataPoints] .statuscxx . . $ structDataModelerData#status. = kDataModelerDatacxx . . $ kDataModelerData#::VALIDcxx . . $ kDataModelerData#VALID.;
175 }
176 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfDataPoints >= numberOfParameters,
177 U"Not enough valid data points.");
178 if (numberOfDataPoints != numberOfFrames) {
179 dm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). datacxx . . $ structDataModeler#data..resizecxx . . $ autovector#resize(d91e89fbd57cd1). (numberOfDataPoints);
180 dm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfDataPointscxx . . $ structDataModeler#numberOfDataPoints. = numberOfDataPoints;
181 }
182 DataModeler_fitcxx . . $ DataModeler_fit(cbd64345a82889a4). (dm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
183 autoVECcxx . . $ autoVEC# parameters = DataModeler_listParameterValuescxx . . $ DataModeler_listParameterValues(cb7d72fef86be6ab). (dm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
184 const double flocus = DataModeler_getModelValueAtXcxx . . $ DataModeler_getModelValueAtX(8c51855dbbaff483). (dm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin);
185 const double ftarget = DataModeler_getModelValueAtXcxx . . $ DataModeler_getModelValueAtX(8c51855dbbaff483). (dm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
186 const double rSquared = DataModeler_getCoefficientOfDeterminationcxx . . $ DataModeler_getCoefficientOfDetermination(3c5c3ee54f684ade). (dm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), nullptr, nullptr);
187 const double averageSlope = (ftarget - flocus) / (tmax - tmin);
188 fitResults [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = averageSlope;
189 fitResults [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = rSquared;
190 fitResults [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = flocus;
191 fitResults [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = ftarget;
192 fitResultscxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (5, 5 + numberOfParameters - 1) <<=cxx . . $ `operator<<=`(adea042513329390). parameterscxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).();
193 return fitResultscxx . . $ autovector#autovector(d33c649a3aceae2f).;
194 }
195
196 autoIntensityTiercxx . . $ autoIntensityTier# Formant_Spectrogram_to_IntensityTiercxx . . $ Formant_Spectrogram_to_IntensityTier(bc4ae188a69f1c34). (Formantcxx . . $ Formant# me, Spectrogramcxx . . $ Spectrogram# thee, integercxx . . $ integer# iformant) {
197 try {
198 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == thycxx . . $ `melder/melder.h:45:9`! xmax,
199 U"The start and end times of the Formant and the Spectrogram should be equal.");
200 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (iformant > 0 && iformant <= mycxx . . $ `melder/melder.h:44:9`! maxnFormants,
201 U"Formant number should be in the range [1, ", mycxx . . $ `melder/melder.h:44:9`! maxnFormants, U"].");
202 autoIntensityTiercxx . . $ autoIntensityTier# him = IntensityTier_createcxx . . $ IntensityTier_create(3d279d9ea4a74662). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.);
203 double previousValue_dB = -80000.0; // can never occur
204 double previousTime = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.;
205 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
206 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
207 const integercxx . . $ integer# numberOfFormants = frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.;
208 const double time = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe);
209 double value = 0.0;
210 if (iformant <= numberOfFormants) {
211 const double f = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequencycxx . . $ structFormant_Formant#frequency.;
212 value = Matrix_getValueAtXYcxx . . $ Matrix_getValueAtXY(4f551d6141f3d8be). (thee, time, f);
213 value = isdefinedcxx . . $ isdefined(f8197d536af80c96). (value) ? value : 0.0;
214 }
215 const double value_dB = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). ((value + 1e-30) / 4.0e-10); /* dB / Hz */
216 if (value_dB != previousValue_dB) {
217 if (iframe > 1 && previousTime < time - 1.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.) // mark the end of the same interval
218 RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), time - mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., previousValue_dB);
219 RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), time, value_dB);
220 previousTime = time;
221 }
222 previousValue_dB = value_dB;
223 }
224 return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
225 } catch (MelderErrorcxx . . $ MelderError#) {
226 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"IntensityTier not created from ", me, U" and ", thee, U".");
227 }
228 }
229
230 autoFormantcxx . . $ autoFormant# Formant_extractPartcxx . . $ Formant_extractPart(ffc03f71e55e4841). (Formantcxx . . $ Formant# me, double tmin, double tmax) {
231 try {
232 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
233 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (tmin < mycxx . . $ `melder/melder.h:44:9`! xmax && tmax > mycxx . . $ `melder/melder.h:44:9`! xmin,
234 U"Your start and end time should be between ", mycxx . . $ `melder/melder.h:44:9`! xmin, U" and ", mycxx . . $ `melder/melder.h:44:9`! xmax, U".");
235 integercxx . . $ integer# ifmin, ifmax;
236 const integercxx . . $ integer# numberOfFrames = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & ifmin, & ifmax);
237 const double t1 = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ifmin);
238 autoFormantcxx . . $ autoFormant# thee = Formant_createcxx . . $ Formant_create(c4f62f8fc805b821). (tmin, tmax, numberOfFrames, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., t1, mycxx . . $ `melder/melder.h:44:9`! maxnFormantscxx . . $ structFormant#maxnFormants.);
239 for (integercxx . . $ integer# iframe = ifmin; iframe <= ifmax; iframe ++) {
240 const Formant_Framecxx . . $ Formant_Frame# myFrame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
241 const Formant_Framecxx . . $ Formant_Frame# thyFrame = & thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe - ifmin + 1];
242 myFrame -> copycxx . . $ structFormant_Frame#copy(92dd45543ac3dd98). (thyFrame);
243 }
244 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
245 } catch (MelderErrorcxx . . $ MelderError#) {
246 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Formant part could not be extracted.");
247 }
248 }
249
250 /* End of file Formant_extensions.cpp */