| 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"cxx . . $ `<file>/LPC/LPC_and_Polynomial.h`/ |
| 24 | |
| 25 | autoPolynomialcxx . . $ autoPolynomial# LPC_Frame_to_Polynomialcxx . . $ LPC_Frame_to_Polynomial(ad2d84d72e496d5e). (constLPC_Framecxx . . $ constLPC_Frame# me) { |
| 26 | const integercxx . . $ integer# numberOfPolynomialCoefficients = mycxx . . $ `melder/melder.h:44:9`! nCoefficientscxx . . $ structLPC_Frame#nCoefficients. + 1; |
| 27 | autoPolynomialcxx . . $ autoPolynomial# thee = Polynomial_createcxx . . $ Polynomial_create(7da2dc008a3770b9). (-1, 1, mycxx . . $ `melder/melder.h:44:9`! nCoefficientscxx . . $ structLPC_Frame#nCoefficients.); |
| 28 | LPC_Frame_into_Polynomialcxx . . $ LPC_Frame_into_Polynomial(243bb52546919744). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 29 | for (integercxx . . $ integer# icof = 1; icof <= mycxx . . $ `melder/melder.h:44:9`! nCoefficientscxx . . $ structLPC_Frame#nCoefficients.; icof ++) |
| 30 | thycxx . . $ `melder/melder.h:45:9`! coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icof] = mycxx . . $ `melder/melder.h:44:9`! acxx . . $ structLPC_Frame#a. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPolynomialCoefficients - icof]; |
| 31 | thycxx . . $ `melder/melder.h:45:9`! coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPolynomialCoefficients] = 1.0; |
| 32 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 33 | } |
| 34 | |
| 35 | void LPC_Frame_into_Polynomialcxx . . $ LPC_Frame_into_Polynomial(243bb52546919744). (constLPC_Framecxx . . $ constLPC_Frame# me, mutablePolynomialcxx . . $ 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 integercxx . . $ integer# numberOfPolynomialCoefficientsNeeded = mycxx . . $ `melder/melder.h:44:9`! nCoefficientscxx . . $ structLPC_Frame#nCoefficients. + 1; |
| 44 | p -> resizecxx . . $ structFunctionSeries#resize(1624ee8275b10bda). (numberOfPolynomialCoefficientsNeeded); |
| 45 | for (integercxx . . $ integer# icof = 1; icof <= mycxx . . $ `melder/melder.h:44:9`! nCoefficientscxx . . $ structLPC_Frame#nCoefficients.; icof ++) |
| 46 | p -> coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icof] = mycxx . . $ `melder/melder.h:44:9`! acxx . . $ structLPC_Frame#a. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPolynomialCoefficientsNeeded - icof]; |
| 47 | p -> coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfPolynomialCoefficientsNeeded] = 1.0; |
| 48 | } |
| 49 | |
| 50 | autoPolynomialcxx . . $ autoPolynomial# LPC_to_Polynomial_slicecxx . . $ LPC_to_Polynomial_slice(f772836a8d467417). (constLPCcxx . . $ constLPC# me, double time) { |
| 51 | try { |
| 52 | integercxx . . $ integer# iFrame = Sampled_xToNearestIndexcxx . . $ Sampled_xToNearestIndex(405c2491bc3636e9). (me, time); |
| 53 | Melder_clipcxx . . $ Melder_clip(971c667ea412f82c). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., & iFrame, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); // constant extrapolation |
| 54 | autoPolynomialcxx . . $ autoPolynomial# thee = LPC_Frame_to_Polynomialcxx . . $ LPC_Frame_to_Polynomial(ad2d84d72e496d5e). (& mycxx . . $ `melder/melder.h:44:9`! d_framescxx . . $ structLPC#d_frames. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iFrame]); |
| 55 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 56 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 57 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Polynomial created."); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* End of file LPC_and_Polynomial.cpp */ |