diff --git a/talk/app/webrtc/test/fakeaudiocapturemodule.h b/talk/app/webrtc/test/fakeaudiocapturemodule.h index 57c1e58aa..8ff4aa19e 100644 --- a/talk/app/webrtc/test/fakeaudiocapturemodule.h +++ b/talk/app/webrtc/test/fakeaudiocapturemodule.h @@ -58,8 +58,8 @@ class FakeAudioCaptureModule // The value for the following constants have been derived by running VoE // using a real ADM. The constants correspond to 10ms of mono audio at 44kHz. - enum{kNumberSamples = 440}; - enum{kNumberBytesPerSample = sizeof(Sample)}; + static const int kNumberSamples = 440; + static const int kNumberBytesPerSample = sizeof(Sample); // Creates a FakeAudioCaptureModule or returns NULL on failure. // |process_thread| is used to push and pull audio frames to and from the diff --git a/webrtc/common_audio/audio_converter_unittest.cc b/webrtc/common_audio/audio_converter_unittest.cc index 6da339f08..590c8ceb5 100644 --- a/webrtc/common_audio/audio_converter_unittest.cc +++ b/webrtc/common_audio/audio_converter_unittest.cc @@ -49,7 +49,7 @@ float ComputeSNR(const ChannelBuffer& ref, int best_delay = 0; // Search within one sample of the expected delay. - for (int delay = std::max(expected_delay - 1, 0); + for (int delay = std::max(expected_delay, 1) - 1; delay <= std::min(expected_delay + 1, ref.num_frames()); ++delay) { float mse = 0; diff --git a/webrtc/common_audio/real_fourier.cc b/webrtc/common_audio/real_fourier.cc index dec2be6d6..30c8ee397 100644 --- a/webrtc/common_audio/real_fourier.cc +++ b/webrtc/common_audio/real_fourier.cc @@ -40,8 +40,7 @@ int RealFourier::FftLength(int order) { } int RealFourier::ComplexLength(int order) { - CHECK_GE(order, 0); - return (1 << order) / 2 + 1; + return FftLength(order) / 2 + 1; } RealFourier::fft_real_scoper RealFourier::AllocRealBuffer(int count) { diff --git a/webrtc/common_audio/resampler/sinc_resampler.h b/webrtc/common_audio/resampler/sinc_resampler.h index 9ad7895bc..062117aa3 100644 --- a/webrtc/common_audio/resampler/sinc_resampler.h +++ b/webrtc/common_audio/resampler/sinc_resampler.h @@ -34,22 +34,20 @@ class SincResamplerCallback { // SincResampler is a high-quality single-channel sample-rate converter. class SincResampler { public: - enum { - // The kernel size can be adjusted for quality (higher is better) at the - // expense of performance. Must be a multiple of 32. - // TODO(dalecurtis): Test performance to see if we can jack this up to 64+. - kKernelSize = 32, + // The kernel size can be adjusted for quality (higher is better) at the + // expense of performance. Must be a multiple of 32. + // TODO(dalecurtis): Test performance to see if we can jack this up to 64+. + static const int kKernelSize = 32; - // Default request size. Affects how often and for how much SincResampler - // calls back for input. Must be greater than kKernelSize. - kDefaultRequestSize = 512, + // Default request size. Affects how often and for how much SincResampler + // calls back for input. Must be greater than kKernelSize. + static const int kDefaultRequestSize = 512; - // The kernel offset count is used for interpolation and is the number of - // sub-sample kernel shifts. Can be adjusted for quality (higher is better) - // at the expense of allocating more memory. - kKernelOffsetCount = 32, - kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1), - }; + // The kernel offset count is used for interpolation and is the number of + // sub-sample kernel shifts. Can be adjusted for quality (higher is better) + // at the expense of allocating more memory. + static const int kKernelOffsetCount = 32; + static const int kKernelStorageSize = kKernelSize * (kKernelOffsetCount + 1); // Constructs a SincResampler with the specified |read_cb|, which is used to // acquire audio data for resampling. |io_sample_rate_ratio| is the ratio diff --git a/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.cc b/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.cc index d38263c68..597820b15 100644 --- a/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.cc +++ b/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.cc @@ -36,12 +36,11 @@ void SinusoidalLinearChirpSource::Run(int frames, float* destination) { destination[i] = 0; } else { // Calculate time in seconds. - double t = (static_cast(current_index_) - delay_samples_) / - sample_rate_; - if (t < 0) { + if (current_index_ < delay_samples_) { destination[i] = 0; } else { // Sinusoidal linear chirp. + double t = (current_index_ - delay_samples_) / sample_rate_; destination[i] = sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t)); } diff --git a/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h b/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h index d6b8ce31e..1bddfc907 100644 --- a/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h +++ b/webrtc/common_audio/resampler/sinusoidal_linear_chirp_source.h @@ -40,7 +40,7 @@ class SinusoidalLinearChirpSource : public SincResamplerCallback { kMinFrequency = 5 }; - double sample_rate_; + int sample_rate_; int total_samples_; double max_frequency_; double k_; diff --git a/webrtc/common_audio/signal_processing/auto_correlation.c b/webrtc/common_audio/signal_processing/auto_correlation.c index 9fb9824eb..fed131221 100644 --- a/webrtc/common_audio/signal_processing/auto_correlation.c +++ b/webrtc/common_audio/signal_processing/auto_correlation.c @@ -51,7 +51,7 @@ int WebRtcSpl_AutoCorrelation(const int16_t* in_vector, for (i = 0; i < order + 1; i++) { sum = 0; /* Unroll the loop to improve performance. */ - for (j = 0; j < in_vector_length - i - 3; j += 4) { + for (j = 0; i + j + 3 < in_vector_length; j += 4) { sum += (in_vector[j + 0] * in_vector[i + j + 0]) >> scaling; sum += (in_vector[j + 1] * in_vector[i + j + 1]) >> scaling; sum += (in_vector[j + 2] * in_vector[i + j + 2]) >> scaling; diff --git a/webrtc/common_audio/signal_processing/dot_product_with_scale.c b/webrtc/common_audio/signal_processing/dot_product_with_scale.c index 389bcf057..c01ec5730 100644 --- a/webrtc/common_audio/signal_processing/dot_product_with_scale.c +++ b/webrtc/common_audio/signal_processing/dot_product_with_scale.c @@ -18,7 +18,7 @@ int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1, int i = 0; /* Unroll the loop to improve performance. */ - for (i = 0; i < length - 3; i += 4) { + for (i = 0; i + 3 < length; i += 4) { sum += (vector1[i + 0] * vector2[i + 0]) >> scaling; sum += (vector1[i + 1] * vector2[i + 1]) >> scaling; sum += (vector1[i + 2] * vector2[i + 2]) >> scaling; diff --git a/webrtc/common_audio/signal_processing/levinson_durbin.c b/webrtc/common_audio/signal_processing/levinson_durbin.c index eaf51430d..536bd0b15 100644 --- a/webrtc/common_audio/signal_processing/levinson_durbin.c +++ b/webrtc/common_audio/signal_processing/levinson_durbin.c @@ -41,7 +41,7 @@ int16_t WebRtcSpl_LevinsonDurbin(const int32_t* R, int16_t* A, int16_t* K, norm = WebRtcSpl_NormW32(R[0]); - for (i = order; i >= 0; i--) + for (i = 0; i <= order; ++i) { temp1W32 = WEBRTC_SPL_LSHIFT_W32(R[i], norm); // Put R in hi and low format diff --git a/webrtc/common_audio/signal_processing/min_max_operations_neon.c b/webrtc/common_audio/signal_processing/min_max_operations_neon.c index dec31ad31..e4b3041e3 100644 --- a/webrtc/common_audio/signal_processing/min_max_operations_neon.c +++ b/webrtc/common_audio/signal_processing/min_max_operations_neon.c @@ -86,7 +86,7 @@ int32_t WebRtcSpl_MaxAbsValueW32Neon(const int32_t* vector, int length) { uint32x4_t max32x4_1 = vdupq_n_u32(0); // First part, unroll the loop 8 times. - for (i = length - residual; i >0; i -= 8) { + for (i = 0; i < length - residual; i += 8) { int32x4_t in32x4_0 = vld1q_s32(p_start); p_start += 4; int32x4_t in32x4_1 = vld1q_s32(p_start); @@ -139,7 +139,7 @@ int16_t WebRtcSpl_MaxValueW16Neon(const int16_t* vector, int length) { int16x8_t max16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MIN); // First part, unroll the loop 8 times. - for (i = length - residual; i >0; i -= 8) { + for (i = 0; i < length - residual; i += 8) { int16x8_t in16x8 = vld1q_s16(p_start); max16x8 = vmaxq_s16(max16x8, in16x8); p_start += 8; @@ -180,7 +180,7 @@ int32_t WebRtcSpl_MaxValueW32Neon(const int32_t* vector, int length) { int32x4_t max32x4_1 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN); // First part, unroll the loop 8 times. - for (i = length - residual; i >0; i -= 8) { + for (i = 0; i < length - residual; i += 8) { int32x4_t in32x4_0 = vld1q_s32(p_start); p_start += 4; int32x4_t in32x4_1 = vld1q_s32(p_start); @@ -223,7 +223,7 @@ int16_t WebRtcSpl_MinValueW16Neon(const int16_t* vector, int length) { int16x8_t min16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MAX); // First part, unroll the loop 8 times. - for (i = length - residual; i >0; i -= 8) { + for (i = 0; i < length - residual; i += 8) { int16x8_t in16x8 = vld1q_s16(p_start); min16x8 = vminq_s16(min16x8, in16x8); p_start += 8; @@ -264,7 +264,7 @@ int32_t WebRtcSpl_MinValueW32Neon(const int32_t* vector, int length) { int32x4_t min32x4_1 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX); // First part, unroll the loop 8 times. - for (i = length - residual; i >0; i -= 8) { + for (i = 0; i < length - residual; i += 8) { int32x4_t in32x4_0 = vld1q_s32(p_start); p_start += 4; int32x4_t in32x4_1 = vld1q_s32(p_start); diff --git a/webrtc/modules/audio_coding/codecs/audio_decoder.cc b/webrtc/modules/audio_coding/codecs/audio_decoder.cc index 9e88f897a..0a4a6a964 100644 --- a/webrtc/modules/audio_coding/codecs/audio_decoder.cc +++ b/webrtc/modules/audio_coding/codecs/audio_decoder.cc @@ -56,7 +56,7 @@ int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded, bool AudioDecoder::HasDecodePlc() const { return false; } -int AudioDecoder::DecodePlc(int num_frames, int16_t* decoded) { return -1; } +int AudioDecoder::DecodePlc(int num_frames, int16_t* decoded) { return 0; } int AudioDecoder::IncomingPacket(const uint8_t* payload, size_t payload_len, diff --git a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc index 9b23607f0..c662b5ba5 100644 --- a/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc +++ b/webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.cc @@ -136,9 +136,9 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal( (frames_to_encode > 3 ? 3 : frames_to_encode); if (frames_to_encode == 4) blocks_in_first_vad_call = 2; + CHECK_GE(frames_to_encode, blocks_in_first_vad_call); const int blocks_in_second_vad_call = frames_to_encode - blocks_in_first_vad_call; - CHECK_GE(blocks_in_second_vad_call, 0); // Check if all of the buffer is passive speech. Start with checking the first // block. @@ -217,7 +217,7 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive( info = speech_encoder_->Encode( rtp_timestamps_.front(), &speech_buffer_[i * samples_per_10ms_frame], samples_per_10ms_frame, max_encoded_bytes, encoded); - if (i == frames_to_encode - 1) { + if (i + 1 == frames_to_encode) { CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data."; } else { CHECK_EQ(info.encoded_bytes, 0u) << "Encoder delivered data too early."; diff --git a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc index 0a3a6398f..ed4961864 100644 --- a/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc +++ b/webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc @@ -88,13 +88,13 @@ AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal( } CHECK_EQ(speech_buffer_.size(), full_frame_samples_); CHECK_GE(max_encoded_bytes, full_frame_samples_); - int16_t ret = EncodeCall(&speech_buffer_[0], full_frame_samples_, encoded); - CHECK_GE(ret, 0); - speech_buffer_.clear(); EncodedInfo info; info.encoded_timestamp = first_timestamp_in_buffer_; info.payload_type = payload_type_; + int16_t ret = EncodeCall(&speech_buffer_[0], full_frame_samples_, encoded); + CHECK_GE(ret, 0); info.encoded_bytes = static_cast(ret); + speech_buffer_.clear(); return info; } diff --git a/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc b/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc index e891810ca..9511df791 100644 --- a/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc +++ b/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc @@ -86,6 +86,10 @@ int main(int argc, char* argv[]) { printf("G.711 version: %s\n\n", versionNumber); /* Get frame length */ framelength = atoi(argv[1]); + if (framelength < 0) { + printf(" G.711: Invalid framelength %d.\n", framelength); + exit(1); + } /* Get compression law */ strcpy(law, argv[2]); diff --git a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc index effb4058f..8e10dffe8 100644 --- a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc +++ b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc @@ -24,7 +24,8 @@ const int kSampleRateHz = 16000; } // namespace bool AudioEncoderG722::Config::IsOk() const { - return (frame_size_ms % 10 == 0) && (num_channels >= 1); + return (frame_size_ms > 0) && (frame_size_ms % 10 == 0) && + (num_channels >= 1); } AudioEncoderG722::EncoderState::EncoderState() { diff --git a/webrtc/modules/audio_coding/codecs/g722/test/testG722.cc b/webrtc/modules/audio_coding/codecs/g722/test/testG722.cc index 6d0c4322e..9b2f54cc4 100644 --- a/webrtc/modules/audio_coding/codecs/g722/test/testG722.cc +++ b/webrtc/modules/audio_coding/codecs/g722/test/testG722.cc @@ -83,6 +83,10 @@ int main(int argc, char* argv[]) /* Get frame length */ framelength = atoi(argv[1]); + if (framelength < 0) { + printf(" G.722: Invalid framelength %d.\n", framelength); + exit(1); + } /* Get Input and Output files */ sscanf(argv[2], "%s", inname); diff --git a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c index b6754418a..bfe0e6431 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/cb_mem_energy_calc.c @@ -41,7 +41,7 @@ void WebRtcIlbcfix_CbMemEnergyCalc( eSh_ptr = &energyShifts[1+base_size]; eW16_ptr = &energyW16[1+base_size]; - for(j=0;j>1); + sInd = ((CB_RESRANGE >> 1) > bestIndex) ? + 0 : (bestIndex - (CB_RESRANGE >> 1)); eInd=sInd+CB_RESRANGE; - if (sInd<0) { - eInd-=sInd; - sInd=0; - } if (eInd>=range) { eInd=range-1; sInd=eInd-CB_RESRANGE; @@ -247,9 +244,11 @@ void WebRtcIlbcfix_CbSearch( interpSamplesFilt, cDot, (int16_t)(sInd+20), (int16_t)(WEBRTC_SPL_MIN(39, (eInd+20))), scale); i=20; + cDotPtr = &cDot[20 - sInd]; + } else { + cDotPtr = cDot; } - cDotPtr=&cDot[WEBRTC_SPL_MAX(0,(20-sInd))]; cb_vecPtr = cbvectors+lMem-20-i; /* Calculate the cross correlations (main part of the filtered CB) */ diff --git a/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.c b/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.c index 169218aa8..c04fd9911 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/decode_residual.c @@ -41,7 +41,7 @@ void WebRtcIlbcfix_DecodeResidual( int16_t *syntdenum /* (i) the decoded synthesis filter coefficients */ ) { - int16_t meml_gotten, Nfor, Nback, diff, start_pos; + int16_t meml_gotten, diff, start_pos; int16_t subcount, subframe; int16_t *reverseDecresidual = iLBCdec_inst->enh_buf; /* Reversed decoded data, used for decoding backwards in time (reuse memory in state) */ int16_t *memVec = iLBCdec_inst->prevResidual; /* Memory for codebook and filter state (reuse memory in state) */ @@ -110,9 +110,7 @@ void WebRtcIlbcfix_DecodeResidual( /* forward prediction of subframes */ - Nfor = iLBCdec_inst->nsub-iLBC_encbits->startIdx-1; - - if( Nfor > 0 ) { + if (iLBCdec_inst->nsub > iLBC_encbits->startIdx + 1) { /* setup memory */ WebRtcSpl_MemSetW16(mem, 0, CB_MEML-STATE_LEN); @@ -121,6 +119,7 @@ void WebRtcIlbcfix_DecodeResidual( /* loop over subframes to encode */ + int16_t Nfor = iLBCdec_inst->nsub - iLBC_encbits->startIdx - 1; for (subframe=0; subframestartIdx-1; - - if( Nback > 0 ){ + if (iLBC_encbits->startIdx > 1) { /* setup memory */ @@ -160,6 +157,7 @@ void WebRtcIlbcfix_DecodeResidual( /* loop over subframes to decode */ + int16_t Nback = iLBC_encbits->startIdx - 1; for (subframe=0; subframeseed = (int16_t)(iLBCdec_inst->seed * 31821 + 13849); randlag = 53 + (int16_t)(iLBCdec_inst->seed & 63); - - pick = i - randlag; - - if (pick < 0) { - randvec[i] = iLBCdec_inst->prevResidual[iLBCdec_inst->blockl+pick]; + if (randlag > i) { + randvec[i] = + iLBCdec_inst->prevResidual[iLBCdec_inst->blockl + i - randlag]; } else { - randvec[i] = iLBCdec_inst->prevResidual[pick]; + randvec[i] = iLBCdec_inst->prevResidual[i - randlag]; } /* pitch repeatition component */ - pick = i - use_lag; - - if (pick < 0) { - PLCresidual[i] = iLBCdec_inst->prevResidual[iLBCdec_inst->blockl+pick]; + if (use_lag > i) { + PLCresidual[i] = + iLBCdec_inst->prevResidual[iLBCdec_inst->blockl + i - use_lag]; } else { - PLCresidual[i] = PLCresidual[pick]; + PLCresidual[i] = PLCresidual[i - use_lag]; } /* Attinuate total gain for each 10 ms */ diff --git a/webrtc/modules/audio_coding/codecs/ilbc/encode.c b/webrtc/modules/audio_coding/codecs/ilbc/encode.c index 1d46eff43..3de84258a 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/encode.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/encode.c @@ -48,7 +48,7 @@ void WebRtcIlbcfix_EncodeImpl( IlbcEncoder *iLBCenc_inst /* (i/o) the general encoder state */ ){ - int n, meml_gotten, Nfor, Nback; + int n, meml_gotten, Nfor; int16_t diff, start_pos; int index; int subcount, subframe; @@ -379,15 +379,14 @@ void WebRtcIlbcfix_EncodeImpl( /* backward prediction of subframes */ - Nback = iLBCbits_inst->startIdx-1; - - if( Nback > 0 ){ + if (iLBCbits_inst->startIdx > 1) { /* create reverse order vectors (The decresidual does not need to be copied since it is contained in the same vector as the residual) */ + int Nback = iLBCbits_inst->startIdx - 1; WebRtcSpl_MemCpyReversedOrder(&reverseResidual[Nback*SUBL-1], residual, Nback*SUBL); /* setup memory */ @@ -425,11 +424,11 @@ void WebRtcIlbcfix_EncodeImpl( if (iLBCenc_inst->section == 1) { start_count = 0; - end_count = WEBRTC_SPL_MAX (2 - Nfor, 0); + end_count = (Nfor >= 2) ? 0 : (2 - NFor); } if (iLBCenc_inst->section == 2) { - start_count = WEBRTC_SPL_MAX (2 - Nfor, 0); + start_count = (Nfor >= 2) ? 0 : (2 - NFor); end_count = Nback; } } diff --git a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c index db4b8d405..257013c6d 100644 --- a/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c +++ b/webrtc/modules/audio_coding/codecs/ilbc/enhancer_interface.c @@ -110,9 +110,8 @@ int WebRtcIlbcfix_EnhancerInterface( /* (o) Estimated lag in end of in[] */ for(iblock = 0; iblockplcstr_obj).prevPitchInvIn[FRAMESAMPLES_HALF - lag0]); minCorr = WEBRTC_SPL_WORD32_MAX; - if ( (FRAMESAMPLES_HALF - 2*lag0 - 10) > 0 ) + if ((FRAMESAMPLES_HALF - 10) > 2 * lag0) { minIdx = 11; for( i = 0; i < 21; i++ ) 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 cfd9a9eb7..3b26a9815 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice.c @@ -279,13 +279,15 @@ void WebRtcIsacfix_NormLatticeFilterAr(int16_t orderCoef, ARfQ0vec[i] = (int16_t)WebRtcSpl_SatW32ToW16(tmp32); // Q0 } - for (i=orderCoef-1;i>=0;i--) //get the state of f&g for the first input, for all orders + for (i=orderCoef;i>0;i--) //get the state of f&g for the first input, for all orders { - tmp32 = (cthQ15[i] * ARfQ0vec[0] - sthQ15[i] * stateGQ0[i] + 16384) >> 15; + tmp32 = (cthQ15[i - 1] * ARfQ0vec[0] - sthQ15[i - 1] * stateGQ0[i - 1] + + 16384) >> 15; tmpAR = (int16_t)WebRtcSpl_SatW32ToW16(tmp32); // Q0 - tmp32 = (sthQ15[i] * ARfQ0vec[0] + cthQ15[i] * stateGQ0[i] + 16384) >> 15; - ARgQ0vec[i+1] = (int16_t)WebRtcSpl_SatW32ToW16(tmp32); // Q0 + tmp32 = (sthQ15[i - 1] * ARfQ0vec[0] + cthQ15[i - 1] * stateGQ0[i - 1] + + 16384) >> 15; + ARgQ0vec[i] = (int16_t)WebRtcSpl_SatW32ToW16(tmp32); // Q0 ARfQ0vec[0] = tmpAR; } ARgQ0vec[0] = ARfQ0vec[0]; 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 35fd9ef74..ccea46799 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 @@ -46,21 +46,21 @@ HALF_SUBFRAME_LOOP: @ for(n = 0; n < HALF_SUBFRAMELEN - 1; n++) 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 - 1 ; k >= 0; k--) +ORDER_COEF_LOOP: @ for(k = order_coef ; k > 0; k--) - ldrh r7, [r3, #-2]! @ sth_Q15[k] - ldrh r6, [r2, #-2]! @ cth_Q15[k] + ldrh r7, [r3, #-2]! @ sth_Q15[k - 1] + ldrh r6, [r2, #-2]! @ cth_Q15[k - 1] - ldrh r8, [r0, #-2] @ ar_g_Q0[k] - smlabb r11, r7, r5, r12 @ sth_Q15[k] * tmpAR + 16384 - smlabb r10, r6, r5, r12 @ cth_Q15[k] * tmpAR + 16384 - smulbb r7, r7, r8 @ sth_Q15[k] * ar_g_Q0[k] - smlabb r11, r6, r8, r11 @ cth_Q15[k]*ar_g_Q0[k]+(sth_Q15[k]*tmpAR+16384) + ldrh r8, [r0, #-2] @ ar_g_Q0[k - 1] + smlabb r11, r7, r5, r12 @ sth_Q15[k - 1] * tmpAR + 16384 + smlabb r10, r6, r5, r12 @ cth_Q15[k - 1] * tmpAR + 16384 + smulbb r7, r7, r8 @ sth_Q15[k - 1] * ar_g_Q0[k - 1] + smlabb r11, r6, r8, r11 @ cth_Q15[k - 1]*ar_g_Q0[k - 1]+(sth_Q15[k - 1]*tmpAR+16384) - sub r10, r10, r7 @ cth_Q15[k]*tmpAR+16384-(sth_Q15[k]*ar_g_Q0[k]) + sub r10, r10, r7 @ cth_Q15[k - 1]*tmpAR+16384-(sth_Q15[k - 1]*ar_g_Q0[k - 1]) ssat r11, #16, r11, asr #15 ssat r5, #16, r10, asr #15 - strh r11, [r0], #-2 @ Output: ar_g_Q0[k+1] + strh r11, [r0], #-2 @ Output: ar_g_Q0[k] subs r9, #1 bgt ORDER_COEF_LOOP diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_c.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_c.c index 8c53b0bf3..43a157943 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_c.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/lattice_c.c @@ -35,11 +35,13 @@ void WebRtcIsacfix_FilterArLoop(int16_t* ar_g_Q0, // Input samples int32_t tmp32_2 = 0; tmpAR = ar_f_Q0[n + 1]; - for (k = order_coef - 1; k >= 0; k--) { - tmp32 = (cth_Q15[k] * tmpAR - sth_Q15[k] * ar_g_Q0[k] + 16384) >> 15; - tmp32_2 = (sth_Q15[k] * tmpAR + cth_Q15[k] * ar_g_Q0[k] + 16384) >> 15; + for (k = order_coef; k > 0; k--) { + tmp32 = (cth_Q15[k - 1] * tmpAR - sth_Q15[k - 1] * ar_g_Q0[k - 1] + + 16384) >> 15; + tmp32_2 = (sth_Q15[k - 1] * tmpAR + cth_Q15[k - 1] * ar_g_Q0[k - 1] + + 16384) >> 15; tmpAR = (int16_t)WebRtcSpl_SatW32ToW16(tmp32); - ar_g_Q0[k + 1] = (int16_t)WebRtcSpl_SatW32ToW16(tmp32_2); + ar_g_Q0[k] = (int16_t)WebRtcSpl_SatW32ToW16(tmp32_2); } ar_f_Q0[n + 1] = tmpAR; ar_g_Q0[0] = tmpAR; diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c index eaf131df6..1149d50b9 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c +++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/pitch_filter.c @@ -69,7 +69,6 @@ void WebRtcIsacfix_PitchFilter(int16_t* indatQQ, // Q10 if type is 1 or 4, int16_t oldLagQ7; int16_t oldGainQ12, lagdeltaQ7, curLagQ7, gaindeltaQ12, curGainQ12; int indW32 = 0, frcQQ = 0; - int32_t tmpW32; const int16_t* fracoeffQQ = NULL; // Assumptions in ARM assembly for WebRtcIsacfix_PitchFilterCoreARM(). @@ -123,8 +122,7 @@ void WebRtcIsacfix_PitchFilter(int16_t* indatQQ, // Q10 if type is 1 or 4, curGainQ12 += gaindeltaQ12; curLagQ7 += lagdeltaQ7; indW32 = CalcLrIntQ(curLagQ7, 7); - tmpW32 = (indW32 << 7) - curLagQ7; - frcQQ = (tmpW32 >> 4) + 4; + frcQQ = ((indW32 << 7) + 64 - curLagQ7) >> 4; if (frcQQ == PITCH_FRACS) { frcQQ = 0; @@ -195,8 +193,7 @@ void WebRtcIsacfix_PitchFilterGains(const int16_t* indatQ0, // Update parameters for each segment. curLagQ7 += lagdeltaQ7; indW16 = (int16_t)CalcLrIntQ(curLagQ7, 7); - tmpW16 = (indW16 << 7) - curLagQ7; - frcQQ = (tmpW16 >> 4) + 4; + frcQQ = ((indW16 << 7) + 64 - curLagQ7) >> 4; if (frcQQ == PITCH_FRACS) { frcQQ = 0; diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc b/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc index bb7625756..3089f5826 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc +++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc @@ -65,18 +65,21 @@ float IsacSpeedTest::EncodeABlock(int16_t* in_data, uint8_t* bit_stream, // ISAC takes 10 ms everycall const int subblocks = block_duration_ms_ / 10; const int subblock_length = 10 * input_sampling_khz_; - int value; + int value = 0; clock_t clocks = clock(); size_t pointer = 0; for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) { value = WebRtcIsacfix_Encode(ISACFIX_main_inst_, &in_data[pointer], bit_stream); + if (idx == subblocks - 1) + EXPECT_GT(value, 0); + else + EXPECT_EQ(0, value); } clocks = clock() - clocks; - EXPECT_GT(value, 0); - assert(value <= max_bytes); *encoded_bytes = value; + assert(*encoded_bytes <= max_bytes); return 1000.0 * clocks / CLOCKS_PER_SEC; } 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 bc1a194ab..ac1efe4be 100644 --- a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc +++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc @@ -232,7 +232,7 @@ int main(int argc, char* argv[]) CodingMode = 0; testNum = 0; testCE = 0; - for (i = 1; i < argc-2;i++) { + for (i = 1; i + 2 < argc; i++) { /* Instantaneous mode */ if (!strcmp ("-I", argv[i])) { printf("\nInstantaneous BottleNeck\n"); 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 f6bfcdcd8..496e8c9f2 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 @@ -185,7 +185,7 @@ int main(int argc, char* argv[]) { char transCodingFileName[500]; int16_t totFileLoop = 0; int16_t numFileLoop = 0; - for (i = 1; i < argc - 2; i++) { + for (i = 1; i + 2 < argc; i++) { if (!strcmp("-LOOP", argv[i])) { i++; totFileLoop = (int16_t)atol(argv[i]); diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc index 15188a97b..bb7bee97b 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc +++ b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc @@ -106,6 +106,7 @@ int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder, input_audio, input_samples, kMaxBytes, bitstream_); + EXPECT_GE(encoded_bytes_, 0); return WebRtcOpus_Decode(decoder, bitstream_, encoded_bytes_, output_audio, audio_type); @@ -539,6 +540,7 @@ TEST_P(OpusTest, DISABLED_ON_IOS(OpusDurationEstimation)) { speech_data_.GetNextBlock(), kOpus10msFrameSamples, kMaxBytes, bitstream_); + EXPECT_GE(encoded_bytes_, 0); EXPECT_EQ(kOpus10msFrameSamples, WebRtcOpus_DurationEst(opus_decoder_, bitstream_, encoded_bytes_)); @@ -548,6 +550,7 @@ TEST_P(OpusTest, DISABLED_ON_IOS(OpusDurationEstimation)) { speech_data_.GetNextBlock(), kOpus20msFrameSamples, kMaxBytes, bitstream_); + EXPECT_GE(encoded_bytes_, 0); EXPECT_EQ(kOpus20msFrameSamples, WebRtcOpus_DurationEst(opus_decoder_, bitstream_, encoded_bytes_)); diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc index 0da2eb5c0..b65964909 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc @@ -89,9 +89,11 @@ int UpMix(const AudioFrame& frame, int length_out_buff, int16_t* out_buff) { if (length_out_buff < frame.samples_per_channel_) { return -1; } - for (int n = frame.samples_per_channel_ - 1; n >= 0; --n) { - out_buff[2 * n + 1] = frame.data_[n]; - out_buff[2 * n] = frame.data_[n]; + for (int n = frame.samples_per_channel_; n > 0; --n) { + int i = n - 1; + int16_t sample = frame.data_[i]; + out_buff[2 * i + 1] = sample; + out_buff[2 * i] = sample; } return 0; } diff --git a/webrtc/modules/audio_coding/neteq/expand.cc b/webrtc/modules/audio_coding/neteq/expand.cc index 4bcb7a88e..cfd2701ca 100644 --- a/webrtc/modules/audio_coding/neteq/expand.cc +++ b/webrtc/modules/audio_coding/neteq/expand.cc @@ -404,7 +404,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { // Find the maximizing index |i| of the cost function // f[i] = best_correlation[i] / best_distortion[i]. int32_t best_ratio = std::numeric_limits::min(); - int best_index = -1; + int best_index = std::numeric_limits::max(); for (int i = 0; i < kNumCorrelationCandidates; ++i) { int32_t ratio; if (best_distortion[i] > 0) { @@ -549,9 +549,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { } // Set the 3 lag values. - int lag_difference = distortion_lag - correlation_lag; - if (lag_difference == 0) { - // |distortion_lag| and |correlation_lag| are equal. + if (distortion_lag == correlation_lag) { expand_lags_[0] = distortion_lag; expand_lags_[1] = distortion_lag; expand_lags_[2] = distortion_lag; @@ -563,7 +561,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { // Second lag is the average of the two. expand_lags_[1] = (distortion_lag + correlation_lag) / 2; // Third lag is the average again, but rounding towards |correlation_lag|. - if (lag_difference > 0) { + if (distortion_lag > correlation_lag) { expand_lags_[2] = (distortion_lag + correlation_lag - 1) / 2; } else { expand_lags_[2] = (distortion_lag + correlation_lag + 1) / 2; @@ -691,9 +689,8 @@ void Expand::AnalyzeSignal(int16_t* random_vector) { temp_sum += kCoefficients[1] * x1; temp_sum += kCoefficients[2] * x2; temp_sum += kCoefficients[3] * x3; - parameters.voice_mix_factor = temp_sum / 4096; - parameters.voice_mix_factor = std::min(parameters.voice_mix_factor, - static_cast(16384)); + parameters.voice_mix_factor = + static_cast(std::min(temp_sum / 4096, 16384)); parameters.voice_mix_factor = std::max(parameters.voice_mix_factor, static_cast(0)); } else { diff --git a/webrtc/modules/audio_coding/neteq/merge.cc b/webrtc/modules/audio_coding/neteq/merge.cc index fa033cf63..23382acdd 100644 --- a/webrtc/modules/audio_coding/neteq/merge.cc +++ b/webrtc/modules/audio_coding/neteq/merge.cc @@ -175,7 +175,7 @@ int Merge::GetExpandedSignal(int* old_length, int* expand_period) { // This is the truncated length. } // This assert should always be true thanks to the if statement above. - assert(210 * kMaxSampleRate / 8000 - *old_length >= 0); + assert(210 * kMaxSampleRate / 8000 >= *old_length); AudioMultiVector expanded_temp(num_channels_); expand_->Process(&expanded_temp); @@ -342,7 +342,7 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max, int start_index = timestamps_per_call_ + static_cast(expand_->overlap_length()); start_index = std::max(start_position, start_index); - start_index = std::max(start_index - input_length, 0); + start_index = (input_length > start_index) ? 0 : (start_index - input_length); // Downscale starting index to 4kHz domain. (fs_mult_ * 2 = fs_hz_ / 4000.) int start_index_downsamp = start_index / (fs_mult_ * 2); diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc index 8cd9aebf6..2d4ff270e 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -1520,10 +1520,10 @@ int NetEqImpl::DoPreemptiveExpand(int16_t* decoded_buffer, borrowed_samples_per_channel = static_cast(required_samples - decoded_length_per_channel); // Calculate how many of these were already played out. - old_borrowed_samples_per_channel = static_cast( - borrowed_samples_per_channel - sync_buffer_->FutureLength()); - old_borrowed_samples_per_channel = std::max( - 0, old_borrowed_samples_per_channel); + const int future_length = static_cast(sync_buffer_->FutureLength()); + old_borrowed_samples_per_channel = + (borrowed_samples_per_channel > future_length) ? + (borrowed_samples_per_channel - future_length) : 0; memmove(&decoded_buffer[borrowed_samples_per_channel * num_channels], decoded_buffer, sizeof(int16_t) * decoded_length); diff --git a/webrtc/modules/audio_coding/neteq/normal.cc b/webrtc/modules/audio_coding/neteq/normal.cc index ce774d749..b172d561b 100644 --- a/webrtc/modules/audio_coding/neteq/normal.cc +++ b/webrtc/modules/audio_coding/neteq/normal.cc @@ -83,8 +83,10 @@ int Normal::Process(const int16_t* input, scaling = std::max(scaling, 0); // |scaling| should always be >= 0. int32_t energy = WebRtcSpl_DotProductWithScale(signal, signal, energy_length, scaling); - if ((energy_length >> scaling) > 0) { - energy = energy / (energy_length >> scaling); + int32_t scaled_energy_length = + static_cast(energy_length >> scaling); + if (scaled_energy_length > 0) { + energy = energy / scaled_energy_length; } else { energy = 0; } diff --git a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc index 7d8d60de5..1ef9ce535 100644 --- a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc +++ b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc @@ -450,7 +450,10 @@ int main(int argc, char* argv[]) { CHECK_NOT_NULL(out_file); printf("Output file: %s\n\n", argv[2]); packet_size = atoi(argv[3]); - CHECK_NOT_NULL(packet_size); + if (packet_size <= 0) { + printf("Packet size %d must be positive", packet_size); + return -1; + } printf("Packet size: %i\n", packet_size); // check for stereo diff --git a/webrtc/modules/audio_processing/ns/nsx_core_neon.c b/webrtc/modules/audio_processing/ns/nsx_core_neon.c index 1c4c816e8..9675d11c1 100644 --- a/webrtc/modules/audio_processing/ns/nsx_core_neon.c +++ b/webrtc/modules/audio_processing/ns/nsx_core_neon.c @@ -208,7 +208,7 @@ void WebRtcNsx_NoiseEstimationNeon(NoiseSuppressionFixedC* inst, uint16x8_t tmp16x8_4; int32x4_t tmp32x4; - for (i = 0; i < inst->magnLen - 7; i += 8) { + for (i = 0; i + 7 < inst->magnLen; i += 8) { // Compute delta. // Smaller step size during startup. This prevents from using // unrealistic values causing overflow. diff --git a/webrtc/modules/interface/module_common_types.h b/webrtc/modules/interface/module_common_types.h index 0b0e063a6..922215518 100644 --- a/webrtc/modules/interface/module_common_types.h +++ b/webrtc/modules/interface/module_common_types.h @@ -442,8 +442,9 @@ inline void AudioFrame::UpdateFrame(int id, uint32_t timestamp, num_channels_ = num_channels; energy_ = energy; + assert(num_channels >= 0); const int length = samples_per_channel * num_channels; - assert(length <= kMaxDataSizeSamples && length >= 0); + assert(length <= kMaxDataSizeSamples); if (data != NULL) { memcpy(data_, data, sizeof(int16_t) * length); } else { @@ -466,8 +467,9 @@ inline void AudioFrame::CopyFrom(const AudioFrame& src) { energy_ = src.energy_; interleaved_ = src.interleaved_; + assert(num_channels_ >= 0); const int length = samples_per_channel_ * num_channels_; - assert(length <= kMaxDataSizeSamples && length >= 0); + assert(length <= kMaxDataSizeSamples); memcpy(data_, src.data_, sizeof(int16_t) * length); }