Miscellaneous changes split from https://codereview.webrtc.org/1230503003 .

These are mostly trivial changes and are separated out just to reduce the
diff on that change to the minimum possible.

Note explanatory comments on patch set 1.

BUG=none
TEST=none

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

Cr-Commit-Position: refs/heads/master@{#9617}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.h b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.h
index 68dd7da..34ff8aa 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.h
+++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy.h
@@ -28,7 +28,7 @@
     int16_t *energyW16,  /* (o) Energy in the CB vectors */
     int16_t *energyShifts, /* (o) Shift value of the energy */
     int scale,   /* (i) The scaling of all energy values */
-    int16_t base_size  /* (i) Index to where the energy values should be stored */
+    int16_t base_size  /* (i) Index to where energy values should be stored */
                                );
 
 #endif
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/do_plc.c b/webrtc/modules/audio_coding/codecs/ilbc/do_plc.c
index ecdd68a..b313b58 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/do_plc.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/do_plc.c
@@ -70,7 +70,8 @@
 
       /* Maximum 60 samples are correlated, preserve as high accuracy
          as possible without getting overflow */
-      max = WebRtcSpl_MaxAbsValueW16((*iLBCdec_inst).prevResidual, (int16_t)iLBCdec_inst->blockl);
+      max = WebRtcSpl_MaxAbsValueW16((*iLBCdec_inst).prevResidual,
+                                     (int16_t)iLBCdec_inst->blockl);
       scale3 = (WebRtcSpl_GetSizeInBits(max)<<1) - 25;
       if (scale3 < 0) {
         scale3 = 0;
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/decode.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/decode.c
index f0ae07e..d0c59d6 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/decode.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/decode.c
@@ -27,9 +27,9 @@
 
 
 
-int WebRtcIsacfix_DecodeImpl(int16_t       *signal_out16,
-                             IsacFixDecoderInstance *ISACdec_obj,
-                             int16_t       *current_framesamples)
+int WebRtcIsacfix_DecodeImpl(int16_t* signal_out16,
+                             IsacFixDecoderInstance* ISACdec_obj,
+                             int16_t* current_framesamples)
 {
   int k;
   int err;
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
index bdb807e..43a9e52 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
@@ -777,7 +777,7 @@
   ISACFIX_SubStruct *ISAC_inst;
   /* number of samples (480 or 960), output from decoder */
   /* that were actually used in the encoder/decoder (determined on the fly) */
-  int16_t     number_of_samples;
+  int16_t number_of_samples;
   int declen = 0;
 
   /* typecast pointer to real structure */
@@ -807,8 +807,8 @@
   /* added for NetEq purposes (VAD/DTX related) */
   *speechType=1;
 
-  declen = WebRtcIsacfix_DecodeImpl(decoded,&ISAC_inst->ISACdec_obj, &number_of_samples);
-
+  declen = WebRtcIsacfix_DecodeImpl(decoded, &ISAC_inst->ISACdec_obj,
+                                    &number_of_samples);
   if (declen < 0) {
     /* Some error inside the decoder */
     ISAC_inst->errorcode = -(int16_t)declen;
@@ -818,14 +818,18 @@
 
   /* error check */
 
-  if (declen & 0x0001) {
-    if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) & 0x00FF) ) {
+  if (declen & 1) {
+    if (len != declen &&
+        len != declen +
+            ((ISAC_inst->ISACdec_obj.bitstr_obj.stream[declen >> 1]) & 0xFF)) {
       ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
       memset(decoded, 0, sizeof(int16_t) * number_of_samples);
       return -1;
     }
   } else {
-    if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) >> 8) ) {
+    if (len != declen &&
+        len != declen +
+            ((ISAC_inst->ISACdec_obj.bitstr_obj.stream[declen >> 1]) >> 8)) {
       ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
       memset(decoded, 0, sizeof(int16_t) * number_of_samples);
       return -1;
@@ -870,7 +874,7 @@
   ISACFIX_SubStruct *ISAC_inst;
   /* twice the number of samples (480 or 960), output from decoder */
   /* that were actually used in the encoder/decoder (determined on the fly) */
-  int16_t     number_of_samples;
+  int16_t number_of_samples;
   int declen = 0;
   int16_t dummy[FRAMESAMPLES/2];
 
@@ -901,8 +905,8 @@
   /* added for NetEq purposes (VAD/DTX related) */
   *speechType=1;
 
-  declen = WebRtcIsacfix_DecodeImpl(decoded,&ISAC_inst->ISACdec_obj, &number_of_samples);
-
+  declen = WebRtcIsacfix_DecodeImpl(decoded, &ISAC_inst->ISACdec_obj,
+                                    &number_of_samples);
   if (declen < 0) {
     /* Some error inside the decoder */
     ISAC_inst->errorcode = -(int16_t)declen;
@@ -912,14 +916,18 @@
 
   /* error check */
 
-  if (declen & 0x0001) {
-    if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) & 0x00FF) ) {
+  if (declen & 1) {
+    if (len != declen &&
+        len != declen +
+            ((ISAC_inst->ISACdec_obj.bitstr_obj.stream[declen >> 1]) & 0xFF)) {
       ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
       memset(decoded, 0, sizeof(int16_t) * number_of_samples);
       return -1;
     }
   } else {
-    if (len != declen && len != declen + (((ISAC_inst->ISACdec_obj.bitstr_obj).stream[declen>>1]) >> 8) ) {
+    if (len != declen &&
+        len != declen +
+            ((ISAC_inst->ISACdec_obj.bitstr_obj.stream[declen >>1]) >> 8)) {
       ISAC_inst->errorcode = ISAC_LENGTH_MISMATCH;
       memset(decoded, 0, sizeof(int16_t) * number_of_samples);
       return -1;
@@ -1319,7 +1327,8 @@
   read_be16(encoded, kRequiredEncodedLenBytes, streamdata.stream);
 
   /* decode frame length, needed to get to the rateIndex in the bitstream */
-  err = WebRtcIsacfix_DecodeFrameLen(&streamdata, rateIndex);
+  int16_t frameLength;
+  err = WebRtcIsacfix_DecodeFrameLen(&streamdata, &frameLength);
   if (err<0)  // error check
     return err;
 
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice.c
index 7fcb9e3..13858d7 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice.c
@@ -218,7 +218,7 @@
                                        int16_t lo_hi,
                                        int16_t *lat_outQ0)
 {
-  int ii,n,k,i,u;
+  int ii, n, k, i, u;
   int16_t sthQ15[MAX_AR_MODEL_ORDER];
   int16_t cthQ15[MAX_AR_MODEL_ORDER];
   int32_t tmp32;
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_armv7.S b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_armv7.S
index 4a0d99f..945d6ee 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_armv7.S
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_armv7.S
@@ -38,7 +38,7 @@
   mov     r4, #HALF_SUBFRAMELEN
   sub     r4, #1                 @ Outer loop counter = HALF_SUBFRAMELEN - 1
 
-HALF_SUBFRAME_LOOP:  @ for(n = 0; n < HALF_SUBFRAMELEN - 1; n++)
+HALF_SUBFRAME_LOOP:  @ for (n = 0; n < HALF_SUBFRAMELEN - 1; n++)
 
   ldr     r9, [sp, #32]          @ Restore the inner loop counter to order_coef
   ldrh    r5, [r1]               @ tmpAR = ar_f_Q0[n+1]
@@ -46,7 +46,7 @@
   add     r2, r9, asl #1         @ Restore r2 to &cth_Q15[order_coef]
   add     r3, r9, asl #1         @ Restore r3 to &sth_Q15[order_coef]
 
-ORDER_COEF_LOOP:  @ for(k = order_coef ; k > 0; k--)
+ORDER_COEF_LOOP:  @ for (k = order_coef; k > 0; k--)
 
   ldrh    r7, [r3, #-2]!         @ sth_Q15[k - 1]
   ldrh    r6, [r2, #-2]!         @ cth_Q15[k - 1]
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
index ab7c640..2628f1f 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
@@ -624,8 +624,8 @@
         errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst);
         printf("\nError in encoder: %d.\n", errtype);
       } else {
-        if (fwrite(streamdata, sizeof(char),
-                   stream_len, outbits) != (size_t)stream_len) {
+        if (fwrite(streamdata, sizeof(char), stream_len, outbits) !=
+            (size_t)stream_len) {
           return -1;
         }
       }
@@ -731,12 +731,12 @@
       /* iSAC decoding */
       if( lostFrame && framecnt >  0) {
         if (nbTest !=2) {
-          declen = WebRtcIsacfix_DecodePlc(ISAC_main_inst,
-                                           decoded, prevFrameSize );
+          declen =
+              WebRtcIsacfix_DecodePlc(ISAC_main_inst, decoded, prevFrameSize);
         } else {
 #ifdef WEBRTC_ISAC_FIX_NB_CALLS_ENABLED
-          declen = WebRtcIsacfix_DecodePlcNb(ISAC_main_inst, decoded,
-                                             prevFrameSize );
+          declen = WebRtcIsacfix_DecodePlcNb(
+              ISAC_main_inst, decoded, prevFrameSize);
 #else
           declen = -1;
 #endif
@@ -755,7 +755,7 @@
               decoded,
               speechType);
           /* Error check */
-          if (err<0 || declen<0 || FL!=declen) {
+          if (err < 0 || declen < 0 || FL != declen) {
             errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst);
             printf("\nError in decode_B/or getFrameLen: %d.\n", errtype);
           }
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c b/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c
index 6dbdb7e..71bd272 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c
@@ -556,12 +556,13 @@
           else
             declen = WebRtcIsacfix_DecodePlcNb(ISACFIX_main_inst, decoded, 1);
         } else {
-          if (nbTest != 2)
+          if (nbTest != 2) {
             declen = WebRtcIsacfix_Decode(ISACFIX_main_inst, streamdata,
                                           stream_len, decoded, speechType);
-          else
+          } else {
             declen = WebRtcIsacfix_DecodeNb(ISACFIX_main_inst, streamdata,
                                             stream_len, decoded, speechType);
+          }
         }
         if (declen <= 0) {
           /* exit if returned with error */
@@ -582,7 +583,7 @@
 
     totalsmpls += declen;
     totalbits += 8 * stream_len;
-    kbps = ((double)FS) / ((double)cur_framesmpls) * 8.0 * stream_len / 1000.0;
+    kbps = (double)FS / (double)cur_framesmpls * 8.0 * stream_len / 1000.0;
     fy = fopen("bit_rate.dat", "a");
     fprintf(fy, "Frame %i = %0.14f\n", framecnt, kbps);
     fclose(fy);
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
index 7a51a1e..ac211e9 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
+++ b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
@@ -750,7 +750,8 @@
                       streamLenUB + garbageLen, &crc);
 #ifndef WEBRTC_ARCH_BIG_ENDIAN
     for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) {
-      encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] = crc >> (24 - k * 8);
+      encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] =
+          (uint8_t)(crc >> (24 - k * 8));
     }
 #else
     memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, LEN_CHECK_SUM_WORD8);
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc b/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
index 4eeeed0..8584c76 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
@@ -662,8 +662,9 @@
       if (stream_len < 0) {
         /* exit if returned with error */
         errtype = WebRtcIsac_GetErrorCode(ISAC_main_inst);
-        printf("\n\nError in encoder: %d.\n\n", errtype);
+        fprintf(stderr, "Error in encoder: %d.\n", errtype);
         cout << flush;
+        exit(0);
       }
       cur_framesmpls += samplesIn10Ms;
       /* exit encoder loop if the encoder returned a bitstream */
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c
index e0d0f41..214dccd 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c
+++ b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c
@@ -350,6 +350,11 @@
       }
 
       rcuStreamLen = WebRtcIsac_GetRedPayload(ISAC_main_inst, payloadRCU);
+      if (rcuStreamLen < 0) {
+        fprintf(stderr, "\nError getting RED payload\n");
+        getc(stdin);
+        exit(EXIT_FAILURE);
+      }
 
       get_arrival_time(cur_framesmpls, stream_len, bottleneck, &packetData,
                        sampFreqKHz * 1000, sampFreqKHz * 1000);
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
index 88e084f..9bf1ae3 100644
--- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc
@@ -115,7 +115,7 @@
   // Calculate the number of bytes we expect the encoder to produce,
   // then multiply by two to give a wide margin for error.
   size_t bytes_per_millisecond =
-       static_cast<size_t>(bitrate_bps_ / (1000 * 8) + 1);
+      static_cast<size_t>(bitrate_bps_ / (1000 * 8) + 1);
   size_t approx_encoded_bytes =
       num_10ms_frames_per_packet_ * 10 * bytes_per_millisecond;
   return 2 * approx_encoded_bytes;
diff --git a/webrtc/modules/audio_coding/main/test/PCMFile.cc b/webrtc/modules/audio_coding/main/test/PCMFile.cc
index 4f46098..4b08f75 100644
--- a/webrtc/modules/audio_coding/main/test/PCMFile.cc
+++ b/webrtc/modules/audio_coding/main/test/PCMFile.cc
@@ -150,8 +150,7 @@
       }
     } else {
       int16_t* stereo_audio = new int16_t[2 * audio_frame.samples_per_channel_];
-      int k;
-      for (k = 0; k < audio_frame.samples_per_channel_; k++) {
+      for (int k = 0; k < audio_frame.samples_per_channel_; k++) {
         stereo_audio[k << 1] = audio_frame.data_[k];
         stereo_audio[(k << 1) + 1] = audio_frame.data_[k];
       }
diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc
index 99ff95a..6a9b953 100644
--- a/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc
@@ -256,16 +256,14 @@
                             static_cast<int16_t>(encoded_len / 2),
                             &decoded[decoded_len], &temp_type);
     if (ret == decoded_len) {
-      decoded_len += ret;
+      ret += decoded_len;  // Return total number of samples.
       // Interleave output.
-      for (int k = decoded_len / 2; k < decoded_len; k++) {
+      for (int k = ret / 2; k < ret; k++) {
           int16_t temp = decoded[k];
-          memmove(&decoded[2 * k - decoded_len + 2],
-                  &decoded[2 * k - decoded_len + 1],
-                  (decoded_len - k - 1) * sizeof(int16_t));
-          decoded[2 * k - decoded_len + 1] = temp;
+          memmove(&decoded[2 * k - ret + 2], &decoded[2 * k - ret + 1],
+                  (ret - k - 1) * sizeof(int16_t));
+          decoded[2 * k - ret + 1] = temp;
       }
-      ret = decoded_len;  // Return total number of samples.
     }
   }
   *speech_type = ConvertSpeechType(temp_type);
diff --git a/webrtc/modules/audio_coding/neteq/dsp_helper.cc b/webrtc/modules/audio_coding/neteq/dsp_helper.cc
index 289e66d..3e5c61d 100644
--- a/webrtc/modules/audio_coding/neteq/dsp_helper.cc
+++ b/webrtc/modules/audio_coding/neteq/dsp_helper.cc
@@ -117,7 +117,7 @@
     peak_index[i] = WebRtcSpl_MaxIndexW16(data, data_length - 1);
 
     if (i != num_peaks - 1) {
-      min_index = std::max(0, peak_index[i] - 2);
+      min_index = (peak_index[i] > 2) ? (peak_index[i] - 2) : 0;
       max_index = std::min(data_length - 1, peak_index[i] + 2);
     }
 
@@ -238,7 +238,7 @@
 int DspHelper::MinDistortion(const int16_t* signal, int min_lag,
                              int max_lag, int length,
                              int32_t* distortion_value) {
-  int best_index = -1;
+  int best_index = 0;
   int32_t min_distortion = WEBRTC_SPL_WORD32_MAX;
   for (int i = min_lag; i <= max_lag; i++) {
     int32_t sum_diff = 0;
diff --git a/webrtc/modules/audio_coding/neteq/expand.cc b/webrtc/modules/audio_coding/neteq/expand.cc
index 10f6a9f..ae12e50 100644
--- a/webrtc/modules/audio_coding/neteq/expand.cc
+++ b/webrtc/modules/audio_coding/neteq/expand.cc
@@ -441,8 +441,8 @@
         &audio_history[signal_length - correlation_length - start_index
                        - correlation_lags],
                        correlation_length + start_index + correlation_lags - 1);
-    correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max))
-        + (31 - WebRtcSpl_NormW32(correlation_length))) - 31;
+    correlation_scale = (31 - WebRtcSpl_NormW32(signal_max * signal_max)) +
+        (31 - WebRtcSpl_NormW32(correlation_length)) - 31;
     correlation_scale = std::max(0, correlation_scale);
 
     // Calculate the correlation, store in |correlation_vector2|.
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer.cc b/webrtc/modules/audio_coding/neteq/packet_buffer.cc
index 5792b22..07fa339 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer.cc
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer.cc
@@ -255,7 +255,7 @@
         continue;
       }
       int duration =
-        decoder->PacketDuration(packet->payload, packet->payload_length);
+          decoder->PacketDuration(packet->payload, packet->payload_length);
       if (duration >= 0) {
         last_duration = duration;  // Save the most up-to-date (valid) duration.
       }
diff --git a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc
index 1aacb40..7e778b8 100644
--- a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc
+++ b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc
@@ -454,7 +454,7 @@
      printf("Packet size %d must be positive", packet_size);
      return -1;
   }
-  printf("Packet size: %i\n", packet_size);
+  printf("Packet size: %d\n", packet_size);
 
   // check for stereo
   if (argv[4][strlen(argv[4]) - 1] == '*') {
@@ -1572,29 +1572,31 @@
   if (useVAD) {
     *vad = 0;
 
+    int sampleRate_10 = 10 * sampleRate / 1000;
+    int sampleRate_20 = 20 * sampleRate / 1000;
+    int sampleRate_30 = 30 * sampleRate / 1000;
     for (int k = 0; k < numChannels; k++) {
       tempLen = frameLen;
       tempdata = &indata[k * frameLen];
       int localVad = 0;
       /* Partition the signal and test each chunk for VAD.
       All chunks must be VAD=0 to produce a total VAD=0. */
-      while (tempLen >= 10 * sampleRate / 1000) {
-        if ((tempLen % 30 * sampleRate / 1000) ==
-            0) {  // tempLen is multiple of 30ms
+      while (tempLen >= sampleRate_10) {
+        if ((tempLen % sampleRate_30) == 0) {  // tempLen is multiple of 30ms
           localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata,
-                                        30 * sampleRate / 1000);
-          tempdata += 30 * sampleRate / 1000;
-          tempLen -= 30 * sampleRate / 1000;
-        } else if (tempLen >= 20 * sampleRate / 1000) {  // tempLen >= 20ms
+                                        sampleRate_30);
+          tempdata += sampleRate_30;
+          tempLen -= sampleRate_30;
+        } else if (tempLen >= sampleRate_20) {  // tempLen >= 20ms
           localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata,
-                                        20 * sampleRate / 1000);
-          tempdata += 20 * sampleRate / 1000;
-          tempLen -= 20 * sampleRate / 1000;
+                                        sampleRate_20);
+          tempdata += sampleRate_20;
+          tempLen -= sampleRate_20;
         } else {  // use 10ms
           localVad |= WebRtcVad_Process(VAD_inst[k], sampleRate, tempdata,
-                                        10 * sampleRate / 1000);
-          tempdata += 10 * sampleRate / 1000;
-          tempLen -= 10 * sampleRate / 1000;
+                                        sampleRate_10);
+          tempdata += sampleRate_10;
+          tempLen -= sampleRate_10;
         }
       }