| 1 |
#ifndef _FormantPath_h_ |
| 2 |
#define _FormantPath_h_ |
| 3 |
/* FormantPath.h |
| 4 |
* |
| 5 |
* Copyright (C) 2020-2023 David Weenink |
| 6 |
* |
| 7 |
* This code is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 10 |
* your option) any later version. |
| 11 |
* |
| 12 |
* This code is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "Collection.h" |
| 22 |
#include "Formant.h" |
| 23 |
#include "Function.h" |
| 24 |
#include "LPC.h" |
| 25 |
#include "Sound.h" |
| 26 |
#include "Table.h" |
| 27 |
#include "TextGrid.h" |
| 28 |
|
| 29 |
#include "FormantPath_def.h" |
| 30 |
|
| 31 |
/* |
| 32 |
A FormantPath inherits from Sampled and contains: |
| 33 |
|
| 34 |
1. An ordered collection of N Formant objects. |
| 35 |
2. A vector of size N with ceiling frequencies in hertz. Ceiling [i] contains the formant ceiling frequency |
| 36 |
that was used to calculate the corresponding Formant from the sound. |
| 37 |
3. A TextGrid in which an intervalTier determines a path. |
| 38 |
Each interval is labeled with an integer number that refers to one of the Formant objects (an integer number |
| 39 |
was chosen instead of the ceiling frequency wich is a real number, because integers can be more easily compared |
| 40 |
for equivalence than real numbers.) |
| 41 |
*/ |
| 42 |
|
| 43 |
autoFormantPath FormantPath_create (double xmin, double xmax, integer nx, double dx, double x1, integer numberOfCandidates); |
| 44 |
|
| 45 |
integer FormantPath_getNumberOfFormantTracks (FormantPath me); |
| 46 |
|
| 47 |
autoTable FormantPath_downTo_Table_optimalInterval (FormantPath me, double tmin, double tmax, |
| 48 |
constINTVEC const& parameters, double powerf, bool includeFrameNumber, bool includeTime, integer numberOfTimeDecimals, |
| 49 |
bool includeIntensity, integer numberOfIntensityDecimals, bool includeNumberOfFormants, integer numberOfFrequencyDecimals, |
| 50 |
bool includeBandwidths, bool includeOptimalCeiling, bool includeMinimumStress); |
| 51 |
|
| 52 |
autoTable FormantPath_downTo_Table_stresses (FormantPath me, double tmin, double tmax, constINTVEC const& parameters, |
| 53 |
double powerf, integer numberOfStressDecimals, bool includeIntervalTimes, integer numberOfTimeDecimals); |
| 54 |
|
| 55 |
autoFormant FormantPath_extractFormant (FormantPath me); |
| 56 |
|
| 57 |
autoMatrix FormantPath_to_Matrix_qSums (FormantPath me, integer numberOfTracks); |
| 58 |
autoMatrix FormantPath_to_Matrix_transition (FormantPath me, integer numberOfTracks, bool maximumCosts); |
| 59 |
autoMatrix FormantPath_to_Matrix_stress (FormantPath me, double windowLength, constINTVEC const& parameters, double powerf); |
| 60 |
|
| 61 |
double FormantPath_getStressOfCandidate (FormantPath me, double tmin, double tmax, integer fromFormant, integer toFormant, |
| 62 |
constINTVEC const& parameters, double powerf, integer candidate); |
| 63 |
|
| 64 |
autoVEC FormantPath_getStressOfCandidates (FormantPath me, double tmin, double tmax, integer fromFormant, integer toFormant, |
| 65 |
constINTVEC const& parameters, double powerf); |
| 66 |
|
| 67 |
double FormantPath_getOptimalCeiling (FormantPath me, double tmin, double tmax, constINTVEC const& parameters, double powerf); |
| 68 |
|
| 69 |
autoINTVEC FormantPath_getOptimumPath (FormantPath me, double qWeight, double frequencyChangeWeight, double stressWeight, |
| 70 |
double ceilingChangeWeight, double intensityModulationStepSize, double windowLength, constINTVEC const& parameters, |
| 71 |
double powerf, autoMatrix *out_delta); |
| 72 |
|
| 73 |
void FormantPath_setPath (FormantPath me, double tmin, double tmax, integer selectedCandidate); |
| 74 |
void FormantPath_setOptimalPath (FormantPath me, double tmin, double tmax, constINTVEC const& parameters, double powerf); |
| 75 |
|
| 76 |
void FormantPath_pathFinder (FormantPath me, double qWeight, double frequencyChangeWeight, double stressWeight, |
| 77 |
double ceilingChangeWeight, double intensityModulationStepSize, double windowLength, constINTVEC const& parameters, |
| 78 |
double powerf); |
| 79 |
|
| 80 |
autoFormantPath Sound_to_FormantPath_any (Sound me, kLPC_Analysis lpcType, double timeStep, double maximumNumberOfFormants, |
| 81 |
double formantCeiling, double analysisWidth, double preemphasisFrequency, double ceilingExtensionFraction, |
| 82 |
integer numberOfStepsUpDown, double marple_tol1, double marple_tol2, double huber_numberOfStdDev, |
| 83 |
double huber_tol, integer huber_maximumNumberOfIterations, autoSound *out_sourcesMultiChannel |
| 84 |
); |
| 85 |
|
| 86 |
static inline autoFormantPath Sound_to_FormantPath_burg (Sound me, double timeStep, double maximumNumberOfFormants, |
| 87 |
double formantCeiling, double analysisWidth, double preemphasisFrequency, double ceilingExtensionFraction, integer numberOfStepsUpDown) |
| 88 |
{ |
| 89 |
return Sound_to_FormantPath_any (me, kLPC_Analysis::BURG, timeStep, maximumNumberOfFormants, |
| 90 |
formantCeiling, analysisWidth, preemphasisFrequency, ceilingExtensionFraction, numberOfStepsUpDown, 1e-6, 1e-6, 1.5, 1e-6, 5, nullptr); |
| 91 |
} |
| 92 |
|
| 93 |
static inline autoFormantPath Sound_to_FormantPath_robust (Sound me, double timeStep, double maximumNumberOfFormants, |
| 94 |
double formantCeiling, double analysisWidth, double preemphasisFrequency, double numberOfStandardDeviations, |
| 95 |
integer maximumNumberOfIterations, double tolerance, double ceilingExtensionFraction, integer numberOfStepsUpDown) |
| 96 |
{ |
| 97 |
return Sound_to_FormantPath_any (me, kLPC_Analysis::ROBUST, timeStep, maximumNumberOfFormants, |
| 98 |
formantCeiling, analysisWidth, preemphasisFrequency, ceilingExtensionFraction, numberOfStepsUpDown, 1e-6, 1e-6, numberOfStandardDeviations, tolerance, maximumNumberOfIterations, nullptr); |
| 99 |
} |
| 100 |
|
| 101 |
void FormantPath_drawAsGrid (FormantPath me, Graphics g, double tmin, double tmax, double fmax, |
| 102 |
integer fromFormant, integer toFormant, bool showBandwidths, MelderColour oddNumberedFormants, MelderColour evenNumberedFormants, |
| 103 |
integer nrow, integer ncol, double spaceBetweenFraction_x, double spaceBetweenFraction_y, double yGridLineEvery_Hz, |
| 104 |
double xCursor, double yCursor, MelderColour selected, constINTVEC const& parameters, |
| 105 |
bool markCandidatesWithinPath, bool showStress, double powerf, bool showEstimatedModels, bool garnish); |
| 106 |
|
| 107 |
void FormantPath_drawAsGrid_inside (FormantPath me, Graphics g, double tmin, double tmax, double fmax, |
| 108 |
integer fromFormant, integer toFormant, bool showBandwidths, MelderColour oddNumberedFormants, MelderColour evenNumberedFormants, |
| 109 |
integer nrow, integer ncol, double spaceBetweenFraction_x, double spaceBetweenFraction_y, double yGridLineEvery_Hz, |
| 110 |
double xCursor, double yCursor, MelderColour selected, constINTVEC const& parameters, |
| 111 |
bool markCandidatesWithinPath, bool showStress, double powerf, bool showEstimatedModels, bool garnish); |
| 112 |
|
| 113 |
void FormantPath_getCandidateAtTime (FormantPath me, double time, double *out_tmin, double *out_tmax, integer *out_candidate); |
| 114 |
|
| 115 |
integer FormantPath_getCandidateInFrame (FormantPath me, integer iframe); |
| 116 |
|
| 117 |
integer FormantPath_getUniqueCandidateInInterval (FormantPath me, double tmin, double tmax); |
| 118 |
|
| 119 |
inline conststring32 FormantPath_getCeilingFrequency_string (FormantPath me, integer candidate) { |
| 120 |
Melder_assert (candidate > 0 && candidate <= my ceilings.size); |
| 121 |
const double ceilingFrequency = my ceilings [candidate]; |
| 122 |
return Melder_double (ceilingFrequency); |
| 123 |
} |
| 124 |
|
| 125 |
/* |
| 126 |
Only needed to convert from version 0 |
| 127 |
*/ |
| 128 |
autoTextGrid FormantPath_to_TextGrid_version0 (FormantPath me, INTVEC const& path); |
| 129 |
|
| 130 |
#endif /* _FormantPath_h_ */ |