Refactor common_audio/vad: Removed usage of WEBRTC_SPL_MUL_16_16_RSFT

The macro is defined as
#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
(WEBRTC_SPL_MUL_16_16(a, b) >> (c))

where the latter macro is in C defined as
#define WEBRTC_SPL_MUL_16_16(a, b) \
((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
(For definitions on ARMv7 and MIPS, see common_audio/signal_processing/include/spl_inl_{armv7,mips}.h)

The replacement consists of
- avoiding casts to int16_t if inputs already are int16_t
- adding explicit cast to <type> if result is assigned to <type> (other than int or int32_t)
- minor cleanups like remove of unnecessary parentheses and style changes

BUG=3347, 3348, 3353
TESTED=locally on Linux for both fixed and floating point and trybots
R=kwiberg@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#8857}
diff --git a/webrtc/common_audio/vad/vad_core.c b/webrtc/common_audio/vad/vad_core.c
index 6ebe65d..d246a4d 100644
--- a/webrtc/common_audio/vad/vad_core.c
+++ b/webrtc/common_audio/vad/vad_core.c
@@ -293,20 +293,16 @@
           //   (|noise_probability[0]| + |noise_probability[1]|)
 
           // (Q14 * Q11 >> 11) = Q14.
-          delt = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(ngprvec[gaussian],
-                                                     deltaN[gaussian],
-                                                     11);
+          delt = (int16_t)((ngprvec[gaussian] * deltaN[gaussian]) >> 11);
           // Q7 + (Q14 * Q15 >> 22) = Q7.
-          nmk2 = nmk + (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(delt,
-                                                           kNoiseUpdateConst,
-                                                           22);
+          nmk2 = nmk + (int16_t)((delt * kNoiseUpdateConst) >> 22);
         }
 
         // Long term correction of the noise mean.
         // Q8 - Q8 = Q8.
         ndelt = (feature_minimum << 4) - tmp1_s16;
         // Q7 + (Q8 * Q8) >> 9 = Q7.
-        nmk3 = nmk2 + (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(ndelt, kBackEta, 9);
+        nmk3 = nmk2 + (int16_t)((ndelt * kBackEta) >> 9);
 
         // Control that the noise mean does not drift to much.
         tmp_s16 = (int16_t) ((k + 5) << 7);
@@ -326,13 +322,9 @@
           //   (|speech_probability[0]| + |speech_probability[1]|)
 
           // (Q14 * Q11) >> 11 = Q14.
-          delt = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(sgprvec[gaussian],
-                                                     deltaS[gaussian],
-                                                     11);
+          delt = (int16_t)((sgprvec[gaussian] * deltaS[gaussian]) >> 11);
           // Q14 * Q15 >> 21 = Q8.
-          tmp_s16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(delt,
-                                                        kSpeechUpdateConst,
-                                                        21);
+          tmp_s16 = (int16_t)((delt * kSpeechUpdateConst) >> 21);
           // Q7 + (Q8 >> 1) = Q7. With rounding.
           smk2 = smk + ((tmp_s16 + 1) >> 1);
 
@@ -351,7 +343,7 @@
 
           tmp_s16 = features[channel] - tmp_s16;  // Q4
           // (Q11 * Q4 >> 3) = Q12.
-          tmp1_s32 = WEBRTC_SPL_MUL_16_16_RSFT(deltaS[gaussian], tmp_s16, 3);
+          tmp1_s32 = (deltaS[gaussian] * tmp_s16) >> 3;
           tmp2_s32 = tmp1_s32 - 4096;
           tmp_s16 = sgprvec[gaussian] >> 2;
           // (Q14 >> 2) * Q12 = Q24.
@@ -381,7 +373,7 @@
           // Q4 - (Q7 >> 3) = Q4.
           tmp_s16 = features[channel] - (nmk >> 3);
           // (Q11 * Q4 >> 3) = Q12.
-          tmp1_s32 = WEBRTC_SPL_MUL_16_16_RSFT(deltaN[gaussian], tmp_s16, 3);
+          tmp1_s32 = (deltaN[gaussian] * tmp_s16) >> 3;
           tmp1_s32 -= 4096;
 
           // (Q14 >> 2) * Q12 = Q24.
@@ -425,8 +417,8 @@
 
         // |tmp1_s16| = ~0.8 * (kMinimumDifference - diff) in Q7.
         // |tmp2_s16| = ~0.2 * (kMinimumDifference - diff) in Q7.
-        tmp1_s16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(13, tmp_s16, 2);
-        tmp2_s16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(3, tmp_s16, 2);
+        tmp1_s16 = (int16_t)((13 * tmp_s16) >> 2);
+        tmp2_s16 = (int16_t)((3 * tmp_s16) >> 2);
 
         // Move Gaussian means for speech model by |tmp1_s16| and update
         // |speech_global_mean|. Note that |self->speech_means[channel]| is
diff --git a/webrtc/common_audio/vad/vad_filterbank.c b/webrtc/common_audio/vad/vad_filterbank.c
index 33d3d04..310678a 100644
--- a/webrtc/common_audio/vad/vad_filterbank.c
+++ b/webrtc/common_audio/vad/vad_filterbank.c
@@ -212,9 +212,8 @@
 
     // |kLogConst| is in Q9, |log2_energy| in Q10 and |tot_rshifts| in Q0.
     // Note that we in our derivation above have accounted for an output in Q4.
-    *log_energy = (int16_t) (WEBRTC_SPL_MUL_16_16_RSFT(
-        kLogConst, log2_energy, 19) +
-        WEBRTC_SPL_MUL_16_16_RSFT(tot_rshifts, kLogConst, 9));
+    *log_energy = (int16_t)(((kLogConst * log2_energy) >> 19) +
+        ((tot_rshifts * kLogConst) >> 9));
 
     if (*log_energy < 0) {
       *log_energy = 0;
diff --git a/webrtc/common_audio/vad/vad_gmm.c b/webrtc/common_audio/vad/vad_gmm.c
index 23d4699..4a01440 100644
--- a/webrtc/common_audio/vad/vad_gmm.c
+++ b/webrtc/common_audio/vad/vad_gmm.c
@@ -43,9 +43,9 @@
   // Calculate |inv_std2| = 1 / s^2, in Q14.
   tmp16 = (inv_std >> 2);  // Q10 -> Q8.
   // Q-domain: (Q8 * Q8) >> 2 = Q14.
-  inv_std2 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(tmp16, tmp16, 2);
+  inv_std2 = (int16_t)((tmp16 * tmp16) >> 2);
   // TODO(bjornv): Investigate if changing to
-  // |inv_std2| = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(|inv_std|, |inv_std|, 6);
+  // inv_std2 = (int16_t)((inv_std * inv_std) >> 6);
   // gives better accuracy.
 
   tmp16 = (input << 3);  // Q4 -> Q7
@@ -54,12 +54,12 @@
   // To be used later, when updating noise/speech model.
   // |delta| = (x - m) / s^2, in Q11.
   // Q-domain: (Q14 * Q7) >> 10 = Q11.
-  *delta = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(inv_std2, tmp16, 10);
+  *delta = (int16_t)((inv_std2 * tmp16) >> 10);
 
   // Calculate the exponent |tmp32| = (x - m)^2 / (2 * s^2), in Q10. Replacing
   // division by two with one shift.
   // Q-domain: (Q11 * Q7) >> 8 = Q10.
-  tmp32 = WEBRTC_SPL_MUL_16_16_RSFT(*delta, tmp16, 9);
+  tmp32 = (*delta * tmp16) >> 9;
 
   // If the exponent is small enough to give a non-zero probability we calculate
   // |exp_value| ~= exp(-(x - m)^2 / (2 * s^2))
@@ -67,7 +67,7 @@
   if (tmp32 < kCompVar) {
     // Calculate |tmp16| = log2(exp(1)) * |tmp32|, in Q10.
     // Q-domain: (Q12 * Q10) >> 12 = Q10.
-    tmp16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(kLog2Exp, (int16_t) tmp32, 12);
+    tmp16 = (int16_t)((kLog2Exp * tmp32) >> 12);
     tmp16 = -tmp16;
     exp_value = (0x0400 | (tmp16 & 0x03FF));
     tmp16 ^= 0xFFFF;
diff --git a/webrtc/common_audio/vad/vad_sp.c b/webrtc/common_audio/vad/vad_sp.c
index fbd4f2e..217ef26 100644
--- a/webrtc/common_audio/vad/vad_sp.c
+++ b/webrtc/common_audio/vad/vad_sp.c
@@ -38,17 +38,15 @@
   for (n = 0; n < half_length; n++) {
     // All-pass filtering upper branch.
     tmp16_1 = (int16_t) ((tmp32_1 >> 1) +
-        WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[0], *signal_in, 14));
+        ((kAllPassCoefsQ13[0] * *signal_in) >> 14));
     *signal_out = tmp16_1;
-    tmp32_1 = (int32_t) (*signal_in++) -
-        WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[0], tmp16_1, 12);
+    tmp32_1 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[0] * tmp16_1) >> 12);
 
     // All-pass filtering lower branch.
     tmp16_2 = (int16_t) ((tmp32_2 >> 1) +
-        WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[1], *signal_in, 14));
+        ((kAllPassCoefsQ13[1] * *signal_in) >> 14));
     *signal_out++ += tmp16_2;
-    tmp32_2 = (int32_t) (*signal_in++) -
-        WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[1], tmp16_2, 12);
+    tmp32_2 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[1] * tmp16_2) >> 12);
   }
   // Store the filter states.
   filter_state[0] = tmp32_1;