Refactoring common_audio/signal_processing: Remove macro WEBRTC_SPL_UDIV

This macro is a direct use of the division operator without checking for division by zero. Hence, it is dangerous to use.
This CL replaces the macro with '/' at place.

BUG=3348,3353
TESTED=locally on linux and trybots
R=kwiberg@webrtc.org, tina.legrand@webrtc.org, turaj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/14169004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6976 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/common_audio/signal_processing/include/signal_processing_library.h b/webrtc/common_audio/signal_processing/include/signal_processing_library.h
index 8e1059e..a9cf384 100644
--- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h
+++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h
@@ -48,8 +48,6 @@
     ((int32_t)(int16_t)(a) * (uint16_t)(b))
 #define WEBRTC_SPL_DIV(a, b) \
     ((int32_t) ((int32_t)(a) / (int32_t)(b)))
-#define WEBRTC_SPL_UDIV(a, b) \
-    ((uint32_t) ((uint32_t)(a) / (uint32_t)(b)))
 
 #ifndef WEBRTC_ARCH_ARM_V7
 // For ARMv7 platforms, these are inline functions in spl_inl_armv7.h
diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
index 88ede79..5d07f16 100644
--- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
+++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
@@ -48,7 +48,6 @@
     a = b;
     b = -3;
     EXPECT_EQ(-5461, WEBRTC_SPL_DIV(a, b));
-    EXPECT_EQ(0u, WEBRTC_SPL_UDIV(a, b));
 
     EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT16(a, b));
     EXPECT_EQ(-1, WEBRTC_SPL_MUL_16_32_RSFT15(a, b));
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c
index 724a900..2ac1535 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.c
@@ -196,7 +196,7 @@
 
       bweStr->maxBwInv = kInvBandwidth[3];
       bweStr->minBwInv = kInvBandwidth[2];
-      bweStr->recBwInv = WEBRTC_SPL_UDIV(1073741824, (bweStr->recBw + bweStr->recHeaderRate));
+      bweStr->recBwInv = 1073741824 / (bweStr->recBw + bweStr->recHeaderRate);
     }
 
     /* kBitsByteSec is in Q15 */
@@ -211,7 +211,7 @@
 
       bweStr->maxBwInv = kInvBandwidth[1];
       bweStr->minBwInv = kInvBandwidth[0];
-      bweStr->recBwInv = WEBRTC_SPL_UDIV(1073741824, (bweStr->recBw + bweStr->recHeaderRate));
+      bweStr->recBwInv = 1073741824 / (bweStr->recBw + bweStr->recHeaderRate);
     }
 
     /* kBitsByteSec is in Q14 */
@@ -265,7 +265,7 @@
       if ((arrivalTime - bweStr->lastUpdate) > FS3) {
 
         /* Calculate expected number of received packets since last update */
-        numPktsExpected =  WEBRTC_SPL_UDIV(arrivalTime - bweStr->lastUpdate, frameSizeSampl);
+        numPktsExpected = (arrivalTime - bweStr->lastUpdate) / frameSizeSampl;
 
         /* If received number of packets is more than 90% of expected (922 = 0.9 in Q10): */
         /* do the update, else not                                                        */
@@ -417,8 +417,7 @@
            and NOT right shifting recBwAvg 5 bits to an integer
            At max 13 bits are used
            shift to Q5 */
-        recBwAvgInv = WEBRTC_SPL_UDIV((uint32_t)(0x80000000 + WEBRTC_SPL_RSHIFT_U32(bweStr->recBwAvg, 1)),
-                                      bweStr->recBwAvg);
+        recBwAvgInv = (0x80000000 + bweStr->recBwAvg / 2) / bweStr->recBwAvg;
 
         /* Calculate Projected arrival time difference */
 
@@ -513,7 +512,7 @@
   bweStr->prevSendTime = sendTime;
 
   /* Replace bweStr->recBw by the new value */
-  bweStr->recBw = WEBRTC_SPL_UDIV(1073741824, bweStr->recBwInv) - bweStr->recHeaderRate;
+  bweStr->recBw = 1073741824 / bweStr->recBwInv - bweStr->recHeaderRate;
 
   if (immediateSet) {
     /* delay correction factor is in Q10 */
@@ -530,7 +529,7 @@
 
     bweStr->recJitterShortTerm = 0;
 
-    bweStr->recBwInv = WEBRTC_SPL_UDIV(1073741824, bweStr->recBw + bweStr->recHeaderRate);
+    bweStr->recBwInv = 1073741824 / (bweStr->recBw + bweStr->recHeaderRate);
 
     immediateSet = 0;
   }
@@ -725,7 +724,7 @@
 
   /* Q18  rec jitter short term abs is in Q13, multiply it by 2^13 to save precision
      2^18 then needs to be shifted 13 bits to 2^31 */
-  rec_jitter_short_term_abs_inv = WEBRTC_SPL_UDIV(0x80000000, bweStr->recJitterShortTermAbs);
+  rec_jitter_short_term_abs_inv = 0x80000000u / bweStr->recJitterShortTermAbs;
 
   /* Q27 = 9 + 18 */
   jitter_sign = WEBRTC_SPL_MUL(WEBRTC_SPL_RSHIFT_W32(bweStr->recJitterShortTerm, 4), (int32_t)rec_jitter_short_term_abs_inv);
@@ -887,7 +886,7 @@
   //round and shift before conversion
   MinRate += 256;
   MinRate = WEBRTC_SPL_RSHIFT_W32(MinRate, 9);
-  MinBytes = (uint16_t)WEBRTC_SPL_UDIV(WEBRTC_SPL_MUL(MinRate, FrameSamples), FS8);
+  MinBytes = MinRate * FrameSamples / FS8;
 
   /* StreamSize will be adjusted if less than MinBytes */
   if (StreamSize < MinBytes) {
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/decode_bwe.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/decode_bwe.c
index c1221e7..b1f5d10 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/decode_bwe.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/decode_bwe.c
@@ -53,7 +53,7 @@
   err = WebRtcIsacfix_UpdateUplinkBwImpl(
       bwest_str,
       rtp_seq_number,
-      (uint16_t)WEBRTC_SPL_UDIV(WEBRTC_SPL_UMUL(frame_samples,1000), FS),
+      frame_samples * 1000 / FS,
       send_ts,
       arr_ts,
       (int16_t) packet_size,  /* in bytes */
diff --git a/webrtc/modules/audio_processing/ns/nsx_core.c b/webrtc/modules/audio_processing/ns/nsx_core.c
index 4b491d2..41244d4 100644
--- a/webrtc/modules/audio_processing/ns/nsx_core.c
+++ b/webrtc/modules/audio_processing/ns/nsx_core.c
@@ -864,8 +864,8 @@
       // 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]++;
@@ -1163,7 +1163,7 @@
     }
     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)
@@ -1681,7 +1681,7 @@
             // 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
         }
@@ -1764,7 +1764,7 @@
       // Current magnitude larger than noise
       tmpU32no1 = WEBRTC_SPL_LSHIFT_U32(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;
@@ -1777,7 +1777,7 @@
     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,7 +1829,7 @@
         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 {
@@ -1994,7 +1994,7 @@
       tmpU32no1 = WEBRTC_SPL_LSHIFT_U32(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,7 +2011,7 @@
     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
diff --git a/webrtc/modules/audio_processing/ns/nsx_core_c.c b/webrtc/modules/audio_processing/ns/nsx_core_c.c
index 1b49754..de92441 100644
--- a/webrtc/modules/audio_processing/ns/nsx_core_c.c
+++ b/webrtc/modules/audio_processing/ns/nsx_core_c.c
@@ -46,7 +46,7 @@
       den = WEBRTC_SPL_RSHIFT_U32(priorLocSnr[i], 11 - normTmp); // Q(normTmp)
     }
     if (den > 0) {
-      besselTmpFX32 -= WEBRTC_SPL_UDIV(num, den); // Q11
+      besselTmpFX32 -= num / den;  // Q11
     } else {
       besselTmpFX32 -= num; // Q11
     }
@@ -157,14 +157,12 @@
                                         20 - inst->stages - normTmp);
       if (tmpU32no2 > 0) {
         // Q(20 - inst->stages)
-        tmpU32no1 = WEBRTC_SPL_UDIV(tmpU32no1, tmpU32no2);
+        tmpU32no1 /= tmpU32no2;
       } else {
         tmpU32no1 = (uint32_t)(0x7fffffff);
       }
     }
-    tmpU32no3 = WEBRTC_SPL_UDIV(WEBRTC_SPL_LSHIFT_U32(inst->thresholdSpecDiff,
-                                                      17),
-                                25);
+    tmpU32no3 = (inst->thresholdSpecDiff << 17) / 25;
     tmpU32no2 = tmpU32no1 - tmpU32no3;
     nShifts = 1;
     tmpIndFX = 16384; // Q14(1.0)
diff --git a/webrtc/modules/audio_processing/ns/nsx_core_mips.c b/webrtc/modules/audio_processing/ns/nsx_core_mips.c
index ccb0c37..29abe93 100644
--- a/webrtc/modules/audio_processing/ns/nsx_core_mips.c
+++ b/webrtc/modules/audio_processing/ns/nsx_core_mips.c
@@ -190,14 +190,12 @@
                                         20 - inst->stages - normTmp);
       if (tmpU32no2 > 0) {
         // Q(20 - inst->stages)
-        tmpU32no1 = WEBRTC_SPL_UDIV(tmpU32no1, tmpU32no2);
+        tmpU32no1 /= tmpU32no2;
       } else {
         tmpU32no1 = (uint32_t)(0x7fffffff);
       }
     }
-    tmpU32no3 = WEBRTC_SPL_UDIV(WEBRTC_SPL_LSHIFT_U32(inst->thresholdSpecDiff,
-                                                      17),
-                                25);
+    tmpU32no3 = (inst->thresholdSpecDiff << 17) / 25;
     tmpU32no2 = tmpU32no1 - tmpU32no3;
     nShifts = 1;
     tmpIndFX = 16384; // Q14(1.0)