Debian Codegraph @

fon/Pitch_AnyTier_to_PitchTier.cpp

raw
1 /* Pitch_AnyTier_to_PitchTier.cpp
2 *
3 * Copyright (C) 1992-2011,2015,2016,2017 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 "Pitch_AnyTier_to_PitchTier.h"
20 #include "Pitch_to_PitchTier.h"
21
22 autoPitchTier PitchTier_AnyTier_to_PitchTier (PitchTier pitch, AnyTier tier) {
23 try {
24 if (pitch -> points.size == 0) Melder_throw (U"No pitch points.");
25
26 /*
27 * Result's domain is a union of both domains.
28 */
29 autoPitchTier thee = PitchTier_create (
30 pitch -> xmin < tier -> xmin ? pitch -> xmin : tier -> xmin,
31 pitch -> xmax > tier -> xmax ? pitch -> xmax : tier -> xmax);
32
33 /*
34 * Copy pitch's frequencies at tier's points to the resulting PitchTier.
35 */
36 for (integer ipoint = 1; ipoint <= tier -> points.size; ipoint ++) {
37 AnyPoint point = tier -> points.at [ipoint];
38 double time = point -> number;
39 double frequency = RealTier_getValueAtTime (pitch, time);
40 RealTier_addPoint (thee.get(), time, frequency);
41 }
42
43 return thee;
44 } catch (MelderError) {
45 Melder_throw (pitch, U" & ", tier, U": not converted to PitchTier.");
46 }
47 }
48
49 autoPitchTier Pitch_AnyTier_to_PitchTier (Pitch pitch, AnyTier tier, int checkMethod) {
50 try {
51 if (checkMethod == 2) {
52 autoPitchTier temp = Pitch_to_PitchTier (pitch);
53 return PitchTier_AnyTier_to_PitchTier (temp.get(), tier);
54 }
55
56 /*
57 * Result's domain is a union of both domains.
58 */
59 autoPitchTier thee = PitchTier_create (
60 pitch -> xmin < tier -> xmin ? pitch -> xmin : tier -> xmin,
61 pitch -> xmax > tier -> xmax ? pitch -> xmax : tier -> xmax);
62
63 /*
64 * Copy pitch's frequencies at tier's points to the resulting PitchTier.
65 */
66 for (integer ipoint = 1; ipoint <= tier -> points.size; ipoint ++) {
67 AnyPoint point = tier -> points.at [ipoint];
68 double time = point -> number;
69 double frequency = Pitch_getValueAtTime (pitch, time, kPitch_unit::HERTZ, Pitch_LINEAR);
70 if (isundef (frequency) && checkMethod != 0)
71 Melder_throw (U"No periodicity at time ", time, U" seconds.");
72 RealTier_addPoint (thee.get(), time, frequency);
73 }
74
75 return thee;
76 } catch (MelderError) {
77 Melder_throw (pitch, U" & ", tier, U": not converted to PitchTier.");
78 }
79 }
80
81 /* End of file Pitch_AnyTier_to_PitchTier.cpp */