📄 owng729.c
字号:
high = (short)(tmp >> 16);
low = (tmp>>1) & IPP_MAX_16S;
L_tmp1 = high*val + ((low*val)>>15);
L_tmp1 = ShiftL_32s(L_tmp1, 2);
L_tmp1 = Add_32s(L_tmp1, (int)BWF_HARMONIC);
L_tmp = IPP_MAX(L_tmp,L_tmp1);
} else {
area1 = areas[indx-LP_SUBFRAME_DIM];
area2 = areas[indx-1];
for(i = area1; i <= area2; i++) {
high = (short)(pSrcDst[i] >> 16);
low = (pSrcDst[i]>>1) & IPP_MAX_16S;
L_tmp1 = high*val + ((low*val)>>15);
L_tmp1 = (L_tmp1 << 2) + (int)BWF_HARMONIC;
L_tmp = IPP_MAX(L_tmp,L_tmp1);
}
}
for(i=3; i>=1; i--) {
pSrcDst[i] = pSrcDst[i-1];
}
pSrcDst[0] = L_tmp;
return;
}
short calcErr_G729(int val, int *pSrc) {
short i, area1;
area1 = areas[IPP_MAX(0, val - LP_SUBFRAME_DIM - 10)];
for(i=areas[val + 10 - 2]; i>=area1; i--) {
if(pSrc[i] > 983040000)
return 1; /* Error threshold improving BWF_HARMONIC. * 60000. */
}
return 0;
}
/* ///////////////////////////////////////////////////////////////////////////////////////
// Name: Log2_G729
// Purpose: update excitation error
// Parameters:
// pDst1 - log2 integer part. 0<=val<=30
// pDst2 - log2 fractional part. 0<=val<1
// pSrcDst - coder error
*/
void Log2_G729(int val, short *pDst1, short *pDst2) {
short order, i, j;
int L_tmp;
if( val <= 0 ) {
pDst1[0] = pDst2[0] = 0;
return;
}
order = Norm_32s16s(val);
val <<= order;
pDst1[0] = 30 - order;
i = val>>25;
j = (val >> 10) & IPP_MAX_16S;
i -= 32;
L_tmp = logTable[i]<<15;
L_tmp -= (logTable[i] - logTable[i+1]) * j;
pDst2[0] = L_tmp >> 15;
return;
}
void NoiseExcitationFactorization_G729B_16s(const Ipp16s *pSrc,
Ipp32s val1, Ipp16s val2, Ipp16s *pDst, int len) {
int order, L_tmp;
short high, low, tmp1;
high = val1>>16;
low = (val1>>1)&IPP_MAX_16S;
tmp1 = ((val2 * 19043)+BWF_HARMONIC)>>15;
tmp1 += val2;
L_tmp = high*tmp1 + ((low*tmp1)>>15);
order = Norm_32s_I(&L_tmp);
tmp1 = L_tmp>>16;
order -= 15;
ippsMulC_NR_16s_Sfs(pSrc,tmp1,pDst,len,15);
if(order<0) {
ippsLShiftC_16s_I(-order,pDst,len);
} else if(order>0) {
short const1=1<<(order-1);
ippsAddC_16s_I(const1,pDst,len);
/* ippsRShiftC_NR_16s_I() */
ippsRShiftC_16s_I(order,pDst,len);
}
}
int ComfortNoiseExcitation_G729B_16s_I(const Ipp16s *pSrc, const Ipp16s *pPos,
const Ipp16s *pSign, Ipp16s val, Ipp16s val1,
Ipp16s *pSrcDst, Ipp16s *pSrcDst1, short *shiftDst){
short i, j, tmp1, tmp2, max, high, low, tmp3;
short x1, x2, x3 = (val1<<1);
int L_tmp, L_tmp1, L_tmp2, order, deltaSign = 1;
ippsMulC_NR_16s_ISfs(x3,pSrcDst,LP_SUBFRAME_DIM,15);
ippsAdd_16s_ISfs(pSrc,pSrcDst,LP_SUBFRAME_DIM,0);
ippsMax_16s(pSrcDst,LP_SUBFRAME_DIM,&tmp1);
ippsMin_16s(pSrcDst,LP_SUBFRAME_DIM,&tmp2);
if(tmp2==IPP_MIN_16S)
tmp2++;
if(tmp2<0)
tmp2 = -tmp2;
max = IPP_MAX(tmp1,tmp2);
if(max == 0)
order = 0;
else {
order = 3 - Exp_16s(max);
if(order < 0)
order = 0;
}
ippsRShiftC_16s(pSrcDst,order,shiftDst, LP_SUBFRAME_DIM);
ippsDotProd_16s32s_Sfs(shiftDst,shiftDst, LP_SUBFRAME_DIM, &L_tmp1, 0);
L_tmp1 <<= 1;
tmp3 = 0;
for(i=0; i<4; i++) {
j = pPos[i];
if(pSign[i] == 0) {
tmp3 -= (pSrcDst[j] >> order);
} else {
tmp3 += (pSrcDst[j] >> order);
}
}
L_tmp = val * LP_SUBFRAME_DIM;
L_tmp >>= 5;
L_tmp2 = val * L_tmp;
tmp1 = (order<<1);
L_tmp = L_tmp2 >> tmp1;
L_tmp -= L_tmp1;
tmp3 >>= 1;
L_tmp += (tmp3 * tmp3)<<1;
order++;
if(L_tmp < 0) {
ippsCopy_16s(pSrc, pSrcDst, LP_SUBFRAME_DIM);
tmp1 = Abs_16s(pSrc[pPos[0]]) | Abs_16s(pSrc[pPos[1]]);
tmp2 = Abs_16s(pSrc[pPos[2]]) | Abs_16s(pSrc[pPos[3]]);
tmp1 = tmp1 | tmp2;
order = ((tmp1 & BWF_HARMONIC) == 0) ? 1 : 2;
for(tmp3=i=0; i<4; i++) {
tmp1 = pSrc[pPos[i]] >> order;
if(pSign[i] == 0) {
tmp3 -= tmp1;
} else {
tmp3 += tmp1;
}
}
high = L_tmp2>>15;
low = L_tmp2 & IPP_MAX_16S;
L_tmp = high * 24576 + ((low*24576)>>15);
tmp1 = 2 * order - 2;
L_tmp = L_tmp >> tmp1;
L_tmp += 2 * tmp3 * tmp3;
deltaSign = -1;
}
tmp2 = ownSqrt_32s(L_tmp>>1);
x1 = tmp2 - tmp3;
x2 = -(tmp3 + tmp2);
if(Abs_16s(x2) < Abs_16s(x1))
x1 = x2;
tmp1 = 2 - order;
if(tmp1>=0)
pSrcDst1[0] = ShiftR_NR_16s(x1, tmp1);
else
pSrcDst1[0] = ShiftL_16s((short)x1, (unsigned short)(-tmp1));
if(pSrcDst1[0] > 5000)
pSrcDst1[0] = 5000;
else
if(pSrcDst1[0] < -5000)
pSrcDst1[0] = -5000;
for(i=0; i<4; i++) {
j = pPos[i];
if(pSign[i] != 0) {
pSrcDst[j] += pSrcDst1[0];
} else {
pSrcDst[j] -= pSrcDst1[0];
}
}
return deltaSign;
}
void RandomCodebookParm_G729B_16s(Ipp16s *pSeed, Ipp16s *pPos, Ipp16s *pSign,
Ipp16s *pGain, short* delay){
short tmp1, tmp2;
short fractal;
/* generate random adaptive codebook & fixed codebook parameters */
tmp1 = Rand_16s(pSeed);
fractal = (tmp1 & 3) - 1;
if(fractal == 2)
fractal = 0;
tmp1 >>= 2;
delay[0] = (tmp1 & 0x003f) + 40;
tmp1 >>= 6;
tmp2 = tmp1 & 7;
pPos[0] = 5 * tmp2;
tmp1 >>= 3;
pSign[0] = tmp1 & 1;
tmp1 >>= 1;
tmp2 = tmp1 & 7;
pPos[1] = 5 * tmp2 + 1;
tmp1 >>= 3;
pSign[1] = tmp1 & 1;
tmp1 = Rand_16s(pSeed);
tmp2 = tmp1 & 7;
pPos[2] = 5 * tmp2 + 2;
tmp1 >>= 3;
pSign[2] = tmp1 & 1;
tmp1 >>= 1;
tmp2 = tmp1 & 0x000f;
pPos[3] = (tmp2 & 1) + 3;
tmp2 = (tmp2>>1) & 7;
pPos[3]+= 5 * tmp2;
tmp1 >>= 4;
pSign[3] = tmp1 & 1;
delay[1] = fractal;
*pGain = Rand_16s(pSeed) & 0x1fff;
}
static short ownQuantizeEnergy(int val, short order, short *pDst) {
short exp, fractal, tmp, tmp1, index;
Log2_G729(val, &exp, &fractal);
tmp1 = exp - order;
tmp = tmp1 << 10;
tmp += (fractal + 0x10)>>5;
if(tmp <= -2721) {/* 8 dB */
pDst[0] = -12;
return 0;
}
if(tmp > 22111) { /* 65 dB */
pDst[0] = 66;
return 31;
}
if(tmp <= 4762) { /* 14 dB */
tmp += 3401;
index = (tmp * 24)>>15;
if(index < 1)
index = 1;
pDst[0] = (index<<2) - 8;
return index;
}
tmp -= 340;
index = ((tmp*193)>>17) - 1;
if(index < 6)
index = 6;
pDst[0] = (index<<1) + 4;
return(index);
}
/* ///////////////////////////////////////////////////////////////////////////////////////
// Name: QuantSIDGain_G729B_16s
// Purpose:
// Parameters:
// pSrc array of energies
// pSrcSfs corresponding scaling factors
// len number of energies
// pDst decoded energies in dB
// pIndx SID gain quantization index
*/
void QuantSIDGain_G729B_16s (const Ipp16s *pSrc, const Ipp16s *pSrcSfs,
int len, Ipp16s *pDst, int *pDstIndx){
short i,order,temp,high,low;
int val;
if(len == 0) {
val = *pSrc;
if(pSrcSfs[0]<0)
val >>= - pSrcSfs[0];
else
val <<= pSrcSfs[0];
order = 0;
high = val >> 16;
low = (val>>1)&IPP_MAX_16S;
val = high * t[0] + ((low * t[0])>>15);
} else {
ippsMin_16s(pSrcSfs,len,&order);
order += 16 - t1[len];
val = 0;
for(i=0; i<len; i++) {
temp = order - pSrcSfs[i];
val += (pSrc[i]<<temp);
}
high = val >> 16;
low = (val>>1)&IPP_MAX_16S;
val = high * t[i] + (((low * t[i] >> 1) & 0xffff8000)>>14);
}
*pDstIndx = ownQuantizeEnergy(val, order, pDst);
}
void Sum_G729_16s_Sfs(const Ipp16s *pSrc, const Ipp16s *pSrcSfs,
Ipp16s *pDst, Ipp16s *pDSfs, int len, int* pSum) {
short sfs, order;
short i, j;
sfs = pSrcSfs[0];
for(i=1; i<len; i++) {
if(pSrcSfs[i] < sfs)
sfs = pSrcSfs[i];
}
for(j=0; j<LPF_DIM+1; j++) {
pSum[j] = 0;
}
sfs += 14;
for(i=0; i<len; i++) {
order = sfs - pSrcSfs[i];
if(order<0) {
for(j=0; j<LPF_DIM+1; j++) {
pSum[j] += pSrc[(LPF_DIM+1)*i+j] >> -order;
}
} else {
for(j=0; j<LPF_DIM+1; j++) {
pSum[j] += pSrc[(LPF_DIM+1)*i+j] << order;
}
}
}
order = Norm_32s_I(&pSum[0]);
pDst[0] = pSum[0]>>16;
for(i=1; i<=LPF_DIM; i++) {
pDst[i] = (pSum[i]<<order)>>16;
}
order -= 16;
*pDSfs = sfs + order;
}
void VoiceActivityDetectSize_G729(int* pVADsize) {
//pVADsize[0] = (sizeof(VADmemory)+7)&(~7);
pVADsize[0] = (sizeof(VADmemory)+32);
}
void VoiceActivityDetectInit_G729(char* pVADmem) {
VADmemory* vadMem = (VADmemory*)pVADmem;
ippsZero_16s(vadMem->LSFMean, LPF_DIM);
ippsZero_16s(vadMem->minBuf, 16);
vadMem->SEMean = 0;
vadMem->SLEMean = 0;
vadMem->EMean = 0;
vadMem->SZCMean = 0;
vadMem->SILcounter = 0;
vadMem->updateCounter = 0;
vadMem->extCounter = 0;
vadMem->lessCounter = 0;
vadMem->frameCounter = 0;
vadMem->VADflag = 1;
vadMem->minVAD = IPP_MAX_16S;
vadMem->VADPrev = 1;
vadMem->VADPPrev = 1;
vadMem->minPrev = IPP_MAX_16S;
vadMem->minNext = IPP_MAX_16S;
vadMem->VADPrevEnergy = IPP_MAX_16S;
vadMem->VADflag2 = 0;
ippsZero_16s(vadMem->musicRC, 10);
vadMem->musicCounter=0;
vadMem->musicMCounter=0;
vadMem->conscCounter=0;
vadMem->MeanPgain =BWF_HARMONIC_E;
vadMem->count_pflag=0;
vadMem->Mcount_pflag=0;
vadMem->conscCounterFlagP=0;
vadMem->conscCounterFlagR=0;
vadMem->musicSEMean =0;
}
/* ///////////////////////////////////////////////////////////////////////////////////////
// Name: ownMakeDecision
// Purpose:
// Parameters:
// lowBandE - energy
// highBandE - fullenergy
// spectrDist - distortion
// crossZeroRate - zero crossing
*/
static short ownMakeDecision(short lowBandE,short highBandE, short spectrDist,short crossZeroRate) {
int L_tmp;
/* spectrDist vs crossZeroRate */
L_tmp = crossZeroRate * (-14680);
L_tmp += BWF_HARMONIC_E * (-28521);
L_tmp = L_tmp >> 7;
if(L_tmp > -spectrDist<<16 )
return 1;
L_tmp = crossZeroRate * 19065;
L_tmp += BWF_HARMONIC_E * (-19446);
L_tmp = L_tmp>>6;
if(L_tmp > -spectrDist<<16)
return 1;
/* highBandE vs crossZeroRate */
L_tmp = crossZeroRate * 20480;
L_tmp += BWF_HARMONIC_E * BWF_HARMONIC;
L_tmp = L_tmp>>1;
if(L_tmp < -highBandE<<16)
return 1;
L_tmp = crossZeroRate * (-BWF_HARMONIC);
L_tmp += BWF_HARMONIC_E * 19660;
L_tmp = L_tmp>>1;
if(L_tmp < -highBandE<<16)
return 1;
L_tmp = highBandE * IPP_MAX_16S;
if(L_tmp < -1024 * 30802)
return 1;
/* highBandE vs spectrDist */
L_tmp = spectrDist * (-28160);
L_tmp += 64 * 19988;
if(L_tmp < -highBandE<<9)
return 1;
L_tmp = spectrDist * IPP_MAX_16S;
if(L_tmp > 32 * 30199)
return 1;
/* lowBandE vs crossZeroRate */
L_tmp = crossZeroRate * (-20480);
L_tmp += BWF_HARMONIC_E * BWF2;
L_tmp = L_tmp >> 1;
if(L_tmp < -highBandE<<16)
return 1;
L_tmp = crossZeroRate * 23831;
L_tmp += (1<<12) * 31576;
L_tmp = L_tmp>>1;
if(L_tmp < -highBandE<<16)
return 1;
L_tmp = highBandE * IPP_MAX_16S;
if(L_tmp < -(1<<11) * 17367
) return 1;
/* lowBandE vs spectrDist */
L_tmp = spectrDist * (-22400);
L_tmp += (1<<5) * 25395;
if(L_tmp < -lowBandE<<8)
return 1;
/* lowBandE vs highBandE */
L_tmp = highBandE * (-30427);
L_tmp += (1<<8) * (-29959);
if(L_tmp > -lowBandE<<15)
return 1;
L_tmp = highBandE * (-23406);
L_tmp += (1<<9) * 28087;
if(L_tmp < -lowBandE<<15)
return 1;
L_tmp = highBandE * 24576;
L_tmp += (1<<10) * COEFF1;
if(L_tmp < -lowBandE<<14)
return 1;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -