| 1 | /* TextGrid_and_PitchTier.cpp |
| 2 | * |
| 3 | * Copyright (C) 2017-2021,2026 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 3 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 "Interpreter.h"cxx . . $ `<file>/sys/Interpreter.h`/ |
| 20 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 21 | #include "RealTier.h"cxx . . $ `<file>/fon/RealTier.h`/ |
| 22 | #include "Strings_extensions.h"cxx . . $ `<file>/dwtools/Strings_extensions.h`/ |
| 23 | #include "TextGrid_and_PitchTier.h"cxx . . $ `<file>/dwtools/TextGrid_and_PitchTier.h`/ |
| 24 | #include "Thing.h"cxx . . $ `<file>/sys/Thing.h`/ |
| 25 | |
| 26 | |
| 27 | #define TIME_OFFSET_AS_FRACTION_FROM_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:27:9`! 1 |
| 28 | #define TIME_OFFSET_AS_PERCENTAGE_FROM_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:28:9`! 2 |
| 29 | #define TIME_OFFSET_AS_SECONDS_FROM_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:29:9`! 3 |
| 30 | |
| 31 | #define PITCH_VALUE_AS_FREQUENCYcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:31:9`! 1 |
| 32 | #define PITCH_VALUE_AS_FRACTIONcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:32:9`! 2 |
| 33 | #define PITCH_VALUE_AS_PERCENTAGEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:33:9`! 3 |
| 34 | #define PITCH_VALUE_AS_START_AND_SLOPEScxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:34:9`! 4 |
| 35 | #define PITCH_VALUE_AS_SLOPES_AND_ENDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:35:9`! 5 |
| 36 | #define PITCH_VALUE_AS_MUSIC_NOTEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:36:9`! 6 |
| 37 | #define PITCH_VALUE_AS_SEMITONEScxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:37:9`! 7 |
| 38 | |
| 39 | #define PITCH_UNIT_HERTZcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:39:9`! 1 |
| 40 | |
| 41 | #define PITCH_ANCHOR_IS_NOT_USEDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:41:9`! 1 |
| 42 | #define PITCH_ANCHOR_IS_CURRENTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:42:9`! 2 |
| 43 | #define PITCH_ANCHOR_IS_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:43:9`! 3 |
| 44 | #define PITCH_ANCHOR_IS_ENDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:44:9`! 4 |
| 45 | #define PITCH_ANCHOR_IS_MEAN_OF_CURVEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:45:9`! 5 |
| 46 | #define PITCH_ANCHOR_IS_MEAN_OF_POINTScxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:46:9`! 6 |
| 47 | #define PITCH_ANCHOR_IS_MAXIMUMcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:47:9`! 7 |
| 48 | #define PITCH_ANCHOR_IS_MINIMUMcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:48:9`! 8 |
| 49 | |
| 50 | static double RealTier_getMinimumValue_intervalcxx . . $ RealTier_getMinimumValue_interval(5a85e5277b8334c5). (RealTiercxx . . $ RealTier# me, double tmin, double tmax) { |
| 51 | integercxx . . $ integer# imin, imax; |
| 52 | (void) AnyTier_getWindowPointscxx . . $ AnyTier_getWindowPoints(466307ef51e9855a). ((AnyTiercxx . . $ AnyTier#) me, tmin, tmax, & imin, & imax); |
| 53 | double result = undefinedcxx . . $ undefined.; |
| 54 | for (integercxx . . $ integer# i = imin; i <= imax; i ++) { |
| 55 | const RealPointcxx . . $ RealPoint# point = mycxx . . $ `melder/melder.h:44:9`! pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 56 | if (isundefcxx . . $ isundef(f8197d536af80c96). (result) || point -> valuecxx . . $ structRealPoint#value. < result) |
| 57 | result = point -> valuecxx . . $ structRealPoint#value.; |
| 58 | } |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | static double RealTier_getMaximumValue_intervalcxx . . $ RealTier_getMaximumValue_interval(5a85e5277b8334c5). (RealTiercxx . . $ RealTier# me, double tmin, double tmax) { |
| 63 | integercxx . . $ integer# imin, imax; |
| 64 | (void) AnyTier_getWindowPointscxx . . $ AnyTier_getWindowPoints(466307ef51e9855a). ((AnyTiercxx . . $ AnyTier#) me, tmin, tmax, & imin, & imax); |
| 65 | double result = undefinedcxx . . $ undefined.; |
| 66 | for (integercxx . . $ integer# i = imin; i <= imax; i ++) { |
| 67 | const RealPointcxx . . $ RealPoint# point = mycxx . . $ `melder/melder.h:44:9`! pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 68 | if (isundefcxx . . $ isundef(f8197d536af80c96). (result) || point -> valuecxx . . $ structRealPoint#value. > result) |
| 69 | result = point -> valuecxx . . $ structRealPoint#value.; |
| 70 | } |
| 71 | return result; |
| 72 | } |
| 73 | |
| 74 | static autoPitchTiercxx . . $ autoPitchTier# PitchTier_createFromPointscxx . . $ PitchTier_createFromPoints(1d051646e0507425). (double xmin, double xmax, constVECcxx . . $ constVEC# times, constVECcxx . . $ constVEC# pitches) { |
| 75 | try { |
| 76 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (times.size == pitches.size); |
| 77 | autoPitchTiercxx . . $ autoPitchTier# me = PitchTier_createcxx . . $ PitchTier_create(6e304f2c8cc67c9c). (xmin, xmax); |
| 78 | for (integercxx . . $ integer# i = 1; i <= times.sizecxx . . $ constvector#size.; i ++) |
| 79 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), times [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i], pitches [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i]); |
| 80 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 81 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 82 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No PitchTier created from points."); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static autoVECcxx . . $ autoVEC# getAbsoluteFromRelativeTimescxx . . $ getAbsoluteFromRelativeTimes(f585e1c7013bad7f). (double tmin, double tmax, constVECVUcxx . . $ constVECVU# const& relativeTimes, int time_offset) { |
| 87 | autoVECcxx . . $ autoVEC# absoluteTimes = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (relativeTimes.sizecxx . . $ constvectorview#size.); |
| 88 | for (integercxx . . $ integer# i = 1; i <= relativeTimes.sizecxx . . $ constvectorview#size.; i ++) { |
| 89 | if (time_offset == TIME_OFFSET_AS_FRACTION_FROM_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:27:9`!) |
| 90 | absoluteTimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = tmin + relativeTimes [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i] * (tmax - tmin); |
| 91 | else if (time_offset == TIME_OFFSET_AS_PERCENTAGE_FROM_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:28:9`!) |
| 92 | absoluteTimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = tmin + relativeTimes [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i] * (tmax - tmin) * 0.01; |
| 93 | else if (time_offset == TIME_OFFSET_AS_SECONDS_FROM_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:29:9`!) |
| 94 | absoluteTimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = tmin + relativeTimes [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]; |
| 95 | else { |
| 96 | // we should not be here |
| 97 | } |
| 98 | } |
| 99 | return absoluteTimescxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | a1, a#1, b1, b#1, ... g#1, a2, a#2, b2, c2, ....; a a# b c c# d d# e f f# g g# |
| 104 | */ |
| 105 | static double note_to_frequencycxx . . $ note_to_frequency(a965db54ac15d884). (conststring32cxx . . $ conststring32# token, double a4) { |
| 106 | const double base = a4 / 8.0; |
| 107 | integercxx . . $ integer# octave, index; |
| 108 | const char32cxx . . $ char32# note = *token++, char2 = *token++; |
| 109 | if (note == U'a' || note == U'A') |
| 110 | index = 1; |
| 111 | else if (note == U'b' || note == U'B') |
| 112 | index = 3; |
| 113 | else if (note == U'c' || note == U'C') |
| 114 | index = 4; |
| 115 | else if (note == U'd' || note == U'D') |
| 116 | index = 6; |
| 117 | else if (note == U'e' || note == U'E') |
| 118 | index = 8; |
| 119 | else if (note == U'f' || note == U'F') |
| 120 | index = 9; |
| 121 | else if (note == U'g' || note == U'G') |
| 122 | index = 11; |
| 123 | else |
| 124 | return undefinedcxx . . $ undefined.; |
| 125 | char32cxx . . $ char32# char3; |
| 126 | if (char2 == U'#') { |
| 127 | index ++; |
| 128 | char3 = *token++; |
| 129 | } else { |
| 130 | char3 = char2; |
| 131 | } |
| 132 | |
| 133 | if (char3 >= U'0' && char3 <= U'9') |
| 134 | octave = char3 - U'0'; |
| 135 | else |
| 136 | return undefinedcxx . . $ undefined.; |
| 137 | |
| 138 | const double frequency = base * powcxx . . $ pow(b71928d39fde4295). (2.0, octave - 1.0 + (index - 1.0) / 12.0); |
| 139 | return frequency; |
| 140 | } |
| 141 | |
| 142 | static autoPitchTiercxx . . $ autoPitchTier# PitchTier_createAsModifiedPartcxx . . $ PitchTier_createAsModifiedPart(bac14f756bf16894). (PitchTiercxx . . $ PitchTier# me, double tmin, double tmax, |
| 143 | constVECVUcxx . . $ constVECVU# const& relativeTimes, int time_offset, conststring32cxx . . $ conststring32# pitches_string, int pitch_unit, int pitch_as, int pitchAnchor_status) |
| 144 | { |
| 145 | (void) pitch_unit; |
| 146 | try { |
| 147 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 148 | |
| 149 | if ((pitch_as == PITCH_VALUE_AS_FRACTIONcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:32:9`! || pitch_as == PITCH_VALUE_AS_PERCENTAGEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:33:9`!) && |
| 150 | pitchAnchor_status == PITCH_ANCHOR_IS_NOT_USEDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:41:9`!) |
| 151 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"You need to specify an anchor value to calculate ", (pitch_as == PITCH_VALUE_AS_FRACTIONcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:32:9`! ? U"fractions" : U"percentages"), U"."); |
| 152 | |
| 153 | autoVECcxx . . $ autoVEC# times = getAbsoluteFromRelativeTimescxx . . $ getAbsoluteFromRelativeTimes(f585e1c7013bad7f). (tmin, tmax, relativeTimes, time_offset); |
| 154 | |
| 155 | autoStringscxx . . $ autoStrings# items = Strings_createAsTokenscxx . . $ Strings_createAsTokens(46a782a57ff120bc). (pitches_string, U" "); |
| 156 | const integercxx . . $ integer# numberOfPitches = items ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings.; |
| 157 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (times.size == numberOfPitches, |
| 158 | U"The number of items in the times and the pitches string have to be equal."); |
| 159 | autoVECcxx . . $ autoVEC# pitchesraw = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfPitches); |
| 160 | for (integercxx . . $ integer# i = 1; i <= numberOfPitches; i ++) { |
| 161 | const conststring32cxx . . $ conststring32# token = items ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 162 | if (pitch_as == PITCH_VALUE_AS_MUSIC_NOTEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:36:9`!) |
| 163 | pitchesraw [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = note_to_frequencycxx . . $ note_to_frequency(a965db54ac15d884). (token, 440.0); |
| 164 | else |
| 165 | Interpreter_numericExpressioncxx . . $ Interpreter_numericExpression(8639512facf48b76). (0, token, & pitchesraw [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]); |
| 166 | } |
| 167 | /* |
| 168 | Now we have the real times and we can sort them together with the pitches |
| 169 | */ |
| 170 | autoVECcxx . . $ autoVEC# pitches = copy_VECcxx . . $ copy_VEC(d4415e68b25283a8). (pitchesrawcxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 171 | NUMsortTogethercxx . . $ NUMsortTogether(13c11f7bd0e7e3d2). (times.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), pitches.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 172 | double pitchAnchor, pitch; |
| 173 | for (integercxx . . $ integer# i = 1; i <= times.sizecxx . . $ autovector#size.; i ++) { |
| 174 | const integercxx . . $ integer# index = pitch_as != PITCH_VALUE_AS_SLOPES_AND_ENDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:35:9`! ? i : times.sizecxx . . $ autovector#size. - i + 1; |
| 175 | const double time = times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; |
| 176 | if (pitchAnchor_status == PITCH_ANCHOR_IS_NOT_USEDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:41:9`!) |
| 177 | pitchAnchor = undefinedcxx . . $ undefined.; |
| 178 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_CURRENTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:42:9`!) |
| 179 | pitchAnchor = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (me, time); |
| 180 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_STARTcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:43:9`!) |
| 181 | pitchAnchor = i == 1 ? RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (me, tmin) : pitchAnchor; |
| 182 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_ENDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:44:9`!) |
| 183 | pitchAnchor = i == 1 ? RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (me, tmax) : pitchAnchor; |
| 184 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_MEAN_OF_CURVEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:45:9`!) |
| 185 | pitchAnchor = i == 1 ? RealTier_getMean_curve_ucxx . . $ RealTier_getMean_curve_u(275ea9f7b70e8f4c). (me, tmin, tmax) : pitchAnchor; |
| 186 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_MEAN_OF_POINTScxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:46:9`!) |
| 187 | pitchAnchor = i == 1 ? RealTier_getMean_points_ucxx . . $ RealTier_getMean_points_u(275ea9f7b70e8f4c). (me, tmin, tmax) : pitchAnchor; |
| 188 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_MAXIMUMcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:47:9`!) |
| 189 | pitchAnchor = i == 1 ? RealTier_getMaximumValue_intervalcxx . . $ RealTier_getMaximumValue_interval(5a85e5277b8334c5). (me, tmin, tmax) : pitchAnchor; |
| 190 | else if (pitchAnchor_status == PITCH_ANCHOR_IS_MINIMUMcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:48:9`!) |
| 191 | pitchAnchor = i == 1 ? RealTier_getMinimumValue_intervalcxx . . $ RealTier_getMinimumValue_interval(5a85e5277b8334c5). (me, tmin, tmax) : pitchAnchor; |
| 192 | else { |
| 193 | // we should not be here |
| 194 | } |
| 195 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (isdefined (pitchAnchor) || pitchAnchor_status == PITCH_ANCHOR_IS_NOT_USEDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:41:9`!, |
| 196 | U"The pitch anchor value is undefined because the PitchTier is empty."); |
| 197 | /* |
| 198 | How to interpret the "pitch" value |
| 199 | */ |
| 200 | if (pitch_as == PITCH_VALUE_AS_FREQUENCYcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:31:9`!) |
| 201 | pitch = pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 202 | else if (pitch_as == PITCH_VALUE_AS_FRACTIONcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:32:9`!) |
| 203 | pitch = pitchAnchor * (1.0 + pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]); |
| 204 | else if (pitch_as == PITCH_VALUE_AS_PERCENTAGEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:33:9`!) |
| 205 | pitch = pitchAnchor * (1.0 + pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * 0.01); |
| 206 | else if (pitch_as == PITCH_VALUE_AS_START_AND_SLOPEScxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:34:9`!) { |
| 207 | if (i == 1) |
| 208 | pitch = pitchAnchor; |
| 209 | else |
| 210 | pitch += (times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] - times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1]) * pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 211 | } else if (pitch_as == PITCH_VALUE_AS_SLOPES_AND_ENDcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:35:9`!) { |
| 212 | if (i == 1) |
| 213 | pitch = pitchAnchor; |
| 214 | else |
| 215 | pitch -= (times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index + 1] - times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]) * pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; |
| 216 | } else if (pitch_as == PITCH_VALUE_AS_MUSIC_NOTEcxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:36:9`!) |
| 217 | pitch = pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 218 | else if (pitch_as == PITCH_VALUE_AS_SEMITONEScxx . . $ `dwtools/TextGrid_and_PitchTier.cpp:37:9`!) |
| 219 | pitch = NUMsemitonesToHertzcxx . . $ NUMsemitonesToHertz(447c67c6676f75c3). (pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]); |
| 220 | else { |
| 221 | // we should not be here |
| 222 | } |
| 223 | pitches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] = pitch; |
| 224 | } |
| 225 | /* |
| 226 | Remove old points |
| 227 | */ |
| 228 | autoPitchTiercxx . . $ autoPitchTier# thee = PitchTier_createFromPointscxx . . $ PitchTier_createFromPoints(1d051646e0507425). (times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).times.sizecxx . . $ autovector#size.], timescxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), pitchescxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 229 | |
| 230 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 231 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 232 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no modified PitchTier created."); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static void PitchTiers_replacePointscxx . . $ PitchTiers_replacePoints(c054e294c51bc970). (PitchTiercxx . . $ PitchTier# me, PitchTiercxx . . $ PitchTier# thee) { |
| 237 | AnyTier_removePointsBetweencxx . . $ AnyTier_removePointsBetween(15327dad64b67f1a). ((AnyTiercxx . . $ AnyTier#) me, thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin., thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax.); |
| 238 | for (integercxx . . $ integer# i = 1; i <= thycxx . . $ `melder/melder.h:45:9`! pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size.; i ++) { |
| 239 | const RealPointcxx . . $ RealPoint# pp = thycxx . . $ `melder/melder.h:45:9`! pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 240 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (me, pp -> numbercxx . . $ structSimpleDouble#number., pp -> valuecxx . . $ structRealPoint#value.); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | void PitchTier_modifyIntervalcxx . . $ PitchTier_modifyInterval(257d05380b60e58c). (PitchTiercxx . . $ PitchTier# me, double tmin, double tmax, |
| 245 | constVECVUcxx . . $ constVECVU# const& relativeTimes, int time_offset, conststring32cxx . . $ conststring32# pitches_string, |
| 246 | int pitch_unit, int pitch_as, int pitchAnchor_status) |
| 247 | { |
| 248 | try { |
| 249 | autoPitchTiercxx . . $ autoPitchTier# thee = PitchTier_createAsModifiedPartcxx . . $ PitchTier_createAsModifiedPart(bac14f756bf16894). (me, tmin, tmax, relativeTimes, time_offset, pitches_string, pitch_unit, pitch_as, pitchAnchor_status); |
| 250 | PitchTiers_replacePointscxx . . $ PitchTiers_replacePoints(c054e294c51bc970). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 251 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 252 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": interval modification not completed."); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | We specify pitches as tone levels (1 - numberOfToneLevels). These levels are relative to the pitch range of a speaker. |
| 258 | (normally in Mandarin Chinese they count 5 levels). |
| 259 | */ |
| 260 | static autoPitchTiercxx . . $ autoPitchTier# PitchTier_createAsModifiedPart_toneLevelscxx . . $ PitchTier_createAsModifiedPart_toneLevels(526bff619f89c187). (PitchTiercxx . . $ PitchTier# me, double tmin, double tmax, double fmin, double fmax, |
| 261 | integercxx . . $ integer# numberOfToneLevels, constVECVUcxx . . $ constVECVU# const& relativeTimes, int time_offset, constVECVUcxx . . $ constVECVU# const& pitchesAsToneLevels) |
| 262 | { |
| 263 | try { |
| 264 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 265 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (fmin < fmax, |
| 266 | U"The lowest frequency should be lower than the highest frequency."); |
| 267 | |
| 268 | autoVECcxx . . $ autoVEC# times = getAbsoluteFromRelativeTimescxx . . $ getAbsoluteFromRelativeTimes(f585e1c7013bad7f). (tmin, tmax, relativeTimes, time_offset); |
| 269 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (times.size == pitchesAsToneLevels.size, |
| 270 | U"The number of times and the number of pitches have to be equal."); |
| 271 | |
| 272 | autoVECcxx . . $ autoVEC# pitches_hertz = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (pitchesAsToneLevels.sizecxx . . $ constvectorview#size.); |
| 273 | const double scale = log10cxx . . $ log10(fee4f1d22bc8e617). (fmax / fmin) / numberOfToneLevels; |
| 274 | for (integercxx . . $ integer# i = 1; i <= pitchesAsToneLevels.sizecxx . . $ constvectorview#size.; i ++) |
| 275 | pitches_hertz [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = fmin * powcxx . . $ pow(b71928d39fde4295). (10.0, scale * pitchesAsToneLevels [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).i]); |
| 276 | NUMsortTogethercxx . . $ NUMsortTogether(13c11f7bd0e7e3d2). (times.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), pitches_hertz.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 277 | autoPitchTiercxx . . $ autoPitchTier# thee = PitchTier_createFromPointscxx . . $ PitchTier_createFromPoints(1d051646e0507425). (times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1], times [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).times.sizecxx . . $ autovector#size.], timescxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), pitches_hertzcxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 278 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 279 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 280 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": interval modification not succeeded."); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | void PitchTier_modifyInterval_toneLevelscxx . . $ PitchTier_modifyInterval_toneLevels(d6c67d6ed557cd18). (PitchTiercxx . . $ PitchTier# me, double tmin, double tmax, double fmin, double fmax, |
| 285 | integercxx . . $ integer# numberOfToneLevels, constVECVUcxx . . $ constVECVU# const& relativeTimes, int time_offset, constVECVUcxx . . $ constVECVU# const& pitchesAsToneLevels) |
| 286 | { |
| 287 | try { |
| 288 | autoPitchTiercxx . . $ autoPitchTier# thee = PitchTier_createAsModifiedPart_toneLevelscxx . . $ PitchTier_createAsModifiedPart_toneLevels(526bff619f89c187). (me, tmin, tmax, fmin, fmax, numberOfToneLevels, relativeTimes, time_offset, pitchesAsToneLevels); |
| 289 | PitchTiers_replacePointscxx . . $ PitchTiers_replacePoints(c054e294c51bc970). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 290 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 291 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": interval modification as tone levels not succeeded."); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /* End of file TextGrid_and_PitchTier.cpp */ |