| 1 | #ifndef _KlattGrid_h_ |
| 2 | #define _KlattGrid_h_ |
| 3 | /* KlattGrid.h |
| 4 | * |
| 5 | * Copyright (C) 2008-2019 David Weenink, 2015 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 "Collection.h" |
| 22 | #include "PointProcess.h" |
| 23 | #include "Sound.h" |
| 24 | #include "IntensityTier.h" |
| 25 | #include "PitchTier.h" |
| 26 | #include "FormantGrid.h" |
| 27 | #include "KlattTable.h" |
| 28 | Thing_declare (Interpreter); |
| 29 | |
| 30 | #include "KlattGrid_enums.h" |
| 31 | |
| 32 | #include "KlattGrid_def.h" |
| 33 | |
| 34 | /******************** PhonationPoint & Tier ************************************/ |
| 35 | |
| 36 | autoPhonationPoint PhonationPoint_create (double time, double period, double openPhase, double collisionPhase, double te, |
| 37 | double power1, double power2, double pulseScale); |
| 38 | |
| 39 | autoPhonationTier PhonationTier_create (double tmin, double tmax); |
| 40 | autoPointProcess PhonationTier_to_PointProcess_closures (PhonationTier me); |
| 41 | |
| 42 | /************************ PhonationGrid *********************************************/ |
| 43 | |
| 44 | autoPhonationGrid PhonationGrid_create (double tmin, double tmax); |
| 45 | autoPhonationGridPlayOptions PhonationGridPlayOptions_create (); |
| 46 | void PhonationGrid_setNames (PhonationGrid me); |
| 47 | |
| 48 | autoSound PhonationGrid_to_Sound_aspiration (PhonationGrid me, double samplingFrequency); |
| 49 | |
| 50 | void PhonationGrid_draw (PhonationGrid me, Graphics g); |
| 51 | |
| 52 | double PhonationGrid_getMaximumPeriod (PhonationGrid me); |
| 53 | |
| 54 | autoPhonationTier PhonationGrid_to_PhonationTier (PhonationGrid me); |
| 55 | |
| 56 | /************************ VocalTractGrid *********************************************/ |
| 57 | |
| 58 | autoVocalTractGrid VocalTractGrid_create (double tmin, double tmax, integer numberOfFormants, |
| 59 | integer numberOfNasalFormants, integer numberOfNasalAntiFormants); |
| 60 | autoVocalTractGridPlayOptions VocalTractGridPlayOptions_create (); |
| 61 | void VocalTractGrid_setNames (VocalTractGrid me); |
| 62 | void VocalTractGrid_draw (VocalTractGrid me, Graphics g, kKlattGridFilterModel filterModel); |
| 63 | |
| 64 | /************************ CouplingGrid *********************************************/ |
| 65 | |
| 66 | autoCouplingGrid CouplingGrid_create (double tmin, double tmax, integer numberOfTrachealFormants, integer numberOfTrachealAntiFormants, integer numberOfDeltaFormants); |
| 67 | autoCouplingGridPlayOptions CouplingGridPlayOptions_create (); |
| 68 | void CouplingGrid_setNames (CouplingGrid me); |
| 69 | double CouplingGrid_getDeltaFormantAtTime (CouplingGrid me, integer iformant, double t); |
| 70 | double CouplingGrid_getDeltaBandwidthAtTime (CouplingGrid me, integer iformant, double t); |
| 71 | |
| 72 | /********************** FormantGrid & CouplingGrid *************************************/ |
| 73 | |
| 74 | void FormantGrid_CouplingGrid_updateOpenPhases (FormantGrid me, CouplingGrid thee); |
| 75 | |
| 76 | /********************** Sound & FormantGrid (& IntensityTier) *************************************/ |
| 77 | |
| 78 | void Sound_FormantGrid_filterWithOneFormant_inplace (Sound me, FormantGrid thee, integer iformant); |
| 79 | void Sound_FormantGrid_filterWithOneAntiFormant_inplace (Sound me, FormantGrid thee, integer iformant); |
| 80 | void Sound_FormantGrid_Intensities_filterWithOneFormant_inplace (Sound me, FormantGrid thee, OrderedOf<structIntensityTier>* amplitudes, integer iformant); |
| 81 | autoSound Sound_FormantGrid_Intensities_filter (Sound me, FormantGrid thee, OrderedOf<structIntensityTier>* amplitudes, integer iformantb, integer iformante, int alternatingSign); |
| 82 | |
| 83 | /************************ FricationGrid *********************************************/ |
| 84 | |
| 85 | autoFricationGrid FricationGrid_create (double tmin, double tmax, integer numberOfFormants); |
| 86 | autoFricationGridPlayOptions FricationGridPlayOptions_create (); |
| 87 | void FricationGrid_setNames (FricationGrid me); |
| 88 | void FricationGrid_draw (FricationGrid me, Graphics g); |
| 89 | |
| 90 | autoSound FricationGrid_to_Sound (FricationGrid me, double samplingFrequency); |
| 91 | |
| 92 | autoSound Sound_FricationGrid_filter (Sound me, FricationGrid thee); |
| 93 | |
| 94 | /************************ Sound & VocalTractGrid & CouplingGrid *********************************************/ |
| 95 | |
| 96 | autoSound Sound_VocalTractGrid_CouplingGrid_filter (Sound me, VocalTractGrid thee, CouplingGrid coupling); |
| 97 | |
| 98 | /************************ KlattGrid *********************************************/ |
| 99 | |
| 100 | autoKlattGrid KlattGrid_create (double tmin, double tmax, integer numberOfFormants, |
| 101 | integer numberOfNasalFormants, integer numberOfNasalAntiFormants, |
| 102 | integer numberOfTrachealFormants, integer numberOfTrachealAntiFormants, |
| 103 | integer numberOfFricationFormants, integer numberOfDeltaFormants); |
| 104 | |
| 105 | autoKlattGrid KlattGrid_createFromVowel (double duration, double f0start, double f1, double b1, double f2, double b2, double f3, double b3, double f4, double bandWidthFraction, double formantFrequencyInterval); |
| 106 | |
| 107 | autoKlattGrid KlattGrid_createExample (); |
| 108 | autoKlattGridPlayOptions KlattGridPlayOptions_create (); |
| 109 | void KlattGrid_setNames (KlattGrid me); |
| 110 | autoKlattGrid KlattTable_to_KlattGrid (KlattTable me, double frameDuration); |
| 111 | |
| 112 | void KlattGrid_draw (KlattGrid me, Graphics g, kKlattGridFilterModel filterModel); |
| 113 | void klattGrid_drawPhonation (KlattGrid me, Graphics g); |
| 114 | void KlattGrid_drawVocalTract (KlattGrid me, Graphics g, kKlattGridFilterModel filterModel, int withTrachea); |
| 115 | |
| 116 | conststring32 KlattGrid_getFormantName (kKlattGridFormantType formantType); |
| 117 | |
| 118 | // Add, Remove, Extract, Replace from PhonationGrid |
| 119 | #define PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO(Name,tierType) \ |
| 120 | double KlattGrid_get##Name##AtTime (KlattGrid me, double t); \ |
| 121 | void KlattGrid_add##Name##Point (KlattGrid me, double t, double value); \ |
| 122 | void KlattGrid_remove##Name##Points (KlattGrid me, double t1, double t2); \ |
| 123 | auto##tierType KlattGrid_extract##Name##Tier (KlattGrid me); \ |
| 124 | void KlattGrid_replace##Name##Tier (KlattGrid me, tierType thee); |
| 125 | |
| 126 | // Generate 55 prototypes |
| 127 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Pitch, PitchTier) |
| 128 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Flutter, RealTier) |
| 129 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (DoublePulsing, RealTier) |
| 130 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (OpenPhase, RealTier) |
| 131 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (CollisionPhase, RealTier) |
| 132 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (SpectralTilt, IntensityTier) |
| 133 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Power1, RealTier) |
| 134 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Power2, RealTier) |
| 135 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (VoicingAmplitude, IntensityTier) |
| 136 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (AspirationAmplitude, IntensityTier) |
| 137 | PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (BreathinessAmplitude, IntensityTier) |
| 138 | |
| 139 | #define KlattGrid_QUERY_ADD_REMOVE_PROTO(Name) \ |
| 140 | double KlattGrid_get##Name##AtTime (KlattGrid me, kKlattGridFormantType formantType, integer iformant, double t); \ |
| 141 | void KlattGrid_add##Name##Point (KlattGrid me, kKlattGridFormantType formantType, integer iformant, double t, double value); \ |
| 142 | void KlattGrid_remove##Name##Points (KlattGrid me, kKlattGridFormantType formantType, integer iformant, double t1, double t2); \ |
| 143 | double KlattGrid_getDelta##Name##AtTime (KlattGrid me, integer iformant, double t); \ |
| 144 | void KlattGrid_addDelta##Name##Point (KlattGrid me, integer iformant, double t, double value); \ |
| 145 | void KlattGrid_removeDelta##Name##Points (KlattGrid me, integer iformant, double t1, double t2); |
| 146 | |
| 147 | // 12 prototypes |
| 148 | KlattGrid_QUERY_ADD_REMOVE_PROTO(Formant) |
| 149 | KlattGrid_QUERY_ADD_REMOVE_PROTO(Bandwidth) |
| 150 | |
| 151 | void KlattGrid_formula_frequencies (KlattGrid me, kKlattGridFormantType formantType, conststring32 expression, Interpreter interpreter); |
| 152 | void KlattGrid_formula_bandwidths (KlattGrid me, kKlattGridFormantType formantType, conststring32 expression, Interpreter interpreter); |
| 153 | void KlattGrid_formula_amplitudes (KlattGrid me, kKlattGridFormantType formantType, conststring32 expression, Interpreter interpreter); |
| 154 | |
| 155 | autoFormantGrid KlattGrid_extractFormantGrid (KlattGrid me, kKlattGridFormantType formantType); |
| 156 | void KlattGrid_replaceFormantGrid (KlattGrid me, kKlattGridFormantType formantType, FormantGrid thee); |
| 157 | |
| 158 | autoFormantGrid KlattGrid_extractDeltaFormantGrid (KlattGrid me); |
| 159 | void KlattGrid_replaceDeltaFormantGrid (KlattGrid me, FormantGrid thee); |
| 160 | |
| 161 | autoFormantGrid KlattGrid_to_oralFormantGrid_openPhases (KlattGrid me, double fadeFraction); |
| 162 | autoPointProcess KlattGrid_extractPointProcess_glottalClosures (KlattGrid me); |
| 163 | |
| 164 | double KlattGrid_getAmplitudeAtTime (KlattGrid me, kKlattGridFormantType formantType, integer iformant, double t); |
| 165 | void KlattGrid_addAmplitudePoint (KlattGrid me, kKlattGridFormantType formantType, integer iformant, double t, double value); |
| 166 | void KlattGrid_removeAmplitudePoints (KlattGrid me, kKlattGridFormantType formantType, integer iformant, double t1, double t2); |
| 167 | autoIntensityTier KlattGrid_extractAmplitudeTier (KlattGrid me, kKlattGridFormantType formantType, integer iformant); |
| 168 | void KlattGrid_replaceAmplitudeTier (KlattGrid me, kKlattGridFormantType formantType, integer iformant, IntensityTier thee); |
| 169 | |
| 170 | double KlattGrid_getFricationAmplitudeAtTime (KlattGrid me, double t); |
| 171 | void KlattGrid_addFricationAmplitudePoint (KlattGrid me, double t, double value); |
| 172 | void KlattGrid_removeFricationAmplitudePoints (KlattGrid me, double t1, double t2); |
| 173 | autoIntensityTier KlattGrid_extractFricationAmplitudeTier (KlattGrid me); |
| 174 | void KlattGrid_replaceFricationAmplitudeTier (KlattGrid me, IntensityTier thee); |
| 175 | |
| 176 | double KlattGrid_getFricationBypassAtTime (KlattGrid me, double t); |
| 177 | void KlattGrid_addFricationBypassPoint (KlattGrid me, double t, double value); |
| 178 | void KlattGrid_removeFricationBypassPoints (KlattGrid me, double t1, double t2); |
| 179 | autoIntensityTier KlattGrid_extractFricationBypassTier (KlattGrid me); |
| 180 | void KlattGrid_replaceFricationBypassTier (KlattGrid me, IntensityTier thee); |
| 181 | |
| 182 | void KlattGrid_setGlottisCoupling (KlattGrid me); |
| 183 | |
| 184 | autoFormantGrid * KlattGrid_getAddressOfFormantGrid (KlattGrid me, kKlattGridFormantType formantType); |
| 185 | OrderedOf<structIntensityTier>* KlattGrid_getAddressOfAmplitudes (KlattGrid me, kKlattGridFormantType formantType); |
| 186 | |
| 187 | /* |
| 188 | One can add (or remove) formant frequency tiers, formant bandwidth tiers and formant amplitude tiers. |
| 189 | The first two types are handled together, the third type is handled separately. |
| 190 | */ |
| 191 | void KlattGrid_addFormantFrequencyAndBandwidthTiers (KlattGrid me, kKlattGridFormantType formantType, integer position); |
| 192 | void KlattGrid_removeFormantFrequencyAndBandwidthTiers (KlattGrid me, kKlattGridFormantType formantType, integer position); |
| 193 | void KlattGrid_addFormantAmplitudeTier (KlattGrid me, kKlattGridFormantType formantType, integer position); |
| 194 | void KlattGrid_removeFormantAmplitudeTier (KlattGrid me, kKlattGridFormantType formantType, integer position); |
| 195 | |
| 196 | /* |
| 197 | The following two functions are deprecated; |
| 198 | they combine the actions of the above functions, |
| 199 | i.e. they add (or remove) a formant frequency tier, a formant bandwidth tier, |
| 200 | and a formant amplitude tier in one go. |
| 201 | Use instead the above division of these actions into two steps. |
| 202 | */ |
| 203 | void KlattGrid_addFormant (KlattGrid me, kKlattGridFormantType formantType, integer position); |
| 204 | void KlattGrid_removeFormant (KlattGrid me, kKlattGridFormantType formantType, integer position); |
| 205 | |
| 206 | /***************** KlattGrid & Sound *************************************/ |
| 207 | |
| 208 | // reset PlayOptions to defaults |
| 209 | void KlattGrid_play (KlattGrid me, Sound_PlayCallback callback, Thing boss); |
| 210 | // use playOptions |
| 211 | void KlattGrid_playSpecial (KlattGrid me, Sound_PlayCallback callback, Thing boss); |
| 212 | |
| 213 | void KlattGrid_setDefaultPlayOptions (KlattGrid me); |
| 214 | |
| 215 | autoSound KlattGrid_to_Sound (KlattGrid me); |
| 216 | |
| 217 | autoSound KlattGrid_to_Sound_phonation (KlattGrid me); |
| 218 | |
| 219 | int KlattGrid_synthesize (KlattGrid me, double t1, double t2, double samplingFrequency, double maximumPeriod); |
| 220 | |
| 221 | /* |
| 222 | glottal: phonation+aspiration, before entering the filter |
| 223 | frication: noise before entering the parallel frication filter section. |
| 224 | */ |
| 225 | |
| 226 | autoSound Sound_KlattGrid_filterByVocalTract (Sound me, KlattGrid thee, kKlattGridFilterModel filterModel); |
| 227 | |
| 228 | autoSound Sound_KlattGrid_filter_frication (Sound me, KlattGrid thee); |
| 229 | |
| 230 | autoKlattGrid Sound_to_KlattGrid_simple (Sound me, double timeStep, integer maximumNumberOfFormants, double maximumFormantFrequency, |
| 231 | double windowLength, double preEmphasisFrequency, double pitchFloor, double pitchCeiling, double pitchFloorForIntensity, int subtractMean); |
| 232 | |
| 233 | #endif /* _KlattGrid_h_ */ |