Debian Codegraph @

fon/Sound_to_Pitch.cpp

raw symbols SCIP
1 /* Sound_to_Pitch.cpp
2 *
3 * Copyright (C) 1992-2005,2007-2012,2014-2020,2023-2025 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * pb 2002/07/16 GPL
21 * pb 2002/10/11 removed some assertions
22 * pb 2003/05/20 default time step is four times oversampling
23 * pb 2003/07/02 checks on NUMrealft
24 * pb 2004/05/10 better error messages
25 * pb 2004/10/18 auto maxnCandidates
26 * pb 2004/10/18 use of constant FFT tables speeds up AC method by a factor of 1.9
27 * pb 2006/12/31 compatible with stereo sounds
28 * pb 2007/01/30 loop split for stereo speeds up CC method by a factor of 6
29 * pb 2008/01/19 double
30 * pb 2010/12/07 compatible with sounds with any number of channels
31 * pb 2011/03/08 C++
32 * pb 2014/05/23 threads
33 */
34
35 #include "Sound_to_Pitch.h"cxx . . $ `<file>/fon/Sound_to_Pitch.h`/
36 #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/
37 #include "Sound_and_Spectrum.h"cxx . . $ `<file>/fon/Sound_and_Spectrum.h`/
38
39 #define AC_HANNINGcxx . . $ `fon/Sound_to_Pitch.cpp:39:9`! 0
40 #define AC_GAUSScxx . . $ `fon/Sound_to_Pitch.cpp:40:9`! 1
41 #define FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`! 2
42 #define FCC_ACCURATEcxx . . $ `fon/Sound_to_Pitch.cpp:42:9`! 3
43
44 static void Sound_into_PitchFramecxx . . $ Sound_into_PitchFrame(73a3b988b8c9c365). (Soundcxx . . $ Sound# me, Pitch_Framecxx . . $ Pitch_Frame# pitchFrame, double t,
45 double pitchFloor, int maxnCandidates, int method, double voicingThreshold, double octaveCost,
46 NUMFourierTablecxx . . $ NUMFourierTable# fftTable, double dt_window, integercxx . . $ integer# nsamp_window, integercxx . . $ integer# halfnsamp_window,
47 integercxx . . $ integer# maximumLag, integercxx . . $ integer# nsampFFT, integercxx . . $ integer# nsamp_period, integercxx . . $ integer# halfnsamp_period,
48 integercxx . . $ integer# brent_ixmax, integercxx . . $ integer# brent_depth, double globalPeak,
49 MATcxx . . $ MAT# const& frame, VECcxx . . $ VEC# const& ac, VECcxx . . $ VEC# const& window, VECcxx . . $ VEC# const& windowR,
50 double *r, INTVECcxx . . $ INTVEC# const& imax, VECcxx . . $ VEC# const& localMean)
51 {
52 integercxx . . $ integer# leftSample = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, t), rightSample = leftSample + 1;
53 integercxx . . $ integer# startSample, endSample;
54
55 for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) {
56 /*
57 Compute the local mean; look one longest period to both sides.
58 */
59 startSample = rightSample - nsamp_period;
60 endSample = leftSample + nsamp_period;
61 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (startSample >= 1);
62 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (endSample <= mycxx . . $ `melder/melder.h:44:9`! nx);
63 localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel] = 0.0;
64 for (integercxx . . $ integer# i = startSample; i <= endSample; i ++)
65 localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel] += mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i];
66 localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel] /= 2 * nsamp_period;
67
68 /*
69 Copy a window to a frame and subtract the local mean.
70 We are going to kill the DC component before windowing.
71 */
72 startSample = rightSample - halfnsamp_window;
73 endSample = leftSample + halfnsamp_window;
74 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (startSample >= 1);
75 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (endSample <= mycxx . . $ `melder/melder.h:44:9`! nx);
76 if (method < FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`!) {
77 for (integercxx . . $ integer# j = 1, i = startSample; j <= nsamp_window; j ++)
78 frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i ++] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel]) * window [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j];
79 for (integercxx . . $ integer# j = nsamp_window + 1; j <= nsampFFT; j ++)
80 frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = 0.0;
81 } else {
82 for (integercxx . . $ integer# j = 1, i = startSample; j <= nsamp_window; j ++)
83 frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i ++] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel];
84 }
85 }
86
87 /*
88 Compute the local peak; look half a longest period to both sides.
89 */
90 double localPeak = 0.0;
91 if ((startSample = halfnsamp_window + 1 - halfnsamp_period) < 1)
92 startSample = 1;
93 if ((endSample = halfnsamp_window + halfnsamp_period) > nsamp_window)
94 endSample = nsamp_window;
95 for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) {
96 for (integercxx . . $ integer# j = startSample; j <= endSample; j ++) {
97 double value = fabscxx . . $ fabs(fee4f1d22bc8e617). (frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]);
98 if (value > localPeak)
99 localPeak = value;
100 }
101 }
102 pitchFrame -> intensitycxx . . $ structPitch_Frame#intensity. = ( localPeak > globalPeak ? 1.0 : localPeak / globalPeak );
103
104 /*
105 Compute the correlation into the array 'r'.
106 */
107 if (method >= FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`!) {
108 const double startTime = t - 0.5 * (1.0 / pitchFloor + dt_window);
109 integercxx . . $ integer# localSpan = maximumLag + nsamp_window;
110 if ((startSample = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, startTime)) < 1)
111 startSample = 1;
112 if (localSpan > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + 1 - startSample)
113 localSpan = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + 1 - startSample;
114 const integercxx . . $ integer# localMaximumLag = localSpan - nsamp_window;
115 const integercxx . . $ integer# offset = startSample - 1;
116 longdoublecxx . . $ longdouble# sumx2 = 0.0; // sum of squares
117 for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) {
118 const double *const amp = & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0] + offset;
119 for (integercxx . . $ integer# i = 1; i <= nsamp_window; i ++) {
120 const double x = amp [i] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel];
121 sumx2 += x * x;
122 }
123 }
124 longdoublecxx . . $ longdouble# sumy2 = sumx2; // at zero lag, these are still equal
125 r [0] = 1.0;
126 for (integercxx . . $ integer# i = 1; i <= localMaximumLag; i ++) {
127 longdoublecxx . . $ longdouble# product = 0.0;
128 for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) {
129 const double *const amp = & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0] + offset;
130 const double y0 = amp [i] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel];
131 const double yZ = amp [i + nsamp_window] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel];
132 sumy2 += yZ * yZ - y0 * y0;
133 for (integercxx . . $ integer# j = 1; j <= nsamp_window; j ++) {
134 const double x = amp [j] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel];
135 const double y = amp [i + j] - localMean [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).channel];
136 product += x * y;
137 }
138 }
139 r [- i] = r [i] = (double) product / sqrtcxx . . $ sqrt(fee4f1d22bc8e617). ((double) sumx2 * (double) sumy2);
140 }
141 } else {
142
143 /*
144 The FFT of the autocorrelation is the power spectrum.
145 */
146 for (integercxx . . $ integer# i = 1; i <= nsampFFT; i ++)
147 ac [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = 0.0;
148 for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) {
149 NUMfft_forwardcxx . . $ NUMfft_forward(aea41fd94d07eee). (fftTable, VECcxx . . $ vector#vector(3aadefc30ed88664). (& frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1], fftTable->ncxx . . $ structNUMFourierTable#n.)); // complex spectrum
150 ac [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] += frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] * frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1]; // DC component
151 for (integercxx . . $ integer# i = 2; i < nsampFFT; i += 2)
152 ac [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] += frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] * frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] + frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i+1] * frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i+1]; // power spectrum
153 ac [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).nsampFFT] += frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).nsampFFT] * frame [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).nsampFFT]; // Nyquist frequency
154 }
155 NUMfft_backwardcxx . . $ NUMfft_backward(aea41fd94d07eee). (fftTable, ac); // autocorrelation
156
157 /*
158 Normalize the autocorrelation to the value with zero lag,
159 and divide it by the normalized autocorrelation of the window.
160 */
161 r [0] = 1.0;
162 for (integercxx . . $ integer# i = 1; i <= brent_ixmax; i ++)
163 r [- i] = r [i] = ac [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i + 1] / (ac [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] * windowR [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i + 1]);
164 }
165
166 /*
167 Register the first candidate, which is always present: voicelessness.
168 */
169 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates.. resizecxx . . $ autovector#resize(d91e89fbd57cd1). (pitchFrame -> nCandidatescxx . . $ structPitch_Frame#nCandidates. = 1); // maintain invariant; no memory allocations
170 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. frequencycxx . . $ structPitch_Candidate#frequency. = 0.0; // voiceless: always present
171 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. strengthcxx . . $ structPitch_Candidate#strength. = 0.0;
172
173 /*
174 Shortcut: absolute silence is always voiceless.
175 We are done for this frame.
176 */
177 if (localPeak == 0.0)
178 return;
179
180 /*
181 Find the strongest maxima of the correlation of this frame,
182 and register them as candidates.
183 */
184 imax [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 0;
185 for (integercxx . . $ integer# i = 2; i < maximumLag && i < brent_ixmax; i ++)
186 if (r [i] > 0.5 * voicingThreshold && // not too unvoiced?
187 r [i] > r [i-1] && r [i] >= r [i+1]) // maximum?
188 {
189 integercxx . . $ integer# place = 0;
190
191 /*
192 Use parabolic interpolation for first estimate of frequency,
193 and sin(x)/x interpolation to compute the strength of this frequency.
194 */
195 const double dr = 0.5 * (r [i+1] - r [i-1]);
196 const double d2r = (r [i] - r [i-1]) + (r [i] - r [i+1]);
197 // not 2.0 * r [i] - r [i-1] - r [i+1] because of rounhding errors! (bug removed 2025-04-18)
198 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (d2r > 0);
199 const double frequencyOfMaximum = 1.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / (i + dr / d2r);
200 const integercxx . . $ integer# offset = - brent_ixmax - 1;
201 double strengthOfMaximum = /* method & 1 ? */
202 NUM_interpolate_sinccxx . . $ NUM_interpolate_sinc(3bff97c7d2c43d6f). (constVECcxx . . $ constvector#constvector(be07d762837ca876). (& r [offset + 1], brent_ixmax - offset), 1.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / frequencyOfMaximum - offset, 30)
203 /* : r [i] + 0.5 * dr * dr / d2r */;
204 /*
205 High values due to short windows are to be reflected around 1.
206 */
207 if (strengthOfMaximum > 1.0)
208 strengthOfMaximum = 1.0 / strengthOfMaximum;
209
210 /*
211 Find a place for this maximum.
212 */
213 if (pitchFrame->nCandidatescxx . . $ structPitch_Frame#nCandidates. < maxnCandidates) { // is there still a free place?
214 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates.. resizecxx . . $ autovector#resize(d91e89fbd57cd1). (++ pitchFrame -> nCandidatescxx . . $ structPitch_Frame#nCandidates.);
215 place = pitchFrame -> nCandidatescxx . . $ structPitch_Frame#nCandidates.;
216 } else {
217 /*
218 Try the place of the weakest candidate so far.
219 */
220 double weakest = 2.0;
221 for (int iweak = 2; iweak <= maxnCandidates; iweak ++) {
222 /*
223 High frequencies are to be favoured
224 if we want to analyze a perfectly periodic signal correctly.
225 */
226 const double localStrength = pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iweak]. strengthcxx . . $ structPitch_Candidate#strength. - octaveCost *
227 NUMlog2cxx . . $ NUMlog2(fee4f1d22bc8e617). (pitchFloor / pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iweak]. frequencycxx . . $ structPitch_Candidate#frequency.);
228 if (localStrength < weakest) {
229 weakest = localStrength;
230 place = iweak;
231 }
232 }
233 /*
234 If this maximum is weaker than the weakest candidate so far, give it no place.
235 */
236 if (strengthOfMaximum - octaveCost * NUMlog2cxx . . $ NUMlog2(fee4f1d22bc8e617). (pitchFloor / frequencyOfMaximum) <= weakest)
237 place = 0;
238 }
239 if (place) { // have we found a place for this candidate?
240 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).place]. frequencycxx . . $ structPitch_Candidate#frequency. = frequencyOfMaximum;
241 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).place]. strengthcxx . . $ structPitch_Candidate#strength. = strengthOfMaximum;
242 imax [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).place] = i;
243 }
244 }
245
246 /*
247 Second pass: for extra precision, maximize sin(x)/x interpolation ('sinc').
248 */
249 for (integercxx . . $ integer# i = 2; i <= pitchFrame -> nCandidatescxx . . $ structPitch_Frame#nCandidates.; i ++) {
250 if (method != AC_HANNINGcxx . . $ `fon/Sound_to_Pitch.cpp:39:9`! || pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. frequencycxx . . $ structPitch_Candidate#frequency. > 0.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.) {
251 double xmid, ymid;
252 const integercxx . . $ integer# offset = - brent_ixmax - 1;
253 ymid = NUMimproveMaximumcxx . . $ NUMimproveMaximum(c86a71e1ecac36cd). (constVECcxx . . $ constvector#constvector(be07d762837ca876). (& r [offset + 1], brent_ixmax - offset), imax [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] - offset,
254 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. frequencycxx . . $ structPitch_Candidate#frequency. > 0.3 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. ? NUM_PEAK_INTERPOLATE_SINC700cxx . . $ `melder/NUMinterpol.h:36:9`! : brent_depth, & xmid);
255 xmid += offset;
256 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. frequencycxx . . $ structPitch_Candidate#frequency. = 1.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / xmid;
257 if (ymid > 1.0)
258 ymid = 1.0 / ymid;
259 pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. strengthcxx . . $ structPitch_Candidate#strength. = ymid;
260 }
261 }
262 }
263
264 autoPitchcxx . . $ autoPitch# Sound_to_Pitch_anycxx . . $ Sound_to_Pitch_any(29e703e14008e8fa). (Soundcxx . . $ Sound# me,
265 int method, double periodsPerWindow,
266 double dt, double pitchFloor, double pitchCeiling,
267 integercxx . . $ integer# maxnCandidates,
268 double silenceThreshold, double voicingThreshold,
269 double octaveCost, double octaveJumpCost, double voicedUnvoicedCost)
270 {
271 try {
272 double t1;
273 integercxx . . $ integer# numberOfFrames;
274 integercxx . . $ integer# nsampFFT;
275 double interpolation_depth;
276 integercxx . . $ integer# brent_ixmax, brent_depth;
277 double globalPeak;
278
279 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (maxnCandidates >= 2);
280 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (method >= AC_HANNINGcxx . . $ `fon/Sound_to_Pitch.cpp:39:9`! && method <= FCC_ACCURATEcxx . . $ `fon/Sound_to_Pitch.cpp:42:9`!);
281
282 if (maxnCandidates < pitchCeiling / pitchFloor)
283 maxnCandidates = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (pitchCeiling / pitchFloor);
284
285 if (dt <= 0.0)
286 dt = periodsPerWindow / pitchFloor / 4.0; // e.g. 3 periods, 75 Hz: 10 milliseconds
287
288 switch (method) {
289 case AC_HANNINGcxx . . $ `fon/Sound_to_Pitch.cpp:39:9`!:
290 brent_depth = NUM_PEAK_INTERPOLATE_SINC70cxx . . $ `melder/NUMinterpol.h:35:9`!;
291 interpolation_depth = 0.5;
292 break;
293 case AC_GAUSScxx . . $ `fon/Sound_to_Pitch.cpp:40:9`!:
294 periodsPerWindow *= 2; // because Gaussian window is twice as long
295 brent_depth = NUM_PEAK_INTERPOLATE_SINC700cxx . . $ `melder/NUMinterpol.h:36:9`!;
296 interpolation_depth = 0.25; // because Gaussian window is twice as long
297 break;
298 case FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`!:
299 brent_depth = NUM_PEAK_INTERPOLATE_SINC70cxx . . $ `melder/NUMinterpol.h:35:9`!;
300 interpolation_depth = 1.0;
301 break;
302 case FCC_ACCURATEcxx . . $ `fon/Sound_to_Pitch.cpp:42:9`!:
303 brent_depth = NUM_PEAK_INTERPOLATE_SINC700cxx . . $ `melder/NUMinterpol.h:36:9`!;
304 interpolation_depth = 1.0;
305 break;
306 }
307 volatile const double duration = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; // volatile, because we need to truncate to 64 bits
308 if (pitchFloor < periodsPerWindow / duration)
309 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"To analyse this Sound, “pitch floor” must not be less than ", periodsPerWindow / duration, U" Hz.");
310
311 /*
312 Determine the number of samples in the longest period.
313 We need this to compute the local mean of the sound (looking one period in both directions),
314 and to compute the local peak of the sound (looking half a period in both directions).
315 */
316 const integercxx . . $ integer# nsamp_period = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (1.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / pitchFloor);
317 const integercxx . . $ integer# halfnsamp_period = nsamp_period / 2 + 1;
318
319 Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& pitchCeiling, 0.5 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.);
320
321 /*
322 Determine window duration in seconds and in samples.
323 */
324 const double dt_window = periodsPerWindow / pitchFloor;
325 integercxx . . $ integer# nsamp_window = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (dt_window / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.);
326 const integercxx . . $ integer# halfnsamp_window = nsamp_window / 2 - 1;
327 if (halfnsamp_window < 2)
328 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Analysis window too short.");
329 nsamp_window = halfnsamp_window * 2;
330
331 /*
332 Determine the minimum and maximum lags.
333 */
334 const integercxx . . $ integer# minimumLag = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (2_integercxx . . $ `operator""_integer`(85240eb457c3721a)., Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (1.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / pitchCeiling));
335 const integercxx . . $ integer# maximumLag = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (nsamp_window / periodsPerWindow) + 2, nsamp_window);
336
337 /*
338 Determine the number of frames.
339 Fit as many frames as possible symmetrically in the total duration.
340 We do this even for the forward cross-correlation method,
341 because that allows us to compare the two methods.
342 */
343 try {
344 Sampled_shortTermAnalysiscxx . . $ Sampled_shortTermAnalysis(77f703705034c8a). (me, method >= FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`! ? 1.0 / pitchFloor + dt_window : dt_window, dt, & numberOfFrames, & t1);
345 } catch (MelderErrorcxx . . $ MelderError#) {
346 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The pitch analysis would give zero pitch frames.");
347 }
348
349 /*
350 Create the resulting pitch contour.
351 */
352 autoPitchcxx . . $ autoPitch# thee = Pitch_createcxx . . $ Pitch_create(15f7ea67007465c5). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfFrames, dt, t1, pitchCeiling, maxnCandidates);
353
354 /*
355 Create (too much) space for candidates.
356 */
357 for (integercxx . . $ integer# iframe = 1; iframe <= numberOfFrames; iframe ++) {
358 const Pitch_Framecxx . . $ Pitch_Frame# pitchFrame = & thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structPitch#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
359 Pitch_Frame_initcxx . . $ Pitch_Frame_init(dff4ec8b4c81c245). (pitchFrame, maxnCandidates);
360 }
361
362 /*
363 Compute the global absolute peak for determination of silence threshold.
364 */
365 globalPeak = 0.0;
366 for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) {
367 const double mean = NUMmeancxx . . $ NUMmean(4bb9c3e3a8dd5442). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan));
368 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) {
369 double value = fabscxx . . $ fabs(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] - mean);
370 if (value > globalPeak)
371 globalPeak = value;
372 }
373 }
374 if (globalPeak == 0.0)
375 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
376
377 autoVECcxx . . $ autoVEC# windowcxx . . $ autovector#autovector(49f6e7a06ebc5aa8)., windowRcxx . . $ autovector#autovector(49f6e7a06ebc5aa8).;
378 if (method >= FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`!) { // for cross-correlation analysis
379
380 nsampFFT = 0;
381 brent_ixmax = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (nsamp_window * interpolation_depth);
382
383 } else { // for autocorrelation analysis
384
385 /*
386 Compute the number of samples needed for doing FFT.
387 To avoid edge effects, we have to append zeroes to the window.
388 The maximum lag considered for maxima is maximumLag.
389 The maximum lag used in interpolation is nsamp_window * interpolation_depth.
390 */
391 nsampFFT = 1;
392 while (nsampFFT < nsamp_window * (1 + interpolation_depth))
393 nsampFFT *= 2;
394
395 /*
396 Create buffers for autocorrelation analysis.
397 */
398 windowR. resizecxx . . $ autovector#resize(d91e89fbd57cd1). (nsampFFT);
399 window. resizecxx . . $ autovector#resize(d91e89fbd57cd1). (nsamp_window);
400 autoNUMFourierTablecxx . . $ autoNUMFourierTable# fftTable = NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (nsampFFT);
401
402 /*
403 A Gaussian or Hanning window is applied against phase effects.
404 The Hanning window is 2 to 5 dB better for 3 periods/window.
405 The Gaussian window is 25 to 29 dB better for 6 periods/window.
406 */
407 if (method == AC_GAUSScxx . . $ `fon/Sound_to_Pitch.cpp:40:9`!) { // Gaussian window
408 double imid = 0.5 * (nsamp_window + 1), edge = expcxx . . $ exp(fee4f1d22bc8e617). (-12.0);
409 for (integercxx . . $ integer# i = 1; i <= nsamp_window; i ++)
410 window [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = (expcxx . . $ exp(fee4f1d22bc8e617). (-48.0 * (i - imid) * (i - imid) /
411 (nsamp_window + 1) / (nsamp_window + 1)) - edge) / (1.0 - edge);
412 } else { // Hanning window
413 for (integercxx . . $ integer# i = 1; i <= nsamp_window; i ++)
414 window [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.5 - 0.5 * coscxx . . $ cos(fee4f1d22bc8e617). (NUM2picxx . . $ NUM2pi. * i / (nsamp_window + 1));
415 }
416
417 /*
418 Compute the normalized autocorrelation of the window.
419 */
420 for (integercxx . . $ integer# i = 1; i <= nsamp_window; i ++)
421 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = window [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i];
422 NUMfft_forwardcxx . . $ NUMfft_forward(aea41fd94d07eee). (fftTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), windowR.getcxx . . $ autovector#get(e8d1da7fe68a6585).());
423 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] *= windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; // DC component
424 for (integercxx . . $ integer# i = 2; i < nsampFFT; i += 2) {
425 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] + windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] * windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1];
426 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] = 0.0; // power spectrum: square and zero
427 }
428 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nsampFFT] *= windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nsampFFT]; // Nyquist frequency
429 NUMfft_backwardcxx . . $ NUMfft_backward(aea41fd94d07eee). (fftTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), windowR.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); // autocorrelation
430 for (integercxx . . $ integer# i = 2; i <= nsamp_window; i ++)
431 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] /= windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; // normalize
432 windowR [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = 1.0; // normalize
433
434 brent_ixmax = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (nsamp_window * interpolation_depth);
435 }
436
437 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Sound to Pitch...");
438 if (MelderThread_TRACINGcxx . . $ `melder/MelderThread.h:353:9`!)
439 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"channel frame time pitch");
440
441 MelderThread_PARALLELcxx . . $ `melder/MelderThread.h:173:9`! (numberOfFrames, 5) {
442 autoMATcxx . . $ autoMAT# framecxx . . $ automatrix#automatrix(49f6e7a06ebc5aa8).;
443 autoNUMFourierTablecxx . . $ autoNUMFourierTable# fftTablecxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
444 autoVECcxx . . $ autoVEC# accxx . . $ autovector#autovector(49f6e7a06ebc5aa8).;
445 if (method >= FCC_NORMALcxx . . $ `fon/Sound_to_Pitch.cpp:41:9`!) { // cross-correlation
446 frame =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., nsamp_window);
447 } else { // autocorrelation
448 fftTable =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (nsampFFT);
449 frame =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., nsampFFT);
450 ac =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (nsampFFT);
451 }
452 autoVECcxx . . $ autoVEC# rbuffer = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (2 * nsamp_window + 1);
453 double *r = & rbuffer [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1 + nsamp_window];
454 autoINTVECcxx . . $ autoINTVEC# imax = zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (maxnCandidates);
455 autoVECcxx . . $ autoVEC# localMean = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.);
456 MelderThread_FORcxx . . $ `melder/MelderThread.h:183:9`! (iframe) {
457 Pitch_Framecxx . . $ Pitch_Frame# pitchFrame = & thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structPitch#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe];
458 const double time = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), iframe);
459 if (MelderThread_IS_MASTERcxx . . $ `melder/MelderThread.h:199:9`!) { // then we can interact with the GUI
460 const double estimatedProgress = MelderThread_ESTIMATED_PROGRESScxx . . $ `melder/MelderThread.h:202:9`!;
461 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (0.1 + 0.8 * estimatedProgress,
462 U"Sound to Pitch: analysed approximately ", Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (numberOfFrames * estimatedProgress),
463 U" out of ", numberOfFrames, U" frames"
464 );
465 }
466 Sound_into_PitchFramecxx . . $ Sound_into_PitchFrame(73a3b988b8c9c365). (me, pitchFrame, time,
467 pitchFloor, maxnCandidates, method, voicingThreshold, octaveCost,
468 fftTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), dt_window, nsamp_window, halfnsamp_window,
469 maximumLag, nsampFFT, nsamp_period, halfnsamp_period,
470 brent_ixmax, brent_depth, globalPeak,
471 frame.getcxx . . $ automatrix#get(b2b81450b5bdda66).(), ac.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), window.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), windowR.getcxx . . $ autovector#get(e8d1da7fe68a6585).(),
472 r, imax.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), localMean.getcxx . . $ autovector#get(e8d1da7fe68a6585).()
473 );
474 if (MelderThread_TRACINGcxx . . $ `melder/MelderThread.h:353:9`!)
475 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (MelderThread_CHANNELcxx . . $ `melder/MelderThread.h:356:9`!, U" ", iframe, U" ", time, U" ", pitchFrame -> candidatescxx . . $ structPitch_Frame#candidates. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. frequencycxx . . $ structPitch_Candidate#frequency.);
476 }
477 } MelderThread_ENDPARALLELcxx . . $ `melder/MelderThread.h:189:9`!
478
479 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (0.95, U"Sound to Pitch: path finder");
480 Pitch_pathFindercxx . . $ Pitch_pathFinder(1fcb5d56a334b7ea). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), silenceThreshold, voicingThreshold,
481 octaveCost, octaveJumpCost, voicedUnvoicedCost, pitchCeiling, Melder_debugcxx . . $ Melder_debug. == 31 ? true : false);
482
483 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
484 } catch (MelderErrorcxx . . $ MelderError#) {
485 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": pitch analysis not performed.");
486 }
487 }
488
489 autoPitchcxx . . $ autoPitch# Sound_to_Pitchcxx . . $ Sound_to_Pitch(c773ddec40eb7e2b). (Soundcxx . . $ Sound# me, double timeStep, double pitchFloor, double pitchCeiling) {
490 return Sound_to_Pitch_rawAccxx . . $ Sound_to_Pitch_rawAc(309fd25349cae727). (me, timeStep, pitchFloor, pitchCeiling,
491 15, false, 0.03, 0.45, 0.01, 0.35, 0.14);
492 }
493
494 autoPitchcxx . . $ autoPitch# Sound_to_Pitch_rawAccxx . . $ Sound_to_Pitch_rawAc(309fd25349cae727). (Soundcxx . . $ Sound# me,
495 double timeStep, double pitchFloor, double pitchCeiling,
496 integercxx . . $ integer# maxnCandidates, bool veryAccurate,
497 double silenceThreshold, double voicingThreshold,
498 double octaveCost, double octaveJumpCost, double voicedUnvoicedCost)
499 {
500 return Sound_to_Pitch_anycxx . . $ Sound_to_Pitch_any(29e703e14008e8fa). (me, (int) veryAccurate, 3.0,
501 timeStep, pitchFloor, pitchCeiling,
502 maxnCandidates,
503 silenceThreshold, voicingThreshold, octaveCost, octaveJumpCost, voicedUnvoicedCost
504 );
505 }
506
507 autoPitchcxx . . $ autoPitch# Sound_to_Pitch_rawCccxx . . $ Sound_to_Pitch_rawCc(309fd25349cae727). (Soundcxx . . $ Sound# me,
508 double timeStep, double pitchFloor, double pitchCeiling,
509 integercxx . . $ integer# maxnCandidates, bool veryAccurate,
510 double silenceThreshold, double voicingThreshold,
511 double octaveCost, double octaveJumpCost, double voicedUnvoicedCost)
512 {
513 return Sound_to_Pitch_anycxx . . $ Sound_to_Pitch_any(29e703e14008e8fa). (me, 2 + (int) veryAccurate, 1.0,
514 timeStep, pitchFloor, pitchCeiling,
515 maxnCandidates,
516 silenceThreshold, voicingThreshold, octaveCost, octaveJumpCost, voicedUnvoicedCost
517 );
518 }
519
520 autoPitchcxx . . $ autoPitch# Sound_to_Pitch_filteredAccxx . . $ Sound_to_Pitch_filteredAc(1339e7d217e38bc7). (Soundcxx . . $ Sound# me,
521 double timeStep, double pitchFloor, double pitchTop,
522 integercxx . . $ integer# maxnCandidates, bool veryAccurate,
523 double attenuationAtTop,
524 double silenceThreshold, double voicingThreshold,
525 double octaveCost, double octaveJumpCost, double voicedUnvoicedCost)
526 {
527 try {
528 const double lowPassCutoffFrequency = pitchTop / NUMsqrt_ecxx . . $ NUMsqrt_e(447c67c6676f75c3). (-2.0 * logcxx . . $ log(fee4f1d22bc8e617). (attenuationAtTop));
529 autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me);
530 if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1) {
531 autoSpectrumcxx . . $ autoSpectrum# spec = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). (me, true);
532 for (integercxx . . $ integer# ibin = 1; ibin <= spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx.; ibin ++) {
533 const double frequency = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ibin);
534 const double factor = expcxx . . $ exp(fee4f1d22bc8e617). (-0.5 * sqrcxx . . $ sqr(ada6a8422704cf8a). (frequency / lowPassCutoffFrequency));
535 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
536 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
537 }
538 autoSoundcxx . . $ autoSound# him = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
539 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.);
540 } else {
541 for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) {
542 autoSoundcxx . . $ autoSound# channel = Sound_extractChannelcxx . . $ Sound_extractChannel(fdb1ba3dfee1bd33). (me, ichan);
543 autoSpectrumcxx . . $ autoSpectrum# spec = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). (channel.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), true);
544 for (integercxx . . $ integer# ibin = 1; ibin <= spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx.; ibin ++) {
545 const double frequency = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ibin);
546 const double factor = expcxx . . $ exp(fee4f1d22bc8e617). (-0.5 * sqrcxx . . $ sqr(ada6a8422704cf8a). (frequency / lowPassCutoffFrequency));
547 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
548 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
549 }
550 autoSoundcxx . . $ autoSound# him = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
551 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan) <<=cxx . . $ `operator<<=`(adea042513329390). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.);
552 }
553 }
554 return Sound_to_Pitch_anycxx . . $ Sound_to_Pitch_any(29e703e14008e8fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), (int) veryAccurate, 3.0,
555 timeStep, pitchFloor, pitchTop,
556 maxnCandidates,
557 silenceThreshold, voicingThreshold, octaveCost, octaveJumpCost, voicedUnvoicedCost
558 );
559 } catch (MelderErrorcxx . . $ MelderError#) {
560 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": pitch analysis (filtered AC) not performed.");
561 }
562 }
563
564 autoPitchcxx . . $ autoPitch# Sound_to_Pitch_filteredCccxx . . $ Sound_to_Pitch_filteredCc(1339e7d217e38bc7). (Soundcxx . . $ Sound# me,
565 double timeStep, double pitchFloor, double pitchTop,
566 integercxx . . $ integer# maxnCandidates, bool veryAccurate,
567 double attenuationAtTop,
568 double silenceThreshold, double voicingThreshold,
569 double octaveCost, double octaveJumpCost, double voicedUnvoicedCost)
570 {
571 try {
572 const double lowPassCutoffFrequency = pitchTop / NUMsqrt_ecxx . . $ NUMsqrt_e(447c67c6676f75c3). (-2.0 * logcxx . . $ log(fee4f1d22bc8e617). (attenuationAtTop));
573 autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me);
574 if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1) {
575 autoSpectrumcxx . . $ autoSpectrum# spec = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). (me, true);
576 for (integercxx . . $ integer# ibin = 1; ibin <= spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx.; ibin ++) {
577 const double frequency = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ibin);
578 const double factor = expcxx . . $ exp(fee4f1d22bc8e617). (-0.5 * sqrcxx . . $ sqr(ada6a8422704cf8a). (frequency / lowPassCutoffFrequency));
579 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
580 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
581 }
582 autoSoundcxx . . $ autoSound# him = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
583 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.);
584 } else {
585 for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) {
586 autoSoundcxx . . $ autoSound# channel = Sound_extractChannelcxx . . $ Sound_extractChannel(fdb1ba3dfee1bd33). (me, ichan);
587 autoSpectrumcxx . . $ autoSpectrum# spec = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). (channel.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), true);
588 for (integercxx . . $ integer# ibin = 1; ibin <= spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nxcxx . . $ structSampled#nx.; ibin ++) {
589 const double frequency = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ibin);
590 const double factor = expcxx . . $ exp(fee4f1d22bc8e617). (-0.5 * sqrcxx . . $ sqr(ada6a8422704cf8a). (frequency / lowPassCutoffFrequency));
591 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
592 spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] *= factor;
593 }
594 autoSoundcxx . . $ autoSound# him = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
595 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan) <<=cxx . . $ `operator<<=`(adea042513329390). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.);
596 }
597 }
598 return Sound_to_Pitch_anycxx . . $ Sound_to_Pitch_any(29e703e14008e8fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 2 + (int) veryAccurate, 1.0,
599 timeStep, pitchFloor, pitchTop,
600 maxnCandidates,
601 silenceThreshold, voicingThreshold, octaveCost, octaveJumpCost, voicedUnvoicedCost
602 );
603 } catch (MelderErrorcxx . . $ MelderError#) {
604 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": pitch analysis (filtered CC) not performed.");
605 }
606 }
607
608 /* End of file Sound_to_Pitch.cpp */