1 /*-------------- Telecommunications & Signal Processing Lab ---------------
2 McGill University
3
4 Routine:
5 void LPlpcSyn (AFILE *AFpI, AFILE *AFpL, AFILE *AFpO,
6 double pre, int Lframe, int Np)
7
8 Purpose:
9 Perform LPC synthesis from a residual signal
10
11 Description:
12 This routine synthesizes the output data frame by frame from an input
13 residual error signal file and an input LPC coefficient file.
14
15 Parameters:
16 -> AFILE *AFpI
17 Audio file pointer for the input residual file
18 -> AFILE *AFpL
19 Audio file pointer for the input LPC coefficient file
20 -> AFILE *AFpO
21 Audio file pointer for the output audio file. If AFpO is NULL, the
22 output signal is not written out.
23 -> double pre
24 Preemphasis factor
25 -> int Lframe
26 Frame length
27 -> int Np
28 Number of LPC coefficients
29
30 Author / revision:
31 P. Kabal Copyright (C) 2003
32 $Revision: 1.3 $ $Date: 2003/05/13 01:18:00 $
33
34 -------------------------------------------------------------------------*/
35
36 #include <libtsp.h>
37 #include "LPsyn.h"
38
39
40 void
LSlpcSyn(AFILE * AFpI,AFILE * AFpL,AFILE * AFpO,double pre,int Lframe,int Np)41 LSlpcSyn (AFILE *AFpI, AFILE *AFpL, AFILE *AFpO, double pre,
42 int Lframe, int Np)
43
44 {
45 int Nout;
46 float Rbuff[MAXFRAME];
47 float Sbuff[MAXFRAME+MAXNP];
48 float Dbuff[MAXFRAME];
49 float pc[MAXNP];
50 float ec[MAXNP+1];
51 float Fmemd;
52 long int offr, nf;
53 int Nv;
54
55 /* Data access:
56 This program is intended to be a skeleton for more complex processing. It
57 uses very simple buffering, processing only one frame at a time.
58 */
59
60 offr = 0;
61 nf = 0;
62
63 /* Deemphasis memory */
64 Fmemd = 0.0;
65
66 /* Filter memory */
67 VRfZero (Sbuff, Np);
68
69 while (1) {
70 /* Read the residual signal */
71 Nout = AFfReadData (AFpI, offr, Rbuff, Lframe);
72 offr = offr + Lframe;
73 if (Nout == 0)
74 break;
75
76 /* read the LPC coefficients */
77 Nv = AFfReadData (AFpL, nf * Np, pc, Np);
78 if (Nv != Np)
79 UThalt ("%s: Unexpected end of LPC file", PROGRAM);
80 nf = nf + 1;
81 SPpcXec (pc, ec, Np);
82
83 /* Filter the data */
84 FIfFiltAP (Rbuff, Sbuff, Lframe, ec, Np+1);
85
86 /* Deemphasize the signal */
87 FIfDeem (pre, &Fmemd, &Sbuff[Np], Dbuff, Lframe);
88
89 /* Write the reconstructed signal to an audio file */
90 if (AFpO != NULL)
91 AFfWriteData (AFpO, Dbuff, Lframe);
92
93 /* Set up the LPC filter memory for the next frame */
94 VRfShift (Sbuff, Np, Lframe);
95 }
96
97 return;
98 }
99