Some general optimization in NS.

No big effort in introducing new style.
Speed improved ~2%.
Bit exact.
Will introduce mulpty-and-accumulate and sqrt_floor next, which increase speed another 2% or so.

Note: In function WebRtcNsx_DataAnalysis, did the block separation because I found one "if" case is more frequent than "else" within a for loop; rest is kind of code re-aligning.
Review URL: http://webrtc-codereview.appspot.com/181002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@692 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kma@webrtc.org
2011-10-05 17:10:06 +00:00
parent a58224f9f0
commit bf39ff4271

View File

@ -1429,25 +1429,26 @@ void WebRtcNsx_SpeechNoiseProb(NsxInst_t *inst, WebRtc_UWord16 *nonSpeechProbFin
tmp16, 14); // Q14
//final speech probability: combine prior model with LR factor:
for (i = 0; i < inst->magnLen; i++)
{
memset(nonSpeechProbFinal, 0, sizeof(WebRtc_UWord16) * inst->magnLen);
if (inst->priorNonSpeechProb > 0) {
for (i = 0; i < inst->magnLen; i++) {
// FLOAT code
// invLrt = exp(inst->logLrtTimeAvg[i]);
// invLrt = inst->priorSpeechProb * invLrt;
// nonSpeechProbFinal[i] = (1.0 - inst->priorSpeechProb) / (1.0 - inst->priorSpeechProb + invLrt);
// invLrt = (1.0 - inst->priorNonSpeechProb) * invLrt;
// nonSpeechProbFinal[i] = inst->priorNonSpeechProb / (inst->priorNonSpeechProb + invLrt);
nonSpeechProbFinal[i] = 0; // Q8
if ((inst->logLrtTimeAvgW32[i] < 65300) && (inst->priorNonSpeechProb > 0))
{
if (inst->logLrtTimeAvgW32[i] < 65300) {
tmp32no1 = WEBRTC_SPL_RSHIFT_W32(WEBRTC_SPL_MUL(inst->logLrtTimeAvgW32[i], 23637),
14); // Q12
intPart = (WebRtc_Word16)WEBRTC_SPL_RSHIFT_W32(tmp32no1, 12);
if (intPart < -8)
{
if (intPart < -8) {
intPart = -8;
}
frac = (WebRtc_Word16)(tmp32no1 & 0x00000fff); // Q12
// Quadratic approximation of 2^frac
tmp32no2 = WEBRTC_SPL_RSHIFT_W32(frac * frac * 44, 19); // Q12
tmp32no2 += WEBRTC_SPL_MUL_16_16_RSFT(frac, 84, 7); // Q12
@ -1456,24 +1457,24 @@ void WebRtcNsx_SpeechNoiseProb(NsxInst_t *inst, WebRtc_UWord16 *nonSpeechProbFin
normTmp = WebRtcSpl_NormW32(invLrtFX);
normTmp2 = WebRtcSpl_NormW16((16384 - inst->priorNonSpeechProb));
if (normTmp + normTmp2 < 15)
{
invLrtFX = WEBRTC_SPL_RSHIFT_W32(invLrtFX, 15 - normTmp2 - normTmp); // Q(normTmp+normTmp2-7)
tmp32no1 = WEBRTC_SPL_MUL_32_16(invLrtFX, (16384 - inst->priorNonSpeechProb)); // Q(normTmp+normTmp2+7)
if (normTmp + normTmp2 >= 7) {
if (normTmp + normTmp2 < 15) {
invLrtFX = WEBRTC_SPL_RSHIFT_W32(invLrtFX, 15 - normTmp2 - normTmp);
// Q(normTmp+normTmp2-7)
tmp32no1 = WEBRTC_SPL_MUL_32_16(invLrtFX, (16384 - inst->priorNonSpeechProb));
// Q(normTmp+normTmp2+7)
invLrtFX = WEBRTC_SPL_SHIFT_W32(tmp32no1, 7 - normTmp - normTmp2); // Q14
} else
{
} else {
tmp32no1 = WEBRTC_SPL_MUL_32_16(invLrtFX, (16384 - inst->priorNonSpeechProb)); // Q22
invLrtFX = WEBRTC_SPL_RSHIFT_W32(tmp32no1, 8); // Q14
}
tmp32no1 = WEBRTC_SPL_LSHIFT_W32((WebRtc_Word32)inst->priorNonSpeechProb, 8); // Q22
nonSpeechProbFinal[i] = (WebRtc_UWord16)WEBRTC_SPL_DIV(tmp32no1,
(WebRtc_Word32)inst->priorNonSpeechProb
+ invLrtFX); // Q8
if (7 - normTmp - normTmp2 > 0)
{
nonSpeechProbFinal[i] = 0; // Q8
}
}
}
}
@ -1570,9 +1571,24 @@ void WebRtcNsx_DataAnalysis(NsxInst_t *inst, short *speechFrame, WebRtc_UWord16
inst->sumMagn = (WebRtc_UWord32)magnU16[0]; // Q(normData-stages)
inst->sumMagn += (WebRtc_UWord32)magnU16[inst->anaLen2];
if (inst->blockIndex >= END_STARTUP_SHORT) {
for (i = 1, j = 2; i < inst->anaLen2; i += 1, j += 2) {
inst->real[i] = realImag[j];
inst->imag[i] = -realImag[j + 1];
// magnitude spectrum
// energy in Q(2*(normData-stages))
tmpU32no1 = (WebRtc_UWord32)WEBRTC_SPL_MUL_16_16(realImag[j], realImag[j]);
tmpU32no1 += (WebRtc_UWord32)WEBRTC_SPL_MUL_16_16(realImag[j + 1], realImag[j + 1]);
inst->magnEnergy += tmpU32no1; // Q(2*(normData-stages))
magnU16[i] = (WebRtc_UWord16)WebRtcSpl_Sqrt(tmpU32no1); // Q(normData-stages)
inst->sumMagn += (WebRtc_UWord32)magnU16[i]; // Q(normData-stages)
}
} else {
//
// Gather information during startup for noise parameter estimation
if (inst->blockIndex < END_STARTUP_SHORT)
{
//
// Switch initMagnEst to Q(minNorm-stages)
inst->initMagnEst[0] = WEBRTC_SPL_RSHIFT_U32(inst->initMagnEst[0],
right_shifts_in_initMagnEst);
@ -1605,11 +1621,9 @@ void WebRtcNsx_DataAnalysis(NsxInst_t *inst, short *speechFrame, WebRtc_UWord16
sum_log_magn = (WebRtc_Word32)log2; // Q8
// sum_log_i_log_magn in Q17
sum_log_i_log_magn = (WEBRTC_SPL_MUL_16_16(kLogIndex[inst->anaLen2], log2) >> 3);
}
for (i = 1; i < inst->anaLen2; i++)
for (i = 1, j = 2; i < inst->anaLen2; i += 1, j += 2)
{
j = WEBRTC_SPL_LSHIFT_W16(i, 1);
inst->real[i] = realImag[j];
inst->imag[i] = -realImag[j + 1];
// magnitude spectrum
@ -1620,8 +1634,7 @@ void WebRtcNsx_DataAnalysis(NsxInst_t *inst, short *speechFrame, WebRtc_UWord16
magnU16[i] = (WebRtc_UWord16)WebRtcSpl_Sqrt(tmpU32no1); // Q(normData-stages)
inst->sumMagn += (WebRtc_UWord32)magnU16[i]; // Q(normData-stages)
if (inst->blockIndex < END_STARTUP_SHORT)
{
// Switch initMagnEst to Q(minNorm-stages)
inst->initMagnEst[i] = WEBRTC_SPL_RSHIFT_U32(inst->initMagnEst[i],
right_shifts_in_initMagnEst);
@ -1651,12 +1664,13 @@ void WebRtcNsx_DataAnalysis(NsxInst_t *inst, short *speechFrame, WebRtc_UWord16
sum_log_i_log_magn += (WEBRTC_SPL_MUL_16_16(kLogIndex[i], log2) >> 3);
}
}
}
//
//compute simplified noise model during startup
if (inst->blockIndex < END_STARTUP_SHORT)
{
//
// Estimate White noise
// Switch whiteNoiseLevel to Q(minNorm-stages)
inst->whiteNoiseLevel = WEBRTC_SPL_RSHIFT_U32(inst->whiteNoiseLevel,
right_shifts_in_initMagnEst);