Asterisk - The Open Source Telephony Project GIT-master-a358458
Functions
iLBC_decode.h File Reference
#include "iLBC_define.h"
Include dependency graph for iLBC_decode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void iLBC_decode (float *decblock, unsigned char *bytes, iLBC_Dec_Inst_t *iLBCdec_inst, int mode)
 
short initDecode (iLBC_Dec_Inst_t *iLBCdec_inst, int mode, int use_enhancer)
 

Function Documentation

◆ iLBC_decode()

void iLBC_decode ( float *  decblock,
unsigned char *  bytes,
iLBC_Dec_Inst_t iLBCdec_inst,
int  mode 
)

Definition at line 326 of file iLBC_decode.c.

333 {
334 float data[BLOCKL_MAX];
335 float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];
336 float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];
337 float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];
338 int k, i, start, idxForMax, pos, lastpart, ulp;
339 int lag, ilag;
340 float cc, maxcc;
341 int idxVec[STATE_LEN];
342 int gain_index[NASUB_MAX*CB_NSTAGES],
343 extra_gain_index[CB_NSTAGES];
344 int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];
345 int lsf_i[LSF_NSPLIT*LPC_N_MAX];
346 int state_first;
347 int last_bit;
348 unsigned char *pbytes;
349 float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
350 int order_plus_one;
351 float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
352 float decresidual[BLOCKL_MAX];
353
354 if (mode>0) { /* the data are good */
355
356 /* decode data */
357
358 pbytes=bytes;
359 pos=0;
360
361
362
363
364
365
366 /* Set everything to zero before decoding */
367
368 for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {
369 lsf_i[k]=0;
370 }
371 start=0;
372 state_first=0;
373 idxForMax=0;
374 for (k=0; k<iLBCdec_inst->state_short_len; k++) {
375 idxVec[k]=0;
376 }
377 for (k=0; k<CB_NSTAGES; k++) {
378 extra_cb_index[k]=0;
379 }
380 for (k=0; k<CB_NSTAGES; k++) {
381 extra_gain_index[k]=0;
382 }
383 for (i=0; i<iLBCdec_inst->nasub; i++) {
384 for (k=0; k<CB_NSTAGES; k++) {
385 cb_index[i*CB_NSTAGES+k]=0;
386 }
387 }
388 for (i=0; i<iLBCdec_inst->nasub; i++) {
389 for (k=0; k<CB_NSTAGES; k++) {
390 gain_index[i*CB_NSTAGES+k]=0;
391 }
392 }
393
394 /* loop over ULP classes */
395
396 for (ulp=0; ulp<3; ulp++) {
397
398 /* LSF */
399 for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){
400 unpack( &pbytes, &lastpart,
401 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);
402 packcombine(&lsf_i[k], lastpart,
403 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);
404 }
405
406 /* Start block info */
407
408 unpack( &pbytes, &lastpart,
409 iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);
410 packcombine(&start, lastpart,
411 iLBCdec_inst->ULP_inst->start_bits[ulp]);
412
413 unpack( &pbytes, &lastpart,
414
415
416
417
418
419 iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);
420 packcombine(&state_first, lastpart,
421 iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);
422
423 unpack( &pbytes, &lastpart,
424 iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);
425 packcombine(&idxForMax, lastpart,
426 iLBCdec_inst->ULP_inst->scale_bits[ulp]);
427
428 for (k=0; k<iLBCdec_inst->state_short_len; k++) {
429 unpack( &pbytes, &lastpart,
430 iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);
431 packcombine(idxVec+k, lastpart,
432 iLBCdec_inst->ULP_inst->state_bits[ulp]);
433 }
434
435 /* 23/22 (20ms/30ms) sample block */
436
437 for (k=0; k<CB_NSTAGES; k++) {
438 unpack( &pbytes, &lastpart,
439 iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp],
440 &pos);
441 packcombine(extra_cb_index+k, lastpart,
442 iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);
443 }
444 for (k=0; k<CB_NSTAGES; k++) {
445 unpack( &pbytes, &lastpart,
446 iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp],
447 &pos);
448 packcombine(extra_gain_index+k, lastpart,
449 iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);
450 }
451
452 /* The two/four (20ms/30ms) 40 sample sub-blocks */
453
454 for (i=0; i<iLBCdec_inst->nasub; i++) {
455 for (k=0; k<CB_NSTAGES; k++) {
456 unpack( &pbytes, &lastpart,
457 iLBCdec_inst->ULP_inst->cb_index[i][k][ulp],
458 &pos);
459 packcombine(cb_index+i*CB_NSTAGES+k, lastpart,
460 iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);
461 }
462 }
463
464 for (i=0; i<iLBCdec_inst->nasub; i++) {
465 for (k=0; k<CB_NSTAGES; k++) {
466 unpack( &pbytes, &lastpart,
467
468
469
470
471
472 iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp],
473 &pos);
474 packcombine(gain_index+i*CB_NSTAGES+k, lastpart,
475 iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);
476 }
477 }
478 }
479 /* Extract last bit. If it is 1 this indicates an
480 empty/lost frame */
481 unpack( &pbytes, &last_bit, 1, &pos);
482
483 /* Check for bit errors or empty/lost frames */
484 if (start<1)
485 mode = 0;
486 if (iLBCdec_inst->mode==20 && start>3)
487 mode = 0;
488 if (iLBCdec_inst->mode==30 && start>5)
489 mode = 0;
490 if (last_bit==1)
491 mode = 0;
492
493 if (mode==1) { /* No bit errors was detected,
494 continue decoding */
495
496 /* adjust index */
497 index_conv_dec(cb_index);
498
499 /* decode the lsf */
500
501 SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);
503 iLBCdec_inst->lpc_n);
504 DecoderInterpolateLSF(syntdenum, weightdenum,
505 lsfdeq, LPC_FILTERORDER, iLBCdec_inst);
506
507 Decode(iLBCdec_inst, decresidual, start, idxForMax,
508 idxVec, syntdenum, cb_index, gain_index,
509 extra_cb_index, extra_gain_index,
510 state_first);
511
512 /* preparing the plc for a future loss! */
513
514 doThePLC(PLCresidual, PLClpc, 0, decresidual,
515 syntdenum +
516 (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),
517 (*iLBCdec_inst).last_lag, iLBCdec_inst);
518
519
520
521
522
523
524
525 memcpy(decresidual, PLCresidual,
526 iLBCdec_inst->blockl*sizeof(float));
527 }
528
529 }
530
531 if (mode == 0) {
532 /* the data is bad (either a PLC call
533 * was made or a severe bit error was detected)
534 */
535
536 /* packet loss conceal */
537
538 memset(zeros, 0, BLOCKL_MAX*sizeof(float));
539
540 one[0] = 1;
541 memset(one+1, 0, LPC_FILTERORDER*sizeof(float));
542
543 start=0;
544
545 doThePLC(PLCresidual, PLClpc, 1, zeros, one,
546 (*iLBCdec_inst).last_lag, iLBCdec_inst);
547 memcpy(decresidual, PLCresidual,
548 iLBCdec_inst->blockl*sizeof(float));
549
550 order_plus_one = LPC_FILTERORDER + 1;
551 for (i = 0; i < iLBCdec_inst->nsub; i++) {
552 memcpy(syntdenum+(i*order_plus_one), PLClpc,
553 order_plus_one*sizeof(float));
554 }
555 }
556
557 if (iLBCdec_inst->use_enhancer == 1) {
558
559 /* post filtering */
560
561 iLBCdec_inst->last_lag =
562 enhancerInterface(data, decresidual, iLBCdec_inst);
563
564 /* synthesis filtering */
565
566 if (iLBCdec_inst->mode==20) {
567 /* Enhancer has 40 samples delay */
568 i=0;
569 syntFilter(data + i*SUBL,
570 iLBCdec_inst->old_syntdenum +
571 (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1),
572 SUBL, iLBCdec_inst->syntMem);
573
574
575
576
577
578 for (i=1; i < iLBCdec_inst->nsub; i++) {
579 syntFilter(data + i*SUBL,
580 syntdenum + (i-1)*(LPC_FILTERORDER+1),
581 SUBL, iLBCdec_inst->syntMem);
582 }
583 } else if (iLBCdec_inst->mode==30) {
584 /* Enhancer has 80 samples delay */
585 for (i=0; i < 2; i++) {
586 syntFilter(data + i*SUBL,
587 iLBCdec_inst->old_syntdenum +
588 (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),
589 SUBL, iLBCdec_inst->syntMem);
590 }
591 for (i=2; i < iLBCdec_inst->nsub; i++) {
592 syntFilter(data + i*SUBL,
593 syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,
594 iLBCdec_inst->syntMem);
595 }
596 }
597
598 } else {
599
600 /* Find last lag */
601 lag = 20;
602 maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
603 &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);
604
605 for (ilag=21; ilag<120; ilag++) {
606 cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
607 &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag],
608 ENH_BLOCKL);
609
610 if (cc > maxcc) {
611 maxcc = cc;
612 lag = ilag;
613 }
614 }
615 iLBCdec_inst->last_lag = lag;
616
617 /* copy data and run synthesis filter */
618
619 memcpy(data, decresidual,
620 iLBCdec_inst->blockl*sizeof(float));
621 for (i=0; i < iLBCdec_inst->nsub; i++) {
622 syntFilter(data + i*SUBL,
623 syntdenum + i*(LPC_FILTERORDER+1), SUBL,
624 iLBCdec_inst->syntMem);
625 }
626
627
628
629
630
631 }
632
633 /* high pass filtering on output if desired, otherwise
634 copy to out */
635
636 hpOutput(data, iLBCdec_inst->blockl,
637 decblock,iLBCdec_inst->hpomem);
638
639 /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/
640
641 memcpy(iLBCdec_inst->old_syntdenum, syntdenum,
642
643 iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));
644
645 iLBCdec_inst->prev_enh_pl=0;
646
647 if (mode==0) { /* PLC was used */
648 iLBCdec_inst->prev_enh_pl=1;
649 }
650 }
void DecoderInterpolateLSF(float *syntdenum, float *weightdenum, float *lsfdeq, int length, iLBC_Dec_Inst_t *iLBCdec_inst)
Definition: LPCdecode.c:89
void SimplelsfDEQ(float *lsfdeq, int *index, int lpc_n)
Definition: LPCdecode.c:42
void doThePLC(float *PLCresidual, float *PLClpc, int PLI, float *decresidual, float *lpc, int inlag, iLBC_Dec_Inst_t *iLBCdec_inst)
Definition: doCPLC.c:79
float xCorrCoef(float *target, float *regressor, int subl)
Definition: enhancer.c:485
int enhancerInterface(float *out, float *in, iLBC_Dec_Inst_t *iLBCdec_inst)
Definition: enhancer.c:517
int LSF_check(float *lsf, int dim, int NoAn)
Definition: helpfun.c:272
void hpOutput(float *In, int len, float *Out, float *mem)
Definition: hpOutput.c:19
void index_conv_dec(int *index)
Definition: iCBConstruct.c:45
void Decode(iLBC_Dec_Inst_t *iLBCdec_inst, float *decresidual, int start, int idxForMax, int *idxVec, float *syntdenum, int *cb_index, int *gain_index, int *extra_cb_index, int *extra_gain_index, int state_first)
Definition: iLBC_decode.c:118
#define ENH_BLOCKL
Definition: iLBC_define.h:66
#define STATE_LEN
Definition: iLBC_define.h:34
#define BLOCKL_MAX
Definition: iLBC_define.h:21
#define CB_NSTAGES
Definition: iLBC_define.h:56
#define SUBL
Definition: iLBC_define.h:33
#define LPC_FILTERORDER
Definition: iLBC_define.h:40
#define NSUB_MAX
Definition: iLBC_define.h:24
#define LPC_N_MAX
Definition: iLBC_define.h:46
#define LSF_NSPLIT
Definition: iLBC_define.h:50
#define NASUB_MAX
Definition: iLBC_define.h:32
void packcombine(int *index, int rest, int bitno_rest)
Definition: packing.c:53
void unpack(unsigned char **bitstream, int *index, int bitno, int *pos)
Definition: packing.c:126
float old_syntdenum[(LPC_FILTERORDER+1) *NSUB_MAX]
Definition: iLBC_define.h:198
const iLBC_ULP_Inst_t * ULP_inst
Definition: iLBC_define.h:174
float syntMem[LPC_FILTERORDER]
Definition: iLBC_define.h:177
int scale_bits[ULP_CLASSES+2]
Definition: iLBC_define.h:118
int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2]
Definition: iLBC_define.h:120
int lsf_bits[6][ULP_CLASSES+2]
Definition: iLBC_define.h:115
int startfirst_bits[ULP_CLASSES+2]
Definition: iLBC_define.h:117
int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]
Definition: iLBC_define.h:122
int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]
Definition: iLBC_define.h:123
int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2]
Definition: iLBC_define.h:121
int start_bits[ULP_CLASSES+2]
Definition: iLBC_define.h:116
int state_bits[ULP_CLASSES+2]
Definition: iLBC_define.h:119
void syntFilter(float *Out, float *a, int len, float *mem)
Definition: syntFilter.c:19

References iLBC_Dec_Inst_t_::blockl, BLOCKL_MAX, iLBC_ULP_Inst_t_::cb_gain, iLBC_ULP_Inst_t_::cb_index, CB_NSTAGES, Decode(), DecoderInterpolateLSF(), doThePLC(), ENH_BLOCKL, enhancerInterface(), iLBC_ULP_Inst_t_::extra_cb_gain, iLBC_ULP_Inst_t_::extra_cb_index, iLBC_Dec_Inst_t_::hpomem, hpOutput(), index_conv_dec(), iLBC_Dec_Inst_t_::last_lag, LPC_FILTERORDER, iLBC_Dec_Inst_t_::lpc_n, LPC_N_MAX, iLBC_ULP_Inst_t_::lsf_bits, LSF_check(), LSF_NSPLIT, iLBC_Dec_Inst_t_::mode, iLBC_Dec_Inst_t_::nasub, NASUB_MAX, iLBC_Dec_Inst_t_::nsub, NSUB_MAX, iLBC_Dec_Inst_t_::old_syntdenum, packcombine(), iLBC_Dec_Inst_t_::prev_enh_pl, iLBC_ULP_Inst_t_::scale_bits, SimplelsfDEQ(), iLBC_ULP_Inst_t_::start_bits, iLBC_ULP_Inst_t_::startfirst_bits, iLBC_ULP_Inst_t_::state_bits, STATE_LEN, iLBC_Dec_Inst_t_::state_short_len, SUBL, syntFilter(), iLBC_Dec_Inst_t_::syntMem, iLBC_Dec_Inst_t_::ULP_inst, unpack(), iLBC_Dec_Inst_t_::use_enhancer, and xCorrCoef().

Referenced by decode(), and ilbctolin_framein().

◆ initDecode()

short initDecode ( iLBC_Dec_Inst_t iLBCdec_inst,
int  mode,
int  use_enhancer 
)

Definition at line 33 of file iLBC_decode.c.

40 {
41 int i;
42
43 iLBCdec_inst->mode = mode;
44
45
46
47
48
49 if (mode==30) {
50 iLBCdec_inst->blockl = BLOCKL_30MS;
51 iLBCdec_inst->nsub = NSUB_30MS;
52 iLBCdec_inst->nasub = NASUB_30MS;
53 iLBCdec_inst->lpc_n = LPC_N_30MS;
54 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;
55 iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;
57 /* ULP init */
58 iLBCdec_inst->ULP_inst=&ULP_30msTbl;
59 }
60 else if (mode==20) {
61 iLBCdec_inst->blockl = BLOCKL_20MS;
62 iLBCdec_inst->nsub = NSUB_20MS;
63 iLBCdec_inst->nasub = NASUB_20MS;
64 iLBCdec_inst->lpc_n = LPC_N_20MS;
65 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;
66 iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;
68 /* ULP init */
69 iLBCdec_inst->ULP_inst=&ULP_20msTbl;
70 }
71 else {
72 exit(2);
73 }
74
75 memset(iLBCdec_inst->syntMem, 0,
76 LPC_FILTERORDER*sizeof(float));
77 memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl,
78 LPC_FILTERORDER*sizeof(float));
79
80 memset(iLBCdec_inst->old_syntdenum, 0,
81 ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));
82 for (i=0; i<NSUB_MAX; i++)
83 iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;
84
85 iLBCdec_inst->last_lag = 20;
86
87 iLBCdec_inst->prevLag = 120;
88 iLBCdec_inst->per = 0.0;
89 iLBCdec_inst->consPLICount = 0;
90 iLBCdec_inst->prevPLI = 0;
91 iLBCdec_inst->prevLpc[0] = 1.0;
92 memset(iLBCdec_inst->prevLpc+1,0,
93 LPC_FILTERORDER*sizeof(float));
94 memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));
95 iLBCdec_inst->seed=777;
96
97
98
99
100
101
102 memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));
103
104 iLBCdec_inst->use_enhancer = use_enhancer;
105 memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));
106 for (i=0;i<ENH_NBLOCKS_TOT;i++)
107 iLBCdec_inst->enh_period[i]=(float)40.0;
108
109 iLBCdec_inst->prev_enh_pl = 0;
110
111 return (iLBCdec_inst->blockl);
112 }
const iLBC_ULP_Inst_t ULP_30msTbl
Definition: constants.c:44
float lsfmeanTbl[LPC_FILTERORDER]
Definition: constants.c:210
const iLBC_ULP_Inst_t ULP_20msTbl
Definition: constants.c:19
#define NO_OF_BYTES_20MS
Definition: iLBC_define.h:95
#define LPC_N_30MS
Definition: iLBC_define.h:45
#define NO_OF_BYTES_30MS
Definition: iLBC_define.h:96
#define NASUB_30MS
Definition: iLBC_define.h:31
#define LPC_N_20MS
Definition: iLBC_define.h:44
#define STATE_SHORT_LEN_20MS
Definition: iLBC_define.h:36
#define NASUB_20MS
Definition: iLBC_define.h:25
#define STATE_SHORT_LEN_30MS
Definition: iLBC_define.h:35
#define NSUB_30MS
Definition: iLBC_define.h:23
#define NO_OF_WORDS_20MS
Definition: iLBC_define.h:97
#define NO_OF_WORDS_30MS
Definition: iLBC_define.h:98
#define ENH_BUFL
Definition: iLBC_define.h:84
#define BLOCKL_20MS
Definition: iLBC_define.h:19
#define ENH_NBLOCKS_TOT
Definition: iLBC_define.h:83
#define BLOCKL_30MS
Definition: iLBC_define.h:20
#define NSUB_20MS
Definition: iLBC_define.h:22
float enh_buf[ENH_BUFL]
Definition: iLBC_define.h:205
unsigned long seed
Definition: iLBC_define.h:195
float enh_period[ENH_NBLOCKS_TOT]
Definition: iLBC_define.h:206
float prevResidual[NSUB_MAX *SUBL]
Definition: iLBC_define.h:193
float prevLpc[LPC_FILTERORDER+1]
Definition: iLBC_define.h:192

References iLBC_Dec_Inst_t_::blockl, BLOCKL_20MS, BLOCKL_30MS, BLOCKL_MAX, iLBC_Dec_Inst_t_::consPLICount, iLBC_Dec_Inst_t_::enh_buf, ENH_BUFL, ENH_NBLOCKS_TOT, iLBC_Dec_Inst_t_::enh_period, iLBC_Dec_Inst_t_::hpomem, iLBC_Dec_Inst_t_::last_lag, LPC_FILTERORDER, iLBC_Dec_Inst_t_::lpc_n, LPC_N_20MS, LPC_N_30MS, lsfmeanTbl, iLBC_Dec_Inst_t_::mode, iLBC_Dec_Inst_t_::nasub, NASUB_20MS, NASUB_30MS, iLBC_Dec_Inst_t_::no_of_bytes, NO_OF_BYTES_20MS, NO_OF_BYTES_30MS, iLBC_Dec_Inst_t_::no_of_words, NO_OF_WORDS_20MS, NO_OF_WORDS_30MS, iLBC_Dec_Inst_t_::nsub, NSUB_20MS, NSUB_30MS, NSUB_MAX, iLBC_Dec_Inst_t_::old_syntdenum, iLBC_Dec_Inst_t_::per, iLBC_Dec_Inst_t_::prev_enh_pl, iLBC_Dec_Inst_t_::prevLag, iLBC_Dec_Inst_t_::prevLpc, iLBC_Dec_Inst_t_::prevPLI, iLBC_Dec_Inst_t_::prevResidual, iLBC_Dec_Inst_t_::seed, iLBC_Dec_Inst_t_::state_short_len, STATE_SHORT_LEN_20MS, STATE_SHORT_LEN_30MS, iLBC_Dec_Inst_t_::syntMem, ULP_20msTbl, ULP_30msTbl, iLBC_Dec_Inst_t_::ULP_inst, and iLBC_Dec_Inst_t_::use_enhancer.

Referenced by ilbctolin_framein(), and main().