| 1 | /* MFCC.cpp |
| 2 | * |
| 3 | * Mel Frequency Cepstral Coefficients class. |
| 4 | * |
| 5 | * Copyright (C) 1993-2017, 2026 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * djmw 20020813 GPL header |
| 23 | * djmw 20110304 Thing_new |
| 24 | */ |
| 25 | |
| 26 | #include "MFCC.h"cxx . . $ `<file>/dwtools/MFCC.h`/ |
| 27 | #include "Spectrogram_extensions.h"cxx . . $ `<file>/dwtools/Spectrogram_extensions.h`/ |
| 28 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 29 | |
| 30 | |
| 31 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (MFCC, CC, 1); |
| 32 | |
| 33 | void structMFCCcxx . . $ structMFCC# :: v1_infocxx . . $ structMFCC#v1_info(49f6e7a06ebc5aa8). () { |
| 34 | structCCcxx . . $ structCC# :: v1_infocxx . . $ structCC#v1_info(49f6e7a06ebc5aa8). (); |
| 35 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Minimum frequency: ", fmincxx . . $ structCC#fmin., U" mel"); |
| 36 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Maximum frequency: ", fmaxcxx . . $ structCC#fmax., U" mel"); |
| 37 | } |
| 38 | |
| 39 | autoMFCCcxx . . $ autoMFCC# MFCC_createcxx . . $ MFCC_create(7f090c33aa14b585). (double tmin, double tmax, integercxx . . $ integer# nt, double dt, double t1, integercxx . . $ integer# maximumNumberOfCoefficients, double fmin_mel, double fmax_mel) { |
| 40 | try { |
| 41 | autoMFCCcxx . . $ autoMFCC# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (MFCC); |
| 42 | CC_initcxx . . $ CC_init(7fa60628e323f54f). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, nt, dt, t1, maximumNumberOfCoefficients, fmin_mel, fmax_mel); |
| 43 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 44 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 45 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"MFCC not created."); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void MFCC_liftercxx . . $ MFCC_lifter(34b43019fb85ab3c). (MFCCcxx . . $ MFCC# me, integercxx . . $ integer# lifter) { |
| 50 | try { |
| 51 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (lifter > 0); |
| 52 | autoVECcxx . . $ autoVEC# c = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! maximumNumberOfCoefficientscxx . . $ structCC#maximumNumberOfCoefficients.); |
| 53 | for (integercxx . . $ integer# icoef = 1; icoef <= mycxx . . $ `melder/melder.h:44:9`! maximumNumberOfCoefficientscxx . . $ structCC#maximumNumberOfCoefficients.; icoef ++) |
| 54 | c [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icoef] = (1 + lifter / 2 * sincxx . . $ sin(fee4f1d22bc8e617). (NUMpicxx . . $ NUMpi. * icoef / lifter)); // BUG ? |
| 55 | for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) { |
| 56 | CC_Framecxx . . $ CC_Frame# cf = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 57 | for (integercxx . . $ integer# icoef = 1; icoef <= cf -> numberOfCoefficientscxx . . $ structCC_Frame#numberOfCoefficients.; icoef ++) |
| 58 | cf -> ccxx . . $ structCC_Frame#c. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icoef] *= c [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icoef]; |
| 59 | } |
| 60 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 61 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not lifted."); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | autoTableOfRealcxx . . $ autoTableOfReal# MFCC_to_TableOfRealcxx . . $ MFCC_to_TableOfReal(7b9f12beb1cbfe33). (MFCCcxx . . $ MFCC# me, bool includeC0) { |
| 66 | try { |
| 67 | integercxx . . $ integer# numberOfColumns = mycxx . . $ `melder/melder.h:44:9`! maximumNumberOfCoefficientscxx . . $ structCC#maximumNumberOfCoefficients. + ( includeC0 ? 1 : 0 ); |
| 68 | autoTableOfRealcxx . . $ autoTableOfReal# thee = TableOfReal_createcxx . . $ TableOfReal_create(e573ed3514e79d3). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., numberOfColumns); |
| 69 | for (integercxx . . $ integer# i = 1; i <= numberOfColumns; i ++) |
| 70 | TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"c", ( includeC0 ? i - 1 : i ))); |
| 71 | const integercxx . . $ integer# offset = ( includeC0 ? 1 : 0 ); |
| 72 | for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) { |
| 73 | const CC_Framecxx . . $ CC_Frame# cf = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 74 | for (integercxx . . $ integer# j = 1; j <= cf -> numberOfCoefficientscxx . . $ structCC_Frame#numberOfCoefficients.; j ++) |
| 75 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iframe] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j + offset] = cf -> ccxx . . $ structCC_Frame#c. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]; |
| 76 | if (includeC0) |
| 77 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iframe] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = cf -> c0cxx . . $ structCC_Frame#c0.; |
| 78 | } |
| 79 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 80 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 81 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to TabelOfReal."); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // as_Sound not to_Sound |
| 86 | autoSoundcxx . . $ autoSound# MFCC_to_Soundcxx . . $ MFCC_to_Sound(6812155c679020aa). (MFCCcxx . . $ MFCC# me) { |
| 87 | try { |
| 88 | /* |
| 89 | All frames of an MFCC have the same size, which can differ from maximumNumberOfCoefficients. |
| 90 | */ |
| 91 | const CC_Framecxx . . $ CC_Frame# cf1 = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 92 | const integercxx . . $ integer# numberOfCoefficients = cf1 -> ccxx . . $ structCC_Frame#c..sizecxx . . $ autovector#size.; |
| 93 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfCoefficients, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 94 | for (integercxx . . $ integer# iframe = 1; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iframe ++) { |
| 95 | const CC_Framecxx . . $ CC_Frame# cf = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 96 | if (cf -> ccxx . . $ structCC_Frame#c..sizecxx . . $ autovector#size. != numberOfCoefficients) |
| 97 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"MFCC_to_Sound: ", cf -> c.size, U" ", numberOfCoefficients); |
| 98 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (iframe) <<=cxx . . $ `operator<<=`(adea042513329390). cfcxx . . $ constvectorview#constvectorview(5c6f246bf1d99401). -> ccxx . . $ structCC_Frame#c..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 99 | } |
| 100 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 101 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 102 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not represented as Sound."); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static void checkMFCCpaircxx . . $ checkMFCCpair(f327d0e48e9ad60f). (MFCCcxx . . $ MFCC# me, MFCCcxx . . $ MFCC# thee) { |
| 107 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! dx == thycxx . . $ `melder/melder.h:45:9`! dx, |
| 108 | U"The samplings of the two MFCC's should be equal."); |
| 109 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! maximumNumberOfCoefficients == thycxx . . $ `melder/melder.h:45:9`! maximumNumberOfCoefficients, |
| 110 | U"The maximum number of coefficients in the two MFCC's should be equal."); |
| 111 | const CC_Framecxx . . $ CC_Frame# my_cf1 = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 112 | const integercxx . . $ integer# my_numberOfCoefficients = my_cf1 -> ccxx . . $ structCC_Frame#c..sizecxx . . $ autovector#size.; |
| 113 | const CC_Framecxx . . $ CC_Frame# thy_cf1 = & thycxx . . $ `melder/melder.h:45:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 114 | const integercxx . . $ integer# thy_numberOfCoefficients = thy_cf1 -> ccxx . . $ structCC_Frame#c..sizecxx . . $ autovector#size.; |
| 115 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (my_numberOfCoefficients == thy_numberOfCoefficients, |
| 116 | U"The number of coefficients in the two MFCC's should be equal."); |
| 117 | } |
| 118 | |
| 119 | autoSoundcxx . . $ autoSound# MFCCs_crossCorrelatecxx . . $ MFCCs_crossCorrelate(635bee82e3ca1db8). (MFCCcxx . . $ MFCC# me, MFCCcxx . . $ MFCC# thee, enum kSounds_convolve_scalingcxx . . $ kSounds_convolve_scaling# scaling, enum kSounds_convolve_signalOutsideTimeDomaincxx . . $ kSounds_convolve_signalOutsideTimeDomain# signalOutsideTimeDomain) { |
| 120 | try { |
| 121 | checkMFCCpaircxx . . $ checkMFCCpair(f327d0e48e9ad60f). (me, thee); |
| 122 | autoSoundcxx . . $ autoSound# target = MFCC_to_Soundcxx . . $ MFCC_to_Sound(6812155c679020aa). (me); |
| 123 | autoSoundcxx . . $ autoSound# source = MFCC_to_Soundcxx . . $ MFCC_to_Sound(6812155c679020aa). (thee); |
| 124 | autoSoundcxx . . $ autoSound# cc = Sounds_crossCorrelatecxx . . $ Sounds_crossCorrelate(b7360aaa447e63e). (target.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), source.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), scaling, signalOutsideTimeDomain); |
| 125 | return cccxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 126 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 127 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No cross-correlation between ", me, U" and ", thee, U" calculated."); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | autoSoundcxx . . $ autoSound# MFCCs_convolvecxx . . $ MFCCs_convolve(635bee82e3ca1db8). (MFCCcxx . . $ MFCC# me, MFCCcxx . . $ MFCC# thee, enum kSounds_convolve_scalingcxx . . $ kSounds_convolve_scaling# scaling, enum kSounds_convolve_signalOutsideTimeDomaincxx . . $ kSounds_convolve_signalOutsideTimeDomain# signalOutsideTimeDomain) { |
| 132 | try { |
| 133 | checkMFCCpaircxx . . $ checkMFCCpair(f327d0e48e9ad60f). (me, thee); |
| 134 | autoSoundcxx . . $ autoSound# target = MFCC_to_Soundcxx . . $ MFCC_to_Sound(6812155c679020aa). (me); |
| 135 | autoSoundcxx . . $ autoSound# source = MFCC_to_Soundcxx . . $ MFCC_to_Sound(6812155c679020aa). (thee); |
| 136 | autoSoundcxx . . $ autoSound# cc = Sounds_convolvecxx . . $ Sounds_convolve(b7360aaa447e63e). (target.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), source.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), scaling, signalOutsideTimeDomain); |
| 137 | return cccxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 138 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 139 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" and ", thee, U" not convolved."); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | static double CC_Frames_distancecxx . . $ CC_Frames_distance(ddcb5126596ec161). (CC_Framecxx . . $ CC_Frame# me, CC_Framecxx . . $ CC_Frame# thee, bool includeEnergy) { |
| 144 | double dist = 0; |
| 145 | if (includeEnergy) { |
| 146 | const double d0 = mycxx . . $ `melder/melder.h:44:9`! c0cxx . . $ structCC_Frame#c0. - thycxx . . $ `melder/melder.h:45:9`! c0cxx . . $ structCC_Frame#c0.; |
| 147 | dist += d0 * d0; |
| 148 | } |
| 149 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfCoefficientscxx . . $ structCC_Frame#numberOfCoefficients.; i ++) { |
| 150 | const double di = mycxx . . $ `melder/melder.h:44:9`! ccxx . . $ structCC_Frame#c. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] - thycxx . . $ `melder/melder.h:45:9`! ccxx . . $ structCC_Frame#c. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 151 | dist += di * di; |
| 152 | } |
| 153 | return sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (dist); |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | 1: cepstral difference function (d) |
| 158 | 2: spectral stability (dstab) |
| 159 | 3: spectral center of gravity (gs) |
| 160 | 4: stable internal duration |
| 161 | */ |
| 162 | autoMatrixcxx . . $ autoMatrix# MFCC_to_Matrix_featurescxx . . $ MFCC_to_Matrix_features(a0cadf97fac2eb6a). (MFCCcxx . . $ MFCC# me, double windowLength, bool includeEnergy) { |
| 163 | try { |
| 164 | const integercxx . . $ integer# nw = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (windowLength / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / 2.0); |
| 165 | autoMelSpectrogramcxx . . $ autoMelSpectrogram# him = MFCC_to_MelSpectrogramcxx . . $ MFCC_to_MelSpectrogram(819a68c6ca5b5468). (me, 0, 0, 1); |
| 166 | autoMatrixcxx . . $ autoMatrix# thee = Matrix_createcxx . . $ Matrix_create(494a3ae9ff7e3b60). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., 1.0, 4.0, 4, 1.0, 1.0); |
| 167 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.] = 0; // first & last frame |
| 168 | for (integercxx . . $ integer# iframe = 2; iframe <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. - 1; iframe ++) { |
| 169 | const CC_Framecxx . . $ CC_Frame# cfi = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 170 | // 1. cepstral difference |
| 171 | integercxx . . $ integer# nwi = ( iframe > nw ? nw : iframe - 1 ); |
| 172 | if (nwi > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. - iframe) |
| 173 | nwi = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. - iframe; |
| 174 | double numer = 0.0; |
| 175 | for (integercxx . . $ integer# j = 1; j <= nwi; j ++) |
| 176 | numer += (double) j * (double) j; |
| 177 | numer *= 2.0; |
| 178 | double dsq = 0.0; |
| 179 | if (includeEnergy) { |
| 180 | longdoublecxx . . $ longdouble# sumj = 0.0; |
| 181 | for (integercxx . . $ integer# j = 1; j <= nwi; j ++) { |
| 182 | const CC_Framecxx . . $ CC_Frame# cfp = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe + j]; |
| 183 | const CC_Framecxx . . $ CC_Frame# cfm = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe - j]; |
| 184 | sumj += j * (cfp -> c0cxx . . $ structCC_Frame#c0. - cfm -> c0cxx . . $ structCC_Frame#c0.); |
| 185 | } |
| 186 | sumj /= numer; |
| 187 | dsq += sumj * sumj; |
| 188 | } |
| 189 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! maximumNumberOfCoefficientscxx . . $ structCC#maximumNumberOfCoefficients.; i ++) { |
| 190 | longdoublecxx . . $ longdouble# sumj = 0.0; |
| 191 | for (integercxx . . $ integer# j = 1; j <= nwi; j ++) { |
| 192 | const CC_Framecxx . . $ CC_Frame# cfp = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe + j]; |
| 193 | const CC_Framecxx . . $ CC_Frame# cfm = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe - j]; |
| 194 | sumj += j * (cfp -> ccxx . . $ structCC_Frame#c. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j] - cfm -> ccxx . . $ structCC_Frame#c. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]); |
| 195 | } |
| 196 | sumj /= numer; |
| 197 | dsq += sumj * sumj; |
| 198 | } |
| 199 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = dsq; |
| 200 | |
| 201 | // 2: spectral stability (dstab) |
| 202 | const CC_Framecxx . . $ CC_Frame# cfp = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe + 1]; |
| 203 | const CC_Framecxx . . $ CC_Frame# cfm = & mycxx . . $ `melder/melder.h:44:9`! framecxx . . $ structCC#frame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iframe - 1]; |
| 204 | const double dim1 = CC_Frames_distancecxx . . $ CC_Frames_distance(ddcb5126596ec161). (cfi, cfm, includeEnergy); |
| 205 | const double dip1 = CC_Frames_distancecxx . . $ CC_Frames_distance(ddcb5126596ec161). (cfi, cfp, includeEnergy); |
| 206 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = (dim1 + dip1) / 2.0; |
| 207 | |
| 208 | // 3: spectral centere of gravity (gs) |
| 209 | longdoublecxx . . $ longdouble# msm = 0.0, sm = 0.0; |
| 210 | for (integercxx . . $ integer# j = 1; j <= hiscxx . . $ `melder/melder.h:47:9`! nycxx . . $ structSampledXY#ny.; j ++) { |
| 211 | sm += hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).j] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 212 | msm += j * hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).j] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe]; |
| 213 | } |
| 214 | const double gs = ( sm == 0.0 ? 0.0 : (double) (msm / sm) ); |
| 215 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).3] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = gs; |
| 216 | |
| 217 | // 4: stable internal duration |
| 218 | } |
| 219 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 220 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 221 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no features calculated."); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /* End of file MFCC.cpp */ |