Properly play a holdtime message if the announce-holdtime option is
[asterisk-bristuff.git] / codecs / lpc10 / lpcdec.c
blobdd859ffcef8f9dc4321cdfd3d58be8b87d6f81ec
1 /*
3 $Log$
4 Revision 1.15 2004/06/26 03:50:14 markster
5 Merge source cleanups (bug #1911)
7 Revision 1.14 2003/02/12 13:59:15 matteo
8 mer feb 12 14:56:57 CET 2003
10 Revision 1.1.1.1 2003/02/12 13:59:15 matteo
11 mer feb 12 14:56:57 CET 2003
13 Revision 1.2 2000/01/05 08:20:39 markster
14 Some OSS fixes and a few lpc changes to make it actually work
16 * Revision 1.2 1996/08/20 20:30:11 jaf
17 * Removed all static local variables that were SAVE'd in the Fortran
18 * code, and put them in struct lpc10_encoder_state that is passed as an
19 * argument.
21 * Removed init function, since all initialization is now done in
22 * init_lpc10_encoder_state().
24 * Changed name of function from lpcenc_ to lpc10_encode, simply to make
25 * all lpc10 functions have more consistent naming with each other.
27 * Revision 1.1 1996/08/19 22:31:48 jaf
28 * Initial revision
33 /* -- translated by f2c (version 19951025).
34 You must link the resulting object file with the libraries:
35 -lf2c -lm (in that order)
38 #include "f2c.h"
40 #ifdef P_R_O_T_O_T_Y_P_E_S
41 extern int lpcdec_(integer *bits, real *speech);
42 extern int initlpcdec_(void);
43 /* comlen contrl_ 12 */
44 /*:ref: chanrd_ 14 5 4 4 4 4 4 */
45 /*:ref: decode_ 14 7 4 4 4 4 4 6 6 */
46 /*:ref: synths_ 14 6 4 4 6 6 6 4 */
47 /*:ref: initdecode_ 14 0 */
48 /*:ref: initsynths_ 14 0 */
49 #endif
51 /* Common Block Declarations */
53 extern struct {
54 integer order, lframe;
55 logical corrp;
56 } contrl_;
58 #define contrl_1 contrl_
60 /* Table of constant values */
62 static integer c__10 = 10;
64 /* ***************************************************************** */
66 /* $Log$
67 * Revision 1.15 2004/06/26 03:50:14 markster
68 * Merge source cleanups (bug #1911)
70 * Revision 1.14 2003/02/12 13:59:15 matteo
71 * mer feb 12 14:56:57 CET 2003
73 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
74 * mer feb 12 14:56:57 CET 2003
76 * Revision 1.2 2000/01/05 08:20:39 markster
77 * Some OSS fixes and a few lpc changes to make it actually work
79 * Revision 1.2 1996/08/20 20:30:11 jaf
80 * Removed all static local variables that were SAVE'd in the Fortran
81 * code, and put them in struct lpc10_encoder_state that is passed as an
82 * argument.
84 * Removed init function, since all initialization is now done in
85 * init_lpc10_encoder_state().
87 * Changed name of function from lpcenc_ to lpc10_encode, simply to make
88 * all lpc10 functions have more consistent naming with each other.
90 * Revision 1.1 1996/08/19 22:31:48 jaf
91 * Initial revision
92 * */
93 /* Revision 1.1 1996/03/28 00:03:00 jaf */
94 /* Initial revision */
97 /* ***************************************************************** */
99 /* Decode 54 bits to one frame of 180 speech samples. */
101 /* Input: */
102 /* BITS - 54 encoded bits, stored 1 per array element. */
103 /* Indices 1 through 53 read (SYNC bit ignored). */
104 /* Output: */
105 /* SPEECH - Speech encoded as real values in the range [-1,+1]. */
106 /* Indices 1 through 180 written. */
108 /* This subroutine maintains local state from one call to the next. If */
109 /* you want to switch to using a new audio stream for this filter, or */
110 /* reinitialize its state for any other reason, call the ENTRY */
111 /* INITLPCDEC. */
113 /* Subroutine */ int lpc10_decode(integer *bits, real *speech,
114 struct lpc10_decoder_state *st)
116 integer irms, voice[2], pitch, ipitv;
117 extern /* Subroutine */ int decode_(integer *, integer *, integer *,
118 integer *, integer *, real *, real *, struct lpc10_decoder_state *);
119 real rc[10];
120 extern /* Subroutine */ int chanrd_(integer *, integer *, integer *,
121 integer *, integer *), synths_(integer *,
122 integer *, real *, real *, real *, integer *,
123 struct lpc10_decoder_state *);
124 integer irc[10], len;
125 real rms;
127 /* $Log$
128 * Revision 1.15 2004/06/26 03:50:14 markster
129 * Merge source cleanups (bug #1911)
131 * Revision 1.14 2003/02/12 13:59:15 matteo
132 * mer feb 12 14:56:57 CET 2003
134 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
135 * mer feb 12 14:56:57 CET 2003
137 * Revision 1.2 2000/01/05 08:20:39 markster
138 * Some OSS fixes and a few lpc changes to make it actually work
140 * Revision 1.2 1996/08/20 20:30:11 jaf
141 * Removed all static local variables that were SAVE'd in the Fortran
142 * code, and put them in struct lpc10_encoder_state that is passed as an
143 * argument.
145 * Removed init function, since all initialization is now done in
146 * init_lpc10_encoder_state().
148 * Changed name of function from lpcenc_ to lpc10_encode, simply to make
149 * all lpc10 functions have more consistent naming with each other.
151 * Revision 1.1 1996/08/19 22:31:48 jaf
152 * Initial revision
153 * */
154 /* Revision 1.3 1996/03/29 22:03:47 jaf */
155 /* Removed definitions for any constants that were no longer used. */
157 /* Revision 1.2 1996/03/26 19:34:33 jaf */
158 /* Added comments indicating which constants are not needed in an */
159 /* application that uses the LPC-10 coder. */
161 /* Revision 1.1 1996/02/07 14:43:51 jaf */
162 /* Initial revision */
164 /* LPC Configuration parameters: */
165 /* Frame size, Prediction order, Pitch period */
166 /* Arguments */
167 /* $Log$
168 * Revision 1.15 2004/06/26 03:50:14 markster
169 * Merge source cleanups (bug #1911)
171 * Revision 1.14 2003/02/12 13:59:15 matteo
172 * mer feb 12 14:56:57 CET 2003
174 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
175 * mer feb 12 14:56:57 CET 2003
177 * Revision 1.2 2000/01/05 08:20:39 markster
178 * Some OSS fixes and a few lpc changes to make it actually work
180 * Revision 1.2 1996/08/20 20:30:11 jaf
181 * Removed all static local variables that were SAVE'd in the Fortran
182 * code, and put them in struct lpc10_encoder_state that is passed as an
183 * argument.
185 * Removed init function, since all initialization is now done in
186 * init_lpc10_encoder_state().
188 * Changed name of function from lpcenc_ to lpc10_encode, simply to make
189 * all lpc10 functions have more consistent naming with each other.
191 * Revision 1.1 1996/08/19 22:31:48 jaf
192 * Initial revision
193 * */
194 /* Revision 1.3 1996/03/29 22:05:55 jaf */
195 /* Commented out the common block variables that are not needed by the */
196 /* embedded version. */
198 /* Revision 1.2 1996/03/26 19:34:50 jaf */
199 /* Added comments indicating which constants are not needed in an */
200 /* application that uses the LPC-10 coder. */
202 /* Revision 1.1 1996/02/07 14:44:09 jaf */
203 /* Initial revision */
205 /* LPC Processing control variables: */
207 /* *** Read-only: initialized in setup */
209 /* Files for Speech, Parameter, and Bitstream Input & Output, */
210 /* and message and debug outputs. */
212 /* Here are the only files which use these variables: */
214 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
216 /* Many files which use fdebug are not listed, since it is only used in */
217 /* those other files conditionally, to print trace statements. */
218 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
219 /* LPC order, Frame size, Quantization rate, Bits per frame, */
220 /* Error correction */
221 /* Subroutine SETUP is the only place where order is assigned a value, */
222 /* and that value is 10. It could increase efficiency 1% or so to */
223 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
225 /* a variable in a COMMON block, since it is used in many places in the */
226 /* core of the coding and decoding routines. Actually, I take that back.
228 /* At least when compiling with f2c, the upper bound of DO loops is */
229 /* stored in a local variable before the DO loop begins, and then that is
231 /* compared against on each iteration. */
232 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
233 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
234 /* is used in only a few places, and never in the core coding and */
235 /* decoding routines, so it could be eliminated entirely. */
236 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
237 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
238 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
239 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
241 /* a constant or a variable, since it is only examined once per frame. */
242 /* Leaving it as a variable that is set to .TRUE. seems like a good */
243 /* idea, since it does enable some error-correction capability for */
244 /* unvoiced frames, with no change in the coding rate, and no noticeable
246 /* quality difference in the decoded speech. */
247 /* integer quant, nbits */
248 /* *** Read/write: variables for debugging, not needed for LPC algorithm
251 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
253 /* Debug listing detail level, Line count on listing page */
255 /* nframe is not needed for an embedded LPC10 at all. */
256 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
257 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
258 /* an application, I would recommend removing the call to ERROR in RCCHK,
260 /* and remove ERROR and nunsfm completely. */
261 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
263 /* sread.f. When LPC10 is embedded into an application, one might want */
264 /* to cause it to be incremented in a routine that takes the output of */
265 /* SYNTHS and sends it to an audio device. It could be optionally */
266 /* displayed, for those that might want to know what it is. */
267 /* maxosp is never initialized to 0 in SETUP, although it probably should
269 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
270 /* would be of much interest to an application in which LPC10 is */
271 /* embedded. */
272 /* listl and lincnt are not needed for an embedded LPC10 at all. */
273 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
274 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
275 /* common /contrl/ quant, nbits */
276 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
277 /* Local variables that need not be saved */
278 /* Uncoded speech parameters */
279 /* Coded speech parameters */
280 /* Others */
281 /* Local state */
282 /* None */
283 /* Parameter adjustments */
284 if (bits) {
285 --bits;
287 if (speech) {
288 --speech;
291 /* Function Body */
293 chanrd_(&c__10, &ipitv, &irms, irc, &bits[1]);
294 decode_(&ipitv, &irms, irc, voice, &pitch, &rms, rc, st);
295 synths_(voice, &pitch, &rms, rc, &speech[1], &len, st);
296 return 0;
297 } /* lpcdec_ */