| 1 |
/* FormantPath_to_IntervalTier.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 2020-2023 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 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. 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_to_IntervalTier.h" |
| 20 |
|
| 21 |
static void IntervalTier_addCandidate (IntervalTier me, double splitTime, integer candidate) { |
| 22 |
conststring32 label = Melder_integer (candidate); |
| 23 |
TextInterval last = my intervals.at [my intervals.size]; |
| 24 |
last -> xmax = splitTime; |
| 25 |
last -> text = Melder_dup (label); |
| 26 |
autoTextInterval interval = TextInterval_create (splitTime, my xmax, U""); |
| 27 |
my intervals. addItem_move (interval.move()); |
| 28 |
} |
| 29 |
|
| 30 |
#if 0 |
| 31 |
autoIntervalTier FormantPath_to_IntervalTier (FormantPath me, double tmin, double tmax) { |
| 32 |
autoIntervalTier thee = IntervalTier_create (tmin, tmax); |
| 33 |
integer ifmin, ifmax; |
| 34 |
Sampled_getWindowSamples (me, tmin, tmax, & ifmin, & ifmax); |
| 35 |
/* |
| 36 |
If the interval [tmin, tmax] did not overlap any samples and falls |
| 37 |
inbetween two successive samples that have index i1 and i1+1, |
| 38 |
itmin == i1+1 && itmax == i1; |
| 39 |
*/ |
| 40 |
integer startIndex = Sampled_xToNearestIndex (me, tmin); |
| 41 |
Melder_clipLeft (1_integer, & startIndex); |
| 42 |
integer candidate = my path [startIndex]; |
| 43 |
for (integer iframe = ifmin; iframe <= ifmax; iframe ++) { |
| 44 |
if (my path [iframe] != candidate) { |
| 45 |
const double endTime = Sampled_indexToX (me, iframe) - 0.5 * my dx; |
| 46 |
IntervalTier_addCandidate (thee.get(), endTime, candidate); |
| 47 |
candidate = my path [iframe]; |
| 48 |
} |
| 49 |
} |
| 50 |
integer endIndex = Sampled_xToNearestIndex (me, tmax); |
| 51 |
Melder_clipRight (& endIndex, my nx); |
| 52 |
integer endCandidate = my path [endIndex]; |
| 53 |
if (endCandidate != candidate) { |
| 54 |
const double endTime = Sampled_indexToX (me, ifmax) + 0.5 * my dx; |
| 55 |
IntervalTier_addCandidate (thee.get(), endTime, candidate); |
| 56 |
candidate = endCandidate; |
| 57 |
} |
| 58 |
/* |
| 59 |
Set label on last interval |
| 60 |
*/ |
| 61 |
const TextInterval textInterval = thy intervals.at [thy intervals.size]; |
| 62 |
TextInterval_setText (textInterval, Melder_integer (candidate)); |
| 63 |
return thee; |
| 64 |
} |
| 65 |
#endif |
| 66 |
/* End of file FormantPath_to_IntervalTier.cpp */ |