Debian Codegraph @

fon/Excitation_to_Formant.cpp

raw symbols SCIP
1 /* Excitation_to_Formant.cpp
2 *
3 * Copyright (C) 1992-2011,2015-2020,2023 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 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "Excitation_to_Formant.h"cxx . . $ `<file>/fon/Excitation_to_Formant.h`/
20
21 autoFormantcxx . . $ autoFormant# Excitation_to_Formantcxx . . $ Excitation_to_Formant(6d6ed3f2ff278dde). (Excitationcxx . . $ Excitation# me, integercxx . . $ integer# maximumNumberOfFormants) {
22 try {
23 integercxx . . $ integer# numberOfFrequencies = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.;
24 double *p = & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0];
25
26 autoFormantcxx . . $ autoFormant# thee = Formant_createcxx . . $ Formant_create(c4f62f8fc805b821). (0.0, 1.0, 1, 1.0, 0.5, maximumNumberOfFormants);
27 for (integercxx . . $ integer# i = 2; i < numberOfFrequencies; i ++)
28 if (p [i] > p [i - 1] && p [i] >= p [i + 1]) {
29 double firstDerivative = p [i+1] - p [i-1], secondDerivative = 2 * p [i] - p [i-1] - p [i+1];
30 Formant_Formantcxx . . $ Formant_Formant# formant = thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. formantcxx . . $ structFormant_Frame#formant.. appendcxx . . $ autovector#append(155dc7f103cdb9db).();
31 formant -> frequencycxx . . $ structFormant_Formant#frequency. = NUMbarkToHertzcxx . . $ NUMbarkToHertz(447c67c6676f75c3). (
32 mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * (i - 1 + 0.5 * firstDerivative / secondDerivative));
33 double min3phon = p [i] + 0.125 * firstDerivative * firstDerivative / secondDerivative - 3.0;
34 /*
35 Search to the left.
36 */
37 integercxx . . $ integer# j = i - 1;
38 while (p [j] > min3phon && j > 1)
39 j --;
40 const double left = NUMbarkToHertzcxx . . $ NUMbarkToHertz(447c67c6676f75c3). (
41 p [j] > min3phon ? mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. : mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * (j - 1 + (min3phon - p [j]) / (p [j + 1] - p [j])));
42 /*
43 Search to the right.
44 */
45 j = i + 1;
46 while (p [j] > min3phon && j < numberOfFrequencies)
47 j ++;
48 const double right = NUMbarkToHertzcxx . . $ NUMbarkToHertz(447c67c6676f75c3). (
49 p [j] > min3phon ? mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. : mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * (j - 1 - (min3phon - p [j]) / (p [j - 1] - p [j])));
50 formant -> bandwidthcxx . . $ structFormant_Formant#bandwidth. = right - left;
51 if (thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. formantcxx . . $ structFormant_Frame#formant..sizecxx . . $ autovector#size. == thycxx . . $ `melder/melder.h:45:9`! maxnFormantscxx . . $ structFormant#maxnFormants.)
52 break;
53 }
54 thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. numberOfFormantscxx . . $ structFormant_Frame#numberOfFormants. = thycxx . . $ `melder/melder.h:45:9`! framescxx . . $ structFormant#frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. formantcxx . . $ structFormant_Frame#formant..sizecxx . . $ autovector#size.; // maintain invariant
55 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
56 } catch (MelderErrorcxx . . $ MelderError#) {
57 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Formant.");
58 }
59 }
60
61 /* End of file Excitation_to_Formant.cpp */