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

Go to the source code of this file.

Functions

int enhancerInterface (float *out, float *in, iLBC_Dec_Inst_t *iLBCdec_inst)
 
float xCorrCoef (float *target, float *regressor, int subl)
 

Function Documentation

◆ enhancerInterface()

int enhancerInterface ( float *  out,
float *  in,
iLBC_Dec_Inst_t iLBCdec_inst 
)

Definition at line 517 of file enhancer.c.

521 {
522 float *enh_buf, *enh_period;
523 int iblock, isample;
524 int lag=0, ilag, i, ioffset;
525 float cc, maxcc;
526 float ftmp1, ftmp2;
527 float *inPtr, *enh_bufPtr1, *enh_bufPtr2;
528 float plc_pred[ENH_BLOCKL];
529
530 float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];
531 int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;
532 int start, plc_blockl, inlag;
533
534 enh_buf=iLBCdec_inst->enh_buf;
535 enh_period=iLBCdec_inst->enh_period;
536
537 memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl],
538 (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));
539
540 memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in,
541 iLBCdec_inst->blockl*sizeof(float));
542
543 if (iLBCdec_inst->mode==30)
544 plc_blockl=ENH_BLOCKL;
545 else
546 plc_blockl=40;
547
548 /* when 20 ms frame, move processing one block */
549 ioffset=0;
550 if (iLBCdec_inst->mode==20) ioffset=1;
551
552 i=3-ioffset;
553 memmove(enh_period, &enh_period[i],
554 (ENH_NBLOCKS_TOT-i)*sizeof(float));
555
556
557
558
559
560
561 /* Set state information to the 6 samples right before
562 the samples to be downsampled. */
563
564 memcpy(lpState,
565 enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126,
566 6*sizeof(float));
567
568 /* Down sample a factor 2 to save computations */
569
570 DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,
571 lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,
572 lpState, downsampled);
573
574 /* Estimate the pitch in the down sampled domain. */
575 for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {
576
577 lag = 10;
578 maxcc = xCorrCoef(downsampled+60+iblock*
579 ENH_BLOCKL_HALF, downsampled+60+iblock*
581 for (ilag=11; ilag<60; ilag++) {
582 cc = xCorrCoef(downsampled+60+iblock*
583 ENH_BLOCKL_HALF, downsampled+60+iblock*
585
586 if (cc > maxcc) {
587 maxcc = cc;
588 lag = ilag;
589 }
590 }
591
592 /* Store the estimated lag in the non-downsampled domain */
593 enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;
594
595
596 }
597
598
599 /* PLC was performed on the previous packet */
600 if (iLBCdec_inst->prev_enh_pl==1) {
601
602 inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];
603
604 lag = inlag-1;
605 maxcc = xCorrCoef(in, in+lag, plc_blockl);
606 for (ilag=inlag; ilag<=inlag+1; ilag++) {
607 cc = xCorrCoef(in, in+ilag, plc_blockl);
608
609
610
611
612
613
614 if (cc > maxcc) {
615 maxcc = cc;
616 lag = ilag;
617 }
618 }
619
620 enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;
621
622 /* compute new concealed residual for the old lookahead,
623 mix the forward PLC with a backward PLC from
624 the new frame */
625
626 inPtr=&in[lag-1];
627
628 enh_bufPtr1=&plc_pred[plc_blockl-1];
629
630 if (lag>plc_blockl) {
631 start=plc_blockl;
632 } else {
633 start=lag;
634 }
635
636 for (isample = start; isample>0; isample--) {
637 *enh_bufPtr1-- = *inPtr--;
638 }
639
640 enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
641 for (isample = (plc_blockl-1-lag); isample>=0; isample--) {
642 *enh_bufPtr1-- = *enh_bufPtr2--;
643 }
644
645 /* limit energy change */
646 ftmp2=0.0;
647 ftmp1=0.0;
648 for (i=0;i<plc_blockl;i++) {
649 ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*
650 enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];
651 ftmp1+=plc_pred[i]*plc_pred[i];
652 }
653 ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);
654 ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);
655 if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {
656 for (i=0;i<plc_blockl-10;i++) {
657 plc_pred[i]*=(float)2.0*ftmp2/ftmp1;
658 }
659 for (i=plc_blockl-10;i<plc_blockl;i++) {
660 plc_pred[i]*=(float)(i-plc_blockl+10)*
661 ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+
662
663
664
665
666
667 (float)2.0*ftmp2/ftmp1;
668 }
669 }
670
671 enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
672 for (i=0; i<plc_blockl; i++) {
673 ftmp1 = (float) (i+1) / (float) (plc_blockl+1);
674 *enh_bufPtr1 *= ftmp1;
675 *enh_bufPtr1 += ((float)1.0-ftmp1)*
676 plc_pred[plc_blockl-1-i];
677 enh_bufPtr1--;
678 }
679 }
680
681 if (iLBCdec_inst->mode==20) {
682 /* Enhancer with 40 samples delay */
683 for (iblock = 0; iblock<2; iblock++) {
684 enhancer(out+iblock*ENH_BLOCKL, enh_buf,
685 ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,
686 ENH_ALPHA0, enh_period, enh_plocsTbl,
688 }
689 } else if (iLBCdec_inst->mode==30) {
690 /* Enhancer with 80 samples delay */
691 for (iblock = 0; iblock<3; iblock++) {
692 enhancer(out+iblock*ENH_BLOCKL, enh_buf,
693 ENH_BUFL, (4+iblock)*ENH_BLOCKL,
694 ENH_ALPHA0, enh_period, enh_plocsTbl,
696 }
697 }
698
699 return (lag*2);
700 }
float lpFilt_coefsTbl[FILTERORDER_DS]
Definition: constants.c:89
float enh_plocsTbl[ENH_NBLOCKS_TOT]
Definition: constants.c:196
float xCorrCoef(float *target, float *regressor, int subl)
Definition: enhancer.c:485
void enhancer(float *odata, float *idata, int idatal, int centerStartPos, float alpha0, float *period, float *plocs, int periodl)
Definition: enhancer.c:455
void DownSample(float *In, float *Coef, int lengthIn, float *state, float *Out)
Definition: filter.c:110
#define ENH_ALPHA0
Definition: iLBC_define.h:85
#define ENH_BLOCKL_HALF
Definition: iLBC_define.h:67
#define ENH_NBLOCKS
Definition: iLBC_define.h:81
#define ENH_BLOCKL
Definition: iLBC_define.h:66
#define ENH_NBLOCKS_EXTRA
Definition: iLBC_define.h:82
#define ENH_BUFL
Definition: iLBC_define.h:84
#define ENH_NBLOCKS_TOT
Definition: iLBC_define.h:83
float enh_buf[ENH_BUFL]
Definition: iLBC_define.h:205
float enh_period[ENH_NBLOCKS_TOT]
Definition: iLBC_define.h:206
FILE * out
Definition: utils/frame.c:33
FILE * in
Definition: utils/frame.c:33

References iLBC_Dec_Inst_t_::blockl, DownSample(), ENH_ALPHA0, ENH_BLOCKL, ENH_BLOCKL_HALF, iLBC_Dec_Inst_t_::enh_buf, ENH_BUFL, ENH_NBLOCKS, ENH_NBLOCKS_EXTRA, ENH_NBLOCKS_TOT, iLBC_Dec_Inst_t_::enh_period, enh_plocsTbl, enhancer(), in, lpFilt_coefsTbl, iLBC_Dec_Inst_t_::mode, out, iLBC_Dec_Inst_t_::prev_enh_pl, and xCorrCoef().

Referenced by iLBC_decode().

◆ xCorrCoef()

float xCorrCoef ( float *  target,
float *  regressor,
int  subl 
)

Definition at line 485 of file enhancer.c.

489 {
490 int i;
491 float ftmp1, ftmp2;
492
493 ftmp1 = 0.0;
494 ftmp2 = 0.0;
495 for (i=0; i<subl; i++) {
496 ftmp1 += target[i]*regressor[i];
497 ftmp2 += regressor[i]*regressor[i];
498 }
499
500 if (ftmp1 > 0.0) {
501 return (float)(ftmp1*ftmp1/ftmp2);
502 }
503
504
505
506
507
508 else {
509 return (float)0.0;
510 }
511 }

Referenced by enhancerInterface(), and iLBC_decode().