Debian Codegraph @

LPC/Sound_and_LPC.h

raw symbols SCIP
1 #cxx . . $ `<file>/LPC/Sound_and_LPC.h`/ifndef _Sound_and_LPC_h_
2 #define _Sound_and_LPC_h_cxx . . $ `LPC/Sound_and_LPC.h:2:9`!
3 /* Sound_and_LPC.h
4 *
5 * Copyright (C) 1994-2025 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 3 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 19971103
23 djmw 20020812 GPL header
24 */
25
26 #include "SoundFrameIntoSampledFrame.h"cxx . . $ `<file>/dwtools/SoundFrameIntoSampledFrame.h`/
27 #include "Sound.h"cxx . . $ `<file>/fon/Sound.h`/
28 #include "LPC.h"cxx . . $ `<file>/LPC/LPC.h`/
29 #include "SVD.h"cxx . . $ `<file>/dwsys/SVD.h`/
30
31 /*
32 20240603:
33 The output of the Sound_to_LPC_<x> might be a little bit different from previous outputs because:
34 1. The sound frame now always has an odd number of samples, irrespective of the sampling frequency or the window shape.
35 This means that also the window function will have an odd number of samples. Therefore the sample at the centre of the sound frame always has weight 1.0.
36 Previously the number of samples could be even or odd, depending on how rounding turned out.
37 2. The Gaussian window function was slightly improved.
38 3. The precision of the autocorrelation and covariance method have been improved a little by using some `longdouble` accumulators.
39 */
40
41 /*********************** Autocorrelation method *************************************************************/
42
43 /*
44 Precondition:
45 Sound and LPC have the same sampling.
46 */
47 void Sound_into_LPC_autocxx . . $ Sound_into_LPC_auto(5892df8d1f4abf78). (constSoundcxx . . $ constSound# me, mutableLPCcxx . . $ mutableLPC# outputLPC, double effectiveAnalysisWidth);
48
49 autoLPCcxx . . $ autoLPC# Sound_to_LPC_autocxx . . $ Sound_to_LPC_auto(ed41325f50f429a4). (constSoundcxx . . $ constSound# me, int predictionOrder, double effectiveAnalysisWidth, double dt, double preEmphasisFrequency);
50
51 /*********************** Covariance method *************************************************************/
52
53 /*
54 Precondition:
55 Sound and LPC have the same sampling.
56 */
57 void Sound_into_LPC_covarcxx . . $ Sound_into_LPC_covar(5892df8d1f4abf78). (constSoundcxx . . $ constSound# me, mutableLPCcxx . . $ mutableLPC# outputLPC, double effectiveAnalysisWidth);
58
59 autoLPCcxx . . $ autoLPC# Sound_to_LPC_covarcxx . . $ Sound_to_LPC_covar(ed41325f50f429a4). (constSoundcxx . . $ constSound# me, int predictionOrder, double effectiveAnalysisWidth, double dt, double preEmphasisFrequency);
60
61 /*********************** Burg method *******************************************************/
62
63 /*
64 Precondition:
65 Sound and LPC have the same sampling.
66 */
67 void Sound_into_LPC_burgcxx . . $ Sound_into_LPC_burg(5892df8d1f4abf78). (constSoundcxx . . $ constSound# me, mutableLPCcxx . . $ mutableLPC# outputLPC, double effectiveAnalysisWidth);
68
69 autoLPCcxx . . $ autoLPC# Sound_to_LPC_burgcxx . . $ Sound_to_LPC_burg(ed41325f50f429a4). (constSoundcxx . . $ constSound# me, int predictionOrder, double effectiveAnalysisWidth, double dt, double preEmphasisFrequency);
70
71 void soundFrameIntoLPCFrame_burgcxx . . $ soundFrameIntoLPCFrame_burg(bf16199e8e1e3d9b). (VECcxx . . $ VEC# soundFrame, LPC_Framecxx . . $ LPC_Frame# lpcFrame, VECcxx . . $ VEC# b1, VECcxx . . $ VEC# b2,
72 VECcxx . . $ VEC# aa, integercxx . . $ integer# &info);
73
74 /*********************** Marple method *****************************************************/
75
76 /*
77 Precondition:
78 Sound and LPC have the same sampling.
79 */
80 void Sound_into_LPC_marplecxx . . $ Sound_into_LPC_marple(ca81e047e6329e35). (constSoundcxx . . $ constSound# me, mutableLPCcxx . . $ mutableLPC# thee, double analysisWidth, double tol1, double tol2);
81
82 autoLPCcxx . . $ autoLPC# Sound_to_LPC_marplecxx . . $ Sound_to_LPC_marple(869b7bf396bbc43a). (constSoundcxx . . $ constSound# me, int predictionOrder, double effectiveAnalysisWidth, double dt,
83 double preEmphasisFrequency, double tol1, double tol2);
84
85 /*********************** PLP (Hermansky) method ******************************************************/
86
87 /*********************** Robust method (LPC & Sound) *******************************************************/
88
89 Thing_definecxx . . $ mutableRobustLPCWorkspace# (RobustLPCWorkspace, Thing) {
90
91 constLPCcxx . . $ constLPC# inputLPCcxx . . $ structRobustLPCWorkspace#inputLPC.;
92 mutableLPCcxx . . $ mutableLPC# outputLPCcxx . . $ structRobustLPCWorkspace#outputLPC.;
93 VECcxx . . $ VEC# soundFramecxx . . $ structRobustLPCWorkspace#soundFrame.;
94 integercxx . . $ integer# ordercxx . . $ structRobustLPCWorkspace#order., currentPredictionOrdercxx . . $ structRobustLPCWorkspace#currentPredictionOrder.;
95 double k_stdevcxx . . $ structRobustLPCWorkspace#k_stdev.;
96 integercxx . . $ integer# itercxx . . $ structRobustLPCWorkspace#iter.;
97 integercxx . . $ integer# itermaxcxx . . $ structRobustLPCWorkspace#itermax.;
98 integercxx . . $ integer# huber_iterationscxx . . $ structRobustLPCWorkspace#huber_iterations. = 5; // = 5;
99 bool wantLocationcxx . . $ structRobustLPCWorkspace#wantLocation. = true; //
100 bool wantScalecxx . . $ structRobustLPCWorkspace#wantScale. = true; //
101 double locationcxx . . $ structRobustLPCWorkspace#location. = 0.0; // not a parameter in initBasic!
102 double scalecxx . . $ structRobustLPCWorkspace#scale.;
103 double tol1cxx . . $ structRobustLPCWorkspace#tol1.;
104 double tolSVDcxx . . $ structRobustLPCWorkspace#tolSVD. = 1e-10; // not a parameter in initBasic!
105 autoVECcxx . . $ autoVEC# errorcxx . . $ structRobustLPCWorkspace#error.; // soundFrameSize
106 autoVECcxx . . $ autoVEC# sampleWeightscxx . . $ structRobustLPCWorkspace#sampleWeights.; // soundFrameSize
107 autoVECcxx . . $ autoVEC# coefficientscxx . . $ structRobustLPCWorkspace#coefficients.; // inputLPC -> maxnCoefficients
108 autoVECcxx . . $ autoVEC# covarianceswcxx . . $ structRobustLPCWorkspace#covariancesw.; // inputLPC -> maxnCoefficients
109 autoMATcxx . . $ autoMAT# covarmatrixwcxx . . $ structRobustLPCWorkspace#covarmatrixw.; // inputLPC -> maxnCoefficients, inputLPC -> maxnCoefficients
110 integercxx . . $ integer# computedSVDworksizecxx . . $ structRobustLPCWorkspace#computedSVDworksize.;
111 autoSVDcxx . . $ autoSVD# svdcxx . . $ structRobustLPCWorkspace#svd.;
112 autoVECcxx . . $ autoVEC# svdwork1cxx . . $ structRobustLPCWorkspace#svdwork1.; // computedSVDworksize
113 autoVECcxx . . $ autoVEC# svdwork2cxx . . $ structRobustLPCWorkspace#svdwork2.; // order
114 autoVECcxx . . $ autoVEC# filterMemorycxx . . $ structRobustLPCWorkspace#filterMemory.; // order
115 autoVECcxx . . $ autoVEC# huberworkcxx . . $ structRobustLPCWorkspace#huberwork.; // soundFrameSize)
116
117 void initcxx . . $ structRobustLPCWorkspace#init(9a303f6b9c9b3e7b). (constLPCcxx . . $ constLPC# inputLPC, constSoundcxx . . $ constSound# inputSound, mutableLPCcxx . . $ mutableLPC# outputLPC, double effectiveAnalysisWidth,
118 kSound_windowShapecxx . . $ kSound_windowShape# windowShape, double k_stdev, integercxx . . $ integer# itermax, double tol, bool wantlocation);
119
120 void resizecxx . . $ structRobustLPCWorkspace#resize(49f6e7a06ebc5aa8). ();
121 void setSampleWeightscxx . . $ structRobustLPCWorkspace#setSampleWeights(49f6e7a06ebc5aa8). ();
122 void setCovariancescxx . . $ structRobustLPCWorkspace#setCovariances(49f6e7a06ebc5aa8). ();
123 void solvelpccxx . . $ structRobustLPCWorkspace#solvelpc(49f6e7a06ebc5aa8). ();
124 void inputFrameIntoOutputFramecxx . . $ structRobustLPCWorkspace#inputFrameIntoOutputFrame(760f3c96cfe6a5b5). (LPC_Framecxx . . $ LPC_Frame# inputLPCFrame, LPC_Framecxx . . $ LPC_Frame# outputLPCFrame,
125 VECcxx . . $ VEC# soundFrame, integercxx . . $ integer#& info);
126 };
127
128 autoRobustLPCWorkspacecxx . . $ autoRobustLPCWorkspace# RobustLPCWorkspace_createcxx . . $ RobustLPCWorkspace_create(7f8ccc0cd9332402). (constLPCcxx . . $ constLPC# inputLPC, constSoundcxx . . $ constSound# inputSound,
129 mutableLPCcxx . . $ mutableLPC# outputLPC, double effectiveAnalysisWidth, kSound_windowShapecxx . . $ kSound_windowShape# windowShape,
130 double k_stdev, integercxx . . $ integer# itermax, double tol, bool wantlocation);
131
132 /*
133 Precondition:
134 Sound and LPC have the same sampling.
135 */
136 void LPC_and_Sound_into_LPC_robustcxx . . $ LPC_and_Sound_into_LPC_robust(cf7985e5989e948d). (constLPCcxx . . $ constLPC# inputLPC, constSoundcxx . . $ constSound# inputSound, mutableLPCcxx . . $ mutableLPC# outputLPC,
137 double effectiveAnalysisWidth, double k_stdev, integercxx . . $ integer# itermax, double tol, bool wantlocation);
138
139 /*
140 Precondition:
141 Sound and LPC have the same sampling.
142 */
143 autoLPCcxx . . $ autoLPC# LPC_and_Sound_to_LPC_robustcxx . . $ LPC_and_Sound_to_LPC_robust(54d8670bb958c0e1). (constLPCcxx . . $ constLPC# inputLPC, constSoundcxx . . $ constSound# inputSound, double effectiveAnalysisWidth,
144 double preEmphasisFrequency, double k_stdev, integercxx . . $ integer# itermax, double tol, bool wantlocation);
145
146 void soundFrameAndLPCFrameIntoLPCFramecxx . . $ soundFrameAndLPCFrameIntoLPCFrame(376f3aa0aacb1ab6). (VECcxx . . $ VEC# soundFrame, LPC_Framecxx . . $ LPC_Frame# inputLPCFrame, LPC_Framecxx . . $ LPC_Frame# outputLPCFrame,
147 RobustLPCWorkspacecxx . . $ RobustLPCWorkspace# ws, integercxx . . $ integer#& info);
148
149 /*********************** Robust method (Sound) *************************************************************/
150
151 void Sound_into_LPC_robustcxx . . $ Sound_into_LPC_robust(889d8559deb2e9ad). (constSoundcxx . . $ constSound# me, mutableLPCcxx . . $ mutableLPC# outputLPC, double effectiveAnalysisWidth,
152 double k_stdev, integercxx . . $ integer# itermax, double tol, bool wantlocation);
153
154 autoLPCcxx . . $ autoLPC# Sound_to_LPC_robustcxx . . $ Sound_to_LPC_robust(c01bc10650f3b13c). (constSoundcxx . . $ constSound# me, int predictionOrder, double effectiveAnalysisWidth, double dt,
155 double preEmphasisFrequency, double k_stdev, integercxx . . $ integer# itermax, double tol, bool wantlocation);
156
157 /*
158 Precondition:
159 Sound has been resampled and pre-emphasized
160 */
161
162 /*
163 * Function:
164 * Calculate linear prediction coefficients according to following model:
165 * Minimize E(m) = Sum(n=n0;n=n1; (x [n] + Sum(k=1;k=m; a [k]*x [n-k])))
166 * Method:
167 * The minimization is carried out by solving the equations:
168 * Sum(i=1;i=m; a [i]*c [i] [k]) = -c [0] [k] for k=1,2,...,m
169 * where c [i] [k] = Sum(n=n0;n=n1;x [n-i]*x [n-k])
170 * 1. Covariance:
171 * n0=m; n1 = N-1;
172 * c [i] [k] is symmetric, positive semi-definite matrix
173 * Markel&Gray, LP of Speech, page 221;
174 * 2. Autocorrelation
175 * signal is zero outside the interval;
176 * n0=-infinity; n1=infinity
177 * c [i] [k] symmetric, positive definite Toeplitz matrix
178 * Markel&Gray, LP of Speech, page 219;
179 * Preconditions:
180 * predictionOrder > 0;
181 * preEmphasisFrequency >= 0;
182 *
183 * Burg method: see Numerical recipes Chapter 13.
184 *
185 * Marple method: see Marple, L. (1980), A new autoregressive spectrum analysis
186 * algorithm, IEEE Trans. on ASSP 28, 441-453.
187 * tol1 : stop iteration when E(m) / E(0) < tol1
188 * tol2 : stop iteration when (E(m)-E(m-1)) / E(m-1) < tol2,
189 */
190
191 autoSoundcxx . . $ autoSound# LPC_Sound_filtercxx . . $ LPC_Sound_filter(94682ef9887ad8d9). (constLPCcxx . . $ constLPC# me, constSoundcxx . . $ constSound# thee, bool useGain);
192 /*
193 E(z) = X(z)A(z),
194 A(z) = 1 + Sum (k=1, k=m, a(k)z^-k);
195
196 filter:
197 given e & a, determine x;
198 x(n) = e(n) - Sum (k=1, m, a(k)x(n-k))
199 useGain determines whether the LPC-gain is used in the synthesis.
200 */
201
202 void LPC_Sound_filterWithFilterAtTime_inplacecxx . . $ LPC_Sound_filterWithFilterAtTime_inplace(1a66f7bef222c354). (constLPCcxx . . $ constLPC# me, mutableSoundcxx . . $ mutableSound# thee, integercxx . . $ integer# channel, double time);
203
204 autoSoundcxx . . $ autoSound# LPC_Sound_filterWithFilterAtTimecxx . . $ LPC_Sound_filterWithFilterAtTime(bf907e3a385d3c6). (constLPCcxx . . $ constLPC# me, constSoundcxx . . $ constSound# thee, integercxx . . $ integer# channel, double time);
205
206 autoSoundcxx . . $ autoSound# LPC_Sound_filterInversecxx . . $ LPC_Sound_filterInverse(f4bce7e21db85b5). (constLPCcxx . . $ constLPC# me, constSoundcxx . . $ constSound# thee);
207 /*
208 E(z) = X(z)A(z),
209 A(z) = 1 + Sum (k=1, k=m, a(k)z^-k);
210
211 filter inverse:
212 given x & a, determine e;
213 e(n) = x(n) + Sum (k=1, m, a(k)x(n-k))
214 */
215
216 autoSoundcxx . . $ autoSound# LPC_Sound_filterInverseWithFilterAtTimecxx . . $ LPC_Sound_filterInverseWithFilterAtTime(bf907e3a385d3c6). (constLPCcxx . . $ constLPC# me, constSoundcxx . . $ constSound# thee, integercxx . . $ integer# channel, double time);
217
218 void LPC_Sound_filterInverseWithFilterAtTime_inplacecxx . . $ LPC_Sound_filterInverseWithFilterAtTime_inplace(1a66f7bef222c354). (constLPCcxx . . $ constLPC# me, mutableSoundcxx . . $ mutableSound# thee, integercxx . . $ integer# channel, double time);
219
220 /*
221 For all LPC analysis
222 */
223 void checkLPCAnalysisParameters_ecxx . . $ checkLPCAnalysisParameters_e(f2b963dca309bb3b). (double sound_dx, integercxx . . $ integer# sound_nx, double physicalAnalysisWidth, integercxx . . $ integer# predictionOrder);
224
225 inline void Sound_and_LPC_require_equalDomainsAndSamplingPeriodscxx . . $ Sound_and_LPC_require_equalDomainsAndSamplingPeriods(504d62ec9a7fd786). (constSoundcxx . . $ constSound# me, constLPCcxx . . $ constLPC# thee) {
226 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && thycxx . . $ `melder/melder.h:45:9`! xmax == mycxx . . $ `melder/melder.h:44:9`! xmax,
227 U"The domains of the Sound and the LPC should be equal.");
228 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! dx == thycxx . . $ `melder/melder.h:45:9`! samplingPeriod,
229 U"The sampling periods of the Sound and the LPC should be equal.");
230 }
231
232 #endif /* _Sound_and_LPC_h_ */