Debian Codegraph @

src/wavesynth/cst_reflpc.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2001 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: November 2001 */
35 /*************************************************************************/
36 /* */
37 /* reflection coefficients, algorithms from Festival */
38 /* */
39 /*************************************************************************/
40
41 #include "cst_alloc.h"
42
43 void lpc2ref(const float *lpc, float *rfc, int order)
44 {
45 /* LPC to reflection coefficients, converted from Festival */
46 int i,j;
47 float f,ai;
48 float *vo,*vx;
49 float *vn = cst_alloc(float,order);
50
51 i = order-1;
52 rfc[i] = ai = lpc[i];
53 f = 1-ai*ai;
54 i--;
55
56 for (j=0; j<=i; j++)
57 rfc[j] = (lpc[j]+((ai*lpc[i-j])))/f;
58
59 vo=rfc;
60
61 for ( ;i>0; )
62 {
63 ai=vo[i];
64 f = 1-ai*ai;
65 i--;
66 for (j=0; j<=i; j++)
67 vn[j] = (vo[j]+((ai*vo[i-j])))/f;
68
69 rfc[i]=vn[i];
70
71 vx = vn;
72 vn = vo;
73 vo = vx;
74 }
75
76 cst_free(vn);
77
78 }
79
80 void ref2lpc(const float *rfc, float *lpc, int order)
81 {
82 /* Here we use Christopher Longet Higgin's algorithm converted to */
83 /* an equivalent by awb. Its doesn't have the reverse order or */
84 /* negation requirement. */
85 float a,b;
86 int n,k;
87
88 for (n=0; n < order; n++)
89 {
90 lpc[n] = rfc[n];
91 for (k=0; 2*(k+1) <= n+1; k++)
92 {
93 a = lpc[k];
94 b = lpc[n-(k+1)];
95 lpc[k] = a-b*lpc[n];
96 lpc[n-(k+1)] = b-a*lpc[n];
97 }
98 }
99
100 }
101