Debian Codegraph @

LPC/LPC_and_Polynomial.cpp

raw
1 /* LPC_and_Polynomial.cpp
2 *
3 * Copyright (C) 1994-2020, 2025, 2026 David Weenink
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 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 /*
20 djmw 20020812 GPL header
21 */
22
23 #include "LPC_and_Polynomial.h"
24
25 autoPolynomial LPC_Frame_to_Polynomial (constLPC_Frame me) {
26 const integer numberOfPolynomialCoefficients = my nCoefficients + 1;
27 autoPolynomial thee = Polynomial_create (-1, 1, my nCoefficients);
28 LPC_Frame_into_Polynomial (me, thee.get());
29 for (integer icof = 1; icof <= my nCoefficients; icof ++)
30 thy coefficients [icof] = my a [numberOfPolynomialCoefficients - icof];
31 thy coefficients [numberOfPolynomialCoefficients] = 1.0;
32 return thee;
33 }
34
35 void LPC_Frame_into_Polynomial (constLPC_Frame me, mutablePolynomial p) {
36 /*
37 The lpc coefficients are a [1..nCoefficients]. a[0] == 1 is not stored.
38 For the polynomial we therefore need one extra coefficient.
39 Since the a's are stored in reverse order in the polynomial and a[0]
40 represents the highest power (==degree) it is stored into the last position
41 of the polynomial.
42 */
43 const integer numberOfPolynomialCoefficientsNeeded = my nCoefficients + 1;
44 p -> resize (numberOfPolynomialCoefficientsNeeded);
45 for (integer icof = 1; icof <= my nCoefficients; icof ++)
46 p -> coefficients [icof] = my a [numberOfPolynomialCoefficientsNeeded - icof];
47 p -> coefficients [numberOfPolynomialCoefficientsNeeded] = 1.0;
48 }
49
50 autoPolynomial LPC_to_Polynomial_slice (constLPC me, double time) {
51 try {
52 integer iFrame = Sampled_xToNearestIndex (me, time);
53 Melder_clip (1_integer, & iFrame, my nx); // constant extrapolation
54 autoPolynomial thee = LPC_Frame_to_Polynomial (& my d_frames [iFrame]);
55 return thee;
56 } catch (MelderError) {
57 Melder_throw (me, U": no Polynomial created.");
58 }
59 }
60
61 /* End of file LPC_and_Polynomial.cpp */