Reland "Upconvert various types to int.", neteq portion.

This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24.  Specifically, the
files in webrtc/modules/audio_coding/neteq/ are relanded.

The original commit message is below:

Upconvert various types to int.

Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t.

Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C."

This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t).  Other locations will be converted to size_t in a separate change.

BUG=none
TBR=kwiberg

Review URL: https://codereview.webrtc.org/1181073002

Cr-Original-Commit-Position: refs/heads/master@{#9427}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 36b7cc32643bae0379d8102ce05dae82ecc466a1
diff --git a/modules/audio_coding/neteq/audio_decoder_impl.cc b/modules/audio_coding/neteq/audio_decoder_impl.cc
index c3f1dbb..99ff95a 100644
--- a/modules/audio_coding/neteq/audio_decoder_impl.cc
+++ b/modules/audio_coding/neteq/audio_decoder_impl.cc
@@ -163,9 +163,9 @@
                                      SpeechType* speech_type) {
   DCHECK_EQ(sample_rate_hz, 8000);
   int16_t temp_type = 1;  // Default is speech.
-  int16_t ret = WebRtcIlbcfix_Decode(dec_state_, encoded,
-                                     static_cast<int16_t>(encoded_len), decoded,
-                                     &temp_type);
+  int ret = WebRtcIlbcfix_Decode(dec_state_, encoded,
+                                 static_cast<int16_t>(encoded_len), decoded,
+                                 &temp_type);
   *speech_type = ConvertSpeechType(temp_type);
   return ret;
 }
@@ -330,11 +330,11 @@
                                      SpeechType* speech_type) {
   DCHECK_EQ(sample_rate_hz, 48000);
   int16_t temp_type = 1;  // Default is speech.
-  int16_t ret = WebRtcOpus_Decode(dec_state_, encoded,
-                                  static_cast<int16_t>(encoded_len), decoded,
-                                  &temp_type);
+  int ret = WebRtcOpus_Decode(dec_state_, encoded,
+                              static_cast<int16_t>(encoded_len), decoded,
+                              &temp_type);
   if (ret > 0)
-    ret *= static_cast<int16_t>(channels_);  // Return total number of samples.
+    ret *= static_cast<int>(channels_);  // Return total number of samples.
   *speech_type = ConvertSpeechType(temp_type);
   return ret;
 }
@@ -352,11 +352,11 @@
 
   DCHECK_EQ(sample_rate_hz, 48000);
   int16_t temp_type = 1;  // Default is speech.
-  int16_t ret = WebRtcOpus_DecodeFec(dec_state_, encoded,
-                                     static_cast<int16_t>(encoded_len), decoded,
-                                     &temp_type);
+  int ret = WebRtcOpus_DecodeFec(dec_state_, encoded,
+                                 static_cast<int16_t>(encoded_len), decoded,
+                                 &temp_type);
   if (ret > 0)
-    ret *= static_cast<int16_t>(channels_);  // Return total number of samples.
+    ret *= static_cast<int>(channels_);  // Return total number of samples.
   *speech_type = ConvertSpeechType(temp_type);
   return ret;
 }
diff --git a/modules/audio_coding/neteq/dsp_helper.cc b/modules/audio_coding/neteq/dsp_helper.cc
index 7451ae2..289e66d 100644
--- a/modules/audio_coding/neteq/dsp_helper.cc
+++ b/modules/audio_coding/neteq/dsp_helper.cc
@@ -272,7 +272,7 @@
 }
 
 void DspHelper::UnmuteSignal(const int16_t* input, size_t length,
-                             int16_t* factor, int16_t increment,
+                             int16_t* factor, int increment,
                              int16_t* output) {
   uint16_t factor_16b = *factor;
   int32_t factor_32b = (static_cast<int32_t>(factor_16b) << 6) + 32;
@@ -284,7 +284,7 @@
   *factor = factor_16b;
 }
 
-void DspHelper::MuteSignal(int16_t* signal, int16_t mute_slope, size_t length) {
+void DspHelper::MuteSignal(int16_t* signal, int mute_slope, size_t length) {
   int32_t factor = (16384 << 6) + 32;
   for (size_t i = 0; i < length; i++) {
     signal[i] = ((factor >> 6) * signal[i] + 8192) >> 14;
diff --git a/modules/audio_coding/neteq/dsp_helper.h b/modules/audio_coding/neteq/dsp_helper.h
index af4f4d6..f903256 100644
--- a/modules/audio_coding/neteq/dsp_helper.h
+++ b/modules/audio_coding/neteq/dsp_helper.h
@@ -110,11 +110,11 @@
   // sample and increases the gain by |increment| (Q20) for each sample. The
   // result is written to |output|. |length| samples are processed.
   static void UnmuteSignal(const int16_t* input, size_t length, int16_t* factor,
-                           int16_t increment, int16_t* output);
+                           int increment, int16_t* output);
 
   // Starts at unity gain and gradually fades out |signal|. For each sample,
   // the gain is reduced by |mute_slope| (Q14). |length| samples are processed.
-  static void MuteSignal(int16_t* signal, int16_t mute_slope, size_t length);
+  static void MuteSignal(int16_t* signal, int mute_slope, size_t length);
 
   // Downsamples |input| from |sample_rate_hz| to 4 kHz sample rate. The input
   // has |input_length| samples, and the method will write |output_length|
diff --git a/modules/audio_coding/neteq/expand.cc b/modules/audio_coding/neteq/expand.cc
index bde6559..10f6a9f 100644
--- a/modules/audio_coding/neteq/expand.cc
+++ b/modules/audio_coding/neteq/expand.cc
@@ -239,14 +239,12 @@
     if (consecutive_expands_ == 3) {
       // Let the mute factor decrease from 1.0 to 0.95 in 6.25 ms.
       // mute_slope = 0.0010 / fs_mult in Q20.
-      parameters.mute_slope = std::max(parameters.mute_slope,
-                                       static_cast<int16_t>(1049 / fs_mult));
+      parameters.mute_slope = std::max(parameters.mute_slope, 1049 / fs_mult);
     }
     if (consecutive_expands_ == 7) {
       // Let the mute factor decrease from 1.0 to 0.90 in 6.25 ms.
       // mute_slope = 0.0020 / fs_mult in Q20.
-      parameters.mute_slope = std::max(parameters.mute_slope,
-                                       static_cast<int16_t>(2097 / fs_mult));
+      parameters.mute_slope = std::max(parameters.mute_slope, 2097 / fs_mult);
     }
 
     // Mute segment according to slope value.
@@ -368,7 +366,7 @@
   InitializeForAnExpandPeriod();
 
   // Calculate correlation in downsampled domain (4 kHz sample rate).
-  int16_t correlation_scale;
+  int correlation_scale;
   int correlation_length = 51;  // TODO(hlundin): Legacy bit-exactness.
   // If it is decided to break bit-exactness |correlation_length| should be
   // initialized to the return value of Correlation().
@@ -445,7 +443,7 @@
                        correlation_length + start_index + correlation_lags - 1);
     correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max))
         + (31 - WebRtcSpl_NormW32(correlation_length))) - 31;
-    correlation_scale = std::max(static_cast<int16_t>(0), correlation_scale);
+    correlation_scale = std::max(0, correlation_scale);
 
     // Calculate the correlation, store in |correlation_vector2|.
     WebRtcSpl_CrossCorrelation(
@@ -472,7 +470,7 @@
 
     // Calculate the correlation coefficient between the two portions of the
     // signal.
-    int16_t corr_coefficient;
+    int32_t corr_coefficient;
     if ((energy1 > 0) && (energy2 > 0)) {
       int energy1_scale = std::max(16 - WebRtcSpl_NormW32(energy1), 0);
       int energy2_scale = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
@@ -481,17 +479,17 @@
         // If sum is odd, add 1 to make it even.
         energy1_scale += 1;
       }
-      int16_t scaled_energy1 = energy1 >> energy1_scale;
-      int16_t scaled_energy2 = energy2 >> energy2_scale;
-      int16_t sqrt_energy_product = WebRtcSpl_SqrtFloor(
-          scaled_energy1 * scaled_energy2);
+      int32_t scaled_energy1 = energy1 >> energy1_scale;
+      int32_t scaled_energy2 = energy2 >> energy2_scale;
+      int16_t sqrt_energy_product = static_cast<int16_t>(
+          WebRtcSpl_SqrtFloor(scaled_energy1 * scaled_energy2));
       // Calculate max_correlation / sqrt(energy1 * energy2) in Q14.
       int cc_shift = 14 - (energy1_scale + energy2_scale) / 2;
       max_correlation = WEBRTC_SPL_SHIFT_W32(max_correlation, cc_shift);
       corr_coefficient = WebRtcSpl_DivW32W16(max_correlation,
                                              sqrt_energy_product);
-      corr_coefficient = std::min(static_cast<int16_t>(16384),
-                                  corr_coefficient);  // Cap at 1.0 in Q14.
+      // Cap at 1.0 in Q14.
+      corr_coefficient = std::min(16384, corr_coefficient);
     } else {
       corr_coefficient = 0;
     }
@@ -512,8 +510,8 @@
     if ((energy1 / 4 < energy2) && (energy1 > energy2 / 4)) {
       // Energy constraint fulfilled. Use both vectors and scale them
       // accordingly.
-      int16_t scaled_energy2 = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
-      int16_t scaled_energy1 = scaled_energy2 - 13;
+      int32_t scaled_energy2 = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
+      int32_t scaled_energy1 = scaled_energy2 - 13;
       // Calculate scaled_energy1 / scaled_energy2 in Q13.
       int32_t energy_ratio = WebRtcSpl_DivW32W16(
           WEBRTC_SPL_SHIFT_W32(energy1, -scaled_energy1),
@@ -682,7 +680,8 @@
     //   voice_mix_factor = 0;
     if (corr_coefficient > 7875) {
       int16_t x1, x2, x3;
-      x1 = corr_coefficient;  // |corr_coefficient| is in Q14.
+      // |corr_coefficient| is in Q14.
+      x1 = static_cast<int16_t>(corr_coefficient);
       x2 = (x1 * x1) >> 14;   // Shift 14 to keep result in Q14.
       x3 = (x1 * x2) >> 14;
       static const int kCoefficients[4] = { -5179, 19931, -16422, 5776 };
@@ -709,7 +708,7 @@
       // the division.
       // Shift the denominator from Q13 to Q5 before the division. The result of
       // the division will then be in Q20.
-      int16_t temp_ratio = WebRtcSpl_DivW32W16(
+      int temp_ratio = WebRtcSpl_DivW32W16(
           (slope - 8192) << 12,
           static_cast<int16_t>((distortion_lag * slope) >> 8));
       if (slope > 14746) {
@@ -730,8 +729,7 @@
         // Make sure the mute factor decreases from 1.0 to 0.9 in no more than
         // 6.25 ms.
         // mute_slope >= 0.005 / fs_mult in Q20.
-        parameters.mute_slope = std::max(static_cast<int16_t>(5243 / fs_mult),
-                                         parameters.mute_slope);
+        parameters.mute_slope = std::max(5243 / fs_mult, parameters.mute_slope);
       } else if (slope > 8028) {
         parameters.mute_slope = 0;
       }
@@ -755,7 +753,7 @@
 void Expand::Correlation(const int16_t* input,
                          size_t input_length,
                          int16_t* output,
-                         int16_t* output_scale) const {
+                         int* output_scale) const {
   // Set parameters depending on sample rate.
   const int16_t* filter_coefficients;
   int16_t num_coefficients;
@@ -844,7 +842,7 @@
 // TODO(turajs): This can be moved to BackgroundNoise class.
 void Expand::GenerateBackgroundNoise(int16_t* random_vector,
                                      size_t channel,
-                                     int16_t mute_slope,
+                                     int mute_slope,
                                      bool too_many_expands,
                                      size_t num_noise_samples,
                                      int16_t* buffer) {
@@ -887,7 +885,7 @@
         bgn_mute_factor > 0) {
       // Fade BGN to zero.
       // Calculate muting slope, approximately -2^18 / fs_hz.
-      int16_t mute_slope;
+      int mute_slope;
       if (fs_hz_ == 8000) {
         mute_slope = -32;
       } else if (fs_hz_ == 16000) {
diff --git a/modules/audio_coding/neteq/expand.h b/modules/audio_coding/neteq/expand.h
index b015959..5fb117d 100644
--- a/modules/audio_coding/neteq/expand.h
+++ b/modules/audio_coding/neteq/expand.h
@@ -72,7 +72,7 @@
 
   void GenerateBackgroundNoise(int16_t* random_vector,
                                size_t channel,
-                               int16_t mute_slope,
+                               int mute_slope,
                                bool too_many_expands,
                                size_t num_noise_samples,
                                int16_t* buffer);
@@ -113,7 +113,7 @@
     AudioVector expand_vector0;
     AudioVector expand_vector1;
     bool onset;
-    int16_t mute_slope; /* Q20 */
+    int mute_slope; /* Q20 */
   };
 
   // Calculate the auto-correlation of |input|, with length |input_length|
@@ -123,7 +123,7 @@
   void Correlation(const int16_t* input,
                    size_t input_length,
                    int16_t* output,
-                   int16_t* output_scale) const;
+                   int* output_scale) const;
 
   void UpdateLagIndex();
 
diff --git a/modules/audio_coding/neteq/merge.cc b/modules/audio_coding/neteq/merge.cc
index 8e686ba..2c515c1 100644
--- a/modules/audio_coding/neteq/merge.cc
+++ b/modules/audio_coding/neteq/merge.cc
@@ -314,7 +314,7 @@
   const int max_corr_length = kMaxCorrelationLength;
   int stop_position_downsamp =
       std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1);
-  int16_t correlation_shift = 0;
+  int correlation_shift = 0;
   if (expanded_max * input_max > 26843546) {
     correlation_shift = 3;
   }
@@ -333,7 +333,7 @@
   int16_t* correlation_ptr = &correlation16[pad_length];
   int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation,
                                                      stop_position_downsamp);
-  int16_t norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation));
+  int norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation));
   WebRtcSpl_VectorBitShiftW32ToW16(correlation_ptr, stop_position_downsamp,
                                    correlation, norm_shift);
 
diff --git a/modules/audio_coding/neteq/neteq_impl.cc b/modules/audio_coding/neteq/neteq_impl.cc
index 29b8d1a..6598a79 100644
--- a/modules/audio_coding/neteq/neteq_impl.cc
+++ b/modules/audio_coding/neteq/neteq_impl.cc
@@ -1278,7 +1278,7 @@
            *operation == kPreemptiveExpand);
     packet_list->pop_front();
     size_t payload_length = packet->payload_length;
-    int16_t decode_length;
+    int decode_length;
     if (packet->sync_packet) {
       // Decode to silence with the same frame size as the last decode.
       LOG(LS_VERBOSE) << "Decoding sync-packet: " <<
diff --git a/modules/audio_coding/neteq/normal.cc b/modules/audio_coding/neteq/normal.cc
index a0e5d2d..bf455c9 100644
--- a/modules/audio_coding/neteq/normal.cc
+++ b/modules/audio_coding/neteq/normal.cc
@@ -111,7 +111,7 @@
       }
 
       // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
-      int16_t increment = 64 / fs_mult;
+      int increment = static_cast<int>(64 / fs_mult);
       for (size_t i = 0; i < length_per_channel; i++) {
         // Scale with mute factor.
         assert(channel_ix < output->Channels());
@@ -178,7 +178,7 @@
     // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are
     // still ramping up from previous muting.
     // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
-    int16_t increment = 64 / fs_mult;
+    int increment = static_cast<int>(64 / fs_mult);
     size_t length_per_channel = length / output->Channels();
     for (size_t i = 0; i < length_per_channel; i++) {
       for (size_t channel_ix = 0; channel_ix < output->Channels();
diff --git a/modules/audio_coding/neteq/test/RTPencode.cc b/modules/audio_coding/neteq/test/RTPencode.cc
index f25a279..1aacb40 100644
--- a/modules/audio_coding/neteq/test/RTPencode.cc
+++ b/modules/audio_coding/neteq/test/RTPencode.cc
@@ -1561,7 +1561,7 @@
                      int useVAD,
                      int bitrate,
                      int numChannels) {
-  short cdlen = 0;
+  int cdlen = 0;
   int16_t* tempdata;
   static int first_cng = 1;
   int16_t tempLen;