Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2179)

Unified Diff: webrtc/modules/audio_coding/neteq/time_stretch.cc

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/time_stretch.cc
diff --git a/webrtc/modules/audio_coding/neteq/time_stretch.cc b/webrtc/modules/audio_coding/neteq/time_stretch.cc
index 5577cd2ecbbd80886e7cda49a9d050417bc7e407..6ae81e6e9662ed4a09a0c1917b03d2143581ced7 100644
--- a/webrtc/modules/audio_coding/neteq/time_stretch.cc
+++ b/webrtc/modules/audio_coding/neteq/time_stretch.cc
@@ -12,6 +12,7 @@
#include <algorithm> // min, max
+#include "webrtc/base/safe_conversions.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/modules/audio_coding/neteq/background_noise.h"
@@ -23,9 +24,10 @@ TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input,
size_t input_len,
bool fast_mode,
AudioMultiVector* output,
- int16_t* length_change_samples) {
+ size_t* length_change_samples) {
// Pre-calculate common multiplication with |fs_mult_|.
- int fs_mult_120 = fs_mult_ * 120; // Corresponds to 15 ms.
+ size_t fs_mult_120 =
+ static_cast<size_t>(fs_mult_ * 120); // Corresponds to 15 ms.
const int16_t* signal;
rtc::scoped_ptr<int16_t[]> signal_array;
@@ -48,8 +50,7 @@ TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input,
}
// Find maximum absolute value of input signal.
- max_input_value_ = WebRtcSpl_MaxAbsValueW16(signal,
- static_cast<int>(signal_len));
+ max_input_value_ = WebRtcSpl_MaxAbsValueW16(signal, signal_len);
// Downsample to 4 kHz sample rate and calculate auto-correlation.
DspHelper::DownsampleTo4kHz(signal, signal_len, kDownsampledLen,
@@ -58,13 +59,12 @@ TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input,
AutoCorrelation();
// Find the strongest correlation peak.
- static const int kNumPeaks = 1;
- int peak_index;
+ static const size_t kNumPeaks = 1;
+ size_t peak_index;
int16_t peak_value;
DspHelper::PeakDetection(auto_correlation_, kCorrelationLen, kNumPeaks,
fs_mult_, &peak_index, &peak_value);
// Assert that |peak_index| stays within boundaries.
- assert(peak_index >= 0);
assert(peak_index <= (2 * kCorrelationLen - 1) * fs_mult_);
// Compensate peak_index for displaced starting position. The displacement
@@ -73,13 +73,13 @@ TimeStretch::ReturnCodes TimeStretch::Process(const int16_t* input,
// multiplication by fs_mult_ * 2.
peak_index += kMinLag * fs_mult_ * 2;
// Assert that |peak_index| stays within boundaries.
- assert(peak_index >= 20 * fs_mult_);
+ assert(peak_index >= static_cast<size_t>(20 * fs_mult_));
assert(peak_index <= 20 * fs_mult_ + (2 * kCorrelationLen - 1) * fs_mult_);
// Calculate scaling to ensure that |peak_index| samples can be square-summed
// without overflowing.
int scaling = 31 - WebRtcSpl_NormW32(max_input_value_ * max_input_value_) -
- WebRtcSpl_NormW32(peak_index);
+ WebRtcSpl_NormW32(static_cast<int32_t>(peak_index));
scaling = std::max(0, scaling);
// |vec1| starts at 15 ms minus one pitch period.
@@ -177,7 +177,7 @@ void TimeStretch::AutoCorrelation() {
}
bool TimeStretch::SpeechDetection(int32_t vec1_energy, int32_t vec2_energy,
- int peak_index, int scaling) const {
+ size_t peak_index, int scaling) const {
// Check if the signal seems to be active speech or not (simple VAD).
// If (vec1_energy + vec2_energy) / (2 * peak_index) <=
// 8 * background_noise_energy, then we say that the signal contains no
@@ -197,7 +197,8 @@ bool TimeStretch::SpeechDetection(int32_t vec1_energy, int32_t vec2_energy,
int right_scale = 16 - WebRtcSpl_NormW32(right_side);
right_scale = std::max(0, right_scale);
left_side = left_side >> right_scale;
- right_side = peak_index * (right_side >> right_scale);
+ right_side =
+ rtc::checked_cast<int32_t>(peak_index) * (right_side >> right_scale);
// Scale |left_side| properly before comparing with |right_side|.
// (|scaling| is the scale factor before energy calculation, thus the scale
« no previous file with comments | « webrtc/modules/audio_coding/neteq/time_stretch.h ('k') | webrtc/modules/audio_coding/neteq/time_stretch_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698