| 1 | /* PowerCepstrum.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012-2025 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 "PowerCepstrum.h"cxx . . $ `<file>/LPC/PowerCepstrum.h`/ |
| 20 | #include "PowerCepstrumWorkspace.h"cxx . . $ `<file>/LPC/PowerCepstrumWorkspace.h`/ |
| 21 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 22 | |
| 23 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (PowerCepstrum, Cepstrum, 2); // derives from Matrix; therefore also version 2 |
| 24 | |
| 25 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (PowerCepstrumWorkspace, Thing, 0); |
| 26 | |
| 27 | |
| 28 | static inline bool greaterThanOrEqualcxx . . $ greaterThanOrEqual(828b76dce88fac). (double x, double y) { |
| 29 | // x >= y means !(x < y) |
| 30 | return ( (x == 0.0 || y == 0.0) ? (x - y) : (x - y) / fabscxx . . $ fabs(fee4f1d22bc8e617). (x) ) > -1e-12; |
| 31 | } |
| 32 | |
| 33 | static inline bool greaterThancxx . . $ greaterThan(828b76dce88fac). (double x, double y) { |
| 34 | return ( (x == 0.0 || y == 0.0) ? (x - y) : (x - y) / fabscxx . . $ fabs(fee4f1d22bc8e617). (x) ) > 1e-12; |
| 35 | } |
| 36 | |
| 37 | static void Vector_getMaximumAndX_twoSideApproachcxx . . $ Vector_getMaximumAndX_twoSideApproach(1a00929398994b85). (constVectorcxx . . $ constVector# me, double xmin, double xmax, integercxx . . $ integer# channelNumber, |
| 38 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType, bool startHigh, double *out_maximum, double *out_xOfMaximum) |
| 39 | { |
| 40 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (channelNumber >= 1 && channelNumber <= mycxx . . $ `melder/melder.h:44:9`! ny); |
| 41 | constVECcxx . . $ constVEC# y = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channelNumber); |
| 42 | double maximum, x; |
| 43 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & xmin, & xmax); |
| 44 | integercxx . . $ integer# imin, imax; |
| 45 | if (! Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, xmin, xmax, & imin, & imax)) { |
| 46 | /* |
| 47 | No samples between xmin and xmax. |
| 48 | Try to return the greater of the values at these two points. |
| 49 | */ |
| 50 | kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# valueInterpolationType = ( peakInterpolationType > kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: NONEcxx . . $ kVector_peakInterpolation#NONE. ? |
| 51 | kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR. : kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: NEARESTcxx . . $ kVector_valueInterpolation#NEAREST. ); |
| 52 | const double yleft = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (me, xmin, channelNumber, valueInterpolationType); |
| 53 | const double yright = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). (me, xmax, channelNumber, valueInterpolationType); |
| 54 | maximum = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (yleft, yright); |
| 55 | x = ( yleft == yright ? (xmin + xmax) / 2.0 : yleft > yright ? xmin : xmax ); |
| 56 | } else { |
| 57 | maximum = y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).imin]; |
| 58 | x = imin; |
| 59 | if (y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).imax] > maximum) { |
| 60 | maximum = y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).imax]; |
| 61 | x = imax; |
| 62 | } |
| 63 | if (imin == 1) |
| 64 | imin ++; |
| 65 | if (imax == mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) |
| 66 | imax --; |
| 67 | if (! startHigh) { // approach from the start |
| 68 | for (integercxx . . $ integer# i = imin; i <= imax; i ++) { |
| 69 | if (greaterThancxx . . $ greaterThan(828b76dce88fac). (y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i], y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i - 1]) && greaterThanOrEqualcxx . . $ greaterThanOrEqual(828b76dce88fac). (y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i], y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + 1])) { |
| 70 | double i_real; |
| 71 | const double localMaximum = NUMimproveMaximumcxx . . $ NUMimproveMaximum(c86a71e1ecac36cd). (y, i, kVector_peakInterpolation_to_interpolationDepthcxx . . $ kVector_peakInterpolation_to_interpolationDepth(5f6fa5b1fce060b0). (peakInterpolationType), & i_real); |
| 72 | if (localMaximum > maximum) { |
| 73 | maximum = localMaximum; |
| 74 | x = i_real; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } else { // approach from the end |
| 79 | for (integercxx . . $ integer# i = imax; i >= imin; i --) { |
| 80 | if (greaterThancxx . . $ greaterThan(828b76dce88fac). (y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i], y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + 1]) && greaterThanOrEqualcxx . . $ greaterThanOrEqual(828b76dce88fac). (y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i], y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i - 1])) { |
| 81 | double i_real; |
| 82 | const double localMaximum = NUMimproveMaximumcxx . . $ NUMimproveMaximum(c86a71e1ecac36cd). (y, i, kVector_peakInterpolation_to_interpolationDepthcxx . . $ kVector_peakInterpolation_to_interpolationDepth(5f6fa5b1fce060b0). (peakInterpolationType), & i_real); |
| 83 | if (localMaximum > maximum) { |
| 84 | maximum = localMaximum; |
| 85 | x = i_real; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | x = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (x - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; // convert sample to x |
| 91 | Melder_clipcxx . . $ Melder_clip(971c667ea412f82c). (xmin, & x, xmax); |
| 92 | |
| 93 | } |
| 94 | if (out_maximum) |
| 95 | *out_maximum = maximum; |
| 96 | if (out_xOfMaximum) |
| 97 | *out_xOfMaximum = x; |
| 98 | } |
| 99 | |
| 100 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). () { |
| 101 | SlopeSelector_getSlopeAndInterceptcxx . . $ SlopeSelector_getSlopeAndIntercept(3ee7399ea56bc19b). (slopeSelectorcxx . . $ structPowerCepstrumWorkspace#slopeSelector..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), slopecxx . . $ structPowerCepstrumWorkspace#slope., interceptcxx . . $ structPowerCepstrumWorkspace#intercept., methodcxx . . $ structPowerCepstrumWorkspace#method.); |
| 102 | slopeKnowncxx . . $ structPowerCepstrumWorkspace#slopeKnown. = true; |
| 103 | } |
| 104 | |
| 105 | double structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getTrendcxx . . $ structPowerCepstrumWorkspace#getTrend(447c67c6676f75c3). (double quefrency) { |
| 106 | if (! slopeKnowncxx . . $ structPowerCepstrumWorkspace#slopeKnown.) |
| 107 | getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). (); |
| 108 | const double xq = ( trendLineTypecxx . . $ structPowerCepstrumWorkspace#trendLineType. == kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::EXPONENTIAL_DECAYcxx . . $ kCepstrum_trendType#EXPONENTIAL_DECAY. ? logcxx . . $ log(fee4f1d22bc8e617). (quefrency) : quefrency ); |
| 109 | trenddBcxx . . $ structPowerCepstrumWorkspace#trenddB. = slopecxx . . $ structPowerCepstrumWorkspace#slope. * xq + interceptcxx . . $ structPowerCepstrumWorkspace#intercept.; |
| 110 | return trenddBcxx . . $ structPowerCepstrumWorkspace#trenddB.; |
| 111 | } |
| 112 | |
| 113 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: subtractTrendcxx . . $ structPowerCepstrumWorkspace#subtractTrend(49f6e7a06ebc5aa8). () { |
| 114 | if (! slopeKnowncxx . . $ structPowerCepstrumWorkspace#slopeKnown.) |
| 115 | getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). (); |
| 116 | for (integercxx . . $ integer# j = 1; j <= powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> nxcxx . . $ structSampled#nx.; j ++) { |
| 117 | /* |
| 118 | For the exponential decay function, y = slope*log(quefrency)+intercept, the PowerCepstrum's first quefrency |
| 119 | value (at x1) has quefrency == 0 and therefore value y(0) is not defined. As an approximation for y(0) |
| 120 | we use y(0.5*dx). This is no problem because the value at quefrency == 0 is not relevant. |
| 121 | */ |
| 122 | const double quefrency = ( j == 1 && trendLineTypecxx . . $ structPowerCepstrumWorkspace#trendLineType. == kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::EXPONENTIAL_DECAYcxx . . $ kCepstrum_trendType#EXPONENTIAL_DECAY. ? 0.5 * powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> dxcxx . . $ structSampled#dx. : (j - 1) * powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> dxcxx . . $ structSampled#dx. ); |
| 123 | const double db_background = getTrendcxx . . $ structPowerCepstrumWorkspace#getTrend(447c67c6676f75c3). (quefrency); |
| 124 | const double db_cepstrum = powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> v_getValueAtSamplecxx . . $ structPowerCepstrum#v_getValueAtSample(8bbfc6ce471470c9). (j, 1, 1); |
| 125 | const double diff = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (0.0, db_cepstrum - db_background); |
| 126 | powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = expcxx . . $ exp(fee4f1d22bc8e617). (diff * NUMln10cxx . . $ NUMln10. / 10.0); |
| 127 | } |
| 128 | trendSubtractedcxx . . $ structPowerCepstrumWorkspace#trendSubtracted. = true; |
| 129 | } |
| 130 | |
| 131 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: newDatacxx . . $ structPowerCepstrumWorkspace#newData(97428d87df076bf). (constPowerCepstrumcxx . . $ constPowerCepstrum# thee) { |
| 132 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (thycxx . . $ `melder/melder.h:45:9`! nx == powerCepstrum -> nx); |
| 133 | for (integercxx . . $ integer# ipoint = 1, i = imincxx . . $ structPowerCepstrumWorkspace#imin.; i <= imaxcxx . . $ structPowerCepstrumWorkspace#imax.; i ++, ipoint ++) { |
| 134 | double xval = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (thee, i); |
| 135 | if (trendLineTypecxx . . $ structPowerCepstrumWorkspace#trendLineType. == kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::EXPONENTIAL_DECAYcxx . . $ kCepstrum_trendType#EXPONENTIAL_DECAY.) |
| 136 | xval = logcxx . . $ log(fee4f1d22bc8e617). (xval); |
| 137 | xcxx . . $ structPowerCepstrumWorkspace#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipoint] = xval; |
| 138 | ycxx . . $ structPowerCepstrumWorkspace#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipoint] = thycxx . . $ `melder/melder.h:45:9`! v_getValueAtSamplecxx . . $ structPowerCepstrum#v_getValueAtSample(8bbfc6ce471470c9). (i, 1, 1); // dB's |
| 139 | } |
| 140 | slopeSelectorcxx . . $ structPowerCepstrumWorkspace#slopeSelector. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). newDataPointscxx . . $ structSlopeSelector#newDataPoints(868ad595302eda0d). (xcxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), ycxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 141 | todBscxx . . $ structPowerCepstrumWorkspace#todBs(49f6e7a06ebc5aa8). (); |
| 142 | peakKnowncxx . . $ structPowerCepstrumWorkspace#peakKnown. = slopeKnowncxx . . $ structPowerCepstrumWorkspace#slopeKnown. = trendSubtractedcxx . . $ structPowerCepstrumWorkspace#trendSubtracted. = false; |
| 143 | } |
| 144 | |
| 145 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). () { |
| 146 | Matrixcxx . . $ Matrix# thee = asdBscxx . . $ structPowerCepstrumWorkspace#asdBs..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); |
| 147 | double peakdBR, peakQuefrencyR; |
| 148 | Vector_getMaximumAndX_twoSideApproachcxx . . $ Vector_getMaximumAndX_twoSideApproach(1a00929398994b85). ((Vectorcxx . . $ Vector#) thee, qminPeakSearchcxx . . $ structPowerCepstrumWorkspace#qminPeakSearch., qmaxPeakSearchcxx . . $ structPowerCepstrumWorkspace#qmaxPeakSearch., |
| 149 | 1, peakInterpolationTypecxx . . $ structPowerCepstrumWorkspace#peakInterpolationType., false, & peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB., & peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.); |
| 150 | Vector_getMaximumAndX_twoSideApproachcxx . . $ Vector_getMaximumAndX_twoSideApproach(1a00929398994b85). ((Vectorcxx . . $ Vector#) thee, qminPeakSearchcxx . . $ structPowerCepstrumWorkspace#qminPeakSearch., qmaxPeakSearchcxx . . $ structPowerCepstrumWorkspace#qmaxPeakSearch., |
| 151 | 1, peakInterpolationTypecxx . . $ structPowerCepstrumWorkspace#peakInterpolationType., true, & peakdBR, & peakQuefrencyR); |
| 152 | const integercxx . . $ integer# index = Sampled_xToIndexcxx . . $ Sampled_xToIndex(b395a896ba2eff9a). (thee, peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.), indexR = Sampled_xToIndexcxx . . $ Sampled_xToIndex(b395a896ba2eff9a).(thee, peakQuefrencyR); |
| 153 | if (index != indexR && (indexR - index) <= 5) { |
| 154 | double indexm = 0.5 * (index + indexR); |
| 155 | peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency. = thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. + (indexm - 1) * thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.; |
| 156 | peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB. = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).index]; // always with flat peak |
| 157 | } |
| 158 | peakKnowncxx . . $ structPowerCepstrumWorkspace#peakKnown. = true; |
| 159 | } |
| 160 | |
| 161 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getCPPcxx . . $ structPowerCepstrumWorkspace#getCPP(49f6e7a06ebc5aa8). () { |
| 162 | if (! slopeKnowncxx . . $ structPowerCepstrumWorkspace#slopeKnown.) |
| 163 | getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). (); |
| 164 | if (! peakKnowncxx . . $ structPowerCepstrumWorkspace#peakKnown.) |
| 165 | getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). (); |
| 166 | trenddBcxx . . $ structPowerCepstrumWorkspace#trenddB. = getTrendcxx . . $ structPowerCepstrumWorkspace#getTrend(447c67c6676f75c3). (peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.); |
| 167 | cppcxx . . $ structPowerCepstrumWorkspace#cpp. = peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB. - trenddBcxx . . $ structPowerCepstrumWorkspace#trenddB.; |
| 168 | } |
| 169 | |
| 170 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: todBscxx . . $ structPowerCepstrumWorkspace#todBs(49f6e7a06ebc5aa8). () { |
| 171 | for (integercxx . . $ integer# i = 1; i <= powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> nxcxx . . $ structSampled#nx.; i ++) |
| 172 | asdBscxx . . $ structPowerCepstrumWorkspace#asdBs. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> v_getValueAtSamplecxx . . $ structPowerCepstrum#v_getValueAtSample(8bbfc6ce471470c9). (i, 1, 1); // 10 log val^2 |
| 173 | } |
| 174 | |
| 175 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: fromdBscxx . . $ structPowerCepstrumWorkspace#fromdBs(49f6e7a06ebc5aa8). () { |
| 176 | for (integercxx . . $ integer# i = 1; i <= powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> nxcxx . . $ structSampled#nx.; i ++) |
| 177 | powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = powcxx . . $ pow(b71928d39fde4295). (10.0, powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] / 10.0) - 1e-30; |
| 178 | } |
| 179 | |
| 180 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: setMaximumNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#setMaximumNumberOfRhamonics(1624ee8275b10bda). (integercxx . . $ integer# maximumNumberOfRhamonics) { |
| 181 | ourcxx . . $ `melder/melder.h:42:9`! maximumNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#maximumNumberOfRhamonics. = maximumNumberOfRhamonics; |
| 182 | // resize when we calculate values. |
| 183 | } |
| 184 | |
| 185 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#getNumberOfRhamonics(bc12c9ec15586e6a). (double qmin, double qmax) { |
| 186 | integercxx . . $ integer# numberOfRhamonics = 2; |
| 187 | if (! peakKnowncxx . . $ structPowerCepstrumWorkspace#peakKnown.) |
| 188 | getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). (); |
| 189 | while (peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency. >= qmin && peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency. * numberOfRhamonics <= qmax) |
| 190 | numberOfRhamonics ++; |
| 191 | numberOfRhamonics --; |
| 192 | numberOfRhamonics = stdcxx . . $ std/:: mincxx . . $ std/min(2a338fce5842aa6a). (numberOfRhamonics, maximumNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#maximumNumberOfRhamonics.); |
| 193 | } |
| 194 | |
| 195 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getRhamonicsPowercxx . . $ structPowerCepstrumWorkspace#getRhamonicsPower(98dd472ac7e5c3d4). (double qmin, double qmax, double f0fractionalWidth) { |
| 196 | getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). (); |
| 197 | getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). (); |
| 198 | getNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#getNumberOfRhamonics(bc12c9ec15586e6a). (qmin, qmax); |
| 199 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics..resizecxx . . $ automatrix#resize(a64d57580b9dfd76). (numberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#numberOfRhamonics., 6_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 200 | // q, peakdB, power, q1, q2, trenddb |
| 201 | for (integercxx . . $ integer# rhamonic = 1; rhamonic <= numberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#numberOfRhamonics.; rhamonic ++) { |
| 202 | const double quefrency = rhamonic * peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 203 | const double f = 1.0 / quefrency; |
| 204 | const double flow = f * (1.0 - f0fractionalWidth); |
| 205 | const double fhigh = f * (1.0 + f0fractionalWidth); |
| 206 | const double qlow = 1.0 / fhigh; |
| 207 | const double qhigh = ( f0fractionalWidth >= 1.0 ? powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> xmaxcxx . . $ structFunction#xmax. : 1.0 / flow ); |
| 208 | integercxx . . $ integer# iqmin, iqmax; |
| 209 | Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum., qlow, qhigh, & iqmin, & iqmax); |
| 210 | double power = 0.0; |
| 211 | for (integercxx . . $ integer# iq = iqmin; iq <= iqmax; iq ++) |
| 212 | power += powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> v_getValueAtSamplecxx . . $ structPowerCepstrum#v_getValueAtSample(8bbfc6ce471470c9). (iq, 1, 0); |
| 213 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = power; |
| 214 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = qlow; |
| 215 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = quefrency; |
| 216 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).4] = qhigh; |
| 217 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).5] = peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB.; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getRhamonicPeakscxx . . $ structPowerCepstrumWorkspace#getRhamonicPeaks(bc12c9ec15586e6a). (double qmin, double qmax) { |
| 222 | getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). (); |
| 223 | getNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#getNumberOfRhamonics(bc12c9ec15586e6a). (qmin, qmax); |
| 224 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics..resizecxx . . $ automatrix#resize(a64d57580b9dfd76). (numberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#numberOfRhamonics., 6_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 225 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 226 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB.; |
| 227 | kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# valueInterpolationType = ( peakInterpolationTypecxx . . $ structPowerCepstrumWorkspace#peakInterpolationType. > kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: NONEcxx . . $ kVector_peakInterpolation#NONE. ? |
| 228 | kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: LINEARcxx . . $ kVector_valueInterpolation#LINEAR. : kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# :: NEARESTcxx . . $ kVector_valueInterpolation#NEAREST. ); |
| 229 | for (integercxx . . $ integer# rhamonic = 2; rhamonic <= numberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#numberOfRhamonics.; rhamonic ++) { |
| 230 | const double quefrency = rhamonic * peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 231 | const double amplitudedB = Vector_getValueAtXcxx . . $ Vector_getValueAtX(1bfdbe9f8adea74f). ((Vectorcxx . . $ Vector#) asdBscxx . . $ structPowerCepstrumWorkspace#asdBs..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), quefrency, 1, valueInterpolationType); |
| 232 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = quefrency; |
| 233 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = amplitudedB; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | double structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: getRNRcxx . . $ structPowerCepstrumWorkspace#getRNR(7678bba071383ab). (double qmin, double qmax, double f0fractionalWidth) { |
| 238 | getRhamonicsPowercxx . . $ structPowerCepstrumWorkspace#getRhamonicsPower(98dd472ac7e5c3d4). (qmin, qmax, f0fractionalWidth); |
| 239 | const double sumOfRhamonics = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (rhamonicscxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (3)); |
| 240 | double power = 0.0; |
| 241 | for (integercxx . . $ integer# iq = imincxx . . $ structPowerCepstrumWorkspace#imin.; iq <= imaxcxx . . $ structPowerCepstrumWorkspace#imax.; iq ++) |
| 242 | power += powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> v_getValueAtSamplecxx . . $ structPowerCepstrum#v_getValueAtSample(8bbfc6ce471470c9). (iq, 1, 0); |
| 243 | const double rnr = sumOfRhamonics / (power - sumOfRhamonics); |
| 244 | return rnr; |
| 245 | } |
| 246 | |
| 247 | double structPowerCepstrumcxx . . $ structPowerCepstrum# :: v_getValueAtSamplecxx . . $ structPowerCepstrum#v_getValueAtSample(8bbfc6ce471470c9). (integercxx . . $ integer# isamp, integercxx . . $ integer# row, int units) const { |
| 248 | double result = undefinedcxx . . $ undefined.; |
| 249 | if (row == 1) { |
| 250 | if (units == 0) |
| 251 | result = zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp]; |
| 252 | else |
| 253 | result = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp] + 1e-30); // result >= -300 |
| 254 | } |
| 255 | return result; |
| 256 | } |
| 257 | |
| 258 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: initWorkspacecxx . . $ structPowerCepstrumWorkspace#initWorkspace(3274f37fea208c61). (constPowerCepstrumcxx . . $ constPowerCepstrum# me, double qminFit, double qmaxFit, |
| 259 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType# trendLineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# method) |
| 260 | { |
| 261 | powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. = me; |
| 262 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum., & qminFit, & qmaxFit); |
| 263 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (qminFit >= powerCepstrum ->xmin && qmaxFit <= powerCepstrum ->xmax, |
| 264 | U"Your quefrency range is outside the domain."); |
| 265 | (void) Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum., qminFit, qmaxFit, & imincxx . . $ structPowerCepstrumWorkspace#imin., & imaxcxx . . $ structPowerCepstrumWorkspace#imax.); |
| 266 | Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (2_integercxx . . $ `operator""_integer`(85240eb457c3721a)., & imincxx . . $ structPowerCepstrumWorkspace#imin.); // never use q=0 in fitting |
| 267 | numberOfPointscxx . . $ structPowerCepstrumWorkspace#numberOfPoints. = imaxcxx . . $ structPowerCepstrumWorkspace#imax. - imincxx . . $ structPowerCepstrumWorkspace#imin. + 1; |
| 268 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfPoints > 2, |
| 269 | U"Not enough points in the selection."); |
| 270 | ourcxx . . $ `melder/melder.h:42:9`! trendLineTypecxx . . $ structPowerCepstrumWorkspace#trendLineType. = trendLineType; |
| 271 | ourcxx . . $ `melder/melder.h:42:9`! methodcxx . . $ structPowerCepstrumWorkspace#method. = ( method == kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::LEAST_SQUAREScxx . . $ kCepstrum_trendFit#LEAST_SQUARES. ? kSlopeSelector_methodcxx . . $ kSlopeSelector_method#::LEAST_SQUAREScxx . . $ kSlopeSelector_method#LEAST_SQUARES. : |
| 272 | (method == kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::ROBUST_SLOWcxx . . $ kCepstrum_trendFit#ROBUST_SLOW. ? kSlopeSelector_methodcxx . . $ kSlopeSelector_method#::THEILSENcxx . . $ kSlopeSelector_method#THEILSEN. : kSlopeSelector_methodcxx . . $ kSlopeSelector_method#::SIEGELcxx . . $ kSlopeSelector_method#SIEGEL.)); |
| 273 | xcxx . . $ structPowerCepstrumWorkspace#x. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfPointscxx . . $ structPowerCepstrumWorkspace#numberOfPoints.); |
| 274 | ycxx . . $ structPowerCepstrumWorkspace#y. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfPointscxx . . $ structPowerCepstrumWorkspace#numberOfPoints.); |
| 275 | asdBscxx . . $ structPowerCepstrumWorkspace#asdBs. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Matrix_createcxx . . $ Matrix_create(494a3ae9ff7e3b60). (powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> xmincxx . . $ structFunction#xmin., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> xmaxcxx . . $ structFunction#xmax., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> nxcxx . . $ structSampled#nx., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> dxcxx . . $ structSampled#dx., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> x1cxx . . $ structSampled#x1., |
| 276 | powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> ymincxx . . $ structSampledXY#ymin., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> ymaxcxx . . $ structSampledXY#ymax., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> nycxx . . $ structSampledXY#ny., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. -> dycxx . . $ structSampledXY#dy., powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum. ->y1cxx . . $ structSampledXY#y1.); |
| 277 | maximumNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#maximumNumberOfRhamonics. = 15; |
| 278 | rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). raw_MATcxx . . $ raw_MAT(3d09731056d2b97d). (maximumNumberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#maximumNumberOfRhamonics., 5_integercxx . . $ `operator""_integer`(85240eb457c3721a).); |
| 279 | slopeSelectorcxx . . $ structPowerCepstrumWorkspace#slopeSelector. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). SlopeSelector_createcxx . . $ SlopeSelector_create(c8b26b5ce4b835b3). (xcxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), ycxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); // only reference to the x and y vectors |
| 280 | newDatacxx . . $ structPowerCepstrumWorkspace#newData(97428d87df076bf). (powerCepstrumcxx . . $ structPowerCepstrumWorkspace#powerCepstrum.); // new xp and yp reference |
| 281 | } |
| 282 | |
| 283 | void structPowerCepstrumWorkspacecxx . . $ structPowerCepstrumWorkspace# :: initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (double qminPeakSearch, double qmaxPeakSearch, |
| 284 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType) |
| 285 | { |
| 286 | ourcxx . . $ `melder/melder.h:42:9`! qminPeakSearchcxx . . $ structPowerCepstrumWorkspace#qminPeakSearch. = qminPeakSearch; |
| 287 | ourcxx . . $ `melder/melder.h:42:9`! qmaxPeakSearchcxx . . $ structPowerCepstrumWorkspace#qmaxPeakSearch. = qmaxPeakSearch; |
| 288 | ourcxx . . $ `melder/melder.h:42:9`! peakInterpolationTypecxx . . $ structPowerCepstrumWorkspace#peakInterpolationType. = peakInterpolationType; |
| 289 | } |
| 290 | |
| 291 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (constPowerCepstrumcxx . . $ constPowerCepstrum# powerCepstrum, double qminFit, double qmaxFit, |
| 292 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType# trendLineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod) |
| 293 | { |
| 294 | try { |
| 295 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PowerCepstrumWorkspace); |
| 296 | mycxx . . $ `melder/melder.h:44:9`! initWorkspacecxx . . $ structPowerCepstrumWorkspace#initWorkspace(3274f37fea208c61). (powerCepstrum, qminFit, qmaxFit, trendLineType, fitMethod); |
| 297 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 298 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 299 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot create PowerCepstrumWorkspace."); |
| 300 | } |
| 301 | |
| 302 | } |
| 303 | |
| 304 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# PowerCepstrum_createcxx . . $ PowerCepstrum_create(65f6cc037cbc1c8a). (double qmax, integercxx . . $ integer# nq) { |
| 305 | try { |
| 306 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PowerCepstrum); |
| 307 | const double dq = qmax / (nq - 1); |
| 308 | Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.0, qmax, nq, dq, 0.0, 1.0, 1.0, 1, 1, 1.0); |
| 309 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 310 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 311 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"PowerCepstrum not created."); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
| 316 | void PowerCepstrum_drawcxx . . $ PowerCepstrum_draw(9f03ac5d8d850d6d). (constPowerCepstrumcxx . . $ constPowerCepstrum# me, Graphicscxx . . $ Graphics# g, double qmin, double qmax, double dBminimum, double dBmaximum, bool garnish) { |
| 317 | Cepstrum_drawcxx . . $ Cepstrum_draw(9dd6d8709e60e29f). (me, g, qmin, qmax, dBminimum, dBmaximum, true, garnish); |
| 318 | } |
| 319 | |
| 320 | void PowerCepstrum_fitTrendLinecxx . . $ PowerCepstrum_fitTrendLine(173d310ec65ed505). (PowerCepstrumcxx . . $ PowerCepstrum# me, double qstartFit, double qendFit, double *out_slope, double *out_intercept, |
| 321 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType# lineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod) |
| 322 | { |
| 323 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & qstartFit, & qendFit); |
| 324 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qstartFit, qendFit, lineType, fitMethod); |
| 325 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). (); |
| 326 | if (out_slope) |
| 327 | *out_slope = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). slopecxx . . $ structPowerCepstrumWorkspace#slope.; |
| 328 | if (out_intercept) |
| 329 | *out_intercept = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interceptcxx . . $ structPowerCepstrumWorkspace#intercept.; |
| 330 | } |
| 331 | |
| 332 | void PowerCepstrum_drawTrendLinecxx . . $ PowerCepstrum_drawTrendLine(91460e9fce48b53a). (PowerCepstrumcxx . . $ PowerCepstrum# me, Graphicscxx . . $ Graphics# g, double qmin, double qmax, double dBminimum, double dBmaximum, |
| 333 | double qstartFit, double qendFit, kCepstrum_trendTypecxx . . $ kCepstrum_trendType# lineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod) |
| 334 | { |
| 335 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & qmin, & qmax); |
| 336 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & qstartFit, & qendFit); |
| 337 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qstartFit, qendFit, lineType, fitMethod); |
| 338 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getSlopeAndInterceptcxx . . $ structPowerCepstrumWorkspace#getSlopeAndIntercept(49f6e7a06ebc5aa8). (); |
| 339 | |
| 340 | if (dBminimum >= dBmaximum) { // autoscaling |
| 341 | MelderExtremaWithInitcxx . . $ MelderExtremaWithInit# extrema_db; |
| 342 | for (integercxx . . $ integer# i = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). imincxx . . $ structPowerCepstrumWorkspace#imin.; i <= workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). imaxcxx . . $ structPowerCepstrumWorkspace#imax.; i ++) |
| 343 | extrema_db.updatecxx . . $ MelderExtremaWithInit#update(ba8836b59fb42830). (workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). ycxx . . $ structPowerCepstrumWorkspace#y.[cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]); |
| 344 | dBmaximum = extrema_db.maxcxx . . $ MelderExtremaWithInit#max.; |
| 345 | dBminimum = extrema_db.mincxx . . $ MelderExtremaWithInit#min.; |
| 346 | } |
| 347 | |
| 348 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 349 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, qmin, qmax, dBminimum, dBmaximum); |
| 350 | const double slope = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). slopecxx . . $ structPowerCepstrumWorkspace#slope., intercept = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interceptcxx . . $ structPowerCepstrumWorkspace#intercept.; |
| 351 | /* |
| 352 | Don't draw part outside window |
| 353 | */ |
| 354 | const double lineWidth = Graphics_inqLineWidthcxx . . $ Graphics_inqLineWidth(f906975acce41a59). (g); |
| 355 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, 2); |
| 356 | if (lineType == kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::EXPONENTIAL_DECAYcxx . . $ kCepstrum_trendType#EXPONENTIAL_DECAY. ) { |
| 357 | integercxx . . $ integer# n = 500; |
| 358 | const double dq = (qendFit - qstartFit) / (n + 1); |
| 359 | const double q1 = qstartFit; |
| 360 | if (qstartFit <= 0.0) { |
| 361 | qstartFit = 0.1 * dq; // some small offset to avoid log(0) |
| 362 | n --; |
| 363 | } |
| 364 | autoVECcxx . . $ autoVEC# y = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (n); |
| 365 | |
| 366 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 367 | const double q = q1 + (i - 1) * dq; |
| 368 | y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = slope * logcxx . . $ log(fee4f1d22bc8e617). (q) + intercept; |
| 369 | } |
| 370 | Graphics_functioncxx . . $ Graphics_function(1c6279e2c8b8beb1). (g, y.asArgumentToFunctionThatExpectsOneBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsOneBasedArray(5a2a78a048fb49a8).(), 1, n, qstartFit, qendFit); |
| 371 | } else { |
| 372 | const double y1 = slope * qstartFit + intercept; |
| 373 | const double y2 = slope * qendFit + intercept; |
| 374 | if (y1 >= dBminimum && y2 >= dBminimum) { |
| 375 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, qstartFit, y1, qendFit, y2); |
| 376 | } else if (y1 < dBminimum) { |
| 377 | qstartFit = (dBminimum - intercept) / slope; |
| 378 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, qstartFit, dBminimum, qendFit, y2); |
| 379 | } else if (y2 < dBminimum) { |
| 380 | qendFit = (dBminimum - intercept) / slope; |
| 381 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, qstartFit, y1, qendFit, dBminimum); |
| 382 | } else { |
| 383 | // don't draw anything below lower limit |
| 384 | } |
| 385 | } |
| 386 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, lineWidth); |
| 387 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 388 | } |
| 389 | |
| 390 | double PowerCepstrum_getTrendLineValuecxx . . $ PowerCepstrum_getTrendLineValue(e272ea76ff694104). (PowerCepstrumcxx . . $ PowerCepstrum# me, double quefrency, double qstartFit, double qendFit, kCepstrum_trendTypecxx . . $ kCepstrum_trendType# lineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod) |
| 391 | { |
| 392 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & qstartFit, & qendFit); |
| 393 | double trenddb = undefinedcxx . . $ undefined.; |
| 394 | if (quefrency >= mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. && quefrency <= mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) { |
| 395 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qstartFit, qendFit, lineType, fitMethod); |
| 396 | trenddb = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getTrendcxx . . $ structPowerCepstrumWorkspace#getTrend(447c67c6676f75c3). (quefrency); |
| 397 | } |
| 398 | return trenddb; |
| 399 | } |
| 400 | |
| 401 | void PowerCepstrum_subtractTrend_inplacecxx . . $ PowerCepstrum_subtractTrend_inplace(e601ab7ba421fc4e). (mutablePowerCepstrumcxx . . $ mutablePowerCepstrum# me, double qstartFit, double qendFit, kCepstrum_trendTypecxx . . $ kCepstrum_trendType# lineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod) |
| 402 | { |
| 403 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & qstartFit, & qendFit); |
| 404 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qstartFit, qendFit, lineType, fitMethod); |
| 405 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). subtractTrendcxx . . $ structPowerCepstrumWorkspace#subtractTrend(49f6e7a06ebc5aa8). (); |
| 406 | } |
| 407 | |
| 408 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# PowerCepstrum_subtractTrendcxx . . $ PowerCepstrum_subtractTrend(c287eab6aa43dfd5). (constPowerCepstrumcxx . . $ constPowerCepstrum# me, double qstartFit, double qendFit, kCepstrum_trendTypecxx . . $ kCepstrum_trendType# lineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod) { |
| 409 | try { |
| 410 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 411 | PowerCepstrum_subtractTrend_inplacecxx . . $ PowerCepstrum_subtractTrend_inplace(e601ab7ba421fc4e). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), qstartFit, qendFit, lineType, fitMethod); |
| 412 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 413 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 414 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": couldn't subtract trend line."); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | static void PowerCepstrum_smooth_inplaceRectangularcxx . . $ PowerCepstrum_smooth_inplaceRectangular(7a6e9b94d2abb698). (mutablePowerCepstrumcxx . . $ mutablePowerCepstrum# me, double quefrencyAveragingWindow, integercxx . . $ integer# numberOfIterations) { |
| 419 | try { |
| 420 | const double halfWindwow = 0.5 * quefrencyAveragingWindow; |
| 421 | const double numberOfQuefrencyBins = quefrencyAveragingWindow / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 422 | if (numberOfQuefrencyBins > 1.0) { |
| 423 | autoVECcxx . . $ autoVEC# qout = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 424 | for (integercxx . . $ integer# k = 1; k <= numberOfIterations; k ++) { |
| 425 | for (integercxx . . $ integer# isamp = 1; isamp <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; isamp ++) { |
| 426 | const double xmid = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, isamp); |
| 427 | qout [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).isamp] = Sampled_getMeancxx . . $ Sampled_getMean(2a8b0d40a92e6734). (me, xmid - halfWindwow, xmid + halfWindwow, 1, 0, true); |
| 428 | } |
| 429 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). qoutcxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 430 | } |
| 431 | } |
| 432 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 433 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not smoothed."); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | static void PowerCepstrum_smooth_inplaceRectangular_oldcxx . . $ PowerCepstrum_smooth_inplaceRectangular_old(7a6e9b94d2abb698). (mutablePowerCepstrumcxx . . $ mutablePowerCepstrum# me, double quefrencyAveragingWindow, integercxx . . $ integer# numberOfIterations) { |
| 438 | try { |
| 439 | const integercxx . . $ integer# numberOfQuefrencyBins = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (quefrencyAveragingWindow / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 440 | if (numberOfQuefrencyBins > 1) { |
| 441 | autoVECcxx . . $ autoVEC# qin = copy_VECcxx . . $ copy_VEC(d4415e68b25283a8). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1)); |
| 442 | autoVECcxx . . $ autoVEC# qout = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 443 | for (integercxx . . $ integer# k = 1; k <= numberOfIterations; k ++) |
| 444 | if (k % 2 == 1) |
| 445 | VECsmoothByMovingAverage_preallocatedcxx . . $ VECsmoothByMovingAverage_preallocated(5e8ce1ad74af04af). (qoutcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), qincxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), numberOfQuefrencyBins); |
| 446 | else |
| 447 | VECsmoothByMovingAverage_preallocatedcxx . . $ VECsmoothByMovingAverage_preallocated(5e8ce1ad74af04af). (qincxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), qoutcxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), numberOfQuefrencyBins); |
| 448 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). (cxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd). numberOfIterations % 2 == 1 ? qout.getcxx . . $ autovector#get(e8d1da7fe68a6585).() : qin.getcxx . . $ autovector#get(e8d1da7fe68a6585).() ); |
| 449 | } |
| 450 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 451 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not smoothed."); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | static void PowerCepstrum_smooth_inplaceGaussiancxx . . $ PowerCepstrum_smooth_inplaceGaussian(7a6e9b94d2abb698). (mutablePowerCepstrumcxx . . $ mutablePowerCepstrum# me, double quefrencyAveragingWindow, integercxx . . $ integer# numberOfIterations) { |
| 456 | try { |
| 457 | const double numberOfQuefrencyBins = quefrencyAveragingWindow / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 458 | if (numberOfQuefrencyBins > 1.0) { |
| 459 | /* |
| 460 | Applying two Gaussians after another is associative: (G(s2)*(G(s1)*f) = (G(s2)*G(s1))*f. |
| 461 | G(s2) * G(s1) = G(s), where s^2=s1^2+s2^2 |
| 462 | */ |
| 463 | const double numberOfSigmasInWindow = 4.0; |
| 464 | const double sigma = numberOfQuefrencyBins / numberOfSigmasInWindow; // 3sigma -> 99.7 % of the data (2sigma -> 95.4%)g |
| 465 | const double sigma_n = sqrtcxx . . $ sqrt(7759b11ec49fe502). (numberOfIterations) * sigma; |
| 466 | VECsmooth_gaussian_inplacecxx . . $ VECsmooth_gaussian_inplace(cb3d2a9455fe8b3e). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1), sigma_n); |
| 467 | /* |
| 468 | Due to imprecise arithmatic some values might turn out to be negative |
| 469 | (but very small). Just make them positive. |
| 470 | */ |
| 471 | abs_VEC_inoutcxx . . $ abs_VEC_inout(41aeeb373bdabfed). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1)); |
| 472 | } |
| 473 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 474 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not smoothed."); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | void PowerCepstrum_smooth_inplacecxx . . $ PowerCepstrum_smooth_inplace(7a6e9b94d2abb698). (mutablePowerCepstrumcxx . . $ mutablePowerCepstrum# me, double quefrencyAveragingWindow, integercxx . . $ integer# numberOfIterations) { |
| 479 | if (Melder_debugcxx . . $ Melder_debug. == -4) |
| 480 | PowerCepstrum_smooth_inplaceRectangular_oldcxx . . $ PowerCepstrum_smooth_inplaceRectangular_old(7a6e9b94d2abb698). (me, quefrencyAveragingWindow, numberOfIterations); |
| 481 | else if (Melder_debugcxx . . $ Melder_debug. == -5) |
| 482 | PowerCepstrum_smooth_inplaceGaussiancxx . . $ PowerCepstrum_smooth_inplaceGaussian(7a6e9b94d2abb698). (me, quefrencyAveragingWindow, numberOfIterations); |
| 483 | else |
| 484 | PowerCepstrum_smooth_inplaceRectangularcxx . . $ PowerCepstrum_smooth_inplaceRectangular(7a6e9b94d2abb698). (me, quefrencyAveragingWindow, numberOfIterations); |
| 485 | } |
| 486 | |
| 487 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# PowerCepstrum_smoothcxx . . $ PowerCepstrum_smooth(e45db4bba98730d0). (constPowerCepstrumcxx . . $ constPowerCepstrum# me, double quefrencyAveragingWindow, integercxx . . $ integer# numberOfIterations) { |
| 488 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 489 | PowerCepstrum_smooth_inplacecxx . . $ PowerCepstrum_smooth_inplace(7a6e9b94d2abb698). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), quefrencyAveragingWindow, numberOfIterations); |
| 490 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | void PowerCepstrum_getMaximumAndQuefrency_qcxx . . $ PowerCepstrum_getMaximumAndQuefrency_q(ecf0e26fab6d82d0). (PowerCepstrumcxx . . $ PowerCepstrum# me, double qminPeakSearch, double qmaxPeakSearch, |
| 495 | kCepstrum_peakInterpolationcxx . . $ kCepstrum_peakInterpolation# peakInterpolationType, double& peakdB, double& quefrency) |
| 496 | { |
| 497 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# interpolation = ( peakInterpolationType == kCepstrum_peakInterpolationcxx . . $ kCepstrum_peakInterpolation# :: PARABOLICcxx . . $ kCepstrum_peakInterpolation#PARABOLIC. ? |
| 498 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: PARABOLICcxx . . $ kVector_peakInterpolation#PARABOLIC. : (peakInterpolationType == kCepstrum_peakInterpolationcxx . . $ kCepstrum_peakInterpolation# :: CUBICcxx . . $ kCepstrum_peakInterpolation#CUBIC. ? |
| 499 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: CUBICcxx . . $ kVector_peakInterpolation#CUBIC. : kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: NONEcxx . . $ kVector_peakInterpolation#NONE.) |
| 500 | ); |
| 501 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & qminPeakSearch, & qmaxPeakSearch); |
| 502 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qminPeakSearch, qmaxPeakSearch, kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::LINEARcxx . . $ kCepstrum_trendType#LINEAR., kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::ROBUST_FASTcxx . . $ kCepstrum_trendFit#ROBUST_FAST.); |
| 503 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch, qmaxPeakSearch, interpolation); |
| 504 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). (); |
| 505 | peakdB = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB.; |
| 506 | quefrency = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 507 | } |
| 508 | |
| 509 | //TODO |
| 510 | void PowerCepstrum_getMaximumAndQuefrency_pitchcxx . . $ PowerCepstrum_getMaximumAndQuefrency_pitch(a96aac5938721765). (PowerCepstrumcxx . . $ PowerCepstrum# me, double pitchFloor, double pitchCeiling, |
| 511 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType, double& peakdB, double& quefrency) |
| 512 | { |
| 513 | const double qminPeakSearch = 1.0 / pitchCeiling; |
| 514 | const double qmaxPeakSearch = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., 1.0 / pitchFloor); |
| 515 | |
| 516 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qminPeakSearch, qmaxPeakSearch, kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::LINEARcxx . . $ kCepstrum_trendType#LINEAR., kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::ROBUST_FASTcxx . . $ kCepstrum_trendFit#ROBUST_FAST.); |
| 517 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch, qmaxPeakSearch, peakInterpolationType); |
| 518 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getPeakAndPositioncxx . . $ structPowerCepstrumWorkspace#getPeakAndPosition(49f6e7a06ebc5aa8). (); |
| 519 | peakdB = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). peakdBcxx . . $ structPowerCepstrumWorkspace#peakdB.; |
| 520 | quefrency = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 521 | } |
| 522 | |
| 523 | autoTablecxx . . $ autoTable# PowerCepstrum_tabulateRhamonicscxx . . $ PowerCepstrum_tabulateRhamonics(1bf238440d631cf2). (PowerCepstrumcxx . . $ PowerCepstrum# me, double pitchFloor, double pitchCeiling, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType) { |
| 524 | try { |
| 525 | const double qminPeakSearch = 1.0 / pitchCeiling; |
| 526 | const double qmaxPeakSearch = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., 1.0 / pitchFloor); |
| 527 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qminPeakSearch, qmaxPeakSearch, |
| 528 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::LINEARcxx . . $ kCepstrum_trendType#LINEAR., kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::ROBUST_FASTcxx . . $ kCepstrum_trendFit#ROBUST_FAST.); |
| 529 | |
| 530 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch, qmaxPeakSearch, peakInterpolationType); |
| 531 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getRhamonicPeakscxx . . $ structPowerCepstrumWorkspace#getRhamonicPeaks(bc12c9ec15586e6a). (qminPeakSearch, qmaxPeakSearch); |
| 532 | |
| 533 | const conststring32cxx . . $ conststring32# columnNames [] = { U"peak(dB)", U"quefrency(s)" }; |
| 534 | autoTablecxx . . $ autoTable# thee = Table_createWithColumnNamescxx . . $ Table_createWithColumnNames(41b41b537590f3f4). (workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#numberOfRhamonics., ARRAY_TO_STRVECcxx . . $ `melder/melder_strvec.h:262:9`! (columnNames)); |
| 535 | |
| 536 | for (integercxx . . $ integer# rhamonic = 1; rhamonic <= workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfRhamonicscxx . . $ structPowerCepstrumWorkspace#numberOfRhamonics.; rhamonic ++) { |
| 537 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rhamonic, 1, workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic][cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1]); |
| 538 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rhamonic, 2, workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rhamonic][cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2]); |
| 539 | } |
| 540 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 541 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 542 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": rhamonics could not be tabulated."); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | static autoMATcxx . . $ autoMAT# PowerCepstrum_getRhamonicsPowercxx . . $ PowerCepstrum_getRhamonicsPower(ecef2312c7f6674c). (PowerCepstrumcxx . . $ PowerCepstrum# me, double pitchFloor, double pitchCeiling, double f0fractionalWidth) { |
| 547 | try { |
| 548 | const double qminPeakSearch = 1.0 /pitchCeiling; |
| 549 | const double qmaxPeakSearch = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., 1.0 / pitchFloor); |
| 550 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qminPeakSearch, qmaxPeakSearch, |
| 551 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::LINEARcxx . . $ kCepstrum_trendType#LINEAR., kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::ROBUST_FASTcxx . . $ kCepstrum_trendFit#ROBUST_FAST.); |
| 552 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch, qmaxPeakSearch, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: CUBICcxx . . $ kVector_peakInterpolation#CUBIC.); |
| 553 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getRhamonicsPowercxx . . $ structPowerCepstrumWorkspace#getRhamonicsPower(98dd472ac7e5c3d4). (qminPeakSearch, qmaxPeakSearch, f0fractionalWidth); |
| 554 | autoMATcxx . . $ autoMAT# result = copy_MATcxx . . $ copy_MAT(a392b09ce3fc3972). (workspacecxx . . $ constmatrixview#constmatrixview(eed9513d24570b3d). ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). rhamonicscxx . . $ structPowerCepstrumWorkspace#rhamonics..getcxx . . $ automatrix#get(b2b81450b5bdda66).()); |
| 555 | return resultcxx . . $ automatrix#automatrix(a69681c49ef9c9eb).; |
| 556 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 557 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": rhamonics could not be calculated."); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | double PowerCepstrum_getRNRcxx . . $ PowerCepstrum_getRNR(28294643cd07da4c). (PowerCepstrumcxx . . $ PowerCepstrum# me, double pitchFloor, double pitchCeiling, double f0fractionalWidth) { |
| 562 | const double qminPeakSearch = 1.0 /pitchCeiling; |
| 563 | const double qmaxPeakSearch = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., 1.0 / pitchFloor); |
| 564 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me,qminPeakSearch, qmaxPeakSearch, |
| 565 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::LINEARcxx . . $ kCepstrum_trendType#LINEAR., kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::ROBUST_FASTcxx . . $ kCepstrum_trendFit#ROBUST_FAST.); |
| 566 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch, qmaxPeakSearch, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: CUBICcxx . . $ kVector_peakInterpolation#CUBIC.); |
| 567 | const double rnr = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getRNRcxx . . $ structPowerCepstrumWorkspace#getRNR(7678bba071383ab). (qminPeakSearch, qmaxPeakSearch, f0fractionalWidth); |
| 568 | return rnr; |
| 569 | } |
| 570 | |
| 571 | double PowerCepstrum_getPeakProminence_hillenbrandcxx . . $ PowerCepstrum_getPeakProminence_hillenbrand(e2f5b9137cc1c6d6). (PowerCepstrumcxx . . $ PowerCepstrum# me, double pitchFloor, double pitchCeiling, double& qpeak) { |
| 572 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, 0.001, mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., kCepstrum_trendTypecxx . . $ kCepstrum_trendType#::LINEARcxx . . $ kCepstrum_trendType#LINEAR., |
| 573 | kCepstrum_trendFitcxx . . $ kCepstrum_trendFit#::LEAST_SQUAREScxx . . $ kCepstrum_trendFit#LEAST_SQUARES.); |
| 574 | const double qminPeakSearch = 1.0 /pitchCeiling; |
| 575 | const double qmaxPeakSearch = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., 1.0 / pitchFloor); |
| 576 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch,qmaxPeakSearch, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# :: NONEcxx . . $ kVector_peakInterpolation#NONE.); |
| 577 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getCPPcxx . . $ structPowerCepstrumWorkspace#getCPP(49f6e7a06ebc5aa8). (); |
| 578 | qpeak = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 579 | return workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). cppcxx . . $ structPowerCepstrumWorkspace#cpp.; |
| 580 | } |
| 581 | |
| 582 | double PowerCepstrum_getPeakProminencecxx . . $ PowerCepstrum_getPeakProminence(4004aa546187d74). (PowerCepstrumcxx . . $ PowerCepstrum# me, double pitchFloor, double pitchCeiling, |
| 583 | kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType, double qstartFit, double qendFit, |
| 584 | kCepstrum_trendTypecxx . . $ kCepstrum_trendType# trendLineType, kCepstrum_trendFitcxx . . $ kCepstrum_trendFit# fitMethod, double& qpeak) |
| 585 | { |
| 586 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & qstartFit, & qendFit); |
| 587 | autoPowerCepstrumWorkspacecxx . . $ autoPowerCepstrumWorkspace# workspace = PowerCepstrumWorkspace_createcxx . . $ PowerCepstrumWorkspace_create(fb1b3573b07a0390). (me, qstartFit, qendFit, trendLineType, fitMethod); |
| 588 | const double qminPeakSearch = 1.0 /pitchCeiling; |
| 589 | const double qmaxPeakSearch = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., 1.0 / pitchFloor); |
| 590 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). initPeakSearchPartcxx . . $ structPowerCepstrumWorkspace#initPeakSearchPart(f64aff899444c20a). (qminPeakSearch,qmaxPeakSearch, peakInterpolationType); |
| 591 | workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getCPPcxx . . $ structPowerCepstrumWorkspace#getCPP(49f6e7a06ebc5aa8). (); |
| 592 | qpeak = workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). peakQuefrencycxx . . $ structPowerCepstrumWorkspace#peakQuefrency.; |
| 593 | return workspace ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). cppcxx . . $ structPowerCepstrumWorkspace#cpp.; |
| 594 | } |
| 595 | |
| 596 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# Cepstrum_downto_PowerCepstrumcxx . . $ Cepstrum_downto_PowerCepstrum(757055eabe9a3793). (constCepstrumcxx . . $ constCepstrum# me) { |
| 597 | try { |
| 598 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# thee = PowerCepstrum_createcxx . . $ PowerCepstrum_create(65f6cc037cbc1c8a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 599 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 600 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = sqrcxx . . $ sqr(ada6a8422704cf8a). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]); |
| 601 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 602 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 603 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" not converted."); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | autoMatrixcxx . . $ autoMatrix# PowerCepstrum_to_Matrixcxx . . $ PowerCepstrum_to_Matrix(dbe01c558b68733d). (constPowerCepstrumcxx . . $ constPowerCepstrum# me) { |
| 608 | try { |
| 609 | autoMatrixcxx . . $ autoMatrix# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Matrix); |
| 610 | mycxx . . $ `melder/melder.h:44:9`! structMatrixcxx . . $ structMatrix# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 611 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 612 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 613 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Matrix created."); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# Matrix_to_PowerCepstrumcxx . . $ Matrix_to_PowerCepstrum(1b9e880dd93d7f4c). (constMatrixcxx . . $ constMatrix# me) { |
| 618 | try { |
| 619 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! ny == 1, |
| 620 | U"Matrix should have exactly 1 row."); |
| 621 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PowerCepstrum); |
| 622 | mycxx . . $ `melder/melder.h:44:9`! structMatrixcxx . . $ structMatrix# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 623 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 624 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 625 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to PowerCepstrum."); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# Matrix_to_PowerCepstrum_rowcxx . . $ Matrix_to_PowerCepstrum_row(3e19dff9545fef25). (constMatrixcxx . . $ constMatrix# me, integercxx . . $ integer# row) { |
| 630 | try { |
| 631 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# thee = PowerCepstrum_createcxx . . $ PowerCepstrum_create(65f6cc037cbc1c8a). (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 632 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (row > 0 && row <= mycxx . . $ `melder/melder.h:44:9`! ny, |
| 633 | U"Row number should be between 1 and ", mycxx . . $ `melder/melder.h:44:9`! ny, U" inclusive."); |
| 634 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (row); |
| 635 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 636 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 637 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no PowerCepstrum created."); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# Matrix_to_PowerCepstrum_columncxx . . $ Matrix_to_PowerCepstrum_column(3e19dff9545fef25). (constMatrixcxx . . $ constMatrix# me, integercxx . . $ integer# col) { |
| 642 | try { |
| 643 | autoPowerCepstrumcxx . . $ autoPowerCepstrum# thee = PowerCepstrum_createcxx . . $ PowerCepstrum_create(65f6cc037cbc1c8a). (mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.); |
| 644 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (col > 0 && col <= mycxx . . $ `melder/melder.h:44:9`! nx, |
| 645 | U"Column number should be between 1 and ", mycxx . . $ `melder/melder.h:44:9`! nx, U" inclusive."); |
| 646 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (col); |
| 647 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 648 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 649 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no PowerCepstrum created."); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /* End of file PowerCepstrum.cpp */ |