Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_processing / ns / nsx_core.c
index 2c8270f..930c2c2 100644 (file)
@@ -503,8 +503,8 @@ static void SynthesisUpdateC(NsxInst_t* inst,
     tmp32 = WEBRTC_SPL_MUL_16_16_RSFT_WITH_ROUND(tmp16a, gain_factor, 13); // Q0
     // Down shift with rounding
     tmp16b = WebRtcSpl_SatW32ToW16(tmp32); // Q0
-    inst->synthesisBuffer[i] = WEBRTC_SPL_ADD_SAT_W16(inst->synthesisBuffer[i],
-                                                      tmp16b); // Q0
+    inst->synthesisBuffer[i] = WebRtcSpl_AddSatW16(inst->synthesisBuffer[i],
+                                                   tmp16b); // Q0
   }
 
   // read out fully processed segment
@@ -620,7 +620,7 @@ void WebRtcNsx_CalcParametricNoiseEstimate(NsxInst_t* inst,
     }
     // Shift fractional part to Q(minNorm-stages)
     tmp32no2 = WEBRTC_SPL_SHIFT_W32(tmp32no2, int_part - 11);
-    *noise_estimate_avg = WEBRTC_SPL_LSHIFT_U32(1, int_part) + (uint32_t)tmp32no2;
+    *noise_estimate_avg = (1 << int_part) + (uint32_t)tmp32no2;
     // Scale up to initMagnEst, which is not block averaged
     *noise_estimate = (*noise_estimate_avg) * (uint32_t)(inst->blockIndex + 1);
   }
@@ -864,8 +864,8 @@ void WebRtcNsx_FeatureParameterExtraction(NsxInst_t* inst, int flag) {
       // Guard against division by zero
       // If timeAvgMagnEnergy == 0 we have no normalizing statistics and
       // therefore can't update the histogram
-      histIndex = WEBRTC_SPL_UDIV((inst->featureSpecDiff * 5) >> inst->stages,
-                                  inst->timeAvgMagnEnergy);
+      histIndex = ((inst->featureSpecDiff * 5) >> inst->stages) /
+          inst->timeAvgMagnEnergy;
     }
     if (histIndex < HIST_PAR_EST) {
       inst->histSpecDiff[histIndex]++;
@@ -885,14 +885,14 @@ void WebRtcNsx_FeatureParameterExtraction(NsxInst_t* inst, int flag) {
       tmp32 = WEBRTC_SPL_MUL_16_16(inst->histLrt[i], j);
       avgHistLrtFX += tmp32;
       numHistLrt += inst->histLrt[i];
-      avgSquareHistLrtFX += WEBRTC_SPL_MUL_32_16(tmp32, j);
+      avgSquareHistLrtFX += tmp32 * j;
     }
     avgHistLrtComplFX = avgHistLrtFX;
     for (; i < HIST_PAR_EST; i++) {
       j = (2 * i + 1);
       tmp32 = WEBRTC_SPL_MUL_16_16(inst->histLrt[i], j);
       avgHistLrtComplFX += tmp32;
-      avgSquareHistLrtFX += WEBRTC_SPL_MUL_32_16(tmp32, j);
+      avgSquareHistLrtFX += tmp32 * j;
     }
     fluctLrtFX = WEBRTC_SPL_MUL(avgSquareHistLrtFX, numHistLrt);
     fluctLrtFX -= WEBRTC_SPL_MUL(avgHistLrtFX, avgHistLrtComplFX);
@@ -1083,7 +1083,7 @@ void WebRtcNsx_ComputeSpectralFlatness(NsxInst_t* inst, uint16_t* magn) {
 
   //time average update of spectral flatness feature
   tmp32 = currentSpectralFlatness - (int32_t)inst->featureSpecFlat; // Q10
-  tmp32 = WEBRTC_SPL_MUL_32_16(SPECT_FLAT_TAVG_Q14, tmp32); // Q24
+  tmp32 *= SPECT_FLAT_TAVG_Q14;  // Q24
   inst->featureSpecFlat = (uint32_t)((int32_t)inst->featureSpecFlat
                                            + WEBRTC_SPL_RSHIFT_W32(tmp32, 14)); // Q10
   // done with flatness feature
@@ -1135,7 +1135,7 @@ void WebRtcNsx_ComputeSpectralDifference(NsxInst_t* inst, uint16_t* magnIn) {
     tmp16no1 = (int16_t)((int32_t)magnIn[i] - avgMagnFX);
     tmp32no2 = inst->avgMagnPause[i] - avgPauseFX;
     varMagnUFX += (uint32_t)WEBRTC_SPL_MUL_16_16(tmp16no1, tmp16no1); // Q(2*qMagn)
-    tmp32no1 = WEBRTC_SPL_MUL_32_16(tmp32no2, tmp16no1); // Q(prevQMagn+qMagn)
+    tmp32no1 = tmp32no2 * tmp16no1;  // Q(prevQMagn+qMagn)
     covMagnPauseFX += tmp32no1; // Q(prevQMagn+qMagn)
     tmp32no1 = WEBRTC_SPL_RSHIFT_W32(tmp32no2, nShifts); // Q(prevQMagn-minPause)
     varPauseUFX += (uint32_t)WEBRTC_SPL_MUL(tmp32no1, tmp32no1); // Q(2*(prevQMagn-minPause))
@@ -1149,7 +1149,7 @@ void WebRtcNsx_ComputeSpectralDifference(NsxInst_t* inst, uint16_t* magnIn) {
     tmpU32no1 = (uint32_t)WEBRTC_SPL_ABS_W32(covMagnPauseFX); // Q(prevQMagn+qMagn)
     norm32 = WebRtcSpl_NormU32(tmpU32no1) - 16;
     if (norm32 > 0) {
-      tmpU32no1 = WEBRTC_SPL_LSHIFT_U32(tmpU32no1, norm32); // Q(prevQMagn+qMagn+norm32)
+      tmpU32no1 <<= norm32;  // Q(prevQMagn+qMagn+norm32)
     } else {
       tmpU32no1 = WEBRTC_SPL_RSHIFT_U32(tmpU32no1, -norm32); // Q(prevQMagn+qMagn+norm32)
     }
@@ -1163,7 +1163,7 @@ void WebRtcNsx_ComputeSpectralDifference(NsxInst_t* inst, uint16_t* magnIn) {
     }
     if (varPauseUFX > 0) {
       // Q(2*(qMagn+norm32-16+minPause))
-      tmpU32no1 = WEBRTC_SPL_UDIV(tmpU32no2, varPauseUFX);
+      tmpU32no1 = tmpU32no2 / varPauseUFX;
       tmpU32no1 = WEBRTC_SPL_RSHIFT_U32(tmpU32no1, nShifts);
 
       // Q(2*qMagn)
@@ -1493,8 +1493,7 @@ void WebRtcNsx_DataSynthesis(NsxInst_t* inst, short* outFrame) {
     }
 
     assert(inst->energyIn > 0);
-    energyRatio = (int16_t)WEBRTC_SPL_DIV(energyOut
-        + WEBRTC_SPL_RSHIFT_W32(inst->energyIn, 1), inst->energyIn); // Q8
+    energyRatio = (energyOut + inst->energyIn / 2) / inst->energyIn;  // Q8
     // Limit the ratio to [0, 1] in Q8, i.e., [0, 256]
     energyRatio = WEBRTC_SPL_SAT(256, energyRatio, 0);
 
@@ -1661,7 +1660,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
         // numerator = (initMagnEst - noise_estimate * overdrive)
         // Result in Q(8+minNorm-stages)
         tmpU32no1 = WEBRTC_SPL_UMUL_32_16(noise_estimate, inst->overdrive);
-        numerator = WEBRTC_SPL_LSHIFT_U32(inst->initMagnEst[i], 8);
+        numerator = inst->initMagnEst[i] << 8;
         if (numerator > tmpU32no1) {
           // Suppression filter coefficient larger than zero, so calculate.
           numerator -= tmpU32no1;
@@ -1672,7 +1671,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
           nShifts = WEBRTC_SPL_SAT(6, nShifts, 0);
 
           // Shift numerator to Q(nShifts+8+minNorm-stages)
-          numerator = WEBRTC_SPL_LSHIFT_U32(numerator, nShifts);
+          numerator <<= nShifts;
 
           // Shift denominator to Q(nShifts-6+minNorm-stages)
           tmpU32no1 = WEBRTC_SPL_RSHIFT_U32(inst->initMagnEst[i], 6 - nShifts);
@@ -1681,7 +1680,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
             // we don't need any division.
             tmpU32no1 = 1;
           }
-          tmpU32no2 = WEBRTC_SPL_UDIV(numerator, tmpU32no1); // Q14
+          tmpU32no2 = numerator / tmpU32no1;  // Q14
           noiseSupFilterTmp[i] = (uint16_t)WEBRTC_SPL_SAT(16384, tmpU32no2,
               (uint32_t)(inst->denoiseBound)); // Q14
         }
@@ -1711,7 +1710,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
       // Add them together and divide by startup length
       noiseU32[i] = WebRtcSpl_DivU32U16(tmpU32no1 + tmpU32no2, END_STARTUP_SHORT);
       // Shift back if necessary
-      noiseU32[i] = WEBRTC_SPL_LSHIFT_U32(noiseU32[i], nShifts);
+      noiseU32[i] <<= nShifts;
     }
     // Update new Q-domain for 'noiseU32'
     qNoise = q_domain_to_use;
@@ -1754,17 +1753,17 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
 
     // calculate post SNR: output in Q11
     postLocSnr[i] = 2048; // 1.0 in Q11
-    tmpU32no1 = WEBRTC_SPL_LSHIFT_U32((uint32_t)magnU16[i], 6); // Q(6+qMagn)
+    tmpU32no1 = (uint32_t)magnU16[i] << 6;  // Q(6+qMagn)
     if (postShifts < 0) {
       tmpU32no2 = WEBRTC_SPL_RSHIFT_U32(noiseU32[i], -postShifts); // Q(6+qMagn)
     } else {
-      tmpU32no2 = WEBRTC_SPL_LSHIFT_U32(noiseU32[i], postShifts); // Q(6+qMagn)
+      tmpU32no2 = noiseU32[i] << postShifts;  // Q(6+qMagn)
     }
     if (tmpU32no1 > tmpU32no2) {
       // Current magnitude larger than noise
-      tmpU32no1 = WEBRTC_SPL_LSHIFT_U32(tmpU32no1, 11); // Q(17+qMagn)
+      tmpU32no1 <<= 11;  // Q(17+qMagn)
       if (tmpU32no2 > 0) {
-        tmpU32no1 = WEBRTC_SPL_UDIV(tmpU32no1, tmpU32no2); // Q11
+        tmpU32no1 /= tmpU32no2;  // Q11
         postLocSnr[i] = WEBRTC_SPL_MIN(satMax, tmpU32no1); // Q11
       } else {
         postLocSnr[i] = satMax;
@@ -1772,12 +1771,13 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
     }
 
     // calculate prevNearSnr[i] and save for later instead of recalculating it later
-    nearMagnEst = WEBRTC_SPL_UMUL_16_16(inst->prevMagnU16[i], inst->noiseSupFilter[i]); // Q(prevQMagn+14)
-    tmpU32no1 = WEBRTC_SPL_LSHIFT_U32(nearMagnEst, 3); // Q(prevQMagn+17)
+    // |nearMagnEst| in Q(prevQMagn + 14)
+    nearMagnEst = inst->prevMagnU16[i] * inst->noiseSupFilter[i];
+    tmpU32no1 = nearMagnEst << 3;  // Q(prevQMagn+17)
     tmpU32no2 = WEBRTC_SPL_RSHIFT_U32(inst->prevNoiseU32[i], nShifts); // Q(prevQMagn+6)
 
     if (tmpU32no2 > 0) {
-      tmpU32no1 = WEBRTC_SPL_UDIV(tmpU32no1, tmpU32no2); // Q11
+      tmpU32no1 /= tmpU32no2;  // Q11
       tmpU32no1 = WEBRTC_SPL_MIN(satMax, tmpU32no1); // Q11
     } else {
       tmpU32no1 = satMax; // Q11
@@ -1829,12 +1829,12 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
         norm32no1++;
       }
       tmpU32no3 = WEBRTC_SPL_UMUL(tmpU32no3, tmpU32no2);
-      tmpU32no3 = WEBRTC_SPL_UDIV(tmpU32no3, inst->timeAvgMagnEnergy);
+      tmpU32no3 /= inst->timeAvgMagnEnergy;
       if (WebRtcSpl_NormU32(tmpU32no3) < norm32no1) {
         inst->featureSpecDiff = 0x007FFFFF;
       } else {
         inst->featureSpecDiff = WEBRTC_SPL_MIN(0x007FFFFF,
-            WEBRTC_SPL_LSHIFT_U32(tmpU32no3, norm32no1));
+                                               tmpU32no3 << norm32no1);
       }
     }
 
@@ -1859,7 +1859,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
     if (postShifts < 0) {
       tmpU32no2 = WEBRTC_SPL_RSHIFT_U32(magnU16[i], -postShifts); // Q(prevQNoise)
     } else {
-      tmpU32no2 = WEBRTC_SPL_LSHIFT_U32(magnU16[i], postShifts); // Q(prevQNoise)
+      tmpU32no2 = (uint32_t)magnU16[i] << postShifts;  // Q(prevQNoise)
     }
     if (prevNoiseU16[i] > tmpU32no2) {
       sign = -1;
@@ -1940,12 +1940,12 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
     if (nonSpeechProbFinal[i] > ONE_MINUS_PROB_RANGE_Q8) {
       if (nShifts < 0) {
         tmp32no1 = (int32_t)magnU16[i] - tmp32no2; // Q(qMagn)
-        tmp32no1 = WEBRTC_SPL_MUL_32_16(tmp32no1, ONE_MINUS_GAMMA_PAUSE_Q8); // Q(8+prevQMagn+nShifts)
+        tmp32no1 *= ONE_MINUS_GAMMA_PAUSE_Q8;  // Q(8+prevQMagn+nShifts)
         tmp32no1 = WEBRTC_SPL_RSHIFT_W32(tmp32no1 + 128, 8); // Q(qMagn)
       } else {
         tmp32no1 = WEBRTC_SPL_LSHIFT_W32((int32_t)magnU16[i], nShifts)
                    - inst->avgMagnPause[i]; // Q(qMagn+nShifts)
-        tmp32no1 = WEBRTC_SPL_MUL_32_16(tmp32no1, ONE_MINUS_GAMMA_PAUSE_Q8); // Q(8+prevQMagn+nShifts)
+        tmp32no1 *= ONE_MINUS_GAMMA_PAUSE_Q8;  // Q(8+prevQMagn+nShifts)
         tmp32no1 = WEBRTC_SPL_RSHIFT_W32(tmp32no1 + (128 << nShifts), 8 + nShifts); // Q(qMagn)
       }
       tmp32no2 += tmp32no1; // Q(qMagn)
@@ -1980,21 +1980,21 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
     if (nShifts < 0) {
       // This case is equivalent with magn < noise which implies curNearSnr = 0;
       tmpMagnU32 = (uint32_t)magnU16[i]; // Q(qMagn)
-      tmpNoiseU32 = WEBRTC_SPL_LSHIFT_U32(noiseU32[i], -nShifts); // Q(qMagn)
+      tmpNoiseU32 = noiseU32[i] << -nShifts;  // Q(qMagn)
     } else if (nShifts > 17) {
-      tmpMagnU32 = WEBRTC_SPL_LSHIFT_U32(magnU16[i], 17); // Q(qMagn+17)
+      tmpMagnU32 = (uint32_t)magnU16[i] << 17;  // Q(qMagn+17)
       tmpNoiseU32 = WEBRTC_SPL_RSHIFT_U32(noiseU32[i], nShifts - 17); // Q(qMagn+17)
     } else {
-      tmpMagnU32 = WEBRTC_SPL_LSHIFT_U32((uint32_t)magnU16[i], nShifts); // Q(qNoise_prev+11)
+      tmpMagnU32 = (uint32_t)magnU16[i] << nShifts;  // Q(qNoise_prev+11)
       tmpNoiseU32 = noiseU32[i]; // Q(qNoise_prev+11)
     }
     if (tmpMagnU32 > tmpNoiseU32) {
       tmpU32no1 = tmpMagnU32 - tmpNoiseU32; // Q(qCur)
       norm32no2 = WEBRTC_SPL_MIN(11, WebRtcSpl_NormU32(tmpU32no1));
-      tmpU32no1 = WEBRTC_SPL_LSHIFT_U32(tmpU32no1, norm32no2); // Q(qCur+norm32no2)
+      tmpU32no1 <<= norm32no2;  // Q(qCur+norm32no2)
       tmpU32no2 = WEBRTC_SPL_RSHIFT_U32(tmpNoiseU32, 11 - norm32no2); // Q(qCur+norm32no2-11)
       if (tmpU32no2 > 0) {
-        tmpU32no1 = WEBRTC_SPL_UDIV(tmpU32no1, tmpU32no2); // Q11
+        tmpU32no1 /= tmpU32no2;  // Q11
       }
       curNearSnr = WEBRTC_SPL_MIN(satMax, tmpU32no1); // Q11
     }
@@ -2011,17 +2011,15 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
     tmpU32no1 = (uint32_t)(inst->overdrive)
                 + WEBRTC_SPL_RSHIFT_U32(priorSnr + 8192, 14); // Q8
     assert(inst->overdrive > 0);
-    tmpU16no1 = (uint16_t)WEBRTC_SPL_UDIV(priorSnr + (tmpU32no1 >> 1), tmpU32no1); // Q14
+    tmpU16no1 = (priorSnr + tmpU32no1 / 2) / tmpU32no1;  // Q14
     inst->noiseSupFilter[i] = WEBRTC_SPL_SAT(16384, tmpU16no1, inst->denoiseBound); // 16384 = Q14(1.0) // Q14
 
     // Weight in the parametric Wiener filter during startup
     if (inst->blockIndex < END_STARTUP_SHORT) {
       // Weight the two suppression filters
-      tmpU32no1 = WEBRTC_SPL_UMUL_16_16(inst->noiseSupFilter[i],
-                                        (uint16_t)inst->blockIndex);
-      tmpU32no2 = WEBRTC_SPL_UMUL_16_16(noiseSupFilterTmp[i],
-                                        (uint16_t)(END_STARTUP_SHORT
-                                                         - inst->blockIndex));
+      tmpU32no1 = inst->noiseSupFilter[i] * inst->blockIndex;
+      tmpU32no2 = noiseSupFilterTmp[i] *
+          (END_STARTUP_SHORT - inst->blockIndex);
       tmpU32no1 += tmpU32no2;
       inst->noiseSupFilter[i] = (uint16_t)WebRtcSpl_DivU32U16(tmpU32no1,
                                                                     END_STARTUP_SHORT);
@@ -2034,7 +2032,7 @@ int WebRtcNsx_ProcessCore(NsxInst_t* inst, short* speechFrame, short* speechFram
   inst->prevQMagn = qMagn;
   if (norm32no1 > 5) {
     for (i = 0; i < inst->magnLen; i++) {
-      inst->prevNoiseU32[i] = WEBRTC_SPL_LSHIFT_U32(noiseU32[i], norm32no1 - 5); // Q(qNoise+11)
+      inst->prevNoiseU32[i] = noiseU32[i] << (norm32no1 - 5);  // Q(qNoise+11)
       inst->prevMagnU16[i] = magnU16[i]; // Q(qMagn)
     }
   } else {