Debian Codegraph @

LPC/FormantPath.cpp

raw symbols SCIP
1 /* FormantPath.cpp
2 *
3 * Copyright (C) 2020-2025 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 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 d 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 "FormantPath.h"cxx . . $ `<file>/LPC/FormantPath.h`/
20 #include "FormantModeler.h"cxx . . $ `<file>/LPC/FormantModeler.h`/
21 #include "Formant_extensions.h"cxx . . $ `<file>/LPC/Formant_extensions.h`/
22 #include "Graphics_extensions.h"cxx . . $ `<file>/dwsys/Graphics_extensions.h`/
23 #include "LPC_and_Formant.h"cxx . . $ `<file>/LPC/LPC_and_Formant.h`/
24 #include "Matrix.h"cxx . . $ `<file>/fon/Matrix.h`/
25 #include "Sound_to_Formant.h"cxx . . $ `<file>/fon/Sound_to_Formant.h`/
26 #include "Sound_and_LPC.h"cxx . . $ `<file>/LPC/Sound_and_LPC.h`/
27 //#include "Sound_and_LPC.h"
28 #include "Sound_extensions.h"cxx . . $ `<file>/dwtools/Sound_extensions.h`/
29 #include "TextGrid_extensions.h"cxx . . $ `<file>/dwtools/TextGrid_extensions.h`/
30
31 #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/
32 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
33 #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/
34 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
35 #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/
36 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
37 #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/
38 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
39 #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/
40 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
41 #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/
42 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
43 #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/
44 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
45 #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/
46 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
47 #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/
48 #include "FormantPath_def.h"cxx . . $ `<file>/LPC/FormantPath_def.h`/
49
50 void FormantPath_getCandidateAtTimecxx . . $ FormantPath_getCandidateAtTime(b935a6477ff02c9c). (FormantPath me, double time, double *out_tmin, double *out_tmax, integercxx . . $ integer# *out_candidate) {
51 IntervalTiercxx . . $ IntervalTier# intervalTier = static_cast <IntervalTiercxx . . $ IntervalTier#> (mycxx . . $ `melder/melder.h:44:9`! path ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). tierscxx . . $ structTextGrid#tiers. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
52 const integercxx . . $ integer# index = IntervalTier_timeToIndexcxx . . $ IntervalTier_timeToIndex(726d97a25667305). (intervalTier, time);
53 TextIntervalcxx . . $ TextInterval# textInterval = ( index > 0 ? intervalTier -> intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).index] : nullptr );
54 if (out_tmin)
55 *out_tmin = ( index > 0 ? textInterval -> xmincxx . . $ structFunction#xmin. : undefinedcxx . . $ undefined. );
56 if (out_tmax)
57 *out_tmax = ( index > 0 ? textInterval -> xmaxcxx . . $ structFunction#xmax. : undefinedcxx . . $ undefined. );
58 if (out_candidate)
59 *out_candidate = ( index > 0 ? (textInterval -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() ? Melder_atoicxx . . $ Melder_atoi(c94c67ff4219bf83). (textInterval -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : 0) : 0 );
60 }
61
62 integercxx . . $ integer# FormantPath_getCandidateInFramecxx . . $ FormantPath_getCandidateInFrame(927d2653fab2afa4). (FormantPath me, integercxx . . $ integer# iframe) {
63 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (iframe > 0 && iframe <= mycxx . . $ `melder/melder.h:44:9`! nx);
64 const double time = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe);
65 integercxx . . $ integer# candidate;
66 FormantPath_getCandidateAtTimecxx . . $ FormantPath_getCandidateAtTime(b935a6477ff02c9c). (me, time, nullptr, nullptr, & candidate);
67 return candidate;
68 }
69
70 integercxx . . $ integer# FormantPath_getUniqueCandidateInIntervalcxx . . $ FormantPath_getUniqueCandidateInInterval(786bab8c8334d64b). (FormantPath me, double tmin, double tmax) {
71 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tmin <= tmax);
72 IntervalTiercxx . . $ IntervalTier# intervalTier = static_cast <IntervalTiercxx . . $ IntervalTier#> (mycxx . . $ `melder/melder.h:44:9`! path ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). tierscxx . . $ structTextGrid#tiers. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
73 const integercxx . . $ integer# index = IntervalTier_timeToLowIndexcxx . . $ IntervalTier_timeToLowIndex(726d97a25667305). (intervalTier, tmin);
74 integercxx . . $ integer# candidate = 0;
75 if (index > 0) {
76 TextIntervalcxx . . $ TextInterval# textInterval = intervalTier -> intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).index];
77 if (tmin >= textInterval -> xmincxx . . $ structFunction#xmin. && tmax <= textInterval -> xmaxcxx . . $ structFunction#xmax.)
78 candidate = (textInterval -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() ? Melder_atoicxx . . $ Melder_atoi(c94c67ff4219bf83). (textInterval -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : 0);
79 }
80 return candidate;
81 }
82
83 void structFormantPath :: v1_info () {
84 structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). ();
85 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of Formant candidates: ", formantCandidates.sizecxx . . $ CollectionOf#size.);
86 for (integercxx . . $ integer# ic = 1; ic <= ceilings.sizecxx . . $ autovector#size.; ic ++)
87 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Ceiling ", ic, U": ", ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ic], U" Hz");
88 }
89
90 double structFormantPath :: v_getValueAtSample (integercxx . . $ integer# iframe, integercxx . . $ integer# which, int units) const {
91 const double time = x1cxx . . $ structSampled#x1. + (iframe - 1) * dxcxx . . $ structSampled#dx.;
92 IntervalTiercxx . . $ IntervalTier# intervalTier = static_cast <IntervalTiercxx . . $ IntervalTier#> (path ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). tierscxx . . $ structTextGrid#tiers. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
93 const integercxx . . $ integer# index = IntervalTier_timeToIndexcxx . . $ IntervalTier_timeToIndex(726d97a25667305). (intervalTier, time);
94 const Formantcxx . . $ Formant# formant = static_cast <Formantcxx . . $ Formant#> (ourcxx . . $ `melder/melder.h:42:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).index]);
95 return formant -> v_getValueAtSamplecxx . . $ structFormant#v_getValueAtSample(8bbfc6ce471470c9). (iframe, which, units);
96 }
97
98 conststring32cxx . . $ conststring32# structFormantPath :: v_getUnitText (integercxx . . $ integer# /*level*/, int /*unit*/, uint32cxx . . $ uint32# /*flags*/) const {
99 return U"Frequency (Hz)";
100 };
101
102 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (FormantPath, Sampled, 1); // version 0: INTVEC path; version 1: TextGrid path
103
104
105 static MelderIntegerRangecxx . . $ MelderIntegerRange# FormantPath_getPathTierIndicesRangecxx . . $ FormantPath_getPathTierIndicesRange(92beeefb819af1e2). (FormantPath me, double tmin, double tmax) {
106 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tmin < tmax);
107 MelderIntegerRangecxx . . $ MelderIntegerRange# range = {1, 1};
108 IntervalTiercxx . . $ IntervalTier# intervalTier = static_cast <IntervalTiercxx . . $ IntervalTier#> (mycxx . . $ `melder/melder.h:44:9`! path ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). tierscxx . . $ structTextGrid#tiers. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
109 range.firstcxx . . $ MelderIntegerRange#first. = IntervalTier_timeToLowIndexcxx . . $ IntervalTier_timeToLowIndex(726d97a25667305). (intervalTier, tmin);
110 range.lastcxx . . $ MelderIntegerRange#last. = IntervalTier_timeToHighIndexcxx . . $ IntervalTier_timeToHighIndex(726d97a25667305). (intervalTier, tmax);
111 return range;
112 }
113
114 autoTextGridcxx . . $ autoTextGrid# FormantPath_to_TextGrid_version0cxx . . $ FormantPath_to_TextGrid_version0(4c602d361d111fd9). (FormantPath me, INTVECcxx . . $ INTVEC# const& path) {
115 autoTextGridcxx . . $ autoTextGrid# thee = TextGrid_createcxx . . $ TextGrid_create(2af4734b8a73c5bc). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., U"path", U"");
116 IntervalTiercxx . . $ IntervalTier# tier = static_cast <IntervalTiercxx . . $ IntervalTier#> (thycxx . . $ `melder/melder.h:45:9`! tierscxx . . $ structTextGrid#tiers. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
117 integercxx . . $ integer# previousPathIndex = path [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1];
118 TextInterval_setTextcxx . . $ TextInterval_setText(bda04a1b3ff14567). (tier ->intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1], Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (previousPathIndex));
119 TextGrid_setIntervalTextcxx . . $ TextGrid_setIntervalText(a77659792e2c2fae). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 1, Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (previousPathIndex));
120 for (integercxx . . $ integer# ip = 2; ip <= path.sizecxx . . $ vector#size.; ip ++) {
121 if (path [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ip] != previousPathIndex) {
122 const double t = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ip) - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
123 const integercxx . . $ integer# currentIndex = IntervalTier_timeToLowIndexcxx . . $ IntervalTier_timeToLowIndex(726d97a25667305). (tier, t);
124 TextIntervalcxx . . $ TextInterval# currentInterval = tier -> intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).currentIndex];
125 autoTextIntervalcxx . . $ autoTextInterval# newInterval = TextInterval_createcxx . . $ TextInterval_create(69da32435edc95c8). (t, mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (path [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ip]));
126 currentInterval -> xmaxcxx . . $ structFunction#xmax. = t;
127 tier -> intervalscxx . . $ structIntervalTier#intervals.. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (newIntervalcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
128 previousPathIndex = path [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ip];
129 }
130 }
131 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
132 }
133
134 autoFormantPath FormantPath_createcxx . . $ FormantPath_create(16da078af6b04e95). (double xmin, double xmax, integercxx . . $ integer# nx, double dx, double x1, integercxx . . $ integer# numberOfCandidates) {
135 autoFormantPath me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (FormantPath);
136 Sampled_initcxx . . $ Sampled_init(5b6f70c633f31208). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab). (), xmin, xmax, nx, dx, x1);
137 mycxx . . $ `melder/melder.h:44:9`! ceilings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (numberOfCandidates);
138 mycxx . . $ `melder/melder.h:44:9`! path =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). TextGrid_createcxx . . $ TextGrid_create(2af4734b8a73c5bc). (xmin, xmax, U"path", U"");
139 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
140 }
141
142 void FormantPath_pathFindercxx . . $ FormantPath_pathFinder(c152c93180464ef5). (FormantPath me, double qWeight, double frequencyChangeWeight, double stressWeight, double ceilingChangeWeight,
143 double intensityModulationStepSize, double windowLength, constINTVECcxx . . $ constINTVEC# const& parameters, double powerf)
144 {
145 autoINTVECcxx . . $ autoINTVEC# path = FormantPath_getOptimumPathcxx . . $ FormantPath_getOptimumPath(8accdf14aef78ca5). (me, qWeight, frequencyChangeWeight, stressWeight, ceilingChangeWeight, intensityModulationStepSize, windowLength, parameters, powerf, nullptr);
146 mycxx . . $ `melder/melder.h:44:9`! path =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). FormantPath_to_TextGrid_version0cxx . . $ FormantPath_to_TextGrid_version0(4c602d361d111fd9). (me, path.getcxx . . $ autovector#get(e8d1da7fe68a6585).());
147 }
148
149 autoINTVECcxx . . $ autoINTVEC# FormantPath_getOptimumPathcxx . . $ FormantPath_getOptimumPath(8accdf14aef78ca5). (FormantPath me, double qWeight, double frequencyChangeWeight, double stressWeight, double ceilingChangeWeight, double intensityModulationStepSize, double windowLength, constINTVECcxx . . $ constINTVEC# const& parameters, double powerf, autoMatrixcxx . . $ autoMatrix# *out_delta) {
150 constexpr double qCutoff = 20.0;
151 constexpr double stressCutoff = 100.0;
152 try {
153 const integercxx . . $ integer# transtionCostType = ( Melder_debugcxx . . $ Melder_debug. == -3 ? 2 : 1 );
154 const integercxx . . $ integer# numberOfCandidates = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.;
155 const double transitionCostCuttoff = ( Melder_debugcxx . . $ Melder_debug. == -3 ? 0.3 : 100.0 );
156 autoMatrixcxx . . $ autoMatrix# stressescxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8)., qsumscxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
157 MelderExtremaWithInitcxx . . $ MelderExtremaWithInit# intensities;
158 const integercxx . . $ integer# midformant = (numberOfCandidates + 1) / 2;
159 if (intensityModulationStepSize > 0.0) {
160 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
161 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).midformant] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
162 intensities.updatecxx . . $ MelderExtremaWithInit#update(ba8836b59fb42830). (frame -> intensitycxx . . $ structFormant_Frame#intensity.);
163 }
164 }
165 const bool hasIntensityDifference = ( intensities.maxcxx . . $ MelderExtremaWithInit#max. - intensities.mincxx . . $ MelderExtremaWithInit#min. > 0.0 );
166 const double dbMid = 0.5 * 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (intensities.maxcxx . . $ MelderExtremaWithInit#max. * intensities.mincxx . . $ MelderExtremaWithInit#min.);
167 const integercxx . . $ integer# maxnFormants = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1] -> maxnFormantscxx . . $ structFormant#maxnFormants.;
168 const integercxx . . $ integer# numberOfTracks = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (maxnFormants, parameters.sizecxx . . $ constvector#size.);
169 if (qWeight > 0.0)
170 qsums =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). FormantPath_to_Matrix_qSumscxx . . $ FormantPath_to_Matrix_qSums(f5559ea80f11849e). (me, numberOfTracks);
171 if (stressWeight > 0.0)
172 stresses =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). FormantPath_to_Matrix_stresscxx . . $ FormantPath_to_Matrix_stress(a34c70565600288e). (me, windowLength, parameters, powerf);
173
174 autoINTMATcxx . . $ autoINTMAT# psi = zero_INTMATcxx . . $ zero_INTMAT(4cdd710bd00a100c). (numberOfCandidates, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.);
175 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., 0.5, numberOfCandidates + 0.5, numberOfCandidates, 1.0, 1.0);
176 /*
177 delta [i] [j] = minimum cost to reach state i at time j
178 */
179 MATcxx . . $ MAT# deltacxx . . $ matrix#matrix(de4adc318dfd88e7). (& thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1], thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny., thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.);
180 autoINTVECcxx . . $ autoINTVEC# path = zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.);
181 autoVECcxx . . $ autoVEC# intensity = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.);
182 /*
183 We have a trellis of size S x T, where S is the number of states, i.e. the number of formant objects,
184 and T the number of frames (S= formantCandidates.size and T=nx).
185 Evaluate the static costs for state s [i] at times t=1..T
186 There are two components at each t:
187 1. (+) the local stress at s [i] [t], which is evaluated from an interval around time t
188 2. (-) the local qsums at s [i] [t], evaluated from the frequencies/bandwidths in s [i] [t]
189 The sum of these components might be modulated by the local intensity
190 */
191 for (integercxx . . $ integer# itime = 1; itime <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; itime ++) {
192 for (integercxx . . $ integer# iformant = 1; iformant <= numberOfCandidates; iformant ++) {
193 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime];
194 double wIntensity = 1.0, costs = 0.0;
195 if (hasIntensityDifference && intensityModulationStepSize > 0.0) {
196 if (frame -> intensitycxx . . $ structFormant_Frame#intensity. > 0.0) {
197 const double dbi = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (frame -> intensitycxx . . $ structFormant_Frame#intensity. / 2e-5);
198 wIntensity = NUMsigmoidcxx . . $ NUMsigmoid(447c67c6676f75c3). ((dbi - dbMid) / intensityModulationStepSize);
199 } else
200 wIntensity = 0.0;
201 }
202 if (stressWeight > 0.0 && isdefinedcxx . . $ isdefined(f8197d536af80c96). (stresses ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime]))
203 costs += stressWeight * stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (stresses ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] / stressCutoff, 1.0);
204 if (qWeight > 0.0)
205 costs -= qWeight * stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (qsums ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] / qCutoff, 1.0);
206 delta [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] += wIntensity * costs;
207 }
208 }
209 /*
210 Evaluate the costs delta [j] [t] going from s [i] [t-1] to s [j] [t]
211 delta [j] [t] = min_over_i { delta [i] [t-1] + transition_costs (s [i] [t-1], s [j] [t] },
212 where the transition_costs consists of two parts:
213 3. (+) costs involving the sum of the distances between the formant frequencies in state s [i] [t-1] and s [j] [t]
214 4. (+) costs involving the difference in ceiling [i] [t-1] and ceiling [j] [t]
215 (or should we measure the costs w.r.t the middle frequency?)
216 */
217 const double ceilingsRange = mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfCandidates] - mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1];
218 for (integercxx . . $ integer# itime = 2; itime <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; itime ++) {
219 for (integercxx . . $ integer# iformant = 1; iformant <= numberOfCandidates; iformant++) {
220 const Formant_Framecxx . . $ Formant_Frame# ffi = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iformant] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime];
221 const integercxx . . $ integer# numberOfTracks_i = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (numberOfTracks, ffi -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.);
222 double deltamin = 1e100;
223 integercxx . . $ integer# minPos = 0;
224 for (integercxx . . $ integer# jformant = 1; jformant <= numberOfCandidates; jformant++) {
225 const Formant_Framecxx . . $ Formant_Frame# ffj = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).jformant] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime - 1];
226 const integercxx . . $ integer# ntracks = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (ffj -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants., numberOfTracks_i);
227 double transitionCosts = delta [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).jformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime - 1];
228 if (frequencyChangeWeight > 0.0) {
229 double fcost = 0.0;
230 for (integercxx . . $ integer# itrack = 1; itrack <= ntracks; itrack ++) {
231 const double fi = ffi -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequencycxx . . $ structFormant_Formant#frequency., fj = ffj -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequencycxx . . $ structFormant_Formant#frequency.;
232 if (transtionCostType == 1) {
233 const double dif = fabscxx . . $ fabs(fee4f1d22bc8e617). (fi - fj);
234 const double sum = fi + fj;
235 const double bw = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (ffi -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. bandwidthcxx . . $ structFormant_Formant#bandwidth. * ffj -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. bandwidthcxx . . $ structFormant_Formant#bandwidth.);
236 fcost += bw * dif / sum;
237 } else
238 fcost += fabscxx . . $ fabs(fee4f1d22bc8e617). (NUMlog2cxx . . $ NUMlog2(fee4f1d22bc8e617). (fi / fj));
239 }
240 fcost /= ntracks;
241 transitionCosts += frequencyChangeWeight * stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (fcost / transitionCostCuttoff, 1.0);
242 }
243 if (ceilingChangeWeight > 0.0) {
244 const double ceilingChangeCosts = fabscxx . . $ fabs(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant] - mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jformant]) / ceilingsRange;
245 transitionCosts += ceilingChangeWeight * ceilingChangeCosts;
246 }
247 if (transitionCosts < deltamin) {
248 deltamin = transitionCosts;
249 minPos = jformant;
250 }
251 }
252 if (stressWeight > 0.0 && isdefinedcxx . . $ isdefined(f8197d536af80c96). (stresses ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime]))
253 deltamin += stressWeight * stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (stresses ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] / stressCutoff, 1.0);
254 if (qWeight > 0.0)
255 deltamin -= qWeight * stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (qsums ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] / qCutoff, 1.0);
256 delta [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] += deltamin;
257 psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iformant] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] = minPos;
258 }
259 }
260 path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.] = NUMmaxPoscxx . . $ NUMmaxPos(99bbb1d062110345). (deltacxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..columncxx . . $ matrix#column(a8b9553e85c2b1fc). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.));
261 /*
262 Backtrack
263 */
264 for (integercxx . . $ integer# itime = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; itime > 1; itime --)
265 path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime - 1] = psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime]] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime];
266 if (out_delta)
267 *out_delta =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). thee.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
268 return pathcxx . . $ autovector#autovector(d33c649a3aceae2f).;
269 } catch (MelderErrorcxx . . $ MelderError#) {
270 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot find path.");
271 }
272 }
273
274 autoFormantcxx . . $ autoFormant# FormantPath_extractFormantcxx . . $ FormantPath_extractFormant(c1105e94bde1773c). (FormantPath me) {
275 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! formantCandidates.size > 0);
276 Formantcxx . . $ Formant# formant = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1];
277 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., 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., formant -> maxnFormantscxx . . $ structFormant#maxnFormants.);
278 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
279 const integercxx . . $ integer# candidate = FormantPath_getCandidateInFramecxx . . $ FormantPath_getCandidateInFrame(927d2653fab2afa4). (me, iframe);
280 Formantcxx . . $ Formant# source = static_cast <Formantcxx . . $ Formant#> (mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).candidate]);
281 Formant_Framecxx . . $ Formant_Frame# targetFrame = & thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
282 Formant_Framecxx . . $ Formant_Frame# sourceFrame = & source -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
283 sourceFrame -> copycxx . . $ structFormant_Frame#copy(92dd45543ac3dd98). (targetFrame);
284 }
285 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
286 }
287
288 static autoVECcxx . . $ autoVEC# getCeilingscxx . . $ getCeilings(628d1e52f0365a5a). (double middleCeiling, double stepSize, integercxx . . $ integer# numberOfStepsUpDown) {
289 const integercxx . . $ integer# numberOfCeilings = 2 * numberOfStepsUpDown + 1, mid = numberOfStepsUpDown + 1;
290 autoVECcxx . . $ autoVEC# ceilings = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfCeilings);
291 for (integercxx . . $ integer# istep = 1; istep <= numberOfStepsUpDown; istep ++) {
292 ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mid + istep] = middleCeiling * expcxx . . $ exp(fee4f1d22bc8e617). ( stepSize * istep);
293 ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mid - istep] = middleCeiling * expcxx . . $ exp(fee4f1d22bc8e617). (- stepSize * istep);
294 }
295 ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mid] = middleCeiling;
296 return ceilingscxx . . $ autovector#autovector(d33c649a3aceae2f).;
297 }
298
299 autoFormantPath Sound_to_FormantPath_anycxx . . $ Sound_to_FormantPath_any(da04c3ed23676d81). (Soundcxx . . $ Sound# me, kLPC_Analysiscxx . . $ kLPC_Analysis# lpcType, double timeStep, double maximumNumberOfFormants,
300 double middleCeiling, double analysisWidth, double preemphasisFrequency, double ceilingStepSize,
301 integercxx . . $ integer# numberOfStepsUpDown, double marple_tol1, double marple_tol2, double huber_numberOfStdDev, double huber_tol,
302 integercxx . . $ integer# huber_maximumNumberOfIterations, autoSoundcxx . . $ autoSound# *out_sourcesMultiChannel)
303 {
304 try {
305 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (timeStep > 0.0,
306 U"The timeStep needs to be larger than zero seconds.");
307 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (ceilingStepSize > 0.0,
308 U"The ceiling step size should be larger than 0.0.");
309 autoVECcxx . . $ autoVEC# ceilings = getCeilingscxx . . $ getCeilings(628d1e52f0365a5a). (middleCeiling, ceilingStepSize, numberOfStepsUpDown);
310 const integercxx . . $ integer# numberOfCandidates = ceilings.sizecxx . . $ autovector#size.;
311 const double maximumCeiling = ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfCandidates];
312 const double nyquistFrequency = 0.5 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
313 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (maximumCeiling <= nyquistFrequency,
314 U"The calculated maximum ceiling is higher than the Nyquist frequency of the sound (", nyquistFrequency, U" Hz). "
315 "Decrease the 'ceiling step size' or the 'number of steps' or both.");
316 volatile const double physicalAnalysisWidth = Melder_clippedRightcxx . . $ Melder_clippedRight(f80f7d6260b3ee3a). (2.0 * analysisWidth, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.);
317 /*
318 If the resampled sound with the lowest sampling frequency passes the minimal duration tests then all will.
319 */
320 const double samplingFrequencyLowest = 2.0 * ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], dxLowest = 1.0 / samplingFrequencyLowest;
321 const integercxx . . $ integer# nxLowest = Melder_iroundDowncxx . . $ Melder_iroundDown(a6e4a4c8b00c35a3). (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. / dxLowest);
322 const integercxx . . $ integer# predictionOrder = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (2.0 * maximumNumberOfFormants);
323
324 checkLPCAnalysisParameters_ecxx . . $ checkLPCAnalysisParameters_e(f2b963dca309bb3b). (dxLowest, nxLowest, physicalAnalysisWidth, predictionOrder);
325
326 /*
327 Get the data for the LPC from the resampled sound with 'middleCeiling' as maximum frequency
328 to make the sampling exactly equal as if performed with a standard LPC analysis.
329 */
330 integercxx . . $ integer# numberOfFrames;
331 double t1;
332 autoSoundcxx . . $ autoSound# midCeiling = Sound_resampleAndOrPreemphasizecxx . . $ Sound_resampleAndOrPreemphasize(50b0edb6f91cc1e7). (me, middleCeiling, 50, preemphasisFrequency);
333 Sampled_shortTermAnalysiscxx . . $ Sampled_shortTermAnalysis(77f703705034c8a). (midCeiling.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), physicalAnalysisWidth, timeStep, & numberOfFrames, & t1); // Gaussian window
334 autoFormantPath thee = FormantPath_createcxx . . $ FormantPath_create(16da078af6b04e95). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfFrames, timeStep, t1, numberOfCandidates);
335 autoSoundcxx . . $ autoSound# multiChannelSoundcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
336 if (out_sourcesMultiChannel)
337 multiChannelSound =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfCandidates, midCeiling ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xmincxx . . $ structFunction#xmin., midCeiling ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xmaxcxx . . $ structFunction#xmax., midCeiling ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx., midCeiling ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). dxcxx . . $ structSampled#dx., midCeiling ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). x1cxx . . $ structSampled#x1.);
338 const double formantSafetyMargin = 50.0;
339 thycxx . . $ `melder/melder.h:45:9`! ceilings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). ceilings.movecxx . . $ autovector#move(57d90d7d77dfc011).();
340 for (integercxx . . $ integer# candidate = 1; candidate <= numberOfCandidates; candidate ++) {
341 autoFormantcxx . . $ autoFormant# formantcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
342 autoSoundcxx . . $ autoSound# resampledAndPreemphasizedcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
343 if (candidate != numberOfStepsUpDown + 1)
344 resampledAndPreemphasized =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Sound_resampleAndOrPreemphasizecxx . . $ Sound_resampleAndOrPreemphasize(50b0edb6f91cc1e7). (me, thycxx . . $ `melder/melder.h:45:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).candidate], 50, preemphasisFrequency);
345 else
346 resampledAndPreemphasized =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). midCeiling.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
347 autoLPCcxx . . $ autoLPC# lpc = LPC_createCompletelyInitializedcxx . . $ LPC_createCompletelyInitialized(dee197ba90f07c69). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfFrames, timeStep, t1, predictionOrder,
348 resampledAndPreemphasized ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). dxcxx . . $ structSampled#dx.);
349 if (lpcType == kLPC_Analysiscxx . . $ kLPC_Analysis#::BURGcxx . . $ kLPC_Analysis#BURG.) {
350 Sound_into_LPC_burgcxx . . $ Sound_into_LPC_burg(5892df8d1f4abf78). (resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth);
351 } else if (lpcType == kLPC_Analysiscxx . . $ kLPC_Analysis#::AUTOCORRELATIONcxx . . $ kLPC_Analysis#AUTOCORRELATION.) {
352 Sound_into_LPC_autocxx . . $ Sound_into_LPC_auto(5892df8d1f4abf78). (resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth);
353 } else if (lpcType == kLPC_Analysiscxx . . $ kLPC_Analysis#::COVARIANCEcxx . . $ kLPC_Analysis#COVARIANCE.) {
354 Sound_into_LPC_covarcxx . . $ Sound_into_LPC_covar(5892df8d1f4abf78). (resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth);
355 } else if (lpcType == kLPC_Analysiscxx . . $ kLPC_Analysis#::MARPLEcxx . . $ kLPC_Analysis#MARPLE.) {
356 Sound_into_LPC_marplecxx . . $ Sound_into_LPC_marple(ca81e047e6329e35). (resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth, marple_tol1, marple_tol2);
357 } else if (lpcType == kLPC_Analysiscxx . . $ kLPC_Analysis#::ROBUSTcxx . . $ kLPC_Analysis#ROBUST.) {
358 Sound_into_LPC_autocxx . . $ Sound_into_LPC_auto(5892df8d1f4abf78). (resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth);
359 lpc =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). LPC_and_Sound_to_LPC_robustcxx . . $ LPC_and_Sound_to_LPC_robust(54d8670bb958c0e1). (lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth, preemphasisFrequency,
360 huber_numberOfStdDev, huber_maximumNumberOfIterations, huber_tol, true);
361 }
362 formant =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). LPC_to_Formantcxx . . $ LPC_to_Formant(6c989ebfc69f4efc). (lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), formantSafetyMargin);
363 thycxx . . $ `melder/melder.h:45:9`! formantCandidates. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (formantcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
364 if (out_sourcesMultiChannel) {
365 // TODO 20240625 is this still correct because we have already pre-emphasized the sound??
366 autoSoundcxx . . $ autoSound# source = LPC_Sound_filterInversecxx . . $ LPC_Sound_filterInverse(f4bce7e21db85b5). (lpc.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), resampledAndPreemphasized.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab). ());
367 autoSoundcxx . . $ autoSound# source_resampled = Sound_resamplecxx . . $ Sound_resample(872961da5f5e69e5). (source.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 2.0 * middleCeiling, 50);
368 const integercxx . . $ integer# numberOfSamples = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (midCeiling ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx., source_resampled ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx.);
369 multiChannelSoundcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd). ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (candidate).partcxx . . $ vector#part(ae267db9e2c04be7). (1, numberOfSamples) <<=cxx . . $ `operator<<=`(adea042513329390). source_resampledcxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd). ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, numberOfSamples);
370 }
371 }
372 /*
373 Maintain invariants
374 */
375 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (thycxx . . $ `melder/melder.h:45:9`! formantCandidates.size == numberOfCandidates);
376 TextGrid_setIntervalTextcxx . . $ TextGrid_setIntervalText(a77659792e2c2fae). (thycxx . . $ `melder/melder.h:45:9`! path.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 1, Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (numberOfStepsUpDown + 1));
377 if (out_sourcesMultiChannel)
378 *out_sourcesMultiChannel =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). multiChannelSound.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
379 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
380 } catch (MelderErrorcxx . . $ MelderError#) {
381 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": FormantPath not created.");
382 }
383 }
384
385 integercxx . . $ integer# FormantPath_getNumberOfFormantTrackscxx . . $ FormantPath_getNumberOfFormantTracks(57eee78a3ac77977). (FormantPath me) {
386 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! formantCandidates.size > 0);
387 return mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1] -> maxnFormantscxx . . $ structFormant#maxnFormants.;
388 }
389
390 autoMatrixcxx . . $ autoMatrix# FormantPath_to_Matrix_qSumscxx . . $ FormantPath_to_Matrix_qSums(f5559ea80f11849e). (FormantPath me, integercxx . . $ integer# numberOfTracks) {
391 try {
392 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (numberOfTracks >= 0);
393 const integercxx . . $ integer# numberOfCandidates = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.;
394 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., 0.5, numberOfCandidates + 0.5, numberOfCandidates, 1.0, 1.0);
395 const integercxx . . $ integer# maxnFormants = FormantPath_getNumberOfFormantTrackscxx . . $ FormantPath_getNumberOfFormantTracks(57eee78a3ac77977). (me);
396 if (numberOfTracks == 0)
397 numberOfTracks = maxnFormants;
398 for (integercxx . . $ integer# itime = 1; itime <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; itime ++) {
399 for (integercxx . . $ integer# candidate = 1; candidate <= numberOfCandidates; candidate ++) {
400 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).candidate] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime];
401 const integercxx . . $ integer# currentNumberOfFormants = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (numberOfTracks, frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.);
402 longdoublecxx . . $ longdouble# qsum = 0.0;
403 for (integercxx . . $ integer# itrack = 1; itrack <= currentNumberOfFormants; itrack ++)
404 qsum += frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequencycxx . . $ structFormant_Formant#frequency. / frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. bandwidthcxx . . $ structFormant_Formant#bandwidth.;
405 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).candidate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] = ( currentNumberOfFormants > 0 ? (double) (qsum / currentNumberOfFormants) : 0.0 );
406 }
407 }
408 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
409 } catch (MelderErrorcxx . . $ MelderError#) {
410 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot calculate qsums.");
411 }
412 }
413
414 autoMatrixcxx . . $ autoMatrix# FormantPath_to_Matrix_transitioncxx . . $ FormantPath_to_Matrix_transition(a57b8db26dabb0bc). (FormantPath me, integercxx . . $ integer# numberOfTracks, bool maximumCosts) {
415 try {
416 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (numberOfTracks >= 0);
417 const integercxx . . $ integer# numberOfCandidates = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.;
418 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., 0.5, numberOfCandidates + 0.5, numberOfCandidates, 1.0, 1.0);
419 const integercxx . . $ integer# maxnFormants = FormantPath_getNumberOfFormantTrackscxx . . $ FormantPath_getNumberOfFormantTracks(57eee78a3ac77977). (me);
420 if (numberOfTracks == 0)
421 numberOfTracks = maxnFormants;
422 for (integercxx . . $ integer# itime = 2; itime <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; itime ++) {
423 for (integercxx . . $ integer# candidate = 1; candidate <= numberOfCandidates; candidate ++) {
424 const Formant_Framecxx . . $ Formant_Frame# ffi = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).candidate] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime];
425 const integercxx . . $ integer# numberOfTracks_i = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (numberOfTracks, ffi -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants.);
426 MelderExtremaWithInitcxx . . $ MelderExtremaWithInit# costs;
427 for (integercxx . . $ integer# jformant = 1; jformant <= mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.; jformant++) {
428 const Formant_Framecxx . . $ Formant_Frame# ffj = & mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).jformant] -> framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itime - 1];
429 const integercxx . . $ integer# ntracks = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (ffj -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants., numberOfTracks_i);
430 longdoublecxx . . $ longdouble# transitionCosts = 0.0;
431 for (integercxx . . $ integer# itrack = 1; itrack <= ntracks; itrack ++) {
432 const double fi = ffi -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequencycxx . . $ structFormant_Formant#frequency., fj = ffj -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. frequencycxx . . $ structFormant_Formant#frequency.;
433 const double dif = fabscxx . . $ fabs(fee4f1d22bc8e617). (fi - fj);
434 const double sum = fi + fj;
435 const double bw = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (ffi -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. bandwidthcxx . . $ structFormant_Formant#bandwidth. * ffj -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itrack]. bandwidthcxx . . $ structFormant_Formant#bandwidth.);
436 double cost = bw * dif / sum;
437 if (Melder_debugcxx . . $ Melder_debug. == -3)
438 cost = fabscxx . . $ fabs(fee4f1d22bc8e617). (NUMlog2cxx . . $ NUMlog2(fee4f1d22bc8e617). (fi / fj));
439 transitionCosts += cost;
440 }
441 transitionCosts /= ntracks;
442 costs.updatecxx . . $ MelderExtremaWithInit#update(ba8836b59fb42830). ((double) transitionCosts);
443 }
444 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).candidate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime] = ( maximumCosts ? costs.maxcxx . . $ MelderExtremaWithInit#max. : costs.mincxx . . $ MelderExtremaWithInit#min. );
445 }
446 }
447 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
448 } catch (MelderErrorcxx . . $ MelderError#) {
449 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot calculate transition costs.");
450 }
451 }
452
453 autoMatrixcxx . . $ autoMatrix# FormantPath_to_Matrix_stresscxx . . $ FormantPath_to_Matrix_stress(a34c70565600288e). (FormantPath me, double windowLength, constINTVECcxx . . $ constINTVEC# const& parameters, double powerf) {
454 try {
455 const integercxx . . $ integer# numberOfCandidates = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.;
456 const integercxx . . $ integer# maxnFormants = FormantPath_getNumberOfFormantTrackscxx . . $ FormantPath_getNumberOfFormantTracks(57eee78a3ac77977). (me);
457 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (parameters.size > 0 && parameters.size <= maxnFormants,
458 U"The number of parameters should be between 1 and ", maxnFormants, U".");
459 integercxx . . $ integer# fromFormant = 1;
460 const integercxx . . $ integer# maximumNumberOfCoefficients = NUMmax_ecxx . . $ NUMmax_e(ff5c8185b8e92fd6). (parameterscxx . . $ constvectorview#constvectorview(fc39adb4395e9baf).);
461 const integercxx . . $ integer# numberOfDataPoints = (windowLength + 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
462 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfDataPoints >= maximumNumberOfCoefficients,
463 U"The window length is too short for the number of coefficients you use in the stress determination (",
464 maximumNumberOfCoefficients, U"). Either increase your window length or decrease the number of coefficients per track."
465 );
466 while (fromFormant <= parameters.sizecxx . . $ constvector#size. && parameters [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).fromFormant] <= 0)
467 fromFormant ++;
468 integercxx . . $ integer# toFormant = parameters.sizecxx . . $ constvector#size.;
469 while (toFormant > 0 && parameters [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).toFormant] <= 0)
470 toFormant --;
471 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (fromFormant <= toFormant,
472 U"Not all parameter values should equal zero.");
473 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., 0.5, numberOfCandidates + 0.5, numberOfCandidates, 1.0, 1.0);
474 for (integercxx . . $ integer# candidate = 1; candidate <= numberOfCandidates; candidate ++) {
475 const Formantcxx . . $ Formant# formanti = (Formantcxx . . $ Formant#) mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).candidate];
476 for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) {
477 const double time = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (iframe - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
478 const double startTime = time - 0.5 * windowLength;
479 const double endTime = time + 0.5 * windowLength;
480 autoFormantModelercxx . . $ autoFormantModeler# fm = Formant_to_FormantModelercxx . . $ Formant_to_FormantModeler(1823957b022b1ce1). (formanti, startTime, endTime, parameters);
481 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).candidate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = FormantModeler_getStresscxx . . $ FormantModeler_getStress(ca00b7081cb84bed). (fm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fromFormant, toFormant, 0, powerf);
482 }
483 }
484 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
485 } catch (MelderErrorcxx . . $ MelderError#) {
486 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot create stress Matrix");
487 }
488 }
489
490
491 double FormantPath_getStressOfCandidatecxx . . $ FormantPath_getStressOfCandidate(7a4b899a2d870095). (FormantPath me, double tmin, double tmax, integercxx . . $ integer# fromFormant, integercxx . . $ integer# toFormant,
492 constINTVECcxx . . $ constINTVEC# const& parameters, double powerf, integercxx . . $ integer# candidate)
493 {
494 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidate > 0);
495 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (candidate <= mycxx . . $ `melder/melder.h:44:9`! formantCandidates.size,
496 U"The candidate number should be between 1 and ", mycxx . . $ `melder/melder.h:44:9`! formantCandidates.size, U".");
497 const Formantcxx . . $ Formant# formant = (Formantcxx . . $ Formant#) mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).candidate];
498 autoFormantModelercxx . . $ autoFormantModeler# fm = Formant_to_FormantModelercxx . . $ Formant_to_FormantModeler(1823957b022b1ce1). (formant, tmin, tmax, parameters);
499 return FormantModeler_getStresscxx . . $ FormantModeler_getStress(ca00b7081cb84bed). (fm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fromFormant, toFormant, 0, powerf);
500 }
501
502 autoVECcxx . . $ autoVEC# FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (FormantPath me, double tmin, double tmax,
503 integercxx . . $ integer# fromFormant, integercxx . . $ integer# toFormant, constINTVECcxx . . $ constINTVEC# const& parameters, double powerf)
504 {
505 autoVECcxx . . $ autoVEC# stresses = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.);
506 for (integercxx . . $ integer# candidate = 1; candidate <= mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.; candidate ++)
507 stresses [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).candidate] = FormantPath_getStressOfCandidatecxx . . $ FormantPath_getStressOfCandidate(7a4b899a2d870095). (me, tmin, tmax, fromFormant, toFormant, parameters, powerf, candidate);
508 return stressescxx . . $ autovector#autovector(d33c649a3aceae2f).;
509 }
510
511 double FormantPath_getOptimalCeilingcxx . . $ FormantPath_getOptimalCeiling(6929afb7af3095ad). (FormantPath me, double tmin, double tmax, constINTVECcxx . . $ constINTVEC# const& parameters, double powerf) {
512 autoVECcxx . . $ autoVEC# stresses = FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (me, tmin, tmax, 0, 0, parameters, powerf);
513 const integercxx . . $ integer# minPos = NUMminPoscxx . . $ NUMminPos(99bbb1d062110345). (stressescxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).());
514 return mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).minPos];
515 }
516
517 void FormantPath_setPathcxx . . $ FormantPath_setPath(a9da2faec368519a). (FormantPath me, double tmin, double tmax, integercxx . . $ integer# selectedCandidate) {
518 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (selectedCandidate > 0);
519 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (selectedCandidate <= mycxx . . $ `melder/melder.h:44:9`! formantCandidates.size,
520 U"The candidate number should be between 1 and ", mycxx . . $ `melder/melder.h:44:9`! formantCandidates.size, U".");
521 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
522 Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & tmin, & tmax);
523 const double ceilingFrequency = mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).selectedCandidate];
524 TextGrid_addInterval_forcecxx . . $ TextGrid_addInterval_force(d24aedbcce6a15af). (mycxx . . $ `melder/melder.h:44:9`! path.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, 1, Melder_doublecxx . . $ Melder_double(f05d861d9dbec9b2). (ceilingFrequency));
525 }
526
527 void FormantPath_setOptimalPathcxx . . $ FormantPath_setOptimalPath(b1c658718653901f). (FormantPath me, double tmin, double tmax, constINTVECcxx . . $ constINTVEC# const& parameters, double powerf) {
528 autoVECcxx . . $ autoVEC# stresses = FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (me, tmin, tmax, 0, 0, parameters, powerf);
529 const integercxx . . $ integer# minPos = NUMminPoscxx . . $ NUMminPos(99bbb1d062110345). (stressescxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).());
530 FormantPath_setPathcxx . . $ FormantPath_setPath(a9da2faec368519a). (me, tmin, tmax, minPos);
531 }
532
533 autoTablecxx . . $ autoTable# FormantPath_downTo_Table_stressescxx . . $ FormantPath_downTo_Table_stresses(e75cb988ad3d5f1a). (FormantPath me, double tmin, double tmax, constINTVECcxx . . $ constINTVEC# const& parameters,
534 double powerf, integercxx . . $ integer# numberOfStressDecimals, bool includeIntervalTimes, integercxx . . $ integer# numberOfTimeDecimals)
535 {
536 try {
537 autoVECcxx . . $ autoVEC# stresses = FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (me, tmin, tmax, 0, 0, parameters, powerf);
538 const integercxx . . $ integer# numberOfCandidates = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.;
539 const integercxx . . $ integer# numberOfFormantsInFit = parameters.sizecxx . . $ constvector#size.;
540 autoTablecxx . . $ autoTable# thee = Table_createWithoutColumnNamescxx . . $ Table_createWithoutColumnNames(9861d2482f105183). (numberOfCandidates, includeIntervalTimes + 1 + includeIntervalTimes + numberOfFormantsInFit + numberOfFormantsInFit - 1);
541 integercxx . . $ integer# icol = 0;
542 if (includeIntervalTimes) {
543 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, U"Start(s)");
544 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 2, U"End(s)");
545 for (integercxx . . $ integer# irow = 1; irow <= numberOfCandidates; irow ++) {
546 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, 1, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (tmin, numberOfTimeDecimals));
547 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, 2, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (tmax, numberOfTimeDecimals));
548 }
549 icol = 2;
550 }
551 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, U"Ceiling(Hz)");
552 for (integercxx . . $ integer# irow = 1; irow <= numberOfCandidates; irow ++)
553 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).irow], 1));
554
555 for (integercxx . . $ integer# iformant = 1; iformant <= numberOfFormantsInFit; iformant ++) {
556 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"Stress", iformant));
557 autoVECcxx . . $ autoVEC# stresses_fi = FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (me, tmin, tmax, iformant, iformant, parameters, powerf);
558 for (integercxx . . $ integer# irow = 1; irow <= numberOfCandidates; irow ++)
559 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (stresses_fi [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).irow], numberOfStressDecimals));
560 }
561 for (integercxx . . $ integer# iformant = 2; iformant <= numberOfFormantsInFit; iformant ++) {
562 Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ++ icol, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"Stress", 1, iformant));
563 autoVECcxx . . $ autoVEC# stresses_fij = FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (me, tmin, tmax, 1, iformant, parameters, powerf);
564 for (integercxx . . $ integer# irow = 1; irow <= numberOfCandidates; irow ++)
565 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, icol, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (stresses_fij [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).irow], numberOfStressDecimals));
566 }
567 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
568 } catch (MelderErrorcxx . . $ MelderError#) {
569 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot create Table with stresses of fit.");
570 }
571 }
572
573 autoTablecxx . . $ autoTable# FormantPath_downTo_Table_optimalIntervalcxx . . $ FormantPath_downTo_Table_optimalInterval(8e4599b1f35d7401). (FormantPath me, double tmin, double tmax,
574 constINTVECcxx . . $ constINTVEC# const& parameters, double powerf, bool includeFrameNumber, bool includeTime, integercxx . . $ integer# numberOfTimeDecimals,
575 bool includeIntensity, integercxx . . $ integer# numberOfIntensityDecimals, bool includeNumberOfFormants, integercxx . . $ integer# numberOfFrequencyDecimals,
576 bool includeBandwidths, bool includeOptimumCeiling, bool includeMinimumStress)
577 {
578 try {
579 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (numberOfTimeDecimals >= 0 && numberOfIntensityDecimals >= 0 && numberOfFrequencyDecimals >= 0);
580 autoVECcxx . . $ autoVEC# stresses = FormantPath_getStressOfCandidatescxx . . $ FormantPath_getStressOfCandidates(ac0ceb70b18df84f). (me, tmin, tmax, 0, 0, parameters, powerf);
581 const integercxx . . $ integer# minPos = NUMminPoscxx . . $ NUMminPos(99bbb1d062110345). (stressescxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).());
582 const integercxx . . $ integer# minPosFallBack = ( minPos != 0 ? minPos : stresses.sizecxx . . $ autovector#size. / 2 );
583 const Formantcxx . . $ Formant# formant = (Formantcxx . . $ Formant#) mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).minPosFallBack];
584 integercxx . . $ integer# ifmin, ifmax;
585 Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (formant, tmin, tmax, & ifmin, & ifmax);
586 autoFormantcxx . . $ autoFormant# thee = Formant_extractPartcxx . . $ Formant_extractPart(ffc03f71e55e4841). (formant, tmin, tmax);
587 autoTablecxx . . $ autoTable# him = Formant_downto_Tablecxx . . $ Formant_downto_Table(79b9edfa34f9b49e). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), includeFrameNumber, includeTime, numberOfTimeDecimals,
588 includeIntensity, numberOfIntensityDecimals, includeNumberOfFormants, numberOfFrequencyDecimals, includeBandwidths);
589 if (includeFrameNumber) {
590 /*
591 Correct frame number, it has to start at ifmin instead of 1
592 */
593 for (integercxx . . $ integer# irow = 1; irow <= hiscxx . . $ `melder/melder.h:47:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; irow ++)
594 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, 1, ifmin + irow - 1);
595 }
596 if (includeOptimumCeiling) {
597 Table_appendColumncxx . . $ Table_appendColumn(268e54517ba24ebd). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), U"Ceiling(Hz)");
598 for (integercxx . . $ integer# irow = 1; irow <= hiscxx . . $ `melder/melder.h:47:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; irow ++)
599 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, hiscxx . . $ `melder/melder.h:47:9`! numberOfColumnscxx . . $ structTable#numberOfColumns., Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).minPosFallBack], 1));
600 }
601 if (includeMinimumStress) {
602 Table_appendColumncxx . . $ Table_appendColumn(268e54517ba24ebd). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), U"Stress");
603 for (integercxx . . $ integer# irow = 1; irow <= hiscxx . . $ `melder/melder.h:47:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; irow ++)
604 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), irow, hiscxx . . $ `melder/melder.h:47:9`! numberOfColumnscxx . . $ structTable#numberOfColumns., Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (stresses [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).minPosFallBack], 2));
605 }
606 return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
607 } catch (MelderErrorcxx . . $ MelderError#) {
608 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U"could not list as Table.");
609 }
610 }
611
612 static void Formant_speckles_insidecxx . . $ Formant_speckles_inside(d2bb85b68f862582). (Formantcxx . . $ Formant# me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmin, double fmax,
613 integercxx . . $ integer# fromFormant, integercxx . . $ integer# toFormant, double suppress_dB, bool drawBandWidths, MelderColourcxx . . $ MelderColour# oddNumberedFormants, MelderColourcxx . . $ MelderColour# evenNumberedFormants)
614 {
615 double maximumIntensity = 0.0, minimumIntensity;
616 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
617 integercxx . . $ integer# ifmin, ifmax;
618 if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & ifmin, & ifmax))
619 return;
620 if (fromFormant == 0 && toFormant == 0) {
621 fromFormant = 1;
622 toFormant = mycxx . . $ `melder/melder.h:44:9`! maxnFormantscxx . . $ structFormant#maxnFormants.;
623 }
624 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, tmin, tmax, fmin, fmax);
625
626 for (integercxx . . $ integer# iframe = ifmin; iframe <= ifmax; iframe ++) {
627 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
628 if (frame -> intensitycxx . . $ structFormant_Frame#intensity. > maximumIntensity)
629 maximumIntensity = frame -> intensitycxx . . $ structFormant_Frame#intensity.;
630 }
631 if (maximumIntensity == 0.0 || suppress_dB <= 0.0)
632 minimumIntensity = 0.0; // ignore
633 else
634 minimumIntensity = maximumIntensity / powcxx . . $ pow(b71928d39fde4295). (10.0, suppress_dB / 10.0);
635
636 for (integercxx . . $ integer# iframe = ifmin; iframe <= ifmax; iframe ++) {
637 const Formant_Framecxx . . $ Formant_Frame# frame = & mycxx . . $ `melder/melder.h:44:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
638 const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iframe);
639 if (frame -> intensitycxx . . $ structFormant_Frame#intensity. < minimumIntensity)
640 continue;
641 /*
642 Higher formants in general have larger bandwidths. Draw them first to show lower formants clearer.
643 */
644 for (integercxx . . $ integer# iformant = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (frame -> numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants., toFormant); iformant >= fromFormant; iformant --) {
645 const double frequency = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. frequencycxx . . $ structFormant_Formant#frequency.;
646 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, iformant % 2 == 1 ? oddNumberedFormants : evenNumberedFormants );
647 if (frequency >= fmin && frequency <= fmax) {
648 Graphics_specklecxx . . $ Graphics_speckle(c84ba9158791aef6). (g, x, frequency);
649 if (drawBandWidths) {
650 const double bandwidth = frame -> formantcxx . . $ structFormant_Frame#formant. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iformant]. bandwidthcxx . . $ structFormant_Formant#bandwidth.;
651 const double upper = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (frequency + 0.5 * bandwidth, fmax);
652 const double lower = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (frequency - 0.5 * bandwidth, fmin);
653 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, upper, x, lower);
654 }
655 }
656 }
657 }
658 }
659
660 void FormantPath_drawAsGrid_insidecxx . . $ FormantPath_drawAsGrid_inside(b4ff202d0916fa3d). (FormantPath me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmax,
661 integercxx . . $ integer# fromFormant, integercxx . . $ integer# toFormant, bool showBandwidths, MelderColourcxx . . $ MelderColour# oddNumberedFormants, MelderColourcxx . . $ MelderColour# evenNumberedFormants,
662 integercxx . . $ integer# nrow, integercxx . . $ integer# ncol, double spaceBetweenFraction_x, double spaceBetweenFraction_y, double yGridLineEvery_Hz,
663 double xCursor, double yCursor, MelderColourcxx . . $ MelderColour# selectedCeilingsColour, constINTVECcxx . . $ constINTVEC# const& parameters,
664 bool markCandidatesWithinPath, bool showStress, double powerf, bool showEstimatedModels, bool garnish)
665 {
666 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (nrow >= 0 && ncol >= 0);
667 constexpr double fmin = 0.0;
668 const integercxx . . $ integer# numberOfCandidates = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.sizecxx . . $ CollectionOf#size.;
669 if (nrow <= 0 || ncol <= 0)
670 getGridLayoutcxx . . $ getGridLayout(b76a3bd1263aa692). (numberOfCandidates, & nrow, & ncol);
671 double x1NDC, x2NDC, y1NDC, y2NDC;
672 Graphics_inqViewportcxx . . $ Graphics_inqViewport(962850f2031ce0d0). (g, & x1NDC, & x2NDC, & y1NDC, & y2NDC);
673 const double fontSize_old = Graphics_inqFontSizecxx . . $ Graphics_inqFontSize(f906975acce41a59). (g);
674 double newFontSize = fontSize_old;
675
676 const double vp_width = x2NDC - x1NDC, vp_height = y2NDC - y1NDC;
677 const double vpi_width = vp_width / (ncol + (ncol - 1) * spaceBetweenFraction_x);
678 const double vpi_height = vp_height / (nrow + (nrow - 1) * spaceBetweenFraction_y);
679 MelderIntegerRangecxx . . $ MelderIntegerRange# intervalRange = FormantPath_getPathTierIndicesRangecxx . . $ FormantPath_getPathTierIndicesRange(92beeefb819af1e2). (me, tmin, tmax);
680 IntervalTiercxx . . $ IntervalTier# intervalTier = static_cast<IntervalTiercxx . . $ IntervalTier#> (mycxx . . $ `melder/melder.h:44:9`! path ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). tierscxx . . $ structTextGrid#tiers.->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at.[cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
681 integercxx . . $ integer# ifmin, ifmax;
682 const integercxx . . $ integer# numberOfSamples = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & ifmin, & ifmax);
683
684 for (integercxx . . $ integer# candidate = 1; candidate <= numberOfCandidates; candidate ++) {
685 const integercxx . . $ integer# irow = 1 + (candidate - 1) / ncol; // left-to-right + top-to-bottom
686 const integercxx . . $ integer# icol = 1 + (candidate - 1) % ncol;
687 const double vpi_x1 = x1NDC + (icol - 1) * vpi_width * (1.0 + spaceBetweenFraction_x);
688 const double vpi_x2 = vpi_x1 + vpi_width;
689 const double vpi_y2 = y2NDC - (irow - 1) * vpi_height * (1.0 + spaceBetweenFraction_y);
690 const double vpi_y1 = vpi_y2 - vpi_height;
691 const Formantcxx . . $ Formant# formant = mycxx . . $ `melder/melder.h:44:9`! formantCandidates.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).candidate];
692 autoFormantModelercxx . . $ autoFormantModeler# fmcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
693 if (numberOfSamples > 0)
694 fm =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Formant_to_FormantModelercxx . . $ Formant_to_FormantModeler(1823957b022b1ce1). (formant, tmin, tmax, parameters);
695 Graphics_setViewportcxx . . $ Graphics_setViewport(72bdb7937dbb13da). (g, vpi_x1, vpi_x2, vpi_y1, vpi_y2);
696 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, tmin, tmax, fmin, fmax);
697 if (candidate == 1) {
698 newFontSize = Graphics_getFontSizeInsideBoxcxx . . $ Graphics_getFontSizeInsideBox(58355cd5a6d131f). (g, tmax - tmin, spaceBetweenFraction_y * (fmax - fmin), 18.0, 3.0);
699 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, newFontSize);
700 }
701 if (garnish && markCandidatesWithinPath) {
702 for (integercxx . . $ integer# interval = intervalRange.firstcxx . . $ MelderIntegerRange#first.; interval <= intervalRange.lastcxx . . $ MelderIntegerRange#last.; interval ++) {
703 TextIntervalcxx . . $ TextInterval# textInterval = intervalTier -> intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).interval];
704 const integercxx . . $ integer# icandidate = ( textInterval -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() ? Melder_atoicxx . . $ Melder_atoi(c94c67ff4219bf83). (textInterval -> textcxx . . $ structTextInterval#text..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : 0);
705 if (icandidate == candidate) {
706 MelderColourcxx . . $ MelderColour# colourCopy = Graphics_inqColourcxx . . $ Graphics_inqColour(322ea1b2fa08ba06). (g);
707 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, selectedCeilingsColour);
708 double x1 = textInterval -> xmincxx . . $ structFunction#xmin., x2 = textInterval -> xmaxcxx . . $ structFunction#xmax.;
709 Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (tmin, & x1);
710 Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& x2, tmax);
711 Graphics_fillRectanglecxx . . $ Graphics_fillRectangle(72bdb7937dbb13da). (g, x1, x2, 0, fmax);
712 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colourCopy);
713 }
714 }
715 }
716 Formant_speckles_insidecxx . . $ Formant_speckles_inside(d2bb85b68f862582). (formant, g, tmin, tmax, fmin, fmax, fromFormant, toFormant, 100.0, showBandwidths, oddNumberedFormants, evenNumberedFormants);
717 if (showEstimatedModels && numberOfSamples > 0)
718 FormantModeler_drawModel_insidecxx . . $ FormantModeler_drawModel_inside(8358242cd9269fd8). (fm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), g, tmin, tmax, fmax, fromFormant, toFormant, oddNumberedFormants, evenNumberedFormants, 100_integercxx . . $ `operator""_integer`(85240eb457c3721a).);
719 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_BLACKcxx . . $ Melder_BLACK.);
720 if (garnish)
721 Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, tmin, tmax, fmin, fmax);
722
723 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!);
724 Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, 1.0);
725 /*
726 Mark ceiling & stress
727 */
728 autoMelderStringcxx . . $ autoMelderString# infocxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).;
729 if (garnish) {
730 const double tLeftPos = tmin - 0.01 * (tmax - tmin);
731 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& info, U"Ceiling = ", Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (mycxx . . $ `melder/melder.h:44:9`! ceilings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).candidate], 0), U" Hz");
732 if (showStress && numberOfSamples > 0) {
733 const double stress = FormantModeler_getStresscxx . . $ FormantModeler_getStress(ca00b7081cb84bed). (fm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fromFormant, toFormant, 0, powerf);
734 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& info, U"\nStress = ", Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (stress, 2));
735 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::LEFTcxx . . $ kGraphics_horizontalAlignment#LEFT., Graphics_TOPcxx . . $ `sys/Graphics.h:254:9`!);
736 }
737 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::LEFTcxx . . $ kGraphics_horizontalAlignment#LEFT., Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!);
738 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, tLeftPos, fmax, info.stringcxx . . $ MelderString#string.);
739 }
740 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
741 if (garnish) {
742 auto getXtick = [] (Graphicscxx . . $ Graphics# gg, double fontSize) {
743 const double margin = 2.8 * fontSize * gg -> resolutioncxx . . $ structGraphics#resolution. / 72.0;
744 const double wDC = (gg -> d_x2DCcxx . . $ structGraphics#d_x2DC. - gg -> d_x1DCcxx . . $ structGraphics#d_x1DC.) / (gg -> d_x2wNDCcxx . . $ structGraphics#d_x2wNDC. - gg -> d_x1wNDCcxx . . $ structGraphics#d_x1wNDC.) * (gg -> d_x2NDCcxx . . $ structGraphics#d_x2NDC. - gg -> d_x1NDCcxx . . $ structGraphics#d_x1NDC.);
745 double dx = 1.5 * margin / wDC;
746 const double xTick = 0.06 * dx;
747 Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& dx, 0.4);
748 return xTick / (1.0 - 2.0 * dx);
749 };
750 auto getYtick = [] (Graphicscxx . . $ Graphics# gg, double fontSize) {
751 const double margin = 2.8 * fontSize * gg -> resolutioncxx . . $ structGraphics#resolution. / 72.0;
752 const double hDC = integer_abscxx . . $ integer_abs(8ce0d1b217db7fd1). (gg->d_y2DCcxx . . $ structGraphics#d_y2DC. - gg->d_y1DCcxx . . $ structGraphics#d_y1DC.) / (gg->d_y2wNDCcxx . . $ structGraphics#d_y2wNDC. - gg->d_y1wNDCcxx . . $ structGraphics#d_y1wNDC.) * (gg->d_y2NDCcxx . . $ structGraphics#d_y2NDC. - gg-> d_y1NDCcxx . . $ structGraphics#d_y1NDC.);
753 double dy = margin / hDC;
754 const double yTick = 0.09 * dy;
755 Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& dy, 0.4);
756 return yTick / (1.0 - 2.0 * dy);
757 };
758 const double xTick = (double) getXtick (cxx . . $ FormantPath_drawAsGrid_inside(b4ff202d0916fa3d).$anonymous_type_0#`operator()`(fcca6b35155eb7d1).g, newFontSize) * (tmax - tmin);
759 const double yTick = (double) getYtick (cxx . . $ FormantPath_drawAsGrid_inside(b4ff202d0916fa3d).$anonymous_type_1#`operator()`(fcca6b35155eb7d1).g, newFontSize) * (fmax - fmin);
760 if (irow == nrow) {
761 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& info);
762 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& info, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (tmin, 3), U" s");
763 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::LEFTcxx . . $ kGraphics_horizontalAlignment#LEFT., Graphics_TOPcxx . . $ `sys/Graphics.h:254:9`!);
764 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tmin, fmin, tmin, fmin - yTick);
765 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, tmin , fmin - yTick, info.stringcxx . . $ MelderString#string.);
766 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& info);
767 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& info, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (tmax, 3), U" s");
768 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tmax, fmin, tmax, fmin - yTick);
769 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::RIGHTcxx . . $ kGraphics_horizontalAlignment#RIGHT., Graphics_TOPcxx . . $ `sys/Graphics.h:254:9`!);
770 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, tmax, fmin - yTick, info.stringcxx . . $ MelderString#string.);
771 }
772 if (icol == 1) {
773 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& info);
774 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& info, Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (fmin), U" Hz");
775 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tmin - xTick, fmin, tmin, fmin);
776 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::RIGHTcxx . . $ kGraphics_horizontalAlignment#RIGHT., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
777 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, tmin - xTick, fmin, info.stringcxx . . $ MelderString#string.);
778 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& info);
779 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& info, Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (fmax), U" Hz");
780 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, tmin - xTick, fmax, info.stringcxx . . $ MelderString#string.);
781
782 }
783 double yGridLine_Hz = yGridLineEvery_Hz;
784 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DOTTEDcxx . . $ `sys/Graphics.h:288:9`!);
785 while (yGridLine_Hz < 0.95 * fmax) {
786 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tmin, yGridLine_Hz, tmax, yGridLine_Hz);
787 yGridLine_Hz += yGridLineEvery_Hz;
788 }
789 /*
790 Cursors
791 */
792 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_REDcxx . . $ Melder_RED.);
793 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DASHEDcxx . . $ `sys/Graphics.h:289:9`!);
794 if (xCursor > tmin && xCursor <= tmax)
795 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, xCursor, 0.0, xCursor, fmax);
796 if (yCursor > fmin && yCursor < fmax)
797 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tmin, yCursor, tmax, yCursor);
798 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_BLACKcxx . . $ Melder_BLACK.);
799 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!);
800 }
801 }
802 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, fontSize_old);
803 Graphics_setViewportcxx . . $ Graphics_setViewport(72bdb7937dbb13da). (g, x1NDC, x2NDC, y1NDC, y2NDC);
804
805 }
806
807 void FormantPath_drawAsGridcxx . . $ FormantPath_drawAsGrid(b4ff202d0916fa3d). (FormantPath me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmax,
808 integercxx . . $ integer# fromFormant, integercxx . . $ integer# toFormant, bool showBandwidths, MelderColourcxx . . $ MelderColour# oddNumberedFormants, MelderColourcxx . . $ MelderColour# evenNumberedFormants,
809 integercxx . . $ integer# nrow, integercxx . . $ integer# ncol, double spaceBetweenFraction_x, double spaceBetweenFraction_y, double yGridLineEvery_Hz,
810 double xCursor, double yCursor, MelderColourcxx . . $ MelderColour# selected, constINTVECcxx . . $ constINTVEC# const& parameters,
811 bool markCandidatesWithinPath, bool showStress, double powerf, bool showEstimatedModels, bool garnish)
812 {
813 Function_bidirectionalAutowindowcxx . . $ Function_bidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
814 Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g);
815 FormantPath_drawAsGrid_insidecxx . . $ FormantPath_drawAsGrid_inside(b4ff202d0916fa3d). (me, g, tmin, tmax, fmax, fromFormant, toFormant, showBandwidths, oddNumberedFormants, evenNumberedFormants,
816 nrow, ncol, spaceBetweenFraction_x, spaceBetweenFraction_y, yGridLineEvery_Hz, xCursor, yCursor, selected, parameters,
817 markCandidatesWithinPath, showStress, powerf, showEstimatedModels, garnish
818 );
819 Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g);
820 }
821
822 /* End of file FormantPath.cpp */