Debian Codegraph @

fon/Pitch_to_PointProcess.cpp

raw symbols SCIP
1 /* Pitch_to_PointProcess.cpp
2 *
3 * Copyright (C) 1992-2005,2007,2008,2011,2014-2018,2020,2021,2024-2026 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 /*
20 * pb 2002/07/16 GPL
21 * pb 2003/02/26 Sound_Pitch_to_PointProcess_peaks
22 * pb 2003/05/17 introduced silence threshold
23 * pb 2003/05/20 removed bug in global peak
24 * pb 2003/05/22 changed 1.2 to 1.25
25 * pb 2004/05/11 undefined pitch is `undefined` rather than 0.0
26 * pb 2004/11/01 Pitch_getVoicedIntervalAfter clips to my xmax
27 * pb 2004/11/28 repaired memory leak in Pitch_to_PointProcess
28 * pb 2004/11/28 truncated tleft in Pitch_getVoicedIntervalAfter to my xmin (otherwise, getValue can crash)
29 * pb 2005/06/16 units
30 * pb 2007/01/26 compatible with stereo sounds
31 * pb 2008/01/19 double
32 * pb 2011/06/04 C++
33 */
34
35 #include "Pitch_to_PointProcess.h"cxx . . $ `<file>/fon/Pitch_to_PointProcess.h`/
36 #include "PitchTier_to_PointProcess.h"cxx . . $ `<file>/fon/PitchTier_to_PointProcess.h`/
37 #include "Pitch_to_PitchTier.h"cxx . . $ `<file>/fon/Pitch_to_PitchTier.h`/
38
39 autoPointProcesscxx . . $ autoPointProcess# Pitch_to_PointProcesscxx . . $ Pitch_to_PointProcess(9d4c69dc4ad51e9a). (Pitchcxx . . $ Pitch# pitch) {
40 try {
41 autoPitchTiercxx . . $ autoPitchTier# pitchTier = Pitch_to_PitchTiercxx . . $ Pitch_to_PitchTier(511873a878854c23). (pitch);
42 autoPointProcesscxx . . $ autoPointProcess# point = PitchTier_Pitch_to_PointProcesscxx . . $ PitchTier_Pitch_to_PointProcess(27581ade3a75b545). (pitchTier.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), pitch);
43 return pointcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
44 } catch (MelderErrorcxx . . $ MelderError#) {
45 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (pitch, U": not converted to PointProcess.");
46 }
47 }
48
49 static int Pitch_getVoicedIntervalAftercxx . . $ Pitch_getVoicedIntervalAfter(fdebf142e4502a2). (Pitchcxx . . $ Pitch# me, double after, double *tleft, double *tright) {
50 integercxx . . $ integer# ileft = Sampled_xToHighIndexcxx . . $ Sampled_xToHighIndex(405c2491bc3636e9). (me, after), iright;
51 if (ileft > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.)
52 return 0; // offright
53 if (ileft < 1)
54 ileft = 1; // offleft
55
56 /*
57 Search for first voiced frame.
58 */
59 for (; ileft <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ileft ++)
60 if (Pitch_isVoiced_icxx . . $ Pitch_isVoiced_i(fd5b671aa7b53262). (me, ileft))
61 break;
62 if (ileft > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.)
63 return 0; // offright
64
65 /*
66 Search for last voiced frame.
67 */
68 for (iright = ileft; iright <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iright ++)
69 if (! Pitch_isVoiced_icxx . . $ Pitch_isVoiced_i(fd5b671aa7b53262). (me, iright))
70 break;
71 iright --;
72
73 *tleft = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ileft) - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; // the whole frame is considered voiced
74 *tright = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, iright) + 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
75 if (*tleft >= mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.)
76 return 0;
77 Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., tleft);
78 Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (tright, mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.);
79 if (*tright <= after)
80 return 0;
81 return 1;
82 }
83
84 static double findExtremum_3cxx . . $ findExtremum_3(3149cbebf403809). (double *channel1_base, double *channel2_base, integercxx . . $ integer# d, integercxx . . $ integer# n, bool includeMaxima, bool includeMinima) {
85 const double *const channel1 = channel1_base + d;
86 const double *const channel2 = ( channel2_base ? channel2_base + d : nullptr );
87 bool includeAll = ( includeMaxima == includeMinima );
88 integercxx . . $ integer# imin = 1, imax = 1, i;
89 double minimum, maximum;
90 if (n < 3) {
91 if (n <= 0)
92 return 0.0; // outside
93 else if (n == 1)
94 return 1.0;
95 else { // n == 2
96 const double x1 = ( channel2 ? 0.5 * (channel1 [1] + channel2 [1]) : channel1 [1] );
97 const double x2 = ( channel2 ? 0.5 * (channel1 [2] + channel2 [2]) : channel1 [2] );
98 const double xleft = ( includeAll ? fabscxx . . $ fabs(fee4f1d22bc8e617). (x1) : includeMaxima ? x1 : - x1 );
99 const double xright = ( includeAll ? fabscxx . . $ fabs(fee4f1d22bc8e617). (x2) : includeMaxima ? x2 : - x2 );
100 if (xleft > xright)
101 return 1.0;
102 else if (xleft < xright)
103 return 2.0;
104 else
105 return 1.5;
106 }
107 }
108 minimum = maximum = ( channel2 ? 0.5 * (channel1 [1] + channel2 [1]) : channel1 [1] );
109 for (i = 2; i <= n; i ++) {
110 const double value = ( channel2 ? 0.5 * (channel1 [i] + channel2 [i]) : channel1 [i] );
111 if (value < minimum) {
112 minimum = value;
113 imin = i;
114 }
115 if (value > maximum) {
116 maximum = value;
117 imax = i;
118 }
119 }
120 if (minimum == maximum)
121 return 0.5 * (n + 1.0); // all equal
122 const integercxx . . $ integer# iextr = includeAll ? ( fabscxx . . $ fabs(fee4f1d22bc8e617). (minimum) > fabscxx . . $ fabs(fee4f1d22bc8e617). (maximum) ? imin : imax ) : includeMaxima ? imax : imin;
123 if (iextr == 1)
124 return 1.0;
125 if (iextr == n)
126 return (double) n;
127 /*
128 Parabolic interpolation.
129 We do NOT need fabs here: we look for a genuine extremum.
130 */
131 const double valueMid = ( channel2 ? 0.5 * (channel1 [iextr] + channel2 [iextr]) : channel1 [iextr] );
132 const double valueLeft = ( channel2 ? 0.5 * (channel1 [iextr - 1] + channel2 [iextr - 1]) : channel1 [iextr - 1] );
133 const double valueRight = ( channel2 ? 0.5 * (channel1 [iextr + 1] + channel2 [iextr + 1]) : channel1 [iextr + 1] );
134 return iextr + 0.5 * (valueRight - valueLeft) / (2 * valueMid - valueLeft - valueRight);
135 }
136
137 static double Sound_findExtremumcxx . . $ Sound_findExtremum(8c959ba41ba6d54). (Soundcxx . . $ Sound# me, double tmin, double tmax, bool includeMaxima, bool includeMinima) {
138 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (tmin));
139 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (tmax));
140 const integercxx . . $ integer# imin = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, tmin));
141 const integercxx . . $ integer# imax = Melder_clippedRightcxx . . $ Melder_clippedRight(f80f7d6260b3ee3a). (Sampled_xToHighIndexcxx . . $ Sampled_xToHighIndex(405c2491bc3636e9). (me, tmax), mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); // SMELL: check the logic
142 const double iextremum = findExtremum_3cxx . . $ findExtremum_3(3149cbebf403809). (& mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0], mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. > 1 ? & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0] : nullptr, imin - 1, imax - imin + 1, includeMaxima, includeMinima);
143 if (iextremum != 0.0)
144 return mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (imin - 1 + iextremum - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
145 else
146 return 0.5 * (tmin + tmax);
147 }
148
149 /*
150 Function `Sound_findMaximumCorrelation`
151
152 Determines at what time point between `tmin2` and `tmax2` the signal is most similar to the signal at `t1`.
153 What is actually compared is the window that runs from
154 t1 - windowLength / 2
155 to
156 t1 + windowLength / 2
157 with the window that runs from
158 t - windowLength / 2
159 to
160 t + windowLength / 2
161 for all `t` between `tmin2` and `tmax2`.
162 */
163 static double Sound_findMaximumCorrelationcxx . . $ Sound_findMaximumCorrelation(c763df1621f0ff67). (Soundcxx . . $ Sound# me, double t1, double windowLength, double tmin2, double tmax2, double *tout, double *peak) {
164 double maximumCorrelation = -1.0; // smart 'impossible' starting value
165 double r1_best = undefinedcxx . . $ undefined., r3_best = undefinedcxx . . $ undefined., ir = undefinedcxx . . $ undefined.; // assignments not necessary, but extra safe
166 /*
167 We hold three consecutive correlation values in a self-cycling ring buffer.
168 */
169 double r1 = 0.0, r2 = 0.0, r3 = 0.0;
170
171 const double halfWindowLength = 0.5 * windowLength;
172 const integercxx . . $ integer# ileft1 = Sampled_xToNearestIndexcxx . . $ Sampled_xToNearestIndex(405c2491bc3636e9). (me, t1 - halfWindowLength);
173 const integercxx . . $ integer# iright1 = Sampled_xToNearestIndexcxx . . $ Sampled_xToNearestIndex(405c2491bc3636e9). (me, t1 + halfWindowLength);
174 const integercxx . . $ integer# ileft2min = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, tmin2 - halfWindowLength);
175 const integercxx . . $ integer# ileft2max = Sampled_xToHighIndexcxx . . $ Sampled_xToHighIndex(405c2491bc3636e9). (me, tmax2 - halfWindowLength);
176 *peak = 0.0; // default
177 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ileft2max >= ileft2min); // if the loop is never executed, the result will be garbage
178 for (integercxx . . $ integer# ileft2 = ileft2min; ileft2 <= ileft2max; ileft2 ++) {
179 longdoublecxx . . $ longdouble# norm1 = 0.0, norm2 = 0.0, product = 0.0;
180 double localPeak = 0.0;
181 for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) {
182 for (integercxx . . $ integer# i1 = ileft1, i2 = ileft2; i1 <= iright1; i1 ++, i2 ++) {
183 if (i1 < 1 || i1 > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. || i2 < 1 || i2 > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.)
184 continue;
185 const double amp1 = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i1], amp2 = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i2];
186 norm1 += amp1 * amp1;
187 norm2 += amp2 * amp2;
188 product += amp1 * amp2;
189 if (fabscxx . . $ fabs(fee4f1d22bc8e617). (amp2) > localPeak)
190 localPeak = fabscxx . . $ fabs(fee4f1d22bc8e617). (amp2);
191 }
192 }
193
194 /*
195 Cycle the ring buffer.
196 */
197 r1 = r2;
198 r2 = r3;
199 /*
200 r3 is the new autocorrelation value. It can be positive, negative, or zero.
201 If `amp1` or `amp2` is silent (i.e. all zeroes, i.e. `norm1` or `norm2` is zero),
202 then we'll safely define `r3` as 0.0.
203 */
204 if (norm1 == 0.0 || norm2 == 0.0) // one or both signals are silent
205 r3 = 0.0;
206 else
207 r3 = double (product) / sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (double (norm1 * norm2)); // well-defined correlation
208
209 if (r2 > maximumCorrelation /* true on first test */ && r2 >= r1 && r2 >= r3) {
210 r1_best = r1;
211 maximumCorrelation = r2;
212 r3_best = r3;
213 ir = ileft2 - 1;
214 *peak = localPeak;
215 }
216 }
217 /*
218 Improve the result by means of parabolic interpolation.
219 */
220 if (maximumCorrelation > -1.0) { // was maximumCorrelation ever assigned to?...
221 // ...then r1_best and r3_best and ir must also have been assigned to:
222 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (r1_best) && isdefined (r3_best) && isdefined (ir));
223 double interpolatedPeakHeight = undefinedcxx . . $ undefined.;
224 const double d2r = (maximumCorrelation - r1_best) + (maximumCorrelation - r3_best); // careful prevention of rounding error
225 if (d2r != 0.0 && ! (Melder_debugcxx . . $ Melder_debug. == 57)) {
226 const double dr = 0.5 * (r3_best - r1_best);
227 interpolatedPeakHeight = maximumCorrelation + 0.5 * dr * dr / d2r;
228 ir += dr / d2r;
229 }
230 const double peakTime = t1 + (ir - ileft1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; // can be interpolated or not
231 if (peakTime >= tmin2 && peakTime <= tmax2) { // NaN-safe
232 *tout = peakTime;
233 if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (interpolatedPeakHeight))
234 maximumCorrelation = interpolatedPeakHeight;
235 } else {
236 const double middleDistanceToT1 = NUMsqrt_acxx . . $ NUMsqrt_a(447c67c6676f75c3). ((tmin2 - t1) * (tmax2 - t1)); // e.g. for 0.8*F0 and 1.25*F0 it's precisely F0
237 // crash if tmin2 and tmax are not on the same side of t1
238 const double middleTime = ( tmin2 < t1 ? t1 - middleDistanceToT1 : t1 + middleDistanceToT1 );
239 *tout = middleTime;
240 //Melder_casual (U"Sound_findMaximumCorrelation: fell back to middle time ", middleTime, U"; correlation last ",
241 // U" ", r1, U" ", r2, U" ", r3, U" best ", r1_best, U" ", maximumCorrelation, U" ", r3_best,
242 // U" interpolated ", interpolatedPeakHeight);
243 if (r3 > maximumCorrelation)
244 maximumCorrelation = r3; // HACK
245 }
246 }
247 return maximumCorrelation;
248 }
249
250 autoPointProcesscxx . . $ autoPointProcess# Sound_Pitch_to_PointProcess_cccxx . . $ Sound_Pitch_to_PointProcess_cc(f94f2d65883a605d). (Soundcxx . . $ Sound# sound, Pitchcxx . . $ Pitch# pitch) {
251 try {
252 autoPointProcesscxx . . $ autoPointProcess# point = PointProcess_createcxx . . $ PointProcess_create(7a858f446a8dd7cc). (sound -> xmincxx . . $ structFunction#xmin., sound -> xmaxcxx . . $ structFunction#xmax., 10);
253 double t = pitch -> xmincxx . . $ structFunction#xmin.;
254 double addedRight = -1e308;
255 const double globalPeak = Vector_getAbsoluteExtremumcxx . . $ Vector_getAbsoluteExtremum(9e5d98b21939784c). (sound, sound -> xmincxx . . $ structFunction#xmin., sound -> xmaxcxx . . $ structFunction#xmax., kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: NONEcxx . . $ kVector_peakInterpolation#NONE.);
256
257 /*
258 Cycle over all voiced intervals.
259 */
260 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Sound & Pitch: To PointProcess (cc)...");
261 for (;;) {
262 double tleft, tright;
263 if (! Pitch_getVoicedIntervalAftercxx . . $ Pitch_getVoicedIntervalAfter(fdebf142e4502a2). (pitch, t, & tleft, & tright))
264 break;
265 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (tright > t);
266
267 /*
268 Go to the middle of the voiced interval.
269 */
270 const double tmiddle = 0.5 * (tleft + tright);
271 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((tmiddle - sound -> xmincxx . . $ structFunction#xmin.) / (sound -> xmaxcxx . . $ structFunction#xmax. - sound -> xmincxx . . $ structFunction#xmin.), U"Sound & Pitch to PointProcess");
272 const double f0middle = Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (pitch, tmiddle, kPitch_unitcxx . . $ kPitch_unit#::HERTZcxx . . $ kPitch_unit#HERTZ., Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`!);
273
274 /*
275 Our first point is near this middle.
276 */
277 if (isundefcxx . . $ isundef(f8197d536af80c96). (f0middle)) {
278 Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sound_Pitch_to_PointProcess_cc:"
279 U" tleft ", tleft,
280 U", tright ", tright,
281 U", f0middle ", f0middle
282 );
283 }
284 double tmax = Sound_findExtremumcxx . . $ Sound_findExtremum(8c959ba41ba6d54). (sound, tmiddle - 0.5 / f0middle, tmiddle + 0.5 / f0middle, true, true);
285 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (tmax));
286 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
287
288 //TRACE
289 double tsave = tmax;
290 for (;;) {
291 const double f0 = Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (pitch, tmax, kPitch_unitcxx . . $ kPitch_unit#::HERTZcxx . . $ kPitch_unit#HERTZ., Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`!);
292 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"1 F0: ", f0);
293 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"1 tmax: ", tmax);
294 if (isundefcxx . . $ isundef(f8197d536af80c96). (f0))
295 break;
296 double peak;
297 const double correlation = Sound_findMaximumCorrelationcxx . . $ Sound_findMaximumCorrelation(c763df1621f0ff67). (sound, tmax, 1.0 / f0, tmax - 1.25 / f0, tmax - 0.8 / f0, & tmax, & peak);
298 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"1 new tmax: ", tmax);
299 if (correlation == -1.0)
300 /*break*/ tmax -= 1.0 / f0; // this one period will drop out
301 if (tmax < tleft) {
302 if (correlation > 0.7 && peak > 0.023333 * globalPeak && tmax - addedRight > 0.8 / f0)
303 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
304 break;
305 }
306 if (correlation > 0.3 && (peak == 0.0 || peak > 0.01 * globalPeak)) {
307 if (tmax - addedRight > 0.8 / f0) { // do not fill in a short originally unvoiced interval twice
308 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"1 adding point at: ", tmax);
309 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
310 }
311 }
312 }
313 tmax = tsave;
314 for (;;) {
315 const double f0 = Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (pitch, tmax, kPitch_unitcxx . . $ kPitch_unit#::HERTZcxx . . $ kPitch_unit#HERTZ., Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`!);
316 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"2 F0: ", f0);
317 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"2 tmax: ", tmax);
318 if (isundefcxx . . $ isundef(f8197d536af80c96). (f0))
319 break;
320 double peak;
321 const double correlation = Sound_findMaximumCorrelationcxx . . $ Sound_findMaximumCorrelation(c763df1621f0ff67). (sound, tmax, 1.0 / f0, tmax + 0.8 / f0, tmax + 1.25 / f0, & tmax, & peak);
322 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"2 new tmax: ", tmax);
323 if (correlation == -1.0)
324 /*break*/ tmax += 1.0 / f0;
325 if (tmax > tright) {
326 if (correlation > 0.7 && peak > 0.023333 * globalPeak) {
327 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
328 addedRight = tmax;
329 }
330 break;
331 }
332 if (correlation > 0.3 && (peak == 0.0 || peak > 0.01 * globalPeak)) {
333 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"2 adding point at: ", tmax);
334 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
335 addedRight = tmax;
336 }
337 }
338 t = tright;
339 }
340 return pointcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
341 } catch (MelderErrorcxx . . $ MelderError#) {
342 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (sound, U" & ", pitch, U": not converted to PointProcess (cc).");
343 }
344 }
345
346 autoPointProcesscxx . . $ autoPointProcess# Sound_Pitch_to_PointProcess_peakscxx . . $ Sound_Pitch_to_PointProcess_peaks(37075ccf8fa5b996). (Soundcxx . . $ Sound# sound, Pitchcxx . . $ Pitch# pitch, int includeMaxima, int includeMinima) {
347 try {
348 autoPointProcesscxx . . $ autoPointProcess# point = PointProcess_createcxx . . $ PointProcess_create(7a858f446a8dd7cc). (sound -> xmincxx . . $ structFunction#xmin., sound -> xmaxcxx . . $ structFunction#xmax., 10);
349 double t = pitch -> xmincxx . . $ structFunction#xmin.;
350 double addedRight = -1e308;
351 /*
352 Cycle over all voiced intervals.
353 */
354
355 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Sound & Pitch: To PointProcess (peaks)...");
356 for (;;) {
357 double tleft, tright;
358 if (! Pitch_getVoicedIntervalAftercxx . . $ Pitch_getVoicedIntervalAfter(fdebf142e4502a2). (pitch, t, & tleft, & tright))
359 break;
360 /*
361 Go to the middle of the voiced interval.
362 */
363 const double tmiddle = 0.5 * (tleft + tright);
364 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((tmiddle - sound -> xmincxx . . $ structFunction#xmin.) / (sound -> xmaxcxx . . $ structFunction#xmax. - sound -> xmincxx . . $ structFunction#xmin.), U"Sound & Pitch: To PointProcess");
365 const double f0middle = Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (pitch, tmiddle, kPitch_unitcxx . . $ kPitch_unit#::HERTZcxx . . $ kPitch_unit#HERTZ., Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`!);
366
367 /*
368 Our first point is near this middle.
369 */
370 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (f0middle));
371 double tmax = Sound_findExtremumcxx . . $ Sound_findExtremum(8c959ba41ba6d54). (sound, tmiddle - 0.5 / f0middle, tmiddle + 0.5 / f0middle, includeMaxima, includeMinima);
372 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (isdefined (tmax));
373 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
374
375 double tsave = tmax;
376 for (;;) {
377 const double f0 = Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (pitch, tmax, kPitch_unitcxx . . $ kPitch_unit#::HERTZcxx . . $ kPitch_unit#HERTZ., Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`!);
378 if (isundefcxx . . $ isundef(f8197d536af80c96). (f0))
379 break;
380 tmax = Sound_findExtremumcxx . . $ Sound_findExtremum(8c959ba41ba6d54). (sound, tmax - 1.25 / f0, tmax - 0.8 / f0, includeMaxima, includeMinima);
381 if (tmax < tleft) {
382 if (tmax - addedRight > 0.8 / f0)
383 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
384 break;
385 }
386 if (tmax - addedRight > 0.8 / f0) // do not fill in a short originally unvoiced interval twice
387 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
388 }
389 tmax = tsave;
390 for (;;) {
391 const double f0 = Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (pitch, tmax, kPitch_unitcxx . . $ kPitch_unit#::HERTZcxx . . $ kPitch_unit#HERTZ., Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`!);
392 if (isundefcxx . . $ isundef(f8197d536af80c96). (f0))
393 break;
394 tmax = Sound_findExtremumcxx . . $ Sound_findExtremum(8c959ba41ba6d54). (sound, tmax + 0.8 / f0, tmax + 1.25 / f0, includeMaxima, includeMinima);
395 if (tmax > tright) {
396 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
397 addedRight = tmax;
398 break;
399 }
400 PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (point.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmax);
401 addedRight = tmax;
402 }
403 t = tright;
404 }
405 return pointcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
406 } catch (MelderErrorcxx . . $ MelderError#) {
407 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (sound, U" & ", pitch, U": not converted to PointProcess (peaks).");
408 }
409 }
410
411 /* End of file Pitch_to_PointProcess.cpp */