提交 fb853397 authored 作者: Michael Jerris's avatar Michael Jerris

update ilbc and lpc10 codecs from openh323 sources.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@211 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 27dd35f0
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
FrameClassify.c FrameClassify.c
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#include "iLBC_define.h" #include "iLBC_define.h"
#include "FrameClassify.h"
/*---------------------------------------------------------------*
/*---------------------------------------------------------------* * Classification of subframes to localize start state
* Classification of subframes to localize start state *--------------------------------------------------------------*/
*--------------------------------------------------------------*/
int FrameClassify( /* index to the max-energy sub-frame */
int FrameClassify( /* index to the max-energy sub-frame */ iLBC_Enc_Inst_t *iLBCenc_inst,
iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) the encoder state structure */
/* (i/o) the encoder state structure */ float *residual /* (i) lpc residual signal */
float *residual /* (i) lpc residual signal */ ) {
) { float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;
float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp; int n, l, max_ssqEn_n;
int n, l, max_ssqEn_n; const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,
const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9, (float)1.0,(float)0.9,(float)0.8};
(float)1.0,(float)0.9,(float)0.8}; const float sampEn_win[5]={(float)1.0/(float)6.0,
const float sampEn_win[5]={(float)1.0/(float)6.0, (float)2.0/(float)6.0, (float)3.0/(float)6.0,
(float)2.0/(float)6.0, (float)3.0/(float)6.0, (float)4.0/(float)6.0, (float)5.0/(float)6.0};
(float)4.0/(float)6.0, (float)5.0/(float)6.0};
/* init the front and back energies to zero */
/* init the front and back energies to zero */
memset(fssqEn, 0, NSUB_MAX*sizeof(float));
memset(fssqEn, 0, NSUB_MAX*sizeof(float)); memset(bssqEn, 0, NSUB_MAX*sizeof(float));
memset(bssqEn, 0, NSUB_MAX*sizeof(float));
/* Calculate front of first seqence */
/* Calculate front of first seqence */
n=0;
n=0; pp=residual;
pp=residual;
for (l=0; l<5; l++) {
for (l=0; l<5; l++) { fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); pp++;
pp++; }
} for (l=5; l<SUBL; l++) {
for (l=5; l<SUBL; l++) { fssqEn[n] += (*pp) * (*pp);
fssqEn[n] += (*pp) * (*pp); pp++;
pp++; }
}
/* Calculate front and back of all middle sequences */
/* Calculate front and back of all middle sequences */
for (n=1; n<iLBCenc_inst->nsub-1; n++) {
for (n=1; n<iLBCenc_inst->nsub-1; n++) { pp=residual+n*SUBL;
pp=residual+n*SUBL; for (l=0; l<5; l++) {
for (l=0; l<5; l++) { fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); bssqEn[n] += (*pp) * (*pp);
bssqEn[n] += (*pp) * (*pp); pp++;
pp++; }
} for (l=5; l<SUBL-5; l++) {
for (l=5; l<SUBL-5; l++) { fssqEn[n] += (*pp) * (*pp);
fssqEn[n] += (*pp) * (*pp); bssqEn[n] += (*pp) * (*pp);
bssqEn[n] += (*pp) * (*pp); pp++;
pp++; }
} for (l=SUBL-5; l<SUBL; l++) {
for (l=SUBL-5; l<SUBL; l++) { fssqEn[n] += (*pp) * (*pp);
fssqEn[n] += (*pp) * (*pp); bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp); pp++;
pp++; }
} }
}
/* Calculate back of last seqence */
/* Calculate back of last seqence */
n=iLBCenc_inst->nsub-1;
n=iLBCenc_inst->nsub-1; pp=residual+n*SUBL;
pp=residual+n*SUBL; for (l=0; l<SUBL-5; l++) {
for (l=0; l<SUBL-5; l++) { bssqEn[n] += (*pp) * (*pp);
bssqEn[n] += (*pp) * (*pp); pp++;
pp++; }
} for (l=SUBL-5; l<SUBL; l++) {
for (l=SUBL-5; l<SUBL; l++) { bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp); pp++;
pp++; }
}
/* find the index to the weighted 80 sample with
/* find the index to the weighted 80 sample with most energy */
most energy */
if (iLBCenc_inst->mode==20) l=1;
if (iLBCenc_inst->mode==20) l=1; else l=0;
else l=0;
max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];
max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l]; max_ssqEn_n=1;
max_ssqEn_n=1; for (n=2; n<iLBCenc_inst->nsub; n++) {
for (n=2; n<iLBCenc_inst->nsub; n++) {
l++;
l++;
if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {
if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) { max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *
max_ssqEn=(fssqEn[n-1]+bssqEn[n]) * ssqEn_win[l];
ssqEn_win[l]; max_ssqEn_n=n;
max_ssqEn_n=n; }
} }
}
return max_ssqEn_n;
return max_ssqEn_n; }
}
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
FrameClassify.h FrameClassify.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_FRAMECLASSIFY_H #ifndef __iLBC_FRAMECLASSIFY_H
#define __iLBC_FRAMECLASSIFY_H #define __iLBC_FRAMECLASSIFY_H
int FrameClassify( /* index to the max-energy sub-frame */ int FrameClassify( /* index to the max-energy sub-frame */
iLBC_Enc_Inst_t *iLBCenc_inst, iLBC_Enc_Inst_t *iLBCenc_inst,
/* (i/o) the encoder state structure */ /* (i/o) the encoder state structure */
float *residual /* (i) lpc residual signal */ float *residual /* (i) lpc residual signal */
); );
#endif #endif
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
LPC_decode.c LPC_decode.c
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include "helpfun.h" #include "helpfun.h"
#include "lsf.h" #include "lsf.h"
#include "iLBC_define.h" #include "iLBC_define.h"
#include "LPCdecode.h" #include "constants.h"
#include "constants.h"
/*---------------------------------------------------------------*
/*---------------------------------------------------------------* * interpolation of lsf coefficients for the decoder
* interpolation of lsf coefficients for the decoder *--------------------------------------------------------------*/
*--------------------------------------------------------------*/
void LSFinterpolate2a_dec(
void LSFinterpolate2a_dec( float *a, /* (o) lpc coefficients for a sub-frame */
float *a, /* (o) lpc coefficients for a sub-frame */ float *lsf1, /* (i) first lsf coefficient vector */
float *lsf1, /* (i) first lsf coefficient vector */
float *lsf2, /* (i) second lsf coefficient vector */
float *lsf2, /* (i) second lsf coefficient vector */ float coef, /* (i) interpolation weight */
float coef, /* (i) interpolation weight */ int length /* (i) length of lsf vectors */
int length /* (i) length of lsf vectors */ ){
){ float lsftmp[LPC_FILTERORDER];
float lsftmp[LPC_FILTERORDER];
interpolate(lsftmp, lsf1, lsf2, coef, length);
interpolate(lsftmp, lsf1, lsf2, coef, length); lsf2a(a, lsftmp);
lsf2a(a, lsftmp); }
}
/*---------------------------------------------------------------*
/*---------------------------------------------------------------* * obtain dequantized lsf coefficients from quantization index
* obtain dequantized lsf coefficients from quantization index *--------------------------------------------------------------*/
*--------------------------------------------------------------*/
void SimplelsfDEQ(
void SimplelsfDEQ( float *lsfdeq, /* (o) dequantized lsf coefficients */
float *lsfdeq, /* (o) dequantized lsf coefficients */ int *index, /* (i) quantization index */
int *index, /* (i) quantization index */ int lpc_n /* (i) number of LPCs */
int lpc_n /* (i) number of LPCs */ ){
){ int i, j, pos, cb_pos;
int i, j, pos, cb_pos;
/* decode first LSF */
/* decode first LSF */
pos = 0;
pos = 0; cb_pos = 0;
cb_pos = 0; for (i = 0; i < LSF_NSPLIT; i++) {
for (i = 0; i < LSF_NSPLIT; i++) { for (j = 0; j < dim_lsfCbTbl[i]; j++) {
for (j = 0; j < dim_lsfCbTbl[i]; j++) { lsfdeq[pos + j] = lsfCbTbl[cb_pos +
lsfdeq[pos + j] = lsfCbTbl[cb_pos + (long)(index[i])*dim_lsfCbTbl[i] + j];
(long)(index[i])*dim_lsfCbTbl[i] + j]; }
} pos += dim_lsfCbTbl[i];
pos += dim_lsfCbTbl[i]; cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; }
}
if (lpc_n>1) {
if (lpc_n>1) {
/* decode last LSF */
/* decode last LSF */
pos = 0;
pos = 0; cb_pos = 0;
cb_pos = 0; for (i = 0; i < LSF_NSPLIT; i++) {
for (i = 0; i < LSF_NSPLIT; i++) { for (j = 0; j < dim_lsfCbTbl[i]; j++) {
for (j = 0; j < dim_lsfCbTbl[i]; j++) { lsfdeq[LPC_FILTERORDER + pos + j] =
lsfdeq[LPC_FILTERORDER + pos + j] = lsfCbTbl[cb_pos +
lsfCbTbl[cb_pos + (long)(index[LSF_NSPLIT + i])*
(long)(index[LSF_NSPLIT + i])* dim_lsfCbTbl[i] + j];
dim_lsfCbTbl[i] + j]; }
} pos += dim_lsfCbTbl[i];
pos += dim_lsfCbTbl[i]; cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; }
} }
} }
}
/*----------------------------------------------------------------*
/*----------------------------------------------------------------*
* obtain synthesis and weighting filters form lsf coefficients
* obtain synthesis and weighting filters form lsf coefficients *---------------------------------------------------------------*/
*---------------------------------------------------------------*/
void DecoderInterpolateLSF(
void DecoderInterpolateLSF( float *syntdenum, /* (o) synthesis filter coefficients */
float *syntdenum, /* (o) synthesis filter coefficients */ float *weightdenum, /* (o) weighting denumerator
float *weightdenum, /* (o) weighting denumerator coefficients */
coefficients */ float *lsfdeq, /* (i) dequantized lsf coefficients */
float *lsfdeq, /* (i) dequantized lsf coefficients */ int length, /* (i) length of lsf coefficient vector */
int length, /* (i) length of lsf coefficient vector */ iLBC_Dec_Inst_t *iLBCdec_inst
iLBC_Dec_Inst_t *iLBCdec_inst /* (i) the decoder state structure */
/* (i) the decoder state structure */ ){
){ int i, pos, lp_length;
int i, pos, lp_length; float lp[LPC_FILTERORDER + 1], *lsfdeq2;
float lp[LPC_FILTERORDER + 1], *lsfdeq2;
lsfdeq2 = lsfdeq + length;
lsfdeq2 = lsfdeq + length; lp_length = length + 1;
lp_length = length + 1;
if (iLBCdec_inst->mode==30) {
if (iLBCdec_inst->mode==30) { /* sub-frame 1: Interpolation between old and first */
/* sub-frame 1: Interpolation between old and first */
LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, lsf_weightTbl_30ms[0], length);
lsf_weightTbl_30ms[0], length); memcpy(syntdenum,lp,lp_length*sizeof(float));
memcpy(syntdenum,lp,lp_length*sizeof(float)); bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM,
bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
lp_length);
/* sub-frames 2 to 6: interpolation between first
/* sub-frames 2 to 6: interpolation between first and last LSF */
and last LSF */
pos = lp_length;
pos = lp_length; for (i = 1; i < 6; i++) {
for (i = 1; i < 6; i++) { LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, lsf_weightTbl_30ms[i], length);
lsf_weightTbl_30ms[i], length); memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); bwexpand(weightdenum + pos, lp,
bwexpand(weightdenum + pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
LPC_CHIRP_WEIGHTDENUM, lp_length); pos += lp_length;
pos += lp_length; }
} }
} else {
else { pos = 0;
pos = 0; for (i = 0; i < iLBCdec_inst->nsub; i++) {
for (i = 0; i < iLBCdec_inst->nsub; i++) { LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, lsf_weightTbl_20ms[i], length);
lsfdeq, lsf_weightTbl_20ms[i], length); memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM,
bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
lp_length); pos += lp_length;
pos += lp_length; }
} }
}
/* update memory */
/* update memory */
if (iLBCdec_inst->mode==30)
if (iLBCdec_inst->mode==30) memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2,
memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, length*sizeof(float));
length*sizeof(float)); else
else memcpy(iLBCdec_inst->lsfdeqold, lsfdeq,
memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, length*sizeof(float));
length*sizeof(float));
}
}
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
LPC_decode.h LPC_decode.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_LPC_DECODE_H #ifndef __iLBC_LPC_DECODE_H
#define __iLBC_LPC_DECODE_H #define __iLBC_LPC_DECODE_H
void LSFinterpolate2a_dec( void LSFinterpolate2a_dec(
float *a, /* (o) lpc coefficients for a sub-frame */ float *a, /* (o) lpc coefficients for a sub-frame */
float *lsf1, /* (i) first lsf coefficient vector */ float *lsf1, /* (i) first lsf coefficient vector */
float *lsf2, /* (i) second lsf coefficient vector */ float *lsf2, /* (i) second lsf coefficient vector */
float coef, /* (i) interpolation weight */ float coef, /* (i) interpolation weight */
int length /* (i) length of lsf vectors */ int length /* (i) length of lsf vectors */
); );
void SimplelsfDEQ( void SimplelsfDEQ(
float *lsfdeq, /* (o) dequantized lsf coefficients */ float *lsfdeq, /* (o) dequantized lsf coefficients */
int *index, /* (i) quantization index */ int *index, /* (i) quantization index */
int lpc_n /* (i) number of LPCs */ int lpc_n /* (i) number of LPCs */
); );
void DecoderInterpolateLSF( void DecoderInterpolateLSF(
float *syntdenum, /* (o) synthesis filter coefficients */ float *syntdenum, /* (o) synthesis filter coefficients */
float *weightdenum, /* (o) weighting denumerator float *weightdenum, /* (o) weighting denumerator
coefficients */ coefficients */
float *lsfdeq, /* (i) dequantized lsf coefficients */ float *lsfdeq, /* (i) dequantized lsf coefficients */
int length, /* (i) length of lsf coefficient vector */ int length, /* (i) length of lsf coefficient vector */
iLBC_Dec_Inst_t *iLBCdec_inst iLBC_Dec_Inst_t *iLBCdec_inst
/* (i) the decoder state structure */ /* (i) the decoder state structure */
); );
#endif #endif
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
LPCencode.h LPCencode.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_LPCENCOD_H #ifndef __iLBC_LPCENCOD_H
#define __iLBC_LPCENCOD_H #define __iLBC_LPCENCOD_H
void LPCencode( void LPCencode(
float *syntdenum, /* (i/o) synthesis filter coefficients float *syntdenum, /* (i/o) synthesis filter coefficients
before/after encoding */ before/after encoding */
float *weightdenum, /* (i/o) weighting denumerator coefficients float *weightdenum, /* (i/o) weighting denumerator coefficients
before/after encoding */ before/after encoding */
int *lsf_index, /* (o) lsf quantization index */ int *lsf_index, /* (o) lsf quantization index */
float *data, /* (i) lsf coefficients to quantize */ float *data, /* (i) lsf coefficients to quantize */
iLBC_Enc_Inst_t *iLBCenc_inst iLBC_Enc_Inst_t *iLBCenc_inst
/* (i/o) the encoder state structure */ /* (i/o) the encoder state structure */
); );
#endif #endif
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
StateConstructW.c StateConstructW.c
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include "iLBC_define.h" #include "iLBC_define.h"
#include "StateConstructW.h" #include "constants.h"
#include "constants.h" #include "filter.h"
#include "filter.h"
/*----------------------------------------------------------------*
/*----------------------------------------------------------------* * decoding of the start state
* decoding of the start state *---------------------------------------------------------------*/
*---------------------------------------------------------------*/
void StateConstructW(
void StateConstructW( int idxForMax, /* (i) 6-bit index for the quantization of
int idxForMax, /* (i) 6-bit index for the quantization of max amplitude */
max amplitude */ int *idxVec, /* (i) vector of quantization indexes */
int *idxVec, /* (i) vector of quantization indexes */ float *syntDenum, /* (i) synthesis filter denumerator */
float *syntDenum, /* (i) synthesis filter denumerator */ float *out, /* (o) the decoded state vector */
float *out, /* (o) the decoded state vector */ int len /* (i) length of a state vector */
int len /* (i) length of a state vector */ ){
){ float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp,
float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, numerator[LPC_FILTERORDER+1];
numerator[LPC_FILTERORDER+1]; float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;
float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout; int k,tmpi;
int k,tmpi;
/* decoding of the maximum value */
/* decoding of the maximum value */
maxVal = state_frgqTbl[idxForMax];
maxVal = state_frgqTbl[idxForMax]; maxVal = (float)pow(10,maxVal)/(float)4.5;
maxVal = (float)pow(10,maxVal)/(float)4.5;
/* initialization of buffers and coefficients */
/* initialization of buffers and coefficients */
memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); for (k=0; k<LPC_FILTERORDER; k++) {
for (k=0; k<LPC_FILTERORDER; k++) { numerator[k]=syntDenum[LPC_FILTERORDER-k];
numerator[k]=syntDenum[LPC_FILTERORDER-k]; }
} numerator[LPC_FILTERORDER]=syntDenum[0];
numerator[LPC_FILTERORDER]=syntDenum[0]; tmp = &tmpbuf[LPC_FILTERORDER];
tmp = &tmpbuf[LPC_FILTERORDER]; fout = &foutbuf[LPC_FILTERORDER];
fout = &foutbuf[LPC_FILTERORDER];
/* decoding of the sample values */
/* decoding of the sample values */
for (k=0; k<len; k++) {
for (k=0; k<len; k++) { tmpi = len-1-k;
tmpi = len-1-k; /* maxVal = 1/scal */
/* maxVal = 1/scal */
tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];
tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]]; }
}
/* circular convolution with all-pass filter */
/* circular convolution with all-pass filter */
memset(tmp+len, 0, len*sizeof(float));
memset(tmp+len, 0, len*sizeof(float)); ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, LPC_FILTERORDER, fout);
LPC_FILTERORDER, fout); for (k=0;k<len;k++) {
for (k=0;k<len;k++) { out[k] = fout[len-1-k]+fout[2*len-1-k];
out[k] = fout[len-1-k]+fout[2*len-1-k]; }
} }
}
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
StateConstructW.h StateConstructW.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_STATECONSTRUCTW_H #ifndef __iLBC_STATECONSTRUCTW_H
#define __iLBC_STATECONSTRUCTW_H #define __iLBC_STATECONSTRUCTW_H
void StateConstructW( void StateConstructW(
int idxForMax, /* (i) 6-bit index for the quantization of int idxForMax, /* (i) 6-bit index for the quantization of
max amplitude */ max amplitude */
int *idxVec, /* (i) vector of quantization indexes */ int *idxVec, /* (i) vector of quantization indexes */
float *syntDenum, /* (i) synthesis filter denumerator */ float *syntDenum, /* (i) synthesis filter denumerator */
float *out, /* (o) the decoded state vector */ float *out, /* (o) the decoded state vector */
int len /* (i) length of a state vector */ int len /* (i) length of a state vector */
); );
#endif #endif
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
StateSearchW.h StateSearchW.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_STATESEARCHW_H #ifndef __iLBC_STATESEARCHW_H
#define __iLBC_STATESEARCHW_H #define __iLBC_STATESEARCHW_H
void AbsQuantW( void AbsQuantW(
iLBC_Enc_Inst_t *iLBCenc_inst, iLBC_Enc_Inst_t *iLBCenc_inst,
/* (i) Encoder instance */ /* (i) Encoder instance */
float *in, /* (i) vector to encode */ float *in, /* (i) vector to encode */
float *syntDenum, /* (i) denominator of synthesis filter */ float *syntDenum, /* (i) denominator of synthesis filter */
float *weightDenum, /* (i) denominator of weighting filter */ float *weightDenum, /* (i) denominator of weighting filter */
int *out, /* (o) vector of quantizer indexes */ int *out, /* (o) vector of quantizer indexes */
int len, /* (i) length of vector to encode and int len, /* (i) length of vector to encode and
vector of quantizer indexes */ vector of quantizer indexes */
int state_first /* (i) position of start state in the int state_first /* (i) position of start state in the
80 vec */ 80 vec */
); );
void StateSearchW( void StateSearchW(
iLBC_Enc_Inst_t *iLBCenc_inst, iLBC_Enc_Inst_t *iLBCenc_inst,
/* (i) Encoder instance */ /* (i) Encoder instance */
float *residual,/* (i) target residual vector */ float *residual,/* (i) target residual vector */
float *syntDenum, /* (i) lpc synthesis filter */ float *syntDenum, /* (i) lpc synthesis filter */
float *weightDenum, /* (i) weighting filter denuminator */ float *weightDenum, /* (i) weighting filter denuminator */
int *idxForMax, /* (o) quantizer index for maximum int *idxForMax, /* (o) quantizer index for maximum
amplitude */ amplitude */
int *idxVec, /* (o) vector of quantization indexes */ int *idxVec, /* (o) vector of quantization indexes */
int len, /* (i) length of all vectors */ int len, /* (i) length of all vectors */
int state_first /* (i) position of start state in the int state_first /* (i) position of start state in the
80 vec */ 80 vec */
); );
#endif #endif
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
anaFilter.c anaFilter.c
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#include <string.h> #include <string.h>
#include "anaFilter.h" #include "iLBC_define.h"
#include "iLBC_define.h"
/*----------------------------------------------------------------*
/*----------------------------------------------------------------* * LP analysis filter.
* LP analysis filter.
*---------------------------------------------------------------*/
*---------------------------------------------------------------*/
void anaFilter(
void anaFilter( float *In, /* (i) Signal to be filtered */
float *In, /* (i) Signal to be filtered */ float *a, /* (i) LP parameters */
float *a, /* (i) LP parameters */ int len,/* (i) Length of signal */
int len,/* (i) Length of signal */ float *Out, /* (o) Filtered signal */
float *Out, /* (o) Filtered signal */ float *mem /* (i/o) Filter state */
float *mem /* (i/o) Filter state */ ){
){ int i, j;
int i, j; float *po, *pi, *pm, *pa;
float *po, *pi, *pm, *pa;
po = Out;
po = Out;
/* Filter first part using memory from past */
/* Filter first part using memory from past */
for (i=0; i<LPC_FILTERORDER; i++) {
for (i=0; i<LPC_FILTERORDER; i++) { pi = &In[i];
pi = &In[i]; pm = &mem[LPC_FILTERORDER-1];
pm = &mem[LPC_FILTERORDER-1]; pa = a;
pa = a; *po=0.0;
*po=0.0; for (j=0; j<=i; j++) {
for (j=0; j<=i; j++) { *po+=(*pa++)*(*pi--);
*po+=(*pa++)*(*pi--); }
} for (j=i+1; j<LPC_FILTERORDER+1; j++) {
for (j=i+1; j<LPC_FILTERORDER+1; j++) {
*po+=(*pa++)*(*pm--);
*po+=(*pa++)*(*pm--); }
} po++;
po++; }
}
/* Filter last part where the state is entierly
/* Filter last part where the state is entierly in the input vector */
in the input vector */
for (i=LPC_FILTERORDER; i<len; i++) {
for (i=LPC_FILTERORDER; i<len; i++) { pi = &In[i];
pi = &In[i]; pa = a;
pa = a; *po=0.0;
*po=0.0; for (j=0; j<LPC_FILTERORDER+1; j++) {
for (j=0; j<LPC_FILTERORDER+1; j++) { *po+=(*pa++)*(*pi--);
*po+=(*pa++)*(*pi--); }
} po++;
po++; }
}
/* Update state vector */
/* Update state vector */
memcpy(mem, &In[len-LPC_FILTERORDER],
memcpy(mem, &In[len-LPC_FILTERORDER], LPC_FILTERORDER*sizeof(float));
LPC_FILTERORDER*sizeof(float)); }
}
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
anaFilter.h anaFilter.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_ANAFILTER_H #ifndef __iLBC_ANAFILTER_H
#define __iLBC_ANAFILTER_H #define __iLBC_ANAFILTER_H
void anaFilter( void anaFilter(
float *In, /* (i) Signal to be filtered */ float *In, /* (i) Signal to be filtered */
float *a, /* (i) LP parameters */ float *a, /* (i) LP parameters */
int len,/* (i) Length of signal */ int len,/* (i) Length of signal */
float *Out, /* (o) Filtered signal */ float *Out, /* (o) Filtered signal */
float *mem /* (i/o) Filter state */ float *mem /* (i/o) Filter state */
); );
#endif #endif
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
constants.h constants.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_CONSTANTS_H #ifndef __iLBC_CONSTANTS_H
#define __iLBC_CONSTANTS_H #define __iLBC_CONSTANTS_H
#include "iLBC_define.h" #include "iLBC_define.h"
/* ULP bit allocation */ /* ULP bit allocation */
extern const iLBC_ULP_Inst_t ULP_20msTbl; extern const iLBC_ULP_Inst_t ULP_20msTbl;
extern const iLBC_ULP_Inst_t ULP_30msTbl; extern const iLBC_ULP_Inst_t ULP_30msTbl;
/* high pass filters */ /* high pass filters */
extern float hpi_zero_coefsTbl[]; extern float hpi_zero_coefsTbl[];
extern float hpi_pole_coefsTbl[]; extern float hpi_pole_coefsTbl[];
extern float hpo_zero_coefsTbl[]; extern float hpo_zero_coefsTbl[];
extern float hpo_pole_coefsTbl[]; extern float hpo_pole_coefsTbl[];
/* low pass filters */ /* low pass filters */
extern float lpFilt_coefsTbl[]; extern float lpFilt_coefsTbl[];
/* LPC analysis and quantization */ /* LPC analysis and quantization */
extern float lpc_winTbl[]; extern float lpc_winTbl[];
extern float lpc_asymwinTbl[]; extern float lpc_asymwinTbl[];
extern float lpc_lagwinTbl[]; extern float lpc_lagwinTbl[];
extern float lsfCbTbl[]; extern float lsfCbTbl[];
extern float lsfmeanTbl[]; extern float lsfmeanTbl[];
extern int dim_lsfCbTbl[]; extern int dim_lsfCbTbl[];
extern int size_lsfCbTbl[]; extern int size_lsfCbTbl[];
extern float lsf_weightTbl_30ms[]; extern float lsf_weightTbl_30ms[];
extern float lsf_weightTbl_20ms[]; extern float lsf_weightTbl_20ms[];
/* state quantization tables */ /* state quantization tables */
extern float state_sq3Tbl[]; extern float state_sq3Tbl[];
extern float state_frgqTbl[]; extern float state_frgqTbl[];
/* gain quantization tables */ /* gain quantization tables */
extern float gain_sq3Tbl[]; extern float gain_sq3Tbl[];
extern float gain_sq4Tbl[]; extern float gain_sq4Tbl[];
extern float gain_sq5Tbl[]; extern float gain_sq5Tbl[];
/* adaptive codebook definitions */ /* adaptive codebook definitions */
extern int search_rangeTbl[5][CB_NSTAGES]; extern int search_rangeTbl[5][CB_NSTAGES];
extern int memLfTbl[]; extern int memLfTbl[];
extern int stMemLTbl; extern int stMemLTbl;
extern float cbfiltersTbl[CB_FILTERLEN]; extern float cbfiltersTbl[CB_FILTERLEN];
/* enhancer definitions */ /* enhancer definitions */
extern float polyphaserTbl[]; extern float polyphaserTbl[];
extern float enh_plocsTbl[]; extern float enh_plocsTbl[];
#endif #endif
差异被折叠。
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
createCB.h createCB.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_CREATECB_H #ifndef __iLBC_CREATECB_H
#define __iLBC_CREATECB_H #define __iLBC_CREATECB_H
void filteredCBvecs( void filteredCBvecs(
float *cbvectors, /* (o) Codebook vector for the float *cbvectors, /* (o) Codebook vector for the
higher section */ higher section */
float *mem, /* (i) Buffer to create codebook float *mem, /* (i) Buffer to create codebook
vectors from */ vectors from */
int lMem /* (i) Length of buffer */ int lMem /* (i) Length of buffer */
); );
void searchAugmentedCB( void searchAugmentedCB(
int low, /* (i) Start index for the search */ int low, /* (i) Start index for the search */
int high, /* (i) End index for the search */ int high, /* (i) End index for the search */
int stage, /* (i) Current stage */ int stage, /* (i) Current stage */
int startIndex, /* (i) CB index for the first int startIndex, /* (i) CB index for the first
augmented vector */ augmented vector */
float *target, /* (i) Target vector for encoding */ float *target, /* (i) Target vector for encoding */
float *buffer, /* (i) Pointer to the end of the float *buffer, /* (i) Pointer to the end of the
buffer for augmented codebook buffer for augmented codebook
construction */ construction */
float *max_measure, /* (i/o) Currently maximum measure */ float *max_measure, /* (i/o) Currently maximum measure */
int *best_index,/* (o) Currently the best index */ int *best_index,/* (o) Currently the best index */
float *gain, /* (o) Currently the best gain */ float *gain, /* (o) Currently the best gain */
float *energy, /* (o) Energy of augmented float *energy, /* (o) Energy of augmented
codebook vectors */ codebook vectors */
float *invenergy/* (o) Inv energy of aug codebook float *invenergy/* (o) Inv energy of aug codebook
vectors */ vectors */
); );
void createAugmentedVec( void createAugmentedVec(
int index, /* (i) Index for the aug vector int index, /* (i) Index for the aug vector
to be created */ to be created */
float *buffer, /* (i) Pointer to the end of the float *buffer, /* (i) Pointer to the end of the
buffer for augmented codebook buffer for augmented codebook
construction */ construction */
float *cbVec /* (o) The construced codebook vector */ float *cbVec /* (o) The construced codebook vector */
); );
#endif #endif
差异被折叠。
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
doCPLC.h doCPLC.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_DOLPC_H #ifndef __iLBC_DOLPC_H
#define __iLBC_DOLPC_H #define __iLBC_DOLPC_H
void doThePLC( void doThePLC(
float *PLCresidual, /* (o) concealed residual */ float *PLCresidual, /* (o) concealed residual */
float *PLClpc, /* (o) concealed LP parameters */ float *PLClpc, /* (o) concealed LP parameters */
int PLI, /* (i) packet loss indicator int PLI, /* (i) packet loss indicator
0 - no PL, 1 = PL */ 0 - no PL, 1 = PL */
float *decresidual, /* (i) decoded residual */ float *decresidual, /* (i) decoded residual */
float *lpc, /* (i) decoded LPC (only used for no PL) */ float *lpc, /* (i) decoded LPC (only used for no PL) */
int inlag, /* (i) pitch lag */ int inlag, /* (i) pitch lag */
iLBC_Dec_Inst_t *iLBCdec_inst iLBC_Dec_Inst_t *iLBCdec_inst
/* (i/o) decoder instance */ /* (i/o) decoder instance */
); );
#endif #endif
差异被折叠。
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
enhancer.h enhancer.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __ENHANCER_H #ifndef __ENHANCER_H
#define __ENHANCER_H #define __ENHANCER_H
#include "iLBC_define.h" #include "iLBC_define.h"
float xCorrCoef( float xCorrCoef(
float *target, /* (i) first array */ float *target, /* (i) first array */
float *regressor, /* (i) second array */ float *regressor, /* (i) second array */
int subl /* (i) dimension arrays */ int subl /* (i) dimension arrays */
); );
int enhancerInterface( int enhancerInterface(
float *out, /* (o) the enhanced recidual signal */ float *out, /* (o) the enhanced recidual signal */
float *in, /* (i) the recidual signal to enhance */ float *in, /* (i) the recidual signal to enhance */
iLBC_Dec_Inst_t *iLBCdec_inst iLBC_Dec_Inst_t *iLBCdec_inst
/* (i/o) the decoder state structure */ /* (i/o) the decoder state structure */
); );
#endif #endif
BEGIN { srcname = "nothing"; }
{ if (/^A\.[0-9][0-9]* [a-zA-Z][a-zA-Z_0-9]*\.[ch]/) {
if (srcname != "nothing")
close(srcname);
srcname = $2;
printf("creating source file %s\n", srcname);
}else if (srcname != "nothing") {
if (/Andersen et\. al\./ || /Internet Low Bit Rate Codec *May 04/)
printf("skipping %s\n", $0);
else
print $0 >> srcname;
}
}
END {
printf("ending file %s\n", srcname);
close(srcname);
}
差异被折叠。
差异被折叠。
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
gainquant.h gainquant.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_GAINQUANT_H #ifndef __iLBC_GAINQUANT_H
#define __iLBC_GAINQUANT_H #define __iLBC_GAINQUANT_H
float gainquant(/* (o) quantized gain value */ float gainquant(/* (o) quantized gain value */
float in, /* (i) gain value */ float in, /* (i) gain value */
float maxIn,/* (i) maximum of gain value */ float maxIn,/* (i) maximum of gain value */
int cblen, /* (i) number of quantization indices */ int cblen, /* (i) number of quantization indices */
int *index /* (o) quantization index */ int *index /* (o) quantization index */
); );
float gaindequant( /* (o) quantized gain value */ float gaindequant( /* (o) quantized gain value */
int index, /* (i) quantization index */ int index, /* (i) quantization index */
float maxIn,/* (i) maximum of unquantized gain */ float maxIn,/* (i) maximum of unquantized gain */
int cblen /* (i) number of quantization indices */ int cblen /* (i) number of quantization indices */
); );
#endif #endif
差异被折叠。
/****************************************************************** /******************************************************************
iLBC Speech Coder ANSI-C Source Code iLBC Speech Coder ANSI-C Source Code
getCBvec.h getCBvec.h
Copyright (C) The Internet Society (2004). Copyright (C) The Internet Society (2004).
All Rights Reserved. All Rights Reserved.
******************************************************************/ ******************************************************************/
#ifndef __iLBC_GETCBVEC_H #ifndef __iLBC_GETCBVEC_H
#define __iLBC_GETCBVEC_H #define __iLBC_GETCBVEC_H
void getCBvec( void getCBvec(
float *cbvec, /* (o) Constructed codebook vector */ float *cbvec, /* (o) Constructed codebook vector */
float *mem, /* (i) Codebook buffer */ float *mem, /* (i) Codebook buffer */
int index, /* (i) Codebook index */ int index, /* (i) Codebook index */
int lMem, /* (i) Length of codebook buffer */ int lMem, /* (i) Length of codebook buffer */
int cbveclen/* (i) Codebook vector length */ int cbveclen/* (i) Codebook vector length */
); );
#endif #endif
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论