| 1 | #cxx . . $ `<file>/fon/Pitch.h`/ifndef _Pitch_h_ |
| 2 | #define _Pitch_h_cxx . . $ `fon/Pitch.h:2:9`! |
| 3 | /* Pitch.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2007,2009,2011,2012,2014-2020 Paul Boersma |
| 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. |
| 15 | * See the GNU 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 "Sampled.h"cxx . . $ `<file>/fon/Sampled.h`/ |
| 22 | #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/ |
| 23 | #include "Table.h"cxx . . $ `<file>/stat/Table.h`/ |
| 24 | Thing_declarecxx . . $ SomeThingHandle# (Interpreter); |
| 25 | |
| 26 | #include "Pitch_enums.h"cxx . . $ `<file>/fon/Pitch_enums.h`/ |
| 27 | #include "Pitch_def.h"cxx . . $ `<file>/fon/Pitch_def.h`/ |
| 28 | |
| 29 | autoPitchcxx . . $ autoPitch# Pitch_createcxx . . $ Pitch_create(15f7ea67007465c5). (double tmin, double tmax, integercxx . . $ integer# nt, double dt, double t1, |
| 30 | double ceiling, integercxx . . $ integer# maxnCandidates); |
| 31 | /* |
| 32 | Function: |
| 33 | create an empty pitch contour (voiceless). |
| 34 | Preconditions: |
| 35 | tmax > tmin; |
| 36 | nt >= 1; |
| 37 | dt > 0.0; |
| 38 | maxnCandidates >= 2; |
| 39 | Postconditions: |
| 40 | my xmin == tmin; |
| 41 | my xmax == tmax; |
| 42 | my nx == nt; |
| 43 | my dx == dt; |
| 44 | my x1 == t1; |
| 45 | my ceiling == ceiling; |
| 46 | my maxnCandidates == maxnCandidates; |
| 47 | my frame [1..nt]. nCandidates == 1; |
| 48 | my frame [1..nt]. candidate [1]. frequency == 0.0; // unvoiced |
| 49 | my frame [1..nt]. candidate [1]. strength == 0.0; // aperiodic |
| 50 | my frame [1..nt]. intensity == 0.0; // silent |
| 51 | */ |
| 52 | |
| 53 | void Pitch_Frame_initcxx . . $ Pitch_Frame_init(dff4ec8b4c81c245). (Pitch_Framecxx . . $ Pitch_Frame# me, integercxx . . $ integer# nCandidates); |
| 54 | /* |
| 55 | Function: |
| 56 | create space for a number of candidates; space already there is disposed of. |
| 57 | Preconditions: |
| 58 | nCandidates >= 1; |
| 59 | Postconditions: |
| 60 | my nCandidates == nCandidates; |
| 61 | my candidate [1..nCandidates]. frequency == 0.0; // unvoiced |
| 62 | my candidate [1..nCandidates]. strength == 0.0; // aperiodic |
| 63 | my intensity == 0.0; // silent |
| 64 | */ |
| 65 | |
| 66 | inline bool Pitch_util_frequencyIsVoicedcxx . . $ Pitch_util_frequencyIsVoiced(828b76dce88fac). (double f, double ceiling) { |
| 67 | return f > 0.0 && f < ceiling; // note: return false is f is NaN |
| 68 | } |
| 69 | |
| 70 | bool Pitch_isVoiced_icxx . . $ Pitch_isVoiced_i(fd5b671aa7b53262). (Pitchcxx . . $ Pitch# me, integercxx . . $ integer# index); |
| 71 | /* |
| 72 | Is the frame 'index' voiced? |
| 73 | A frame is considered voiced if the frequency of its first candidate |
| 74 | is greater than 0.0 but less than my ceiling. |
| 75 | Precondition: |
| 76 | index >= 1 && index <= my nx; |
| 77 | */ |
| 78 | |
| 79 | bool Pitch_isVoiced_tcxx . . $ Pitch_isVoiced_t(9b4a997843717fd9). (Pitchcxx . . $ Pitch# me, double t); |
| 80 | /* |
| 81 | Are you voiced at time `t`? |
| 82 | The answer is `true` iff `t` lies within a voiced frame. |
| 83 | */ |
| 84 | |
| 85 | #define Pitch_LEVEL_FREQUENCYcxx . . $ `fon/Pitch.h:85:9`! 1 |
| 86 | #define Pitch_LEVEL_STRENGTHcxx . . $ `fon/Pitch.h:86:9`! 2 |
| 87 | |
| 88 | #define Pitch_STRENGTH_UNIT_mincxx . . $ `fon/Pitch.h:88:9`! 0 |
| 89 | #define Pitch_STRENGTH_UNIT_AUTOCORRELATIONcxx . . $ `fon/Pitch.h:89:9`! 0 |
| 90 | #define Pitch_STRENGTH_UNIT_NOISE_HARMONICS_RATIOcxx . . $ `fon/Pitch.h:90:9`! 1 |
| 91 | #define Pitch_STRENGTH_UNIT_HARMONICS_NOISE_DBcxx . . $ `fon/Pitch.h:91:9`! 2 |
| 92 | #define Pitch_STRENGTH_UNIT_maxcxx . . $ `fon/Pitch.h:92:9`! 2 |
| 93 | |
| 94 | #define Pitch_NEARESTcxx . . $ `fon/Pitch.h:94:9`! 0 |
| 95 | #define Pitch_LINEARcxx . . $ `fon/Pitch.h:95:9`! 1 |
| 96 | |
| 97 | double Pitch_getValueAtTimecxx . . $ Pitch_getValueAtTime(b0f5a36024d7459c). (Pitchcxx . . $ Pitch# me, double time, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate); |
| 98 | double Pitch_getStrengthAtTimecxx . . $ Pitch_getStrengthAtTime(b0f5a36024d7459c). (Pitchcxx . . $ Pitch# me, double time, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate); |
| 99 | |
| 100 | integercxx . . $ integer# Pitch_countVoicedFramescxx . . $ Pitch_countVoicedFrames(997a30077526ca88). (Pitchcxx . . $ Pitch# me); |
| 101 | |
| 102 | double Pitch_getMeancxx . . $ Pitch_getMean(cc94e07c5e8f52a8). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit); |
| 103 | double Pitch_getMeanStrengthcxx . . $ Pitch_getMeanStrength(44948828c55500f8). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, int strengthUnit); |
| 104 | double Pitch_getQuantilecxx . . $ Pitch_getQuantile(5072ddcaf167d3af). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, double quantile, kPitch_unitcxx . . $ kPitch_unit# unit); |
| 105 | double Pitch_getStandardDeviationcxx . . $ Pitch_getStandardDeviation(cc94e07c5e8f52a8). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit); |
| 106 | void Pitch_getMaximumAndTimecxx . . $ Pitch_getMaximumAndTime(546369d10a3d6cd5). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate, |
| 107 | double *return_maximum, double *return_timeOfMaximum); |
| 108 | double Pitch_getMaximumcxx . . $ Pitch_getMaximum(d2c3727f00a8ab5d). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate); |
| 109 | double Pitch_getTimeOfMaximumcxx . . $ Pitch_getTimeOfMaximum(d2c3727f00a8ab5d). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate); |
| 110 | void Pitch_getMinimumAndTimecxx . . $ Pitch_getMinimumAndTime(546369d10a3d6cd5). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate, |
| 111 | double *return_minimum, double *return_timeOfMinimum); |
| 112 | double Pitch_getMinimumcxx . . $ Pitch_getMinimum(d2c3727f00a8ab5d). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate); |
| 113 | double Pitch_getTimeOfMinimumcxx . . $ Pitch_getTimeOfMinimum(d2c3727f00a8ab5d). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, kPitch_unitcxx . . $ kPitch_unit# unit, bool interpolate); |
| 114 | |
| 115 | integercxx . . $ integer# Pitch_getMaxnCandidatescxx . . $ Pitch_getMaxnCandidates(997a30077526ca88). (Pitchcxx . . $ Pitch# me); |
| 116 | /* |
| 117 | Returns the largest number of candidates actually attested in a frame. |
| 118 | */ |
| 119 | |
| 120 | void Pitch_setCeilingcxx . . $ Pitch_setCeiling(d3990d425b43aa2d). (Pitchcxx . . $ Pitch# me, double ceiling); |
| 121 | /* |
| 122 | Postcondition: |
| 123 | my ceiling = ceiling; |
| 124 | */ |
| 125 | |
| 126 | autoMATcxx . . $ autoMAT# Pitch_Frame_getAllCandidatescxx . . $ Pitch_Frame_getAllCandidates(bbd3ee3fcd574f92). (Pitch_Framecxx . . $ Pitch_Frame# me); |
| 127 | autoMATcxx . . $ autoMAT# Pitch_getAllCandidatesInFramecxx . . $ Pitch_getAllCandidatesInFrame(43dd165f7f88f76b). (Pitchcxx . . $ Pitch# me, integercxx . . $ integer# frameNumber); |
| 128 | |
| 129 | void Pitch_pathFindercxx . . $ Pitch_pathFinder(1fcb5d56a334b7ea). (Pitchcxx . . $ Pitch# me, double silenceThreshold, double voicingThreshold, |
| 130 | double octaveCost, double octaveJumpCost, double voicedUnvoicedCost, |
| 131 | double ceiling, int pullFormants); |
| 132 | |
| 133 | /* Drawing methods. */ |
| 134 | #define Pitch_speckle_NOcxx . . $ `fon/Pitch.h:134:9`! false |
| 135 | #define Pitch_speckle_YEScxx . . $ `fon/Pitch.h:135:9`! true |
| 136 | void Pitch_drawInsidecxx . . $ Pitch_drawInside(f80e0c98ecd25e28). (Pitchcxx . . $ Pitch# me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmin, double fmax, |
| 137 | bool speckle, kPitch_unitcxx . . $ kPitch_unit# yscale); |
| 138 | void Pitch_drawcxx . . $ Pitch_draw(65d8d523c77dc1c3). (Pitchcxx . . $ Pitch# me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmin, double fmax, bool garnish, |
| 139 | bool speckle, kPitch_unitcxx . . $ kPitch_unit# yscale); |
| 140 | /* |
| 141 | draw a pitch contour into a Graphics. |
| 142 | If tmax <= tmin, draw whole time domain. |
| 143 | */ |
| 144 | |
| 145 | void Pitch_differencecxx . . $ Pitch_difference(24913c87c2d9b791). (Pitchcxx . . $ Pitch# me, Pitchcxx . . $ Pitch# thee); |
| 146 | /* give information about frames that are different in me and thee. */ |
| 147 | |
| 148 | integercxx . . $ integer# Pitch_getMeanAbsSlope_hertzcxx . . $ Pitch_getMeanAbsSlope_hertz(c383aeae9ef2f409). (Pitchcxx . . $ Pitch# me, double *slope); |
| 149 | integercxx . . $ integer# Pitch_getMeanAbsSlope_melcxx . . $ Pitch_getMeanAbsSlope_mel(c383aeae9ef2f409). (Pitchcxx . . $ Pitch# me, double *slope); |
| 150 | integercxx . . $ integer# Pitch_getMeanAbsSlope_semitonescxx . . $ Pitch_getMeanAbsSlope_semitones(c383aeae9ef2f409). (Pitchcxx . . $ Pitch# me, double *slope); |
| 151 | integercxx . . $ integer# Pitch_getMeanAbsSlope_erbcxx . . $ Pitch_getMeanAbsSlope_erb(c383aeae9ef2f409). (Pitchcxx . . $ Pitch# me, double *slope); |
| 152 | integercxx . . $ integer# Pitch_getMeanAbsSlope_noOctavecxx . . $ Pitch_getMeanAbsSlope_noOctave(c383aeae9ef2f409). (Pitchcxx . . $ Pitch# me, double *slope); |
| 153 | /* |
| 154 | The value returned is the number of voiced frames (nVoiced); |
| 155 | this signals if the values are valid: |
| 156 | 'value', 'minimum', 'maximum', and 'mean' are valid if nVoiced >= 1; |
| 157 | 'variance' and 'slope' are valid if nVoiced >= 2. |
| 158 | Invalid variables are always set to 0.0. |
| 159 | 'minimum', 'maximum', 'mean', and 'variance' may be null. |
| 160 | */ |
| 161 | |
| 162 | MelderFractioncxx . . $ MelderFraction# Pitch_getFractionOfLocallyVoicedFramescxx . . $ Pitch_getFractionOfLocallyVoicedFrames(13be60e20f2c1d0a). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, |
| 163 | double ceiling, double silenceThreshold, double voicingThreshold); |
| 164 | MelderFractioncxx . . $ MelderFraction# Pitch_getFractionOfLocallyUnvoicedFramescxx . . $ Pitch_getFractionOfLocallyUnvoicedFrames(13be60e20f2c1d0a). (Pitchcxx . . $ Pitch# me, double tmin, double tmax, |
| 165 | double ceiling, double silenceThreshold, double voicingThreshold); |
| 166 | |
| 167 | autoPitchcxx . . $ autoPitch# Pitch_killOctaveJumpscxx . . $ Pitch_killOctaveJumps(2efd9ac11c35629f). (Pitchcxx . . $ Pitch# me); |
| 168 | /* Add octave jumps so that every pitch step, |
| 169 | including those across unvoiced frames, |
| 170 | does not exceed 1/2 octave. |
| 171 | Postcondition: |
| 172 | result -> ceiling = my ceiling * 2; |
| 173 | */ |
| 174 | |
| 175 | autoPitchcxx . . $ autoPitch# Pitch_interpolatecxx . . $ Pitch_interpolate(2efd9ac11c35629f). (Pitchcxx . . $ Pitch# me); |
| 176 | /* Interpolate the pitch values of unvoiced frames. */ |
| 177 | /* No extrapolation beyond first and last voiced frames. */ |
| 178 | |
| 179 | autoPitchcxx . . $ autoPitch# Pitch_subtractLinearFitcxx . . $ Pitch_subtractLinearFit(2045f9b8c890505e). (Pitchcxx . . $ Pitch# me, kPitch_unitcxx . . $ kPitch_unit# unit); |
| 180 | |
| 181 | autoPitchcxx . . $ autoPitch# Pitch_smoothcxx . . $ Pitch_smooth(8c3978e901f12399). (Pitchcxx . . $ Pitch# me, double bandWidth); |
| 182 | /* Smoothing by convolution with Gaussian curve. |
| 183 | Time domain: exp (- (pi t bandWidth) ^ 2) |
| 184 | down to 8.5 % for t = +- 0.5/bandWidth |
| 185 | Frequency domain: exp (- (f / bandWidth) ^ 2) |
| 186 | down to 1/e for f = +- bandWidth |
| 187 | Example: |
| 188 | if bandWidth = 10 Hz, |
| 189 | then the Gaussian curve has a 8.5% duration of 0.1 s, |
| 190 | and a 1/e low-pass point of 10 Hz. |
| 191 | Algorithm: |
| 192 | Interpolation of pitch at internal unvoiced parts. |
| 193 | Zeroth-degree extrapolation at edges (duration triples). |
| 194 | FFT; multiply by Gaussian; inverse FFT. |
| 195 | Cut back to normal duration. |
| 196 | Undo interpolation. |
| 197 | */ |
| 198 | |
| 199 | void Pitch_stepcxx . . $ Pitch_step(f6b5eeb97b0728b). (Pitchcxx . . $ Pitch# me, double step, double precision, double tmin, double tmax); |
| 200 | /* |
| 201 | Instead of the currently chosen candidate, |
| 202 | choose the candidate with another ("target") frequency, determined by 'step'. |
| 203 | E.g., for an upward octave jump, 'step' is 2. |
| 204 | Only consider frequencies between (1 - precision) * targetFrequency |
| 205 | and (1 - precision) * targetFrequency. |
| 206 | Take the candidate nearest to targetFrequency, |
| 207 | as long as that candidate is in between 0 and my ceiling. |
| 208 | */ |
| 209 | |
| 210 | void Pitch_formulacxx . . $ Pitch_formula(c6d7dbb5c31319a6). (Pitchcxx . . $ Pitch# me, conststring32cxx . . $ conststring32# formula, Interpretercxx . . $ Interpreter# interpreter); |
| 211 | |
| 212 | autoVECcxx . . $ autoVEC# Pitch_listValuesInAllFramescxx . . $ Pitch_listValuesInAllFrames(347c10438f5e8a73). (Pitchcxx . . $ Pitch# me); |
| 213 | |
| 214 | autoTablecxx . . $ autoTable# Pitch_tabulateCandidatesInFramecxx . . $ Pitch_tabulateCandidatesInFrame(6d63b585f1bbcca7). (Pitchcxx . . $ Pitch# me, integercxx . . $ integer# frameNumber); |
| 215 | autoTablecxx . . $ autoTable# Pitch_tabulateCandidatescxx . . $ Pitch_tabulateCandidates(d89a02564e434a83). (Pitchcxx . . $ Pitch# me); |
| 216 | |
| 217 | /* End of file Pitch.h */ |
| 218 | #endif |