formats: clarify setting of reverse_bytes
[sox.git] / lpc10 / lpcini.c
blobb5311268ac95f8bafad9e75c2801b5ebb192d47b
1 /*
3 * Revision 1.2 1996/08/20 20:35:41 jaf
4 * Added functions for allocating and initializing lpc10_encoder_state
5 * and lpc10_decoder_state structures.
7 * Revision 1.1 1996/08/19 22:31:40 jaf
8 * Initial revision
13 /* -- translated by f2c (version 19951025).
14 You must link the resulting object file with the libraries:
15 -lf2c -lm (in that order)
18 #include <stdlib.h>
20 #include "f2c.h"
22 extern int lpcini_(void);
24 /* Common Block Declarations */
26 struct {
27 integer order, lframe;
28 logical corrp;
29 } contrl_;
31 #define contrl_1 contrl_
33 /* ***************************************************************** */
36 * Revision 1.2 1996/08/20 20:35:41 jaf
37 * Added functions for allocating and initializing lpc10_encoder_state
38 * and lpc10_decoder_state structures.
40 * Revision 1.1 1996/08/19 22:31:40 jaf
41 * Initial revision
42 * */
43 /* Revision 1.1 1996/03/28 00:04:05 jaf */
44 /* Initial revision */
47 /* ***************************************************************** */
49 /* Initialize COMMON block variables used by LPC-10 encoder and decoder, */
50 /* and call initialization routines for both of them. */
52 /* Subroutine */ int lpcini_(void)
55 /* LPC Processing control variables: */
57 /* *** Read-only: initialized in setup */
59 /* Files for Speech, Parameter, and Bitstream Input & Output, */
60 /* and message and debug outputs. */
62 /* Here are the only files which use these variables: */
64 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
66 /* Many files which use fdebug are not listed, since it is only used in */
67 /* those other files conditionally, to print trace statements. */
68 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
69 /* LPC order, Frame size, Quantization rate, Bits per frame, */
70 /* Error correction */
71 /* Subroutine SETUP is the only place where order is assigned a value, */
72 /* and that value is 10. It could increase efficiency 1% or so to */
73 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
75 /* a variable in a COMMON block, since it is used in many places in the */
76 /* core of the coding and decoding routines. Actually, I take that back.
78 /* At least when compiling with f2c, the upper bound of DO loops is */
79 /* stored in a local variable before the DO loop begins, and then that is
81 /* compared against on each iteration. */
82 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
83 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
84 /* is used in only a few places, and never in the core coding and */
85 /* decoding routines, so it could be eliminated entirely. */
86 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
87 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
88 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
89 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
91 /* a constant or a variable, since it is only examined once per frame. */
92 /* Leaving it as a variable that is set to .TRUE. seems like a good */
93 /* idea, since it does enable some error-correction capability for */
94 /* unvoiced frames, with no change in the coding rate, and no noticeable
96 /* quality difference in the decoded speech. */
97 /* integer quant, nbits */
98 /* *** Read/write: variables for debugging, not needed for LPC algorithm
101 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
103 /* Debug listing detail level, Line count on listing page */
105 /* nframe is not needed for an embedded LPC10 at all. */
106 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
107 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
108 /* an application, I would recommend removing the call to ERROR in RCCHK,
110 /* and remove ERROR and nunsfm completely. */
111 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
113 /* sread.f. When LPC10 is embedded into an application, one might want */
114 /* to cause it to be incremented in a routine that takes the output of */
115 /* SYNTHS and sends it to an audio device. It could be optionally */
116 /* displayed, for those that might want to know what it is. */
117 /* maxosp is never initialized to 0 in SETUP, although it probably should
119 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
120 /* would be of much interest to an application in which LPC10 is */
121 /* embedded. */
122 /* listl and lincnt are not needed for an embedded LPC10 at all. */
123 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
124 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
125 /* common /contrl/ quant, nbits */
126 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
127 contrl_1.order = 10;
128 contrl_1.lframe = 180;
129 contrl_1.corrp = TRUE_;
130 return 0;
131 } /* lpcini_ */
135 /* Allocate memory for, and initialize, the state that needs to be
136 kept from encoding one frame to the next for a single
137 LPC-10-compressed audio stream. Return 0 if malloc fails,
138 otherwise return pointer to new structure. */
140 struct lpc10_encoder_state *
141 create_lpc10_encoder_state(void)
143 struct lpc10_encoder_state *st;
145 st = (struct lpc10_encoder_state *)
146 malloc((unsigned) sizeof (struct lpc10_encoder_state));
147 if (st != 0) {
148 init_lpc10_encoder_state(st);
150 return (st);
155 void init_lpc10_encoder_state(struct lpc10_encoder_state *st)
157 int i;
159 lpcini_();
161 /* State used only by function hp100 */
162 st->z11 = 0.0f;
163 st->z21 = 0.0f;
164 st->z12 = 0.0f;
165 st->z22 = 0.0f;
167 /* State used by function analys */
168 for (i = 0; i < 540; i++) {
169 st->inbuf[i] = 0.0f;
170 st->pebuf[i] = 0.0f;
172 for (i = 0; i < 696; i++) {
173 st->lpbuf[i] = 0.0f;
175 for (i = 0; i < 312; i++) {
176 st->ivbuf[i] = 0.0f;
178 st->bias = 0.0f;
179 /* integer osbuf[10]; no initial value necessary */
180 st->osptr = 1;
181 for (i = 0; i < 3; i++) {
182 st->obound[i] = 0;
184 st->vwin[4] = 307;
185 st->vwin[5] = 462;
186 st->awin[4] = 307;
187 st->awin[5] = 462;
188 for (i = 0; i < 8; i++) {
189 st->voibuf[i] = 0;
191 for (i = 0; i < 3; i++) {
192 st->rmsbuf[i] = 0.0f;
194 for (i = 0; i < 30; i++) {
195 st->rcbuf[i] = 0.0f;
197 st->zpre = 0.0f;
200 /* State used by function onset */
201 st->n = 0.0f;
202 st->d__ = 1.0f;
203 /* real fpc; no initial value necessary */
204 for (i = 0; i < 16; i++) {
205 st->l2buf[i] = 0.0f;
207 st->l2sum1 = 0.0f;
208 st->l2ptr1 = 1;
209 st->l2ptr2 = 9;
210 /* integer lasti; no initial value necessary */
211 st->hyst = FALSE_;
213 /* State used by function voicin */
214 st->dither = 20.0f;
215 st->maxmin = 0.0f;
216 for (i = 0; i < 6; i++) {
217 st->voice[i] = 0.0f;
219 st->lbve = 3000;
220 st->fbve = 3000;
221 st->fbue = 187;
222 st->ofbue = 187;
223 st->sfbue = 187;
224 st->lbue = 93;
225 st->olbue = 93;
226 st->slbue = 93;
227 st->snr = (real) (st->fbve / st->fbue << 6);
229 /* State used by function dyptrk */
230 for (i = 0; i < 60; i++) {
231 st->s[i] = 0.0f;
233 for (i = 0; i < 120; i++) {
234 st->p[i] = 0;
236 st->ipoint = 0;
237 st->alphax = 0.0f;
239 /* State used by function chanwr */
240 st->isync = 0;
246 /* Allocate memory for, and initialize, the state that needs to be
247 kept from decoding one frame to the next for a single
248 LPC-10-compressed audio stream. Return 0 if malloc fails,
249 otherwise return pointer to new structure. */
251 struct lpc10_decoder_state *
252 create_lpc10_decoder_state(void)
254 struct lpc10_decoder_state *st;
256 st = (struct lpc10_decoder_state *)
257 malloc((unsigned) sizeof (struct lpc10_decoder_state));
258 if (st != 0) {
259 init_lpc10_decoder_state(st);
261 return (st);
266 void init_lpc10_decoder_state(struct lpc10_decoder_state *st)
268 int i;
270 lpcini_();
272 /* State used by function decode */
273 st->iptold = 60;
274 st->first = TRUE_;
275 st->ivp2h = 0;
276 st->iovoic = 0;
277 st->iavgp = 60;
278 st->erate = 0;
279 for (i = 0; i < 30; i++) {
280 st->drc[i] = 0;
282 for (i = 0; i < 3; i++) {
283 st->dpit[i] = 0;
284 st->drms[i] = 0;
287 /* State used by function synths */
288 for (i = 0; i < 360; i++) {
289 st->buf[i] = 0.0f;
291 st->buflen = 180;
293 /* State used by function pitsyn */
294 /* ivoico; no initial value necessary as long as first_pitsyn is initially TRUE_ */
295 /* ipito; no initial value necessary as long as first_pitsyn is initially TRUE_ */
296 st->rmso = 1.0f;
297 /* rco[10]; no initial value necessary as long as first_pitsyn is initially TRUE_ */
298 /* integer jsamp; no initial value necessary as long as first_pitsyn is initially TRUE_ */
299 st->first_pitsyn = TRUE_;
301 /* State used by function bsynz */
302 st->ipo = 0;
303 for (i = 0; i < 166; i++) {
304 st->exc[i] = 0.0f;
305 st->exc2[i] = 0.0f;
307 st->lpi1 = 0.0f;
308 st->lpi2 = 0.0f;
309 st->lpi3 = 0.0f;
310 st->hpi1 = 0.0f;
311 st->hpi2 = 0.0f;
312 st->hpi3 = 0.0f;
313 st->rmso_bsynz = 0.0f;
315 /* State used by function random */
316 st->j = 2;
317 st->k = 5;
318 st->y[0] = (shortint) -21161;
319 st->y[1] = (shortint) -8478;
320 st->y[2] = (shortint) 30892;
321 st->y[3] = (shortint) -10216;
322 st->y[4] = (shortint) 16950;
324 /* State used by function deemp */
325 st->dei1 = 0.0f;
326 st->dei2 = 0.0f;
327 st->deo1 = 0.0f;
328 st->deo2 = 0.0f;
329 st->deo3 = 0.0f;