diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-04-07 12:47:34 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-04-07 12:47:34 +0000 |
commit | 81d1b2797aa3945c529d57f9ddf6179ec2b392a4 (patch) | |
tree | 2ae3b710e8152fb1140653473fbc338a6638178e /third_party/ilbc/getCBvec.c | |
parent | 3ade1510e72926d02d7c7d4416257449bc0cd3f3 (diff) |
Moved ilbc to third_party directory
git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/split-3rd-party@1169 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'third_party/ilbc/getCBvec.c')
-rw-r--r-- | third_party/ilbc/getCBvec.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/third_party/ilbc/getCBvec.c b/third_party/ilbc/getCBvec.c new file mode 100644 index 00000000..4f2d2914 --- /dev/null +++ b/third_party/ilbc/getCBvec.c @@ -0,0 +1,193 @@ + + /****************************************************************** + + iLBC Speech Coder ANSI-C Source Code + + getCBvec.c + + Copyright (C) The Internet Society (2004). + All Rights Reserved. + + ******************************************************************/ + + #include "iLBC_define.h" + #include "constants.h" + #include <string.h> + + /*----------------------------------------------------------------* + * Construct codebook vector for given index. + *---------------------------------------------------------------*/ + + void getCBvec( + + + + + + float *cbvec, /* (o) Constructed codebook vector */ + float *mem, /* (i) Codebook buffer */ + int index, /* (i) Codebook index */ + int lMem, /* (i) Length of codebook buffer */ + int cbveclen/* (i) Codebook vector length */ + ){ + int j, k, n, memInd, sFilt; + float tmpbuf[CB_MEML]; + int base_size; + int ilow, ihigh; + float alfa, alfa1; + + /* Determine size of codebook sections */ + + base_size=lMem-cbveclen+1; + + if (cbveclen==SUBL) { + base_size+=cbveclen/2; + } + + /* No filter -> First codebook section */ + + if (index<lMem-cbveclen+1) { + + /* first non-interpolated vectors */ + + k=index+cbveclen; + /* get vector */ + memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float)); + + } else if (index < base_size) { + + k=2*(index-(lMem-cbveclen+1))+cbveclen; + + ihigh=k/2; + ilow=ihigh-5; + + /* Copy first noninterpolated part */ + + memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float)); + + /* interpolation */ + + alfa1=(float)0.2; + alfa=0.0; + for (j=ilow; j<ihigh; j++) { + cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+ + alfa*mem[lMem-k+j]; + + + + + + alfa+=alfa1; + } + + /* Copy second noninterpolated part */ + + memcpy(cbvec+ihigh, mem+lMem-k+ihigh, + (cbveclen-ihigh)*sizeof(float)); + + } + + /* Higher codebook section based on filtering */ + + else { + + /* first non-interpolated vectors */ + + if (index-base_size<lMem-cbveclen+1) { + float tempbuff2[CB_MEML+CB_FILTERLEN+1]; + float *pos; + float *pp, *pp1; + + memset(tempbuff2, 0, + CB_HALFFILTERLEN*sizeof(float)); + memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, + lMem*sizeof(float)); + memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0, + (CB_HALFFILTERLEN+1)*sizeof(float)); + + k=index-base_size+cbveclen; + sFilt=lMem-k; + memInd=sFilt+1-CB_HALFFILTERLEN; + + /* do filtering */ + pos=cbvec; + memset(pos, 0, cbveclen*sizeof(float)); + for (n=0; n<cbveclen; n++) { + pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN]; + pp1=&cbfiltersTbl[CB_FILTERLEN-1]; + for (j=0; j<CB_FILTERLEN; j++) { + (*pos)+=(*pp++)*(*pp1--); + } + pos++; + } + } + + /* interpolated vectors */ + + else { + + + + + + float tempbuff2[CB_MEML+CB_FILTERLEN+1]; + + float *pos; + float *pp, *pp1; + int i; + + memset(tempbuff2, 0, + CB_HALFFILTERLEN*sizeof(float)); + memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, + lMem*sizeof(float)); + memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0, + (CB_HALFFILTERLEN+1)*sizeof(float)); + + k=2*(index-base_size- + (lMem-cbveclen+1))+cbveclen; + sFilt=lMem-k; + memInd=sFilt+1-CB_HALFFILTERLEN; + + /* do filtering */ + pos=&tmpbuf[sFilt]; + memset(pos, 0, k*sizeof(float)); + for (i=0; i<k; i++) { + pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN]; + pp1=&cbfiltersTbl[CB_FILTERLEN-1]; + for (j=0; j<CB_FILTERLEN; j++) { + (*pos)+=(*pp++)*(*pp1--); + } + pos++; + } + + ihigh=k/2; + ilow=ihigh-5; + + /* Copy first noninterpolated part */ + + memcpy(cbvec, tmpbuf+lMem-k/2, + ilow*sizeof(float)); + + /* interpolation */ + + alfa1=(float)0.2; + alfa=0.0; + for (j=ilow; j<ihigh; j++) { + cbvec[j]=((float)1.0-alfa)* + tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j]; + alfa+=alfa1; + } + + + + + + + /* Copy second noninterpolated part */ + + memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh, + (cbveclen-ihigh)*sizeof(float)); + } + } + } + |