📄 acb_parm.c
字号:
* Exc_len int i Lenght of excitation vector
* conv fxpt_16 o Truncated convolved impulse response
*
**************************************************************************
Calculate and save convolution of truncated (to len)
impulse response for first lag of t (=mmin) samples:
min(i, len)
y = SUM h * ex , where i = 1, ..., L points
i, t j=1 j i-j+1
h |1 2...len x x|
ex |L . . . 2 1| = y(1)
ex |L . . . 2 1| = y(2)
: :
ex |L . . . 2 1| = y(L)
**************************************************************************/
#if 0 /* now implemented in its own file */
void CalcAdaptConv(
fxpt_16 pc_imp[], /* 2.13 format */
int len_trunc,
fxpt_16 Exc[], /* 15.0 format */
int Exc_len,
fxpt_16 conv[]) /* 15.0 format */
{
int i, j;
FXPT_PUSHSTATE("CalcAdaptConv", -1.0, -1.0);
/* Calculate convolution */
for (i=0; i<Exc_len; i++) {
conv[i] = 0;
for(j=0; j<=min(i, len_trunc); j++) {
/*conv[i] += pc_imp[j] * Exc[i-j];*/
conv[i] = fxpt_add16(conv[i],
fxpt_mult16_round(pc_imp[j], Exc[i-j], 13));
}
}
FXPT_POPSTATE();
}
#endif
/**************************************************************************
*
* ROUTINE
* EndCorrectAdapt
*
* FUNCTION
* End correct the convulution sum
* SYNOPSIS
* EndCorrectAdapt(conv, Exc, Exc_len, pc_imp, len_trunc)
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* conv fxpt_16 i/o Truncated convolved impulse response
* Exc fxpt_16 i Excitation vector
* Exc_len int i Length of excitation vector
* pc_imp fxpt_16 i Impulse response of PCs
* len_trunc int i Length of truncated impulse response
*
**************************************************************************
* End correct the convolution sum on subsequent delays:
*
* y = 0
* 0, t
* y = y + ex * h where i = 1, ..., L points
* i, m i-1, m-1 -m i and m = t+1, ..., tmax lags
*
**************************************************************************/
#if 0 /* routine now has a dedicated file */
void EndCorrectAdapt(
fxpt_16 conv[], /* 15.0 format */
fxpt_16 Exc[], /* 15.0 format */
int Exc_len,
fxpt_16 pc_imp[], /* 2.13 format */
int len_trunc)
{
int i;
FXPT_PUSHSTATE("EndCorrectAdapt", -1.0, -1.0);
for (i=len_trunc-1; i>=1; i--) {
/*conv[i-1] += Exc[0] * pc_imp[i];*/
conv[i-1] = fxpt_add16(conv[i-1],
fxpt_mult16_round(Exc[0], pc_imp[i], 13));
}
for(i=Exc_len;i>=1;i--) {
conv[i] = conv[i-1];
}
/*conv[0] = Exc[0] * pc_imp[0];*/
conv[0] = fxpt_mult16_round(Exc[0], pc_imp[0], 13);
FXPT_POPSTATE();
}
#endif
/**************************************************************************
* *
* ROUTINE
* ReplicateShortToFull
* FUNCTION
* Replicate the short adaptive codeword to the full codeword
* length
* SYNOPSIS
* ReplicateShortToFull(Exc_len, delay, Conv, FullConv)
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* Exc_len int i Length of excitation vector
* delay int i Pitch lag
* Conv fxpt_16 i Truncated convolved impulse response
* FullConv fxpt_16 o Replicated convolved impulse response
*
**************************************************************************/
#if 0 /* Routine no longer called */
void ReplicateShortToFull(
int delay,
fxpt_16 Conv[], /* 15.0 format */
fxpt_16 FullConv[])
{
int i;
FXPT_PUSHSTATE("ReplicateShortToFull", -1.0, -1.0);
MoveArray16 (FullConv, Conv, SF_LEN);
// for (i=0; i<SF_LEN; i++) {
// FullConv[i] = Conv[i];
// }
if (delay < SF_LEN) {
/* Add in 2nd convolution */
for (i=delay; i<SF_LEN; i++) {
/*FullConv[i] += Conv[i-delay];*/
FullConv[i] = fxpt_add16(FullConv[i], Conv[i-delay]);
}
if (delay < (SF_LEN / 2)) {
/* Add in 3rd convolution */
for (i=2*delay; i< SF_LEN; i++) {
/*FullConv[i] += Conv[i-2*delay];*/
FullConv[i] = fxpt_add16(FullConv[i],
Conv[i-2*delay]);
}
}
}
FXPT_POPSTATE();
}
#endif
/**************************************************************************
* *
* ROUTINE
* CalcCorEngAdapt
* FUNCTION
* Calculate Correlation and Energy
* SYNOPSIS
* CalcCorEngAdapt(AnaSignal, MatchSignal, length,
* correlation, energy)
*
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* AnaSignal fxpt_16 i Signal to analyze
* MatchSignal fxpt_16 i Signal to match
* length int i Length of signals
* correlation fxpt_32 o Correlation between to signals
* energy fxpt_32 o Energy in signal to analyze
*
*
**************************************************************************/
#if 0
void CalcCorEngAdapt(
fxpt_16 AnaSignal[], /* 15.0 format */
fxpt_16 MatchSignal[], /* 15.0 format */
int length,
fxpt_32 *correlation, /* 30.1 format */
fxpt_32 *energy) /* 30.1 format */
{
int i;
FXPT_PUSHSTATE("CalcCorEngAdapt", -1.0, -1.0);
*correlation = 0; /* need 27 bits for this */
*energy = 0; /* need 27 bits for this */
for(i=0; i<length; i++) {
/* 32 bits may be inadequate to hold the non-normalized
* correlation and energy values. Since we are interested
* in the relative values anyway, we scale these values
* by shifting them to the right 4 times (* 1/16).
*/
/**correlation += AnaSignal[i] * MatchSignal[i];*/
*correlation = fxpt_add32(*correlation, fxpt_shr32_fast(
fxpt_mult32(AnaSignal[i], MatchSignal[i]), 4));
/**energy += AnaSignal[i] * AnaSignal[i];*/
*energy = fxpt_add32(*energy, fxpt_shr32_fast(
fxpt_mult32(AnaSignal[i], AnaSignal[i]), 4));
}
FXPT_POPSTATE();
}
#endif
/**************************************************************************
* *
* ROUTINE
* CompGainErrAdapt
* FUNCTION
* Compute gain and error
* SYNOPSIS
* CompGainErrAdapt(correlation, energy, gain, match)
*
*
*
* formal
*
* data I/O
* name type type function
* -------------------------------------------------------------------
* correlation fxpt_32 i Correlation
* energy fxpt_32 i Energy
* gain fxpt_32 o Adaptive Codebook gain
* match fxpt_32 o Negative partial squared error
*
*
**************************************************************************/
void CompGainErrAdapt(
fxpt_32 correlation, /* 30.1 format */
fxpt_32 energy, /* 30.1 format */
fxpt_32 *gain, /* 17.14 format */
fxpt_32 *match) /* 30.1 format */
{
if (energy <= 0)
energy = 1;
FXPT_PUSHSTATE("CompGainErrAdapt", -1.0, -1.0);
/**gain = correlation / energy;*/
*gain = fxpt_div32(correlation, energy, 14);
/**match = correlation * *gain;*/
*match = fxpt_mult64_fix(correlation, *gain, 14);
FXPT_POPSTATE();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -