xMean=(word16_t)SUB32(xLow,MULT16_32_Q15(SUB32(xHigh,xLow),DIV32(SHL(previousCx,14),SHR(SUB32(Cx,previousCx),1))));/* Cx are in Q2.15 so we can shift them left 14 bits, the denominator is shifted righ by 1 so the division result is in Q15 */
xMean=(word16_t)SUB32(xLow,MULT16_32_Q15(SUB32(xHigh,xLow),DIV32(SSHL(SATURATE(previousCx,MAXINT17),14),SHR(SUB32(Cx,previousCx),1))));/* Cx are in Q2.15 so we can shift them left 14 bits, the denominator is shifted righ by 1 so the division result is in Q15 */
/* recompute previousCx with the new coefficients */
/* compute the weighted mean square distance using the final quantized vector according to eq21 */
weightedMeanSquareError[L0]=0;
for(i=0;i<NB_LSP_COEFF;i++){
word16_tdifftargetVectorQuantizedVector=SATURATE(MULT16_16_Q15(SUB32(targetVector[i],quantizedVector[i]),noiseMAPredictorSum[L0][i]),MAXINT16);/* targetVector and quantizedVector in Q13 -> result in Q13 */
weightedMeanSquareError[L0]=MAC16_16(weightedMeanSquareError[L0],difftargetVectorQuantizedVector,MULT16_16_Q11(difftargetVectorQuantizedVector,weights[i]));/* weights in Q11, diff in Q13 */
uword16_tdifftargetVectorQuantizedVector=USATURATE(ABS(MULT16_16_Q15(SUB32(targetVector[i],quantizedVector[i]),noiseMAPredictorSum[L0][i])),MAXUINT16);/* targetVector and quantizedVector in Q13 -> result in Q13 */
weightedMeanSquareError[L0]=UMAC16_16(weightedMeanSquareError[L0],difftargetVectorQuantizedVector,MULT16_16_Q11(difftargetVectorQuantizedVector,weights[i]));/* weights in Q11, diff in Q13 */
}
@ -257,10 +257,10 @@ void LSPQuantization(bcg729EncoderChannelContextStruct *encoderChannelContext, w
{
inti,j;
word16_tLSF[NB_LSP_COEFF];/* LSF coefficients in Q2.13 range [0, Pi[ */
word16_tweights[NB_LSP_COEFF];/* weights in Q11 */
uword16_tweights[NB_LSP_COEFF];/* weights in Q11 */
word16_tweightsThreshold[NB_LSP_COEFF];/* store in Q13 the threshold used to compute the weights */
intL0;
word32_tweightedMeanSquareError[L0_RANGE];
uword32_tweightedMeanSquareError[L0_RANGE];
word16_tL1index[L0_RANGE];
word16_tL2index[L0_RANGE];
word16_tL3index[L0_RANGE];
@ -391,8 +391,8 @@ void LSPQuantization(bcg729EncoderChannelContextStruct *encoderChannelContext, w
/* compute the weighted mean square distance using the final quantized vector according to eq21 */
weightedMeanSquareError[L0]=0;
for(i=0;i<NB_LSP_COEFF;i++){
word16_tdifftargetVectorQuantizedVector=SATURATE(MULT16_16_Q15(SUB32(targetVector[i],quantizedVector[i]),MAPredictorSum[L0][i]),MAXINT16);/* targetVector and quantizedVector in Q13 -> result in Q13 */
weightedMeanSquareError[L0]=MAC16_16(weightedMeanSquareError[L0],difftargetVectorQuantizedVector,MULT16_16_Q11(difftargetVectorQuantizedVector,weights[i]));/* weights in Q11, diff in Q13 */
uword16_tdifftargetVectorQuantizedVector=USATURATE(ABS(MULT16_16_Q15(SUB32(targetVector[i],quantizedVector[i]),MAPredictorSum[L0][i])),MAXUINT16);/* targetVector and quantizedVector in Q13 -> result in Q13 */
weightedMeanSquareError[L0]=UMAC16_16(weightedMeanSquareError[L0],difftargetVectorQuantizedVector,MULT16_16_Q11(difftargetVectorQuantizedVector,weights[i]));/* weights in Q11, diff in Q13 */
LPCoefficients[1]=-DIV32_32_Q27(autoCorrelationCoefficients[1],autoCorrelationCoefficients[0]);/* result in Q27(but<1) */
reflectionCoefficients[0]=SHL(LPCoefficients[1],4);/* k[0] is -r1/r0 in Q31 */
reflectionCoefficients[0]=SSHL(LPCoefficients[1],4);/* k[0] is -r1/r0 in Q31 */
/* E = r0(1 - a[1]^2) in Q31 */
E=MULT32_32_Q31(autoCorrelationCoefficients[0],SUB32(ONE_IN_Q31,MULT32_32_Q23(LPCoefficients[1],LPCoefficients[1])));/* LPCoefficient[1] is in Q27, using a Q23 operation will result in a Q31 variable */
sum=MAC32_32_Q31(sum,LPCoefficients[j],autoCorrelationCoefficients[i-j]);/* LPCoefficients in Q27, autoCorrelation in Q31 -> result in Q27 -> sum in Q27 */
}
sum=ADD32(SHL(sum,4),autoCorrelationCoefficients[i]);/* set sum in Q31 and add r[0] */
sum=ADD32(SSHL(sum,4),autoCorrelationCoefficients[i]);/* set sum in Q31 and add r[0] */
/* a[i] = -sum/E */
LPCoefficients[i]=-DIV32_32_Q31(sum,E);/* LPCoefficient of current iteration is in Q31 for now, it will be set to Q27 at the end of this iteration */
staticconstword16_tpreviousqLSPInitialValues[NB_LSP_COEFF]={30000,26000,21000,15000,8000,0,-8000,-15000,-21000,-26000};/* in Q0.15 the initials values for the previous qLSP buffer */
/* Note : index of qLSP are -1 respect of what is in the spec because qLSP array is indexed from 0-9 and not 1-10 */
for(i=2;i<6;i++){
/* spec: f[i] = 2(f[i-2] - qLSP[2i-1]*f[i-1]) */
f[i]=SHL(SUB32(f[i-2],MULT16_32_P15(qLSP[2*i-2],f[i-1])),1);/* with qLSP in Q0.15 and f in Q24 */
f[i]=SSHL(SUB32(f[i-2],MULT16_32_P15(qLSP[2*i-2],f[i-1])),1);/* with qLSP in Q0.15 and f in Q24 */
for(j=i-1;j>1;j--){/* case of j=1 is just doing f[1] -= 2*qLSP[2i-1], done after the loop in order to avoid reference to f[-1] */
/* spec: f[j] = f[j] -2*qLSP[2i-i]*f[j-1] + f[j-2] (all right terms refer to the value at the previous iteration on i indexed loop) */
f[j]=ADD32(f[j],SUB32(f[j-2],MULT16_32_P14(qLSP[2*i-2],f[j-1])));/* qLPS in Q0.15 and f in Q24, using MULT16_32_P14 instead of P15 does the *2 on qLSP. Result in Q24 */
}
/* f[1] -= 2*qLSP[2i-1] */
f[1]=SUB32(f[1],SHL(qLSP[2*i-2],10));/* qLSP in Q0.15, must be shift by 9 to get in Q24 and one more to be *2 */
f[1]=SUB32(f[1],SSHL(qLSP[2*i-2],10));/* qLSP in Q0.15, must be shift by 9 to get in Q24 and one more to be *2 */