Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Functions | Variables
lpc10/decode.c File Reference
#include "f2c.h"
Include dependency graph for lpc10/decode.c:

Go to the source code of this file.

Macros

#define contrl_1   contrl_
 

Functions

int decode_ (integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st)
 

Variables

static integer c__2 = 2
 
struct {
   logical   corrp
 
   integer   lframe
 
   integer   order
 
contrl_
 

Macro Definition Documentation

◆ contrl_1

#define contrl_1   contrl_

Definition at line 54 of file lpc10/decode.c.

Function Documentation

◆ decode_()

int decode_ ( integer ipitv,
integer irms,
integer irc,
integer voice,
integer pitch,
real rms,
real rc,
struct lpc10_decoder_state st 
)

Definition at line 147 of file lpc10/decode.c.

150{
151 /* Initialized data */
152
153 logical *first;
154 static integer ethrs = 2048;
155 static integer ethrs1 = 128;
156 static integer ethrs2 = 1024;
157 static integer ethrs3 = 2048;
158 static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,
159 25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,
160 24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,
161 3641 };
162 static real corth[32] /* was [4][8] */ = { 32767.f,10.f,5.f,0.f,
163 32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,
164 11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,
165 3.2f,0.f };
166 static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,
167 20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,
168 3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,
169 100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,
170 3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,
171 3,3,3,3,1,3,3,3,1,3,1,1,1 };
172 static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
173 384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
174 92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
175 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
176 static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,
177 96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,
178 127 };
179 static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,
180 .3828f };
181 integer *ivp2h;
182 static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }
183 ;
184 static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };
185 static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };
186 static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };
187 static integer bit[5] = { 2,4,8,16,32 };
188 integer *iovoic;
189 integer *iavgp;
190 integer *iptold;
191 integer *erate;
192 integer *drc;
193 integer *dpit;
194 integer *drms;
195
196 /* System generated locals */
197 integer i__1, i__2;
198
199 /* Builtin functions */
201
202 /* Local variables */
203 extern /* Subroutine */ int ham84_(integer *, integer *, integer *);
204 integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;
205 extern integer median_(integer *, integer *, integer *);
206 integer ishift, errcnt, lsb;
207
208/* $Log$
209 * Revision 1.16 2004/06/26 03:50:14 markster
210 * Merge source cleanups (bug #1911)
211 *
212 * Revision 1.15 2003/09/19 01:20:22 markster
213 * Code cleanups (bug #66)
214 *
215 * Revision 1.2 2003/09/19 01:20:22 markster
216 * Code cleanups (bug #66)
217 *
218 * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
219 * mer feb 12 14:56:57 CET 2003
220 *
221 * Revision 1.2 2000/01/05 08:20:39 markster
222 * Some OSS fixes and a few lpc changes to make it actually work
223 *
224 * Revision 1.2 1996/08/20 20:22:39 jaf
225 * Removed all static local variables that were SAVE'd in the Fortran
226 * code, and put them in struct lpc10_decoder_state that is passed as an
227 * argument.
228 *
229 * Removed init function, since all initialization is now done in
230 * init_lpc10_decoder_state().
231 *
232 * Revision 1.1 1996/08/19 22:32:38 jaf
233 * Initial revision
234 * */
235/* Revision 1.3 1996/03/29 22:03:47 jaf */
236/* Removed definitions for any constants that were no longer used. */
237
238/* Revision 1.2 1996/03/26 19:34:33 jaf */
239/* Added comments indicating which constants are not needed in an */
240/* application that uses the LPC-10 coder. */
241
242/* Revision 1.1 1996/02/07 14:43:51 jaf */
243/* Initial revision */
244
245/* LPC Configuration parameters: */
246/* Frame size, Prediction order, Pitch period */
247/* Arguments */
248/* $Log$
249 * Revision 1.16 2004/06/26 03:50:14 markster
250 * Merge source cleanups (bug #1911)
251 *
252 * Revision 1.15 2003/09/19 01:20:22 markster
253 * Code cleanups (bug #66)
254 *
255 * Revision 1.2 2003/09/19 01:20:22 markster
256 * Code cleanups (bug #66)
257 *
258 * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
259 * mer feb 12 14:56:57 CET 2003
260 *
261 * Revision 1.2 2000/01/05 08:20:39 markster
262 * Some OSS fixes and a few lpc changes to make it actually work
263 *
264 * Revision 1.2 1996/08/20 20:22:39 jaf
265 * Removed all static local variables that were SAVE'd in the Fortran
266 * code, and put them in struct lpc10_decoder_state that is passed as an
267 * argument.
268 *
269 * Removed init function, since all initialization is now done in
270 * init_lpc10_decoder_state().
271 *
272 * Revision 1.1 1996/08/19 22:32:38 jaf
273 * Initial revision
274 * */
275/* Revision 1.3 1996/03/29 22:05:55 jaf */
276/* Commented out the common block variables that are not needed by the */
277/* embedded version. */
278
279/* Revision 1.2 1996/03/26 19:34:50 jaf */
280/* Added comments indicating which constants are not needed in an */
281/* application that uses the LPC-10 coder. */
282
283/* Revision 1.1 1996/02/07 14:44:09 jaf */
284/* Initial revision */
285
286/* LPC Processing control variables: */
287
288/* *** Read-only: initialized in setup */
289
290/* Files for Speech, Parameter, and Bitstream Input & Output, */
291/* and message and debug outputs. */
292
293/* Here are the only files which use these variables: */
294
295/* lpcsim.f setup.f trans.f error.f vqsetup.f */
296
297/* Many files which use fdebug are not listed, since it is only used in */
298/* those other files conditionally, to print trace statements. */
299/* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
300/* LPC order, Frame size, Quantization rate, Bits per frame, */
301/* Error correction */
302/* Subroutine SETUP is the only place where order is assigned a value, */
303/* and that value is 10. It could increase efficiency 1% or so to */
304/* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
305*/
306/* a variable in a COMMON block, since it is used in many places in the */
307/* core of the coding and decoding routines. Actually, I take that back.
308*/
309/* At least when compiling with f2c, the upper bound of DO loops is */
310/* stored in a local variable before the DO loop begins, and then that is
311*/
312/* compared against on each iteration. */
313/* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
314/* Similarly for quant, which is given a value of 2400 in SETUP. quant */
315/* is used in only a few places, and never in the core coding and */
316/* decoding routines, so it could be eliminated entirely. */
317/* nbits is similar to quant, and is given a value of 54 in SETUP. */
318/* corrp is given a value of .TRUE. in SETUP, and is only used in the */
319/* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
320/* coder significantly whether it is .TRUE. or .FALSE., or whether it is
321*/
322/* a constant or a variable, since it is only examined once per frame. */
323/* Leaving it as a variable that is set to .TRUE. seems like a good */
324/* idea, since it does enable some error-correction capability for */
325/* unvoiced frames, with no change in the coding rate, and no noticeable
326*/
327/* quality difference in the decoded speech. */
328/* integer quant, nbits */
329/* *** Read/write: variables for debugging, not needed for LPC algorithm
330*/
331
332/* Current frame, Unstable frames, Output clip count, Max onset buffer,
333*/
334/* Debug listing detail level, Line count on listing page */
335
336/* nframe is not needed for an embedded LPC10 at all. */
337/* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
338/* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
339/* an application, I would recommend removing the call to ERROR in RCCHK,
340*/
341/* and remove ERROR and nunsfm completely. */
342/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
343*/
344/* sread.f. When LPC10 is embedded into an application, one might want */
345/* to cause it to be incremented in a routine that takes the output of */
346/* SYNTHS and sends it to an audio device. It could be optionally */
347/* displayed, for those that might want to know what it is. */
348/* maxosp is never initialized to 0 in SETUP, although it probably should
349*/
350/* be, and it is updated in subroutine ANALYS. I doubt that its value */
351/* would be of much interest to an application in which LPC10 is */
352/* embedded. */
353/* listl and lincnt are not needed for an embedded LPC10 at all. */
354/* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
355/* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
356/* common /contrl/ quant, nbits */
357/* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
358/* Function return value definitions */
359
360/* Parameters/constants */
361
362/* The variables below that are not Fortran PARAMETER's are */
363/* initialized with DATA statements, and then never modified. */
364/* The following are used regardless of CORRP's value. */
365
366/* DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */
367
368/* The following are used only if CORRP is .TRUE. */
369
370/* ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */
371
372/* Local variables that need not be saved */
373
374/* The following are used regardless of CORRP's value */
375/* The following are used only if CORRP is .TRUE. */
376
377/* Local state */
378
379/* The following are used regardless of CORRP's value */
380/* The following are used only if CORRP is .TRUE. */
381/* I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */
382/* and DRMS. They should be checked to see if they are reasonable.
383*/
384/* I'm also guessing for ERATE, but I think 0 is the right initial
385*/
386/* value. */
387 /* Parameter adjustments */
388 if (irc) {
389 --irc;
390 }
391 if (voice) {
392 --voice;
393 }
394 if (rc) {
395 --rc;
396 }
397
398 /* Function Body */
399
400 iptold = &(st->iptold);
401 first = &(st->first);
402 ivp2h = &(st->ivp2h);
403 iovoic = &(st->iovoic);
404 iavgp = &(st->iavgp);
405 erate = &(st->erate);
406 drc = &(st->drc[0]);
407 dpit = &(st->dpit[0]);
408 drms = &(st->drms[0]);
409
410/* DATA statements for "constants" defined above. */
411/* IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) */
412/* 800 FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) */
413/* If no error correction, do pitch and voicing then jump to decode */
414 i4 = detau[*ipitv];
415 if (! contrl_1.corrp) {
416 voice[1] = 1;
417 voice[2] = 1;
418 if (*ipitv <= 1) {
419 voice[1] = 0;
420 }
421 if (*ipitv == 0 || *ipitv == 2) {
422 voice[2] = 0;
423 }
424 *pitch = i4;
425 if (*pitch <= 4) {
426 *pitch = *iptold;
427 }
428 if (voice[1] == 1 && voice[2] == 1) {
429 *iptold = *pitch;
430 }
431 if (voice[1] != voice[2]) {
432 *pitch = *iptold;
433 }
434 goto L900;
435 }
436/* Do error correction pitch and voicing */
437 if (i4 > 4) {
438 dpit[0] = i4;
439 ivoic = 2;
440 *iavgp = (*iavgp * 15 + i4 + 8) / 16;
441 } else {
442 ivoic = i4;
443 dpit[0] = *iavgp;
444 }
445 drms[0] = *irms;
446 i__1 = contrl_1.order;
447 for (i__ = 1; i__ <= i__1; ++i__) {
448 drc[i__ * 3 - 3] = irc[i__];
449 }
450/* Determine index to IVTAB from V/UV decision */
451/* If error rate is high then use alternate table */
452 index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;
453 i1 = ivtab[index - 1];
454 ipit = i1 & 3;
455 icorf = i1 / 8;
456 if (*erate < ethrs) {
457 icorf /= 64;
458 }
459/* Determine error rate: 4=high 1=low */
460 ixcor = 4;
461 if (*erate < ethrs3) {
462 ixcor = 3;
463 }
464 if (*erate < ethrs2) {
465 ixcor = 2;
466 }
467 if (*erate < ethrs1) {
468 ixcor = 1;
469 }
470/* Voice/unvoice decision determined from bits 0 and 1 of IVTAB */
471 voice[1] = icorf / 2 & 1;
472 voice[2] = icorf & 1;
473/* Skip decoding on first frame because present data not yet available */
474 if (*first) {
475 *first = FALSE_;
476/* Assign PITCH a "default" value on the first call, since */
477/* otherwise it would be left uninitialized. The two lines
478*/
479/* below were copied from above, since it seemed like a */
480/* reasonable thing to do for the first call. */
481 *pitch = i4;
482 if (*pitch <= 4) {
483 *pitch = *iptold;
484 }
485 goto L500;
486 }
487/* If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). */
488/* Determine error rate and correct errors using a Hamming 8,4 code */
489/* during transition or unvoiced frame. If IOUT is negative, */
490/* more than 1 error occurred, use previous frame's parameters. */
491 if ((icorf & bit[3]) != 0) {
492 errcnt = 0;
493 lsb = drms[1] & 1;
494 index = (drc[22] << 4) + drms[1] / 2;
495 ham84_(&index, &iout, &errcnt);
496 drms[1] = drms[2];
497 if (iout >= 0) {
498 drms[1] = (iout << 1) + lsb;
499 }
500 for (i__ = 1; i__ <= 4; ++i__) {
501 if (i__ == 1) {
502 i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);
503 } else {
504 i1 = drc[(9 - i__) * 3 - 2] & 15;
505 }
506 i2 = drc[(5 - i__) * 3 - 2] & 31;
507 lsb = i2 & 1;
508 index = (i1 << 4) + i2 / 2;
509 ham84_(&index, &iout, &errcnt);
510 if (iout >= 0) {
511 iout = (iout << 1) + lsb;
512 if ((iout & 16) == 16) {
513 iout += -32;
514 }
515 } else {
516 iout = drc[(5 - i__) * 3 - 1];
517 }
518 drc[(5 - i__) * 3 - 2] = iout;
519 }
520/* Determine error rate */
521 *erate = (integer)(*erate * .96875f + errcnt * 102);
522 }
523/* Get unsmoothed RMS, RC's, and PITCH */
524 *irms = drms[1];
525 i__1 = contrl_1.order;
526 for (i__ = 1; i__ <= i__1; ++i__) {
527 irc[i__] = drc[i__ * 3 - 2];
528 }
529 if (ipit == 1) {
530 dpit[1] = dpit[2];
531 }
532 if (ipit == 3) {
533 dpit[1] = dpit[0];
534 }
535 *pitch = dpit[1];
536/* If bit 2 of ICORF is set then smooth RMS and RC's, */
537 if ((icorf & bit[1]) != 0) {
538 if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3]
539 && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[
540 ixcor + 3]) {
541 *irms = median_(&drms[2], &drms[1], drms);
542 }
543 for (i__ = 1; i__ <= 6; ++i__) {
544 if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))
545 >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *
546 3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[
547 ixcor + ((i__ + 2) << 2) - 5]) {
548 irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[
549 i__ * 3 - 3]);
550 }
551 }
552 }
553/* If bit 3 of ICORF is set then smooth pitch */
554 if ((icorf & bit[2]) != 0) {
555 if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1]
556 && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[
557 ixcor - 1]) {
558 *pitch = median_(&dpit[2], &dpit[1], dpit);
559 }
560 }
561/* If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with */
562/* values so that after quantization bias is removed in decode */
563/* the values will be zero. */
564L500:
565 if ((icorf & bit[4]) != 0) {
566 i__1 = contrl_1.order;
567 for (i__ = 5; i__ <= i__1; ++i__) {
568 irc[i__] = zrc[i__ - 1];
569 }
570 }
571/* House keeping - one frame delay */
572 *iovoic = ivoic;
573 *ivp2h = voice[2];
574 dpit[2] = dpit[1];
575 dpit[1] = dpit[0];
576 drms[2] = drms[1];
577 drms[1] = drms[0];
578 i__1 = contrl_1.order;
579 for (i__ = 1; i__ <= i__1; ++i__) {
580 drc[i__ * 3 - 1] = drc[i__ * 3 - 2];
581 drc[i__ * 3 - 2] = drc[i__ * 3 - 3];
582 }
583L900:
584/* IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) */
585/* 801 FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) */
586/* Decode RMS */
587 *irms = rmst[(31 - *irms) * 2];
588/* Decode RC(1) and RC(2) from log-area-ratios */
589/* Protect from illegal coded value (-16) caused by bit errors */
590 for (i__ = 1; i__ <= 2; ++i__) {
591 i2 = irc[i__];
592 i1 = 0;
593 if (i2 < 0) {
594 i1 = 1;
595 i2 = -i2;
596 if (i2 > 15) {
597 i2 = 0;
598 }
599 }
600 i2 = detab7[i2 * 2];
601 if (i1 == 1) {
602 i2 = -i2;
603 }
604 ishift = 15 - nbit[i__ - 1];
605 irc[i__] = i2 * pow_ii(&c__2, &ishift);
606 }
607/* Decode RC(3)-RC(10) to sign plus 14 bits */
608 i__1 = contrl_1.order;
609 for (i__ = 3; i__ <= i__1; ++i__) {
610 i2 = irc[i__];
611 ishift = 15 - nbit[i__ - 1];
612 i2 *= pow_ii(&c__2, &ishift);
613 i2 += qb[i__ - 3];
614 irc[i__] = (integer)(i2 * descl[i__ - 3] + deadd[i__ - 3]);
615 }
616/* IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) */
617/* 811 FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) */
618/* Scale RMS and RC's to reals */
619 *rms = (real) (*irms);
620 i__1 = contrl_1.order;
621 for (i__ = 1; i__ <= i__1; ++i__) {
622 rc[i__] = irc[i__] / 16384.f;
623 }
624 return 0;
625} /* decode_ */
struct sla_ringing_trunk * first
Definition: app_sla.c:332
#define abs(x)
Definition: f2c.h:195
integer pow_ii(integer *ap, integer *bp)
Definition: f2clib.c:30
integer median_(integer *d1, integer *d2, integer *d3)
Definition: median.c:69
#define FALSE_
Definition: f2c.h:68
int ham84_(integer *input, integer *output, integer *errcnt)
Definition: ham84.c:85
static integer c__2
Definition: lpc10/decode.c:58
#define contrl_1
Definition: lpc10/decode.c:54
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80
INT32 logical
Definition: lpc10.h:81
integer iovoic
Definition: lpc10.h:155
logical first
Definition: lpc10.h:153
integer dpit[3]
Definition: lpc10.h:159
integer iptold
Definition: lpc10.h:152
integer iavgp
Definition: lpc10.h:156
integer drc[30]
Definition: lpc10.h:158
integer drms[3]
Definition: lpc10.h:160
integer ivp2h
Definition: lpc10.h:154
integer erate
Definition: lpc10.h:157

References abs, c__2, contrl_1, lpc10_decoder_state::dpit, lpc10_decoder_state::drc, lpc10_decoder_state::drms, lpc10_decoder_state::erate, FALSE_, first, lpc10_decoder_state::first, ham84_(), lpc10_decoder_state::iavgp, lpc10_decoder_state::iovoic, lpc10_decoder_state::iptold, lpc10_decoder_state::ivp2h, median_(), and pow_ii().

Referenced by lpc10_decode().

Variable Documentation

◆ c__2

integer c__2 = 2
static

Definition at line 58 of file lpc10/decode.c.

Referenced by decode_().

◆ 

struct { ... } contrl_

◆ corrp

logical corrp

Definition at line 51 of file lpc10/decode.c.

◆ lframe

integer lframe

Definition at line 50 of file lpc10/decode.c.

◆ order

integer order

Definition at line 50 of file lpc10/decode.c.