4 Revision 1.4 2000/01/05 08:20:39 markster
7 Revision 1.2 2000/01/05 08:20:39 markster
8 Some OSS fixes and a few lpc changes to make it actually work
10 * Revision 1.2 1996/08/20 20:35:41 jaf
11 * Added functions for allocating and initializing lpc10_encoder_state
12 * and lpc10_decoder_state structures.
14 * Revision 1.1 1996/08/19 22:31:40 jaf
20 #ifdef P_R_O_T_O_T_Y_P_E_S
21 extern int lpcini_(void);
22 /* comlen contrl_ 12 */
23 /*:ref: initlpcenc_ 14 0 */
24 /*:ref: initlpcdec_ 14 0 */
27 /* -- translated by f2c (version 19951025).
28 You must link the resulting object file with the libraries:
29 -lf2c -lm (in that order)
36 /* Common Block Declarations */
39 integer order, lframe;
43 #define contrl_1 contrl_
45 /* ***************************************************************** */
48 * Revision 1.4 2000/01/05 08:20:39 markster
49 * Version 0.1.5 from FTP
51 /* Revision 1.2 2000/01/05 08:20:39 markster
52 /* Some OSS fixes and a few lpc changes to make it actually work
54 * Revision 1.2 1996/08/20 20:35:41 jaf
55 * Added functions for allocating and initializing lpc10_encoder_state
56 * and lpc10_decoder_state structures.
58 * Revision 1.1 1996/08/19 22:31:40 jaf
61 /* Revision 1.1 1996/03/28 00:04:05 jaf */
62 /* Initial revision */
65 /* ***************************************************************** */
67 /* Initialize COMMON block variables used by LPC-10 encoder and decoder, */
68 /* and call initialization routines for both of them. */
70 /* Subroutine */ int lpcini_(void)
74 * Revision 1.4 2000/01/05 08:20:39 markster
75 * Version 0.1.5 from FTP
77 /* Revision 1.2 2000/01/05 08:20:39 markster
78 /* Some OSS fixes and a few lpc changes to make it actually work
80 * Revision 1.2 1996/08/20 20:35:41 jaf
81 * Added functions for allocating and initializing lpc10_encoder_state
82 * and lpc10_decoder_state structures.
84 * Revision 1.1 1996/08/19 22:31:40 jaf
87 /* Revision 1.3 1996/03/29 22:03:47 jaf */
88 /* Removed definitions for any constants that were no longer used. */
90 /* Revision 1.2 1996/03/26 19:34:33 jaf */
91 /* Added comments indicating which constants are not needed in an */
92 /* application that uses the LPC-10 coder. */
94 /* Revision 1.1 1996/02/07 14:43:51 jaf */
95 /* Initial revision */
97 /* LPC Configuration parameters: */
98 /* Frame size, Prediction order, Pitch period */
100 * Revision 1.4 2000/01/05 08:20:39 markster
101 * Version 0.1.5 from FTP
103 /* Revision 1.2 2000/01/05 08:20:39 markster
104 /* Some OSS fixes and a few lpc changes to make it actually work
106 * Revision 1.2 1996/08/20 20:35:41 jaf
107 * Added functions for allocating and initializing lpc10_encoder_state
108 * and lpc10_decoder_state structures.
110 * Revision 1.1 1996/08/19 22:31:40 jaf
113 /* Revision 1.3 1996/03/29 22:05:55 jaf */
114 /* Commented out the common block variables that are not needed by the */
115 /* embedded version. */
117 /* Revision 1.2 1996/03/26 19:34:50 jaf */
118 /* Added comments indicating which constants are not needed in an */
119 /* application that uses the LPC-10 coder. */
121 /* Revision 1.1 1996/02/07 14:44:09 jaf */
122 /* Initial revision */
124 /* LPC Processing control variables: */
126 /* *** Read-only: initialized in setup */
128 /* Files for Speech, Parameter, and Bitstream Input & Output, */
129 /* and message and debug outputs. */
131 /* Here are the only files which use these variables: */
133 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
135 /* Many files which use fdebug are not listed, since it is only used in */
136 /* those other files conditionally, to print trace statements. */
137 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
138 /* LPC order, Frame size, Quantization rate, Bits per frame, */
139 /* Error correction */
140 /* Subroutine SETUP is the only place where order is assigned a value, */
141 /* and that value is 10. It could increase efficiency 1% or so to */
142 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
144 /* a variable in a COMMON block, since it is used in many places in the */
145 /* core of the coding and decoding routines. Actually, I take that back.
147 /* At least when compiling with f2c, the upper bound of DO loops is */
148 /* stored in a local variable before the DO loop begins, and then that is
150 /* compared against on each iteration. */
151 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
152 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
153 /* is used in only a few places, and never in the core coding and */
154 /* decoding routines, so it could be eliminated entirely. */
155 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
156 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
157 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
158 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
160 /* a constant or a variable, since it is only examined once per frame. */
161 /* Leaving it as a variable that is set to .TRUE. seems like a good */
162 /* idea, since it does enable some error-correction capability for */
163 /* unvoiced frames, with no change in the coding rate, and no noticeable
165 /* quality difference in the decoded speech. */
166 /* integer quant, nbits */
167 /* *** Read/write: variables for debugging, not needed for LPC algorithm
170 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
172 /* Debug listing detail level, Line count on listing page */
174 /* nframe is not needed for an embedded LPC10 at all. */
175 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
176 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
177 /* an application, I would recommend removing the call to ERROR in RCCHK,
179 /* and remove ERROR and nunsfm completely. */
180 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
182 /* sread.f. When LPC10 is embedded into an application, one might want */
183 /* to cause it to be incremented in a routine that takes the output of */
184 /* SYNTHS and sends it to an audio device. It could be optionally */
185 /* displayed, for those that might want to know what it is. */
186 /* maxosp is never initialized to 0 in SETUP, although it probably should
188 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
189 /* would be of much interest to an application in which LPC10 is */
191 /* listl and lincnt are not needed for an embedded LPC10 at all. */
192 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
193 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
194 /* common /contrl/ quant, nbits */
195 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
197 contrl_1.lframe = 180;
198 contrl_1.corrp = TRUE_;
204 /* Allocate memory for, and initialize, the state that needs to be
205 kept from encoding one frame to the next for a single
206 LPC-10-compressed audio stream. Return 0 if malloc fails,
207 otherwise return pointer to new structure. */
209 struct lpc10_encoder_state *
210 create_lpc10_encoder_state()
212 struct lpc10_encoder_state *st;
214 st = (struct lpc10_encoder_state *)
215 malloc((unsigned) sizeof (struct lpc10_encoder_state));
217 init_lpc10_encoder_state(st);
224 void init_lpc10_encoder_state(struct lpc10_encoder_state *st)
230 /* State used only by function hp100 */
236 /* State used by function analys */
237 for (i = 0; i < 540; i++) {
241 for (i = 0; i < 696; i++) {
244 for (i = 0; i < 312; i++) {
248 /* integer osbuf[10]; /* no initial value necessary */
250 for (i = 0; i < 3; i++) {
257 for (i = 0; i < 8; i++) {
260 for (i = 0; i < 3; i++) {
261 st->rmsbuf[i] = 0.0f;
263 for (i = 0; i < 30; i++) {
269 /* State used by function onset */
272 /* real fpc; /* no initial value necessary */
273 for (i = 0; i < 16; i++) {
279 /* integer lasti; /* no initial value necessary */
282 /* State used by function voicin */
285 for (i = 0; i < 6; i++) {
296 st->snr = (real) (st->fbve / st->fbue << 6);
298 /* State used by function dyptrk */
299 for (i = 0; i < 60; i++) {
302 for (i = 0; i < 120; i++) {
308 /* State used by function chanwr */
315 /* Allocate memory for, and initialize, the state that needs to be
316 kept from decoding one frame to the next for a single
317 LPC-10-compressed audio stream. Return 0 if malloc fails,
318 otherwise return pointer to new structure. */
320 struct lpc10_decoder_state *
321 create_lpc10_decoder_state()
323 struct lpc10_decoder_state *st;
325 st = (struct lpc10_decoder_state *)
326 malloc((unsigned) sizeof (struct lpc10_decoder_state));
328 init_lpc10_decoder_state(st);
335 void init_lpc10_decoder_state(struct lpc10_decoder_state *st)
341 /* State used by function decode */
348 for (i = 0; i < 30; i++) {
351 for (i = 0; i < 3; i++) {
356 /* State used by function synths */
357 for (i = 0; i < 360; i++) {
362 /* State used by function pitsyn */
363 /* ivoico; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
364 /* ipito; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
366 /* rco[10]; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
367 /* integer jsamp; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
368 st->first_pitsyn = TRUE_;
370 /* State used by function bsynz */
372 for (i = 0; i < 166; i++) {
382 st->rmso_bsynz = 0.0f;
384 /* State used by function random */
387 st->y[0] = (shortint) -21161;
388 st->y[1] = (shortint) -8478;
389 st->y[2] = (shortint) 30892;
390 st->y[3] = (shortint) -10216;
391 st->y[4] = (shortint) 16950;
393 /* State used by function deemp */