Debian Codegraph @

fon/Formant.cpp

raw symbols SCIP
1 /* Formant.cpp
2 *
3 * Copyright (C) 1992-2009,2011,2012,2014-2020,2022-2025 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 3 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 "Formant.h"cxx . . $ `<file>/fon/Formant.h`/
20
21 #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/
22 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
23 #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/
24 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
25 #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/
26 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
27 #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/
28 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
29 #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/
30 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
31 #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/
32 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
33 #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/
34 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
35 #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/
36 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
37 #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/
38 #include "Formant_def.h"cxx . . $ `<file>/fon/Formant_def.h`/
39
40 #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/
41 #include "Formant_enums.h"cxx . . $ `<file>/fon/Formant_enums.h`/
42 #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/
43 #include "Formant_enums.h"cxx . . $ `<file>/fon/Formant_enums.h`/
44
45 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Formant, Sampled, 2); // version 1 = with intensity, 2 = double
46
47 void structFormant :: v1_info () {
48 structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). ();
49 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Time domain:");
50 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Start time: ", xmincxx . . $ structFunction#xmin., U" seconds");
51 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" End time: ", xmaxcxx . . $ structFunction#xmax., U" seconds");
52 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Total duration: ", xmaxcxx . . $ structFunction#xmax. - xmincxx . . $ structFunction#xmin., U" seconds");
53 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Time sampling:");
54 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Number of frames: ", nxcxx . . $ structSampled#nx.);
55 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Time step: ", dxcxx . . $ structSampled#dx., U" seconds");
56 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" First frame centred at: ", x1cxx . . $ structSampled#x1., U" seconds");
57 }
58
59 double structFormant :: v_getValueAtSample (integercxx . . $ integer# iframe, integercxx . . $ integer# which, int units) const {
60 const Formant_Frame frame = & ourcxx . . $ `melder/melder.h:42:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
61 const integercxx . . $ integer# iformant = which >> 1;
62 if (iformant < 1 || iformant > frame -> numberOfFormants)
63 return undefinedcxx . . $ undefined.;
64 const double frequency = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency;
65 if ((which & 1) == 0) {
66 return ( units ? NUMhertzToBarkcxx . . $ NUMhertzToBark(447c67c6676f75c3). (frequency) : frequency );
67 } else {
68 const double bandwidth = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidth;
69 if (units) {
70 double fleft = frequency - 0.5 * bandwidth, fright = frequency + 0.5 * bandwidth;
71 fleft = ( fleft <= 0.0 ? 0.0 : NUMhertzToBarkcxx . . $ NUMhertzToBark(447c67c6676f75c3). (fleft) ); // prevent undefined
72 fright = NUMhertzToBarkcxx . . $ NUMhertzToBark(447c67c6676f75c3). (fright);
73 return fright - fleft;
74 }
75 return bandwidth;
76 }
77 return undefinedcxx . . $ undefined.;
78 }
79
80 autoFormant Formant_createcxx . . $ Formant_create(c4f62f8fc805b821). (double tmin, double tmax, integercxx . . $ integer# nt, double dt, double t1,
81 integercxx . . $ integer# maximumNumberOfFormants)
82 {
83 try {
84 autoFormant me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Formant);
85 Sampled_initcxx . . $ Sampled_init(5b6f70c633f31208). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, nt, dt, t1);
86 mycxx . . $ `melder/melder.h:44:9`! frames =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structFormant_Frame> (nt);
87 mycxx . . $ `melder/melder.h:44:9`! maxnFormants = maximumNumberOfFormants;
88 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
89 } catch (MelderErrorcxx . . $ MelderError#) {
90 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Formant object not created.");
91 }
92 }
93
94 integercxx . . $ integer# Formant_getMinNumFormantscxx . . $ Formant_getMinNumFormants(6a0b146f5923ed8d). (Formant me) {
95 integercxx . . $ integer# minNumFormants = 100000000;
96 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++)
97 if (mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. numberOfFormants < minNumFormants)
98 minNumFormants = mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. numberOfFormants;
99 return minNumFormants;
100 }
101
102 integercxx . . $ integer# Formant_getMaxNumFormantscxx . . $ Formant_getMaxNumFormants(6a0b146f5923ed8d). (Formant me) {
103 integercxx . . $ integer# maxNumFormants = 0;
104 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++)
105 if (mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. numberOfFormants > maxNumFormants)
106 maxNumFormants = mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. numberOfFormants;
107 return maxNumFormants;
108 }
109
110 void Formant_drawTrackscxx . . $ Formant_drawTracks(6f80ecb0dfd052dc). (Formant me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmax, bool garnish) {
111 const integercxx . . $ integer# ntrack = Formant_getMinNumFormantscxx . . $ Formant_getMinNumFormants(6a0b146f5923ed8d). (me);
112 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
113 integercxx . . $ integer# itmin, itmax;
114 if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax))
115 return;
116 Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g);
117 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, tmin, tmax, 0.0, fmax);
118 for (integercxx . . $ integer# itrack = 1; itrack <= ntrack; itrack ++) {
119 for (integercxx . . $ integer# iframe = itmin; iframe < itmax; iframe ++) {
120 const Formant_Frame curFrame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe], nextFrame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe + 1];
121 const double x1 = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe), x2 = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe + 1);
122 const double f1 = curFrame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequency;
123 const double f2 = nextFrame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequency;
124 if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (x1) && isdefinedcxx . . $ isdefined(f8197d536af80c96). (f1) && isdefinedcxx . . $ isdefined(f8197d536af80c96). (x2) && isdefinedcxx . . $ isdefined(f8197d536af80c96). (f2))
125 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x1, f1, x2, f2);
126 }
127 }
128 Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g);
129 if (garnish) {
130 Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g);
131 Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, U"Time (s)");
132 Graphics_textLeftcxx . . $ Graphics_textLeft(48cf1f690ec61203). (g, true, U"Formant frequency (Hz)");
133 Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false);
134 Graphics_marksLeftEverycxx . . $ Graphics_marksLeftEvery(d1b58b4f93ec67ea). (g, 1.0, 1000.0, true, true, true);
135 }
136 }
137
138 void Formant_drawSpeckles_insidecxx . . $ Formant_drawSpeckles_inside(36952de78a0af76c). (Formant me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmin, double fmax,
139 double suppress_dB, MelderColourcxx . . $ MelderColour# oddColour, MelderColourcxx . . $ MelderColour# evenColour, bool drawWithContrast)
140 {
141 double maximumIntensity = 0.0, minimumIntensity;
142 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
143 integercxx . . $ integer# itmin, itmax;
144 if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax))
145 return;
146 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, tmin, tmax, fmin, fmax);
147
148 for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) {
149 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
150 if (frame -> intensity > maximumIntensity)
151 maximumIntensity = frame -> intensity;
152 }
153 if (maximumIntensity == 0.0 || suppress_dB <= 0.0)
154 minimumIntensity = 0.0; // ignore
155 else
156 minimumIntensity = maximumIntensity / powcxx . . $ pow(b71928d39fde4295). (10.0, suppress_dB / 10.0);
157
158 for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) {
159 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
160 const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe);
161 if (frame -> intensity < minimumIntensity)
162 continue;
163 for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormants; iformant ++) {
164 const double frequency = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency;
165 if (frequency >= fmin && frequency <= fmax) {
166 if (drawWithContrast) {
167 #if macintosh
168 const double original_speckleSize = Graphics_inqSpeckleSize (g);
169 Graphics_setSpeckleSize (g, 1.111 * original_speckleSize);
170 Graphics_setColour (g, iformant % 2 == 1 ? evenColour : oddColour);
171 Graphics_speckle (g, x, frequency);
172 Graphics_setSpeckleSize (g, 0.900 * original_speckleSize);
173 Graphics_setColour (g, iformant % 2 == 1 ? oddColour : evenColour);
174 Graphics_speckle (g, x, frequency);
175 Graphics_setSpeckleSize (g, original_speckleSize);
176 #else
177 const double original_lineWidth = Graphics_inqLineWidthcxx . . $ Graphics_inqLineWidth(f906975acce41a59). (g);
178 const bool even = ( iformant % 2 == 0 );
179 const double speckleSize = Graphics_inqSpeckleSizecxx . . $ Graphics_inqSpeckleSize(f906975acce41a59). (g);
180 Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, 1.0);
181 if (even) {
182 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, evenColour);
183 Graphics_fillCircle_mmcxx . . $ Graphics_fillCircle_mm(8752bb7a78272ca7). (g, x, frequency, speckleSize * 1.4);
184 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, oddColour);
185 Graphics_circle_mmcxx . . $ Graphics_circle_mm(8752bb7a78272ca7). (g, x, frequency, speckleSize * 1.4);
186 } else {
187 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, oddColour);
188 Graphics_fillCircle_mmcxx . . $ Graphics_fillCircle_mm(8752bb7a78272ca7). (g, x, frequency, speckleSize * 1.15);
189 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, evenColour);
190 Graphics_circle_mmcxx . . $ Graphics_circle_mm(8752bb7a78272ca7). (g, x, frequency, speckleSize * 1.15);
191 }
192 Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, original_lineWidth);
193 #endif
194 } else {
195 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, iformant % 2 == 1 ? oddColour : evenColour);
196 Graphics_specklecxx . . $ Graphics_speckle(c84ba9158791aef6). (g, x, frequency);
197 }
198 }
199 }
200 }
201 }
202
203 void Formant_drawSpeckles_insidecxx . . $ Formant_drawSpeckles_inside(6710bc27ed3d1c6f). (Formant me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmin, double fmax,
204 double suppress_dB)
205 {
206 Formant_drawSpeckles_insidecxx . . $ Formant_drawSpeckles_inside(36952de78a0af76c). (me, g, tmin, tmax, fmin, fmax, suppress_dB, Graphics_inqColourcxx . . $ Graphics_inqColour(322ea1b2fa08ba06). (g), Graphics_inqColourcxx . . $ Graphics_inqColour(322ea1b2fa08ba06). (g), false);
207 }
208
209 void Formant_drawSpecklescxx . . $ Formant_drawSpeckles(e07d2c1a1c131b2d). (Formant me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmax, double suppress_dB,
210 bool garnish)
211 {
212 Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g);
213 Formant_drawSpeckles_insidecxx . . $ Formant_drawSpeckles_inside(6710bc27ed3d1c6f). (me, g, tmin, tmax, 0.0, fmax, suppress_dB);
214 Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g);
215 if (garnish) {
216 Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g);
217 Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, U"Time (s)");
218 Graphics_textLeftcxx . . $ Graphics_textLeft(48cf1f690ec61203). (g, true, U"Formant frequency (Hz)");
219 Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false);
220 Graphics_marksLeftEverycxx . . $ Graphics_marksLeftEvery(d1b58b4f93ec67ea). (g, 1.0, 1000.0, true, true, true);
221 }
222 }
223
224 void Formant_formula_bandwidthscxx . . $ Formant_formula_bandwidths(314195a2e8ee2927). (Formant me, conststring32cxx . . $ conststring32# formula, Interpretercxx . . $ Interpreter# interpreter) {
225 try {
226 const integercxx . . $ integer# nrow = Formant_getMaxNumFormantscxx . . $ Formant_getMaxNumFormants(6a0b146f5923ed8d). (me);
227 if (nrow < 1)
228 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No formants available.");
229 autoMatrixcxx . . $ autoMatrix# mat = 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., 0.5, nrow + 0.5, nrow, 1.0, 1.0);
230 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
231 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
232 for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormants; iformant ++)
233 mat ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidth;
234 }
235 Matrix_formulacxx . . $ Matrix_formula(3b405620ba9cc26e). (mat.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), formula, interpreter, nullptr);
236 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
237 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
238 for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormants; iformant ++)
239 frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidth = mat ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe];
240 }
241 } catch (MelderErrorcxx . . $ MelderError#) {
242 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": bandwidth formula not executed.");
243 }
244 }
245
246 void Formant_formula_frequenciescxx . . $ Formant_formula_frequencies(314195a2e8ee2927). (Formant me, conststring32cxx . . $ conststring32# formula, Interpretercxx . . $ Interpreter# interpreter) {
247 try {
248 const integercxx . . $ integer# nrow = Formant_getMaxNumFormantscxx . . $ Formant_getMaxNumFormants(6a0b146f5923ed8d). (me);
249 if (nrow < 1)
250 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No formants available.");
251 autoMatrixcxx . . $ autoMatrix# mat = 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., 0.5, nrow + 0.5, nrow, 1.0, 1.0);
252 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
253 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
254 for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormants; iformant ++)
255 mat ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency;
256 }
257 Matrix_formulacxx . . $ Matrix_formula(3b405620ba9cc26e). (mat.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), formula, interpreter, nullptr);
258 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
259 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
260 for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormants; iformant ++)
261 frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency = mat ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe];
262 }
263 } catch (MelderErrorcxx . . $ MelderError#) {
264 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": frequency formula not executed.");
265 }
266 }
267
268 void Formant_getExtremacxx . . $ Formant_getExtrema(2fa30d9ec54c33d6). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, double *fmin, double *fmax) {
269 if (fmin)
270 *fmin = 0.0;
271 if (fmax)
272 *fmax = 0.0;
273 if (iformant < 1)
274 return;
275 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
276 integercxx . . $ integer# itmin, itmax;
277 if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax))
278 return;
279 for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) {
280 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
281 if (iformant > frame -> numberOfFormants)
282 continue;
283 const double f = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency;
284 if (f == 0.0)
285 continue;
286 if (fmin && (f < *fmin || *fmin == 0.0))
287 *fmin = f;
288 if (fmax && f > *fmax)
289 *fmax = f;
290 }
291 }
292
293 void Formant_getMinimumAndTimecxx . . $ Formant_getMinimumAndTime(ba445e06d2f3b291). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit, int interpolate,
294 double *return_minimum, double *return_timeOfMinimum)
295 {
296 Sampled_getMinimumAndXcxx . . $ Sampled_getMinimumAndX(12ff5d535a2c4655). (me, tmin, tmax, iformant << 1, (int) unit, interpolate, return_minimum, return_timeOfMinimum);
297 if (return_minimum && *return_minimum <= 0.0)
298 *return_minimum = undefinedcxx . . $ undefined.;
299 }
300
301 double Formant_getMinimumcxx . . $ Formant_getMinimum(cf5257ee3bd02a26). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit, int interpolate) {
302 double minimum;
303 Formant_getMinimumAndTimecxx . . $ Formant_getMinimumAndTime(ba445e06d2f3b291). (me, iformant, tmin, tmax, unit, interpolate, & minimum, nullptr);
304 return minimum;
305 }
306
307 double Formant_getTimeOfMinimumcxx . . $ Formant_getTimeOfMinimum(cf5257ee3bd02a26). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit, int interpolate) {
308 double time;
309 Formant_getMinimumAndTimecxx . . $ Formant_getMinimumAndTime(ba445e06d2f3b291). (me, iformant, tmin, tmax, unit, interpolate, nullptr, & time);
310 return time;
311 }
312
313 void Formant_getMaximumAndTimecxx . . $ Formant_getMaximumAndTime(ba445e06d2f3b291). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit, int interpolate,
314 double *return_maximum, double *return_timeOfMaximum)
315 {
316 Sampled_getMaximumAndXcxx . . $ Sampled_getMaximumAndX(12ff5d535a2c4655). (me, tmin, tmax, iformant << 1, (int) unit, interpolate, return_maximum, return_timeOfMaximum);
317 if (return_maximum && *return_maximum <= 0.0)
318 *return_maximum = undefinedcxx . . $ undefined.; // unlikely
319 }
320
321 double Formant_getMaximumcxx . . $ Formant_getMaximum(cf5257ee3bd02a26). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit, int interpolate) {
322 double maximum;
323 Formant_getMaximumAndTimecxx . . $ Formant_getMaximumAndTime(ba445e06d2f3b291). (me, iformant, tmin, tmax, unit, interpolate, & maximum, nullptr);
324 return maximum;
325 }
326
327 double Formant_getTimeOfMaximumcxx . . $ Formant_getTimeOfMaximum(cf5257ee3bd02a26). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit, int interpolate) {
328 double time;
329 Formant_getMaximumAndTimecxx . . $ Formant_getMaximumAndTime(ba445e06d2f3b291). (me, iformant, tmin, tmax, unit, interpolate, nullptr, & time);
330 return time;
331 }
332
333 double Formant_getQuantilecxx . . $ Formant_getQuantile(990efb58928d8047). (Formant me, integercxx . . $ integer# iformant, double quantile, double tmin, double tmax, kFormant_unit unit) {
334 return Sampled_getQuantilecxx . . $ Sampled_getQuantile(c0fbffff6f4b8bff). (me, tmin, tmax, quantile, iformant << 1, (int) unit);
335 }
336
337 double Formant_getMeancxx . . $ Formant_getMean(a5942552e86a8eee). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit) {
338 return Sampled_getMeancxx . . $ Sampled_getMean(2a8b0d40a92e6734). (me, tmin, tmax, iformant << 1, (int) unit, true);
339 }
340
341 double Formant_getStandardDeviationcxx . . $ Formant_getStandardDeviation(a5942552e86a8eee). (Formant me, integercxx . . $ integer# iformant, double tmin, double tmax, kFormant_unit unit) {
342 if (iformant < 1 || isundefcxx . . $ isundef(f8197d536af80c96). (tmin) || isundefcxx . . $ isundef(f8197d536af80c96). (tmax))
343 return undefinedcxx . . $ undefined.;
344 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
345 integercxx . . $ integer# itmin, itmax;
346 if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax))
347 return undefinedcxx . . $ undefined.;
348 const double mean = Formant_getMeancxx . . $ Formant_getMean(a5942552e86a8eee). (me, iformant, tmin, tmax, unit);
349 longdoublecxx . . $ longdouble# sum = 0.0;
350 integercxx . . $ integer# n = 0;
351 for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) {
352 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
353 if (iformant > frame -> numberOfFormants)
354 continue;
355 double f = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency;
356 if (f == 0.0)
357 continue;
358 if (unit == kFormant_unit::BARK)
359 f = NUMhertzToBarkcxx . . $ NUMhertzToBark(447c67c6676f75c3). (f);
360 n += 1;
361 sum += (f - mean) * (f - mean);
362 }
363 if (n > 1)
364 return sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (double (sum) / (n - 1));
365 return undefinedcxx . . $ undefined.;
366 }
367
368 double Formant_getValueAtTimecxx . . $ Formant_getValueAtTime(d698bca4b3ab6c2d). (Formant me, integercxx . . $ integer# iformant, double time, kFormant_unit unit) {
369 return Sampled_getValueAtXcxx . . $ Sampled_getValueAtX(a51129e8ab7e98e9). (me, time, iformant << 1, (int) unit, true);
370 }
371
372 double Formant_getBandwidthAtTimecxx . . $ Formant_getBandwidthAtTime(d698bca4b3ab6c2d). (Formant me, integercxx . . $ integer# iformant, double time, kFormant_unit unit) {
373 return Sampled_getValueAtXcxx . . $ Sampled_getValueAtX(a51129e8ab7e98e9). (me, time, (iformant << 1) + 1, (int) unit, true);
374 }
375
376 double Formant_getQuantileOfBandwidthcxx . . $ Formant_getQuantileOfBandwidth(990efb58928d8047). (Formant me, integercxx . . $ integer# iformant, double quantile, double tmin, double tmax, kFormant_unit unit) {
377 return Sampled_getQuantilecxx . . $ Sampled_getQuantile(c0fbffff6f4b8bff). (me, tmin, tmax, quantile, (iformant << 1) + 1, (int) unit);
378 }
379
380 void Formant_scatterPlotcxx . . $ Formant_scatterPlot(208224acb2000031). (Formant me, Graphicscxx . . $ Graphics# g, double tmin, double tmax,
381 integercxx . . $ integer# iformant1, double fmin1, double fmax1, integercxx . . $ integer# iformant2, double fmin2, double fmax2,
382 double size_mm, conststring32cxx . . $ conststring32# mark, bool garnish)
383 {
384 if (iformant1 < 1 || iformant2 < 1)
385 return;
386 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
387 integercxx . . $ integer# itmin, itmax;
388 if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax))
389 return;
390 if (fmax1 == fmin1)
391 Formant_getExtremacxx . . $ Formant_getExtrema(2fa30d9ec54c33d6). (me, iformant1, tmin, tmax, & fmin1, & fmax1);
392 if (fmax1 == fmin1)
393 return;
394 if (fmax2 == fmin2)
395 Formant_getExtremacxx . . $ Formant_getExtrema(2fa30d9ec54c33d6). (me, iformant2, tmin, tmax, & fmin2, & fmax2);
396 if (fmax2 == fmin2)
397 return;
398 Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g);
399 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, fmin1, fmax1, fmin2, fmax2);
400 for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) {
401 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
402 if (iformant1 > frame -> numberOfFormants || iformant2 > frame -> numberOfFormants)
403 continue;
404 const double x = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant1]. frequency;
405 const double y = frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant2]. frequency;
406 if (x == 0.0 || y == 0.0)
407 continue;
408 Graphics_markcxx . . $ Graphics_mark(406417efd31feba3). (g, x, y, size_mm, mark);
409 }
410 Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g);
411 if (garnish) {
412 Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g);
413 Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"%%F_", iformant1, U" (Hz)"));
414 Graphics_textLeftcxx . . $ Graphics_textLeft(48cf1f690ec61203). (g, true, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"%%F_", iformant2, U" (Hz)"));
415 Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false);
416 Graphics_marksLeftcxx . . $ Graphics_marksLeft(c3a11a8a55b243ff). (g, 2, true, true, false);
417 }
418 }
419
420 autoMatrixcxx . . $ autoMatrix# Formant_to_Matrixcxx . . $ Formant_to_Matrix(7624c35d99f8fce7). (Formant me, integercxx . . $ integer# iformant) {
421 try {
422 autoMatrixcxx . . $ autoMatrix# thee = 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, 1.0, 1, 1.0, 1.0);
423 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
424 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
425 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = ( iformant <= frame -> numberOfFormants ? frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequency : 0.0 );
426 }
427 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
428 } catch (MelderErrorcxx . . $ MelderError#) {
429 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": frequencies of formant ", iformant, U" not converted to Matrix.");
430 }
431 }
432
433 autoMatrixcxx . . $ autoMatrix# Formant_to_Matrix_bandwidthscxx . . $ Formant_to_Matrix_bandwidths(7624c35d99f8fce7). (Formant me, integercxx . . $ integer# iformant) {
434 try {
435 autoMatrixcxx . . $ autoMatrix# thee = 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, 1.0, 1, 1.0, 1.0);
436 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
437 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
438 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = ( iformant <= frame -> numberOfFormants ? frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidth : 0.0 );
439 }
440 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
441 } catch (MelderErrorcxx . . $ MelderError#) {
442 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": bandwidths of formant ", iformant, U" not converted to Matrix.");
443 }
444 }
445
446 /*** Viterbi methods. ***/
447
448 struct fparmcxx . . $ fparm# { Formant mecxx . . $ fparm#me., theecxx . . $ fparm#thee.; double dfCostcxx . . $ fparm#dfCost., bfCostcxx . . $ fparm#bfCost., octaveJumpCostcxx . . $ fparm#octaveJumpCost., refFcxx . . $ fparm#refF. [1 + 5]; };
449
450 static double getLocalCostcxx . . $ getLocalCost(557e8ff0ab70c1a1). (integercxx . . $ integer# iframe, integercxx . . $ integer# icand, integercxx . . $ integer# itrack, void *closure) {
451 struct fparmcxx . . $ fparm# *me = (struct fparmcxx . . $ fparm# *) closure;
452 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
453 if (icand > frame -> numberOfFormants)
454 return 1e30;
455 Formant_Formant candidate = & frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
456 /*if (candidate -> frequency <= 0.0) candidate -> frequency = 0.001;
457 Melder_crash (U"Weird formant frequency ", candidate -> frequency, U" Hz.")*/;
458 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidate -> bandwidth > 0.0);
459 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (itrack > 0 && itrack <= 5);
460 return mycxx . . $ `melder/melder.h:44:9`! dfCostcxx . . $ fparm#dfCost. * fabscxx . . $ fabs(fee4f1d22bc8e617). (candidate -> frequency - mycxx . . $ `melder/melder.h:44:9`! refFcxx . . $ fparm#refF. [itrack]) +
461 mycxx . . $ `melder/melder.h:44:9`! bfCostcxx . . $ fparm#bfCost. * candidate -> bandwidth / candidate -> frequency;
462 }
463 static double getTransitionCostcxx . . $ getTransitionCost(f743cd0a2b4d46e7). (integercxx . . $ integer# iframe, integercxx . . $ integer# icand1, integercxx . . $ integer# icand2, integercxx . . $ integer# /* itrack */, void *closure) {
464 struct fparmcxx . . $ fparm# *me = (struct fparmcxx . . $ fparm# *) closure;
465 const Formant_Frame prevFrame = & mycxx . . $ `melder/melder.h:44:9`! mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe - 1], curFrame = & mycxx . . $ `melder/melder.h:44:9`! mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
466 if (icand1 > prevFrame -> numberOfFormants || icand2 > curFrame -> numberOfFormants)
467 return 1e30;
468 const double f1 = prevFrame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand1]. frequency;
469 const double f2 = curFrame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand2]. frequency;
470 /*Melder_assert (f1 > 0.0);*/
471 /*Melder_assert (f2 > 0.0);*/
472 return mycxx . . $ `melder/melder.h:44:9`! octaveJumpCostcxx . . $ fparm#octaveJumpCost. * fabscxx . . $ fabs(fee4f1d22bc8e617). (NUMlog2cxx . . $ NUMlog2(fee4f1d22bc8e617). (f1 / f2));
473 }
474 static void putResultcxx . . $ putResult(5ee23ec9629fdc15). (integercxx . . $ integer# iframe, integercxx . . $ integer# place, integercxx . . $ integer# itrack, void *closure) {
475 struct fparmcxx . . $ fparm# *me = (struct fparmcxx . . $ fparm# *) closure;
476 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (iframe > 0 && iframe <= mycxx . . $ `melder/melder.h:44:9`! mycxx . . $ `melder/melder.h:44:9`! nx);
477 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (itrack > 0 && itrack <= 5);
478 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (place > 0);
479 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (place <= mycxx . . $ `melder/melder.h:44:9`! mycxx . . $ `melder/melder.h:44:9`! frames [iframe]. numberOfFormants);
480 mycxx . . $ `melder/melder.h:44:9`! thycxx . . $ `melder/melder.h:45:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack] = mycxx . . $ `melder/melder.h:44:9`! mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).place];
481 }
482
483 autoFormant Formant_trackercxx . . $ Formant_tracker(4e742720fb596b63). (Formant me, integercxx . . $ integer# ntrack,
484 double refF1, double refF2, double refF3, double refF4, double refF5,
485 double dfCost, /* Per kHz. */
486 double bfCost, double octaveJumpCost)
487 {
488 try {
489 integercxx . . $ integer# nformmin = Formant_getMinNumFormantscxx . . $ Formant_getMinNumFormants(6a0b146f5923ed8d). (me);
490 struct fparmcxx . . $ fparm# parm;
491 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (ntrack <= nformmin,
492 U"Number of tracks (", ntrack, U") should not exceed minimum number of formants (", nformmin, U").");
493 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., 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., ntrack);
494 for (integercxx . . $ integer# iframe = 1; iframe <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
495 thycxx . . $ `melder/melder.h:45:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. formant =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structFormant_Formant> (ntrack);
496 thycxx . . $ `melder/melder.h:45:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. numberOfFormants = ntrack; // maintain invariant
497 thycxx . . $ `melder/melder.h:45:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. intensity = mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]. intensity;
498 }
499 /* BUG: limit costs to 1e10 or so */
500 parm.mecxx . . $ fparm#me. = me;
501 parm.theecxx . . $ fparm#thee. = thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
502 parm.dfCostcxx . . $ fparm#dfCost. = dfCost / 1000.0; // per Hz
503 parm.bfCostcxx . . $ fparm#bfCost. = bfCost;
504 parm.octaveJumpCostcxx . . $ fparm#octaveJumpCost. = octaveJumpCost;
505 parm.refFcxx . . $ fparm#refF. [1] = refF1;
506 parm.refFcxx . . $ fparm#refF. [2] = refF2;
507 parm.refFcxx . . $ fparm#refF. [3] = refF3;
508 parm.refFcxx . . $ fparm#refF. [4] = refF4;
509 parm.refFcxx . . $ fparm#refF. [5] = refF5;
510 NUM_viterbi_multicxx . . $ NUM_viterbi_multi(23bde724377b0527). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! maxnFormants, ntrack,
511 getLocalCostcxx . . $ getLocalCost(557e8ff0ab70c1a1)., getTransitionCostcxx . . $ getTransitionCost(f743cd0a2b4d46e7)., putResultcxx . . $ putResult(5ee23ec9629fdc15)., & parm);
512 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
513 } catch (MelderErrorcxx . . $ MelderError#) {
514 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not tracked.");
515 }
516 }
517
518 autoTablecxx . . $ autoTable# Formant_downto_Tablecxx . . $ Formant_downto_Table(79b9edfa34f9b49e). (Formant me, bool includeFrameNumbers,
519 bool includeTimes, integercxx . . $ integer# timeDecimals,
520 bool includeIntensity, integercxx . . $ integer# intensityDecimals,
521 bool includeNumberOfFormants, integercxx . . $ integer# frequencyDecimals,
522 bool includeBandwidths)
523 {
524 try {
525 autoTablecxx . . $ autoTable# thee = Table_createWithoutColumnNamescxx . . $ Table_createWithoutColumnNames(9861d2482f105183). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., includeFrameNumbers + includeTimes + includeIntensity +
526 includeNumberOfFormants + mycxx . . $ `melder/melder.h:44:9`! maxnFormants * (1 + includeBandwidths));
527 integercxx . . $ integer# icol = 0;
528 if (includeFrameNumbers)
529 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"frame");
530 if (includeTimes)
531 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"time(s)");
532 if (includeIntensity)
533 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"intensity");
534 if (includeNumberOfFormants)
535 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"nformants");
536 for (integercxx . . $ integer# iformant = 1; iformant <= mycxx . . $ `melder/melder.h:44:9`! maxnFormants; iformant ++) {
537 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"F", iformant, U"(Hz)"));
538 if (includeBandwidths)
539 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"B", iformant, U"(Hz)"));
540 }
541 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
542 icol = 0;
543 if (includeFrameNumbers)
544 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, iframe);
545 if (includeTimes)
546 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (iframe - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., timeDecimals));
547 const Formant_Frame frame = & mycxx . . $ `melder/melder.h:44:9`! frames [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
548 if (includeIntensity)
549 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (frame -> intensity, intensityDecimals));
550 if (includeNumberOfFormants)
551 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, frame -> numberOfFormants);
552 for (integercxx . . $ integer# iformant = 1; iformant <= frame -> numberOfFormants; iformant ++) {
553 const Formant_Formant formant = & frame -> formant [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant];
554 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (formant -> frequency, frequencyDecimals));
555 if (includeBandwidths)
556 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (formant -> bandwidth, frequencyDecimals));
557 }
558 for (integercxx . . $ integer# iformant = frame -> numberOfFormants + 1; iformant <= mycxx . . $ `melder/melder.h:44:9`! maxnFormants; iformant ++) {
559 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, undefinedcxx . . $ undefined.);
560 if (includeBandwidths)
561 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe, ++ icol, undefinedcxx . . $ undefined.);
562 }
563 }
564 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
565 } catch (MelderErrorcxx . . $ MelderError#) {
566 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Table.");
567 }
568 }
569
570 void Formant_listcxx . . $ Formant_list(acc5c1edbce3e631). (
571 const Formant me,
572 const bool includeFrameNumbers,
573 const bool includeTimes,
574 const integercxx . . $ integer# timeDecimals,
575 const bool includeIntensity,
576 const integercxx . . $ integer# intensityDecimals,
577 const bool includeNumberOfFormants,
578 const integercxx . . $ integer# frequencyDecimals,
579 const bool includeBandwidths
580 ) {
581 try {
582 autoTablecxx . . $ autoTable# table = Formant_downto_Tablecxx . . $ Formant_downto_Table(79b9edfa34f9b49e). (me, includeFrameNumbers,
583 includeTimes, timeDecimals,
584 includeIntensity, intensityDecimals,
585 includeNumberOfFormants, frequencyDecimals, includeBandwidths
586 );
587 Table_listcxx . . $ Table_list(8e854cd23ee58a8f). (table.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), false);
588 } catch (MelderErrorcxx . . $ MelderError#) {
589 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not listed.");
590 }
591 }
592
593 /* End of file Formant.cpp */