| 1 | /* Sound_to_PowerCepstrogram.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012-2025 David Weenink, 2025 Paul Boersma |
| 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 "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 20 | #include "Cepstrum_and_Spectrum.h"cxx . . $ `<file>/LPC/Cepstrum_and_Spectrum.h`/ |
| 21 | #include "Sound_and_Spectrum.h"cxx . . $ `<file>/fon/Sound_and_Spectrum.h`/ |
| 22 | #include "Sound_extensions.h"cxx . . $ `<file>/dwtools/Sound_extensions.h`/ |
| 23 | #include "SoundFrames.h"cxx . . $ `<file>/dwtools/SoundFrames.h`/ |
| 24 | #include "Sound_to_PowerCepstrogram.h"cxx . . $ `<file>/LPC/Sound_to_PowerCepstrogram.h`/ |
| 25 | |
| 26 | autoPowerCepstrogramcxx . . $ autoPowerCepstrogram# Sound_to_PowerCepstrogramcxx . . $ Sound_to_PowerCepstrogram(7d2d8c6a98e2d6e7). (constSoundcxx . . $ constSound# me, double pitchFloor, double dt, double maximumFrequency, double preEmphasisFrequency) { |
| 27 | try { |
| 28 | const kSound_windowShapecxx . . $ kSound_windowShape# windowShape = kSound_windowShapecxx . . $ kSound_windowShape#::GAUSSIAN_2cxx . . $ kSound_windowShape#GAUSSIAN_2.; |
| 29 | const double effectiveAnalysisWidth = 3.0 / pitchFloor; // minimum analysis window has 3 periods of lowest pitch |
| 30 | const double physicalAnalysisWidth = getPhysicalAnalysisWidthcxx . . $ getPhysicalAnalysisWidth(746d57f737047cdc). (effectiveAnalysisWidth, windowShape); |
| 31 | const double physicalSoundDuration = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 32 | volatile const double windowDuration = Melder_clippedRightcxx . . $ Melder_clippedRight(f80f7d6260b3ee3a). (physicalAnalysisWidth, physicalSoundDuration); |
| 33 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (physicalSoundDuration >= physicalAnalysisWidth, |
| 34 | U"Your sound is too short:\n" |
| 35 | U"it should be longer than ", physicalAnalysisWidth, U" s." |
| 36 | ); |
| 37 | const double samplingFrequency = 2.0 * maximumFrequency; |
| 38 | autoSoundcxx . . $ autoSound# input = Sound_resampleAndOrPreemphasizecxx . . $ Sound_resampleAndOrPreemphasize(50b0edb6f91cc1e7). (me, maximumFrequency, 50_integercxx . . $ `operator""_integer`(85240eb457c3721a)., preEmphasisFrequency); |
| 39 | double t1; |
| 40 | integercxx . . $ integer# nFrames; |
| 41 | Sampled_shortTermAnalysiscxx . . $ Sampled_shortTermAnalysis(77f703705034c8a). (input.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), windowDuration, dt, & nFrames, & t1); |
| 42 | const integercxx . . $ integer# soundFrameSize = getSoundFrameSizecxx . . $ getSoundFrameSize(e4170d96af58b73c). (physicalAnalysisWidth, input ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). dxcxx . . $ structSampled#dx.); |
| 43 | const integercxx . . $ integer# numberOfFourierSamples = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (2_integercxx . . $ `operator""_integer`(85240eb457c3721a)., Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (soundFrameSize)); |
| 44 | const integercxx . . $ integer# halfNumberOfFourierSamples = numberOfFourierSamples / 2; |
| 45 | const integercxx . . $ integer# numberOfFrequencies = halfNumberOfFourierSamples + 1; |
| 46 | const integercxx . . $ integer# numberOfChannels = mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; |
| 47 | const double qmax = 0.5 * numberOfFourierSamples / samplingFrequency, dq = 1.0 / samplingFrequency; |
| 48 | autoPowerCepstrogramcxx . . $ autoPowerCepstrogram# output = PowerCepstrogram_createcxx . . $ PowerCepstrogram_create(bde97b71e31956b6). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., nFrames, dt, t1, 0, qmax, numberOfFrequencies, dq, 0); |
| 49 | bool subtractFrameMean = true; |
| 50 | const double powerScaling = input ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). dxcxx . . $ structSampled#dx. * input ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). dxcxx . . $ structSampled#dx.; // =amplitude_scaling^2 |
| 51 | |
| 52 | MelderThread_PARALLELcxx . . $ `melder/MelderThread.h:173:9`! (nFrames, 10) { |
| 53 | autoSoundFramescxx . . $ autoSoundFrames# soundFrames = SoundFrames_createForIntoSampledcxx . . $ SoundFrames_createForIntoSampled(bc9244df65bbc83e). (input.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), output.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), effectiveAnalysisWidth, windowShape, subtractFrameMean); |
| 54 | autoVECcxx . . $ autoVEC# fourierSamples = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfFourierSamples); |
| 55 | autoVECcxx . . $ autoVEC# onesidedPowerSpectrum = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfFrequencies); |
| 56 | autoNUMFourierTablecxx . . $ autoNUMFourierTable# fourierTable = NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (numberOfFourierSamples); // of dimension numberOfFourierSamples; |
| 57 | MelderThread_FORcxx . . $ `melder/MelderThread.h:183:9`! (iframe) { |
| 58 | /* |
| 59 | Get average power spectrum of channels |
| 60 | Let X(f) be the Fourier Transform, defined on the domain [-F,+F], of the real signal x(t). |
| 61 | The power spectrum is defined as the Fourier transform of the autocorrelation of x(t) which |
| 62 | equals |X(f)|^2 |
| 63 | The one-sided power spectrum is then P(f)= |X(f)|^2+|X(-f)|^2 = 2|X(f)|^2 for 0 <= f <= F |
| 64 | The bin width of the first and last frequency in the onesidedPowerSpectrum is half the bin width at the other frequencies |
| 65 | Do scaling and averaging together |
| 66 | */ |
| 67 | Soundcxx . . $ Sound# sound = soundFrames ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). getFramecxx . . $ structSoundFrames#getFrame(4fb1c00207b05668). (iframe); |
| 68 | onesidedPowerSpectrumcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).() <<=cxx . . $ `operator<<=`(c555d170d72ff256). 0.0; |
| 69 | for (integercxx . . $ integer# ichannel = 1; ichannel <= numberOfChannels; ichannel ++) { |
| 70 | fourierSamplescxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (1, soundFrameSize) <<=cxx . . $ `operator<<=`(adea042513329390). soundcxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd). -> zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichannel); |
| 71 | fourierSamplescxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (soundFrameSize + 1, numberOfFourierSamples) <<=cxx . . $ `operator<<=`(c555d170d72ff256). 0.0; |
| 72 | NUMfft_forwardcxx . . $ NUMfft_forward(aea41fd94d07eee). (fourierTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fourierSamples.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 73 | onesidedPowerSpectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] += fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] * fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 74 | for (integercxx . . $ integer# i = 2; i < numberOfFrequencies; i ++) { |
| 75 | double re = fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2 * i - 2], im = fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2 * i - 1]; |
| 76 | onesidedPowerSpectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] += re * re + im * im; |
| 77 | } |
| 78 | onesidedPowerSpectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfFrequencies] += fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfFourierSamples] * fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfFourierSamples]; |
| 79 | } |
| 80 | onesidedPowerSpectrumcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).() *=cxx . . $ `operator*=`(c555d170d72ff256). 2.0 * powerScaling / numberOfChannels; // scaling and averaging over channels |
| 81 | /* |
| 82 | Get log power. |
| 83 | */ |
| 84 | fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = logcxx . . $ log(fee4f1d22bc8e617). (onesidedPowerSpectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] + 1e-300); |
| 85 | for (integercxx . . $ integer# i = 2; i < numberOfFrequencies; i ++) { |
| 86 | fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2 * i - 2] = logcxx . . $ log(fee4f1d22bc8e617). (onesidedPowerSpectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] + 1e-300); |
| 87 | fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2 * i - 1] = 0.0; |
| 88 | } |
| 89 | fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfFourierSamples] = logcxx . . $ log(fee4f1d22bc8e617). (onesidedPowerSpectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfFrequencies]); |
| 90 | /* |
| 91 | Inverse transform |
| 92 | */ |
| 93 | NUMfft_backwardcxx . . $ NUMfft_backward(aea41fd94d07eee). (fourierTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fourierSamples.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 94 | /* |
| 95 | scale first. |
| 96 | */ |
| 97 | const double df = 1.0 / (sound -> dxcxx . . $ structSampled#dx. * numberOfFourierSamples); |
| 98 | fourierSamplescxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).() *=cxx . . $ `operator*=`(c555d170d72ff256). df; |
| 99 | for (integercxx . . $ integer# i = 1; i <= numberOfFrequencies; i ++) |
| 100 | output ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * fourierSamples [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 101 | } |
| 102 | } MelderThread_ENDPARALLELcxx . . $ `melder/MelderThread.h:189:9`! |
| 103 | return outputcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 104 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 105 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no PowerCepstrogram created."); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // 1 2 nfftdiv2 |
| 110 | // re im re im re im |
| 111 | // ((fft [1],0) (fft [2],fft [3]), (,), (,), (fft [nfft], 0)) nfft even |
| 112 | // ((fft [1],0) (fft [2],fft [3]), (,), (,), (fft [nfft-1], fft [nfft])) nfft odd |
| 113 | |
| 114 | #define TOLOGcxx . . $ `LPC/Sound_to_PowerCepstrogram.cpp:114:9`!(x) ((1 / NUMln10) * log ((x) + 1e-30)) |
| 115 | |
| 116 | static void complexfftoutput_to_powercxx . . $ complexfftoutput_to_power(402c4b092ab635c7). (constVECcxx . . $ constVEC# fft, VECcxx . . $ VEC# dbs, bool to_db) { |
| 117 | double valsq = fft [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).1] * fft [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).1]; |
| 118 | dbs [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = ( to_db ? TOLOGcxx . . $ `LPC/Sound_to_PowerCepstrogram.cpp:114:9`! (valsq) : valsq ); |
| 119 | const integercxx . . $ integer# nfftdiv2p1 = (fft.sizecxx . . $ constvector#size. + 2) / 2; |
| 120 | const integercxx . . $ integer# nend = ( fft.sizecxx . . $ constvector#size. % 2 == 0 ? nfftdiv2p1 : nfftdiv2p1 + 1 ); |
| 121 | for (integercxx . . $ integer# i = 2; i < nend; i ++) { |
| 122 | const double re = fft [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + i - 2], im = fft [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + i - 1]; |
| 123 | valsq = re * re + im * im; |
| 124 | dbs [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = ( to_db ? TOLOGcxx . . $ `LPC/Sound_to_PowerCepstrogram.cpp:114:9`! (valsq) : valsq ); |
| 125 | } |
| 126 | if (fft.sizecxx . . $ constvector#size. % 2 == 0) { |
| 127 | valsq = fft [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).fft.sizecxx . . $ constvector#size.] * fft [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).fft.sizecxx . . $ constvector#size.]; |
| 128 | dbs [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).nfftdiv2p1] = ( to_db ? TOLOGcxx . . $ `LPC/Sound_to_PowerCepstrogram.cpp:114:9`! (valsq) : valsq ); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | autoPowerCepstrogramcxx . . $ autoPowerCepstrogram# Sound_to_PowerCepstrogram_hillenbrandcxx . . $ Sound_to_PowerCepstrogram_hillenbrand(e120b70edcc7a09c). (constSoundcxx . . $ constSound# me, double pitchFloor, double dt) { |
| 133 | try { |
| 134 | // minimum analysis window has 3 periods of lowest pitch |
| 135 | const double physicalDuration = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 136 | const double analysisWidth = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (3.0 / pitchFloor, physicalDuration); |
| 137 | |
| 138 | double samplingFrequency = 1.0 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 139 | autoSoundcxx . . $ autoSound# theecxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 140 | if (samplingFrequency > 30000.0) { |
| 141 | samplingFrequency = samplingFrequency / 2.0; |
| 142 | thee =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Sound_resamplecxx . . $ Sound_resample(872961da5f5e69e5). (me, samplingFrequency, 1); |
| 143 | } else { |
| 144 | thee =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 145 | } |
| 146 | /* |
| 147 | Pre-emphasis with fixed coefficient 0.9 |
| 148 | */ |
| 149 | for (integercxx . . $ integer# i = thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; i > 1; i --) |
| 150 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] -= 0.9 * thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i - 1]; |
| 151 | |
| 152 | const integercxx . . $ integer# nosInWindow = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (analysisWidth * samplingFrequency); |
| 153 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (nosInWindow >= 8, |
| 154 | U"Analysis window too short."); |
| 155 | |
| 156 | double t1; |
| 157 | integercxx . . $ integer# numberOfFrames; |
| 158 | Sampled_shortTermAnalysiscxx . . $ Sampled_shortTermAnalysis(77f703705034c8a). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), analysisWidth, dt, & numberOfFrames, & t1); |
| 159 | autoVECcxx . . $ autoVEC# hamming = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nosInWindow); |
| 160 | for (integercxx . . $ integer# i = 1; i <= nosInWindow; i ++) |
| 161 | hamming [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.54 - 0.46 * coscxx . . $ cos(fee4f1d22bc8e617). (NUM2picxx . . $ NUM2pi. * (i - 1) / (nosInWindow - 1)); |
| 162 | |
| 163 | const integercxx . . $ integer# nfft = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (8_integercxx . . $ `operator""_integer`(85240eb457c3721a). /* minimum possible */, Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (nosInWindow)); |
| 164 | const integercxx . . $ integer# nfftdiv2 = nfft / 2; |
| 165 | autoVECcxx . . $ autoVEC# fftbuf = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (nfft); // "complex" array |
| 166 | autoVECcxx . . $ autoVEC# spectrum = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (nfftdiv2 + 1); // +1 needed |
| 167 | autoNUMFourierTablecxx . . $ autoNUMFourierTable# fftTable = NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (nfft); // sound to spectrum |
| 168 | |
| 169 | const double qmax = 0.5 * nfft / samplingFrequency, dq = qmax / (nfftdiv2 + 1); |
| 170 | autoPowerCepstrogramcxx . . $ autoPowerCepstrogram# him = PowerCepstrogram_createcxx . . $ PowerCepstrogram_create(bde97b71e31956b6). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfFrames, dt, t1, 0, qmax, nfftdiv2+1, dq, 0); |
| 171 | |
| 172 | autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Sound to PowerCepstrogram..."); |
| 173 | |
| 174 | for (integercxx . . $ integer# iframe = 1; iframe <= numberOfFrames; iframe ++) { |
| 175 | const double tbegin = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin., t1 + (iframe - 1) * dt - analysisWidth / 2.0); |
| 176 | const integercxx . . $ integer# istart = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., Sampled_xToNearestIndexcxx . . $ Sampled_xToNearestIndex(405c2491bc3636e9). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tbegin)); |
| 177 | integercxx . . $ integer# iend = istart + nosInWindow - 1; |
| 178 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& iend, thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.); |
| 179 | fftbufcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (1, nosInWindow) <<=cxx . . $ `operator<<=`(74defdd9e9be7864). thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (istart, iend) *cxx . . $ `operator*`(8a83e1da43fd4c40). hammingcxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 180 | fftbufcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (nosInWindow + 1, nfft) <<=cxx . . $ `operator<<=`(c555d170d72ff256). 0.0; |
| 181 | |
| 182 | NUMfft_forwardcxx . . $ NUMfft_forward(aea41fd94d07eee). (fftTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fftbuf.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 183 | complexfftoutput_to_powercxx . . $ complexfftoutput_to_power(402c4b092ab635c7). (fftbufcxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), spectrum.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), true); // log10(|fft|^2) |
| 184 | |
| 185 | centre_VEC_inoutcxx . . $ centre_VEC_inout(b915798f9bafc8a). (spectrumcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); // subtract average |
| 186 | /* |
| 187 | Here we diverge from Hillenbrand as he takes the fft of half of the spectral values. |
| 188 | H. forgets that the actual spectrum has nfft/2+1 values. Therefore, we take the inverse |
| 189 | transform because this keeps the number of samples a power of 2. |
| 190 | At the same time this results in twice as many numbers in the quefrency domain, i.e. we end up with nfft/2+1 |
| 191 | numbers while H. has only nfft/4! |
| 192 | */ |
| 193 | fftbuf [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = spectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 194 | for (integercxx . . $ integer# i = 2; i < nfftdiv2 + 1; i ++) { |
| 195 | fftbuf [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i+i-2] = spectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 196 | fftbuf [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i+i-1] = 0.0; |
| 197 | } |
| 198 | fftbuf [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nfft] = spectrum [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nfftdiv2 + 1]; |
| 199 | NUMfft_backwardcxx . . $ NUMfft_backward(aea41fd94d07eee). (fftTable.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fftbuf.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 200 | for (integercxx . . $ integer# i = 1; i <= nfftdiv2 + 1; i ++) |
| 201 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] = fftbuf [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * fftbuf [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 202 | |
| 203 | if (iframe % 10 == 1) |
| 204 | Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((double) iframe / numberOfFrames, U"Cepstrogram analysis of frame ", |
| 205 | iframe, U" out of ", numberOfFrames, U"."); |
| 206 | } |
| 207 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 208 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 209 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Cepstrogram created."); |
| 210 | } |
| 211 | } |
| 212 | /* End of file Sound_to_PowerCepstrogram.cpp */ |