Asterisk - The Open Source Telephony Project  21.4.1
lpc10.h
1 /*
2 
3 $Log$
4 Revision 1.18 2004/08/31 13:32:11 markster
5 Merge NetBSD and Courtesy tone with modifications (bug #2329)
6 
7 Revision 1.17 2003/10/26 18:50:49 markster
8 Make it build and run on MacOS X
9 
10 Revision 1.3 2003/10/26 18:50:49 markster
11 Make it build and run on MacOS X
12 
13 Revision 1.2 2003/04/23 19:13:35 markster
14 More OpenBSD patches
15 
16 Revision 1.1.1.2 2003/03/16 22:37:30 matteo
17 dom mar 16 23:37:23 CET 2003
18 
19 Revision 1.2 2003/03/16 16:09:48 markster
20 Mere James's cleanups for fewer build warnings
21 
22 Revision 1.1 2000/01/05 00:20:06 markster
23 Add broken lpc10 code... It's not too far from working I don't think...
24 
25  * Revision 1.1 1996/08/19 22:47:31 jaf
26  * Initial revision
27  *
28 
29 */
30 
31 #ifndef __LPC10_H__
32 #define __LPC10_H__
33 
34 #define P_R_O_T_O_T_Y_P_E_S
35 
36 #define LPC10_SAMPLES_PER_FRAME 180
37 #define LPC10_BITS_IN_COMPRESSED_FRAME 54
38 
39 
40 /*
41 
42  The "#if defined"'s in this file are by no means intended to be
43  complete. They are what Nautilus uses, which has been successfully
44  compiled under DOS with the Microsoft C compiler, and under a few
45  versions of Unix with the GNU C compiler.
46 
47  */
48 
49 #if defined(unix) || defined(__unix__) || defined(__NetBSD__)
50 typedef short INT16;
51 typedef int INT32;
52 #endif
53 
54 
55 #if defined(__MSDOS__) || defined(MSDOS)
56 typedef int INT16;
57 typedef long INT32;
58 #endif
59 
60 #if defined(__APPLE__)
61 typedef short INT16;
62 typedef int INT32;
63 #endif
64 
65 #if defined(WIN32) && defined(_MSC_VER)
66 typedef __int16 INT16;
67 typedef __int32 INT32;
68 #pragma warning(disable: 4005)
69 #endif
70 
71 
72 /* The initial values for every member of this structure is 0, except
73  where noted in comments. */
74 
75 /* These two lines are copied from f2c.h. There should be a more
76  elegant way of doing this than having the same declarations in two
77  files. */
78 
79 typedef float real;
80 typedef INT32 integer;
81 typedef INT32 logical;
82 typedef INT16 shortint;
83 
85  /* State used only by function hp100 */
86  real z11;
87  real z21;
88  real z12;
89  real z22;
90 
91  /* State used by function analys */
92  real inbuf[540], pebuf[540];
93  real lpbuf[696], ivbuf[312];
94  real bias;
95  integer osbuf[10]; /* no initial value necessary */
96  integer osptr; /* initial value 1 */
97  integer obound[3];
98  integer vwin[6] /* was [2][3] */; /* initial value vwin[4] = 307; vwin[5] = 462; */
99  integer awin[6] /* was [2][3] */; /* initial value awin[4] = 307; awin[5] = 462; */
100  integer voibuf[8] /* was [2][4] */;
101  real rmsbuf[3];
102  real rcbuf[30] /* was [10][3] */;
103  real zpre;
104 
105 
106  /* State used by function onset */
107  real n;
108  real d__; /* initial value 1.f */
109  real fpc; /* no initial value necessary */
110  real l2buf[16];
111  real l2sum1;
112  integer l2ptr1; /* initial value 1 */
113  integer l2ptr2; /* initial value 9 */
114  integer lasti; /* no initial value necessary */
115  logical hyst; /* initial value FALSE_ */
116 
117  /* State used by function voicin */
118  real dither; /* initial value 20.f */
119  real snr;
120  real maxmin;
121  real voice[6] /* was [2][3] */; /* initial value is probably unnecessary */
122  integer lbve, lbue, fbve, fbue;
123  integer ofbue, sfbue;
124  integer olbue, slbue;
125  /* Initial values:
126  lbve = 3000;
127  fbve = 3000;
128  fbue = 187;
129  ofbue = 187;
130  sfbue = 187;
131  lbue = 93;
132  olbue = 93;
133  slbue = 93;
134  snr = (real) (fbve / fbue << 6);
135  */
136 
137  /* State used by function dyptrk */
138  real s[60];
139  integer p[120] /* was [60][2] */;
140  integer ipoint;
141  real alphax;
142 
143  /* State used by function chanwr */
144  integer isync;
145 
146 };
147 
148 
150 
151  /* State used by function decode */
152  integer iptold; /* initial value 60 */
153  logical first; /* initial value TRUE_ */
154  integer ivp2h;
155  integer iovoic;
156  integer iavgp; /* initial value 60 */
157  integer erate;
158  integer drc[30] /* was [3][10] */;
159  integer dpit[3];
160  integer drms[3];
161 
162  /* State used by function synths */
163  real buf[360];
164  integer buflen; /* initial value 180 */
165 
166  /* State used by function pitsyn */
167  integer ivoico; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
168  integer ipito; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
169  real rmso; /* initial value 1.f */
170  real rco[10]; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
171  integer jsamp; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
172  logical first_pitsyn; /* initial value TRUE_ */
173 
174  /* State used by function bsynz */
175  integer ipo;
176  real exc[166];
177  real exc2[166];
178  real lpi1;
179  real lpi2;
180  real lpi3;
181  real hpi1;
182  real hpi2;
183  real hpi3;
184  real rmso_bsynz;
185 
186  /* State used by function random */
187  integer j; /* initial value 2 */
188  integer k; /* initial value 5 */
189  shortint y[5]; /* initial value { -21161,-8478,30892,-10216,16950 } */
190 
191  /* State used by function deemp */
192  real dei1;
193  real dei2;
194  real deo1;
195  real deo2;
196  real deo3;
197 
198 };
199 
200 
201 
202 /*
203 
204  Calling sequence:
205 
206  Call create_lpc10_encoder_state(), which returns a pointer to an
207  already initialized lpc10_encoder_state structure.
208 
209  lpc10_encode reads indices 0 through (LPC10_SAMPLES_PER_FRAME-1) of
210  array speech[], and writes indices 0 through
211  (LPC10_BITS_IN_COMPRESSED_FRAME-1) of array bits[], and both reads
212  and writes the lpc10_encoder_state structure contents. The
213  lpc10_encoder_state structure should *not* be initialized for every
214  frame of encoded speech. Once at the beginning of execution, done
215  automatically for you by create_lpc10_encoder_state(), is enough.
216 
217  init_lpc10_encoder_state() reinitializes the lpc10_encoder_state
218  structure. This might be useful if you are finished processing one
219  sound sample, and want to reuse the same lpc10_encoder_state
220  structure to process another sound sample. There might be other
221  uses as well.
222 
223  Note that the comments in the lpc10/lpcenc.c file imply that indices
224  1 through 180 of array speech[] are read. These comments were
225  written for the Fortran version of the code, before it was
226  automatically converted to C by the conversion program f2c. f2c
227  seems to use the convention that the pointers to arrays passed as
228  function arguments point to the first index used in the Fortran
229  code, whatever index that might be (usually 1), and then it modifies
230  the pointer inside of the function, like so:
231 
232  if (speech) {
233  --speech;
234  }
235 
236  So that the code can access the first value at index 1 and the last
237  at index 180. This makes the translated C code "closer" to the
238  original Fortran code.
239 
240  The calling sequence for the decoder is similar to the encoder. The
241  only significant difference is that the array bits[] is read
242  (indices 0 through (LPC10_BITS_IN_COMPRESSED_FRAME-1)), and the
243  array speech[] is written (indices 0 through
244  (LPC10_SAMPLES_PER_FRAME-1)).
245 
246  */
247 
248 struct lpc10_encoder_state * create_lpc10_encoder_state (void);
249 void init_lpc10_encoder_state (struct lpc10_encoder_state *st);
250 int lpc10_encode (real *speech, INT32 *bits, struct lpc10_encoder_state *st);
251 
252 struct lpc10_decoder_state * create_lpc10_decoder_state (void);
253 void init_lpc10_decoder_state (struct lpc10_decoder_state *st);
254 int lpc10_decode (INT32 *bits, real *speech, struct lpc10_decoder_state *st);
255 
256 #endif /* __LPC10_H__ */