1 /*
2 
3  * Revision 1.2  1996/08/20  20:30:11  jaf
4  * Removed all static local variables that were SAVE'd in the Fortran
5  * code, and put them in struct lpc10_encoder_state that is passed as an
6  * argument.
7  *
8  * Removed init function, since all initialization is now done in
9  * init_lpc10_encoder_state().
10  *
11  * Changed name of function from lpcenc_ to lpc10_encode, simply to make
12  * all lpc10 functions have more consistent naming with each other.
13  *
14  * Revision 1.1  1996/08/19  22:31:48  jaf
15  * Initial revision
16  *
17 
18 */
19 
20 /*  -- translated by f2c (version 19951025).
21    You must link the resulting object file with the libraries:
22 	-lf2c -lm   (in that order)
23 */
24 
25 #include "f2c.h"
26 
27 extern int lpcdec_(integer *bits, real *speech);
28 extern int initlpcdec_(void);
29 
30 /* Common Block Declarations */
31 
32 extern struct {
33     integer order, lframe;
34     logical corrp;
35 } contrl_;
36 
37 #define contrl_1 contrl_
38 
39 /* Table of constant values */
40 
41 static integer c__10 = 10;
42 
43 /* ***************************************************************** */
44 
45 /*
46  * Revision 1.2  1996/08/20  20:30:11  jaf
47  * Removed all static local variables that were SAVE'd in the Fortran
48  * code, and put them in struct lpc10_encoder_state that is passed as an
49  * argument.
50  *
51  * Removed init function, since all initialization is now done in
52  * init_lpc10_encoder_state().
53  *
54  * Changed name of function from lpcenc_ to lpc10_encode, simply to make
55  * all lpc10 functions have more consistent naming with each other.
56  *
57  * Revision 1.1  1996/08/19  22:31:48  jaf
58  * Initial revision
59  * */
60 /* Revision 1.1  1996/03/28  00:03:00  jaf */
61 /* Initial revision */
62 
63 
64 /* ***************************************************************** */
65 
66 /* Decode 54 bits to one frame of 180 speech samples. */
67 
68 /* Input: */
69 /*  BITS   - 54 encoded bits, stored 1 per array element. */
70 /*           Indices 1 through 53 read (SYNC bit ignored). */
71 /* Output: */
72 /*  SPEECH - Speech encoded as real values in the range [-1,+1]. */
73 /*           Indices 1 through 180 written. */
74 
75 /* This subroutine maintains local state from one call to the next.  If */
76 /* you want to switch to using a new audio stream for this filter, or */
77 /* reinitialize its state for any other reason, call the ENTRY */
78 /* INITLPCDEC. */
79 
lpc10_decode(integer * bits,real * speech,struct lpc10_decoder_state * st)80 /* Subroutine */ int lpc10_decode(integer *bits, real *speech,
81 				  struct lpc10_decoder_state *st)
82 {
83     integer irms, voice[2], pitch, ipitv;
84     extern /* Subroutine */ int decode_(integer *, integer *, integer *,
85 	    integer *, integer *, real *, real *, struct lpc10_decoder_state *);
86     real rc[10];
87     extern /* Subroutine */ int chanrd_(integer *, integer *, integer *,
88 	    integer *, integer *), synths_(integer *,
89 	    integer *, real *, real *, real *, integer *,
90 					   struct lpc10_decoder_state *);
91     integer irc[10], len;
92     real rms;
93 
94 
95 /*   LPC Configuration parameters: */
96 /* Frame size, Prediction order, Pitch period */
97 /*       Arguments */
98 /*   LPC Processing control variables: */
99 
100 /* *** Read-only: initialized in setup */
101 
102 /*  Files for Speech, Parameter, and Bitstream Input & Output, */
103 /*    and message and debug outputs. */
104 
105 /* Here are the only files which use these variables: */
106 
107 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
108 
109 /* Many files which use fdebug are not listed, since it is only used in */
110 /* those other files conditionally, to print trace statements. */
111 /* 	integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
112 /*  LPC order, Frame size, Quantization rate, Bits per frame, */
113 /*    Error correction */
114 /* Subroutine SETUP is the only place where order is assigned a value, */
115 /* and that value is 10.  It could increase efficiency 1% or so to */
116 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
117 */
118 /* a variable in a COMMON block, since it is used in many places in the */
119 /* core of the coding and decoding routines.  Actually, I take that back.
120 */
121 /* At least when compiling with f2c, the upper bound of DO loops is */
122 /* stored in a local variable before the DO loop begins, and then that is
123 */
124 /* compared against on each iteration. */
125 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
126 /* Similarly for quant, which is given a value of 2400 in SETUP.  quant */
127 /* is used in only a few places, and never in the core coding and */
128 /* decoding routines, so it could be eliminated entirely. */
129 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
130 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
131 /* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */
132 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
133 */
134 /* a constant or a variable, since it is only examined once per frame. */
135 /* Leaving it as a variable that is set to .TRUE.  seems like a good */
136 /* idea, since it does enable some error-correction capability for */
137 /* unvoiced frames, with no change in the coding rate, and no noticeable
138 */
139 /* quality difference in the decoded speech. */
140 /* 	integer quant, nbits */
141 /* *** Read/write: variables for debugging, not needed for LPC algorithm
142 */
143 
144 /*  Current frame, Unstable frames, Output clip count, Max onset buffer,
145 */
146 /*    Debug listing detail level, Line count on listing page */
147 
148 /* nframe is not needed for an embedded LPC10 at all. */
149 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
150 /* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
151 /* an application, I would recommend removing the call to ERROR in RCCHK,
152 */
153 /* and remove ERROR and nunsfm completely. */
154 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
155 */
156 /* sread.f.  When LPC10 is embedded into an application, one might want */
157 /* to cause it to be incremented in a routine that takes the output of */
158 /* SYNTHS and sends it to an audio device.  It could be optionally */
159 /* displayed, for those that might want to know what it is. */
160 /* maxosp is never initialized to 0 in SETUP, although it probably should
161 */
162 /* be, and it is updated in subroutine ANALYS.  I doubt that its value */
163 /* would be of much interest to an application in which LPC10 is */
164 /* embedded. */
165 /* listl and lincnt are not needed for an embedded LPC10 at all. */
166 /* 	integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
167 /* 	common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
168 /* 	common /contrl/ quant, nbits */
169 /* 	common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
170 /*       Local variables that need not be saved */
171 /*       Uncoded speech parameters */
172 /*       Coded speech parameters */
173 /*       Others */
174 /*       Local state */
175 /*       None */
176     /* Parameter adjustments */
177     if (bits) {
178 	--bits;
179 	}
180     if (speech) {
181 	--speech;
182 	}
183 
184     /* Function Body */
185 
186     chanrd_(&c__10, &ipitv, &irms, irc, &bits[1]);
187     decode_(&ipitv, &irms, irc, voice, &pitch, &rms, rc, st);
188     synths_(voice, &pitch, &rms, rc, &speech[1], &len, st);
189     return 0;
190 } /* lpcdec_ */
191