Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Original-Commit-Position: refs/heads/master@{#9768}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: dce40cf804019a9898b6ab8d8262466b697c56e0
diff --git a/modules/audio_coding/neteq/dsp_helper.cc b/modules/audio_coding/neteq/dsp_helper.cc
index 3e5c61d..4188914 100644
--- a/modules/audio_coding/neteq/dsp_helper.cc
+++ b/modules/audio_coding/neteq/dsp_helper.cc
@@ -99,13 +99,13 @@
return end_factor;
}
-void DspHelper::PeakDetection(int16_t* data, int data_length,
- int num_peaks, int fs_mult,
- int* peak_index, int16_t* peak_value) {
- int16_t min_index = 0;
- int16_t max_index = 0;
+void DspHelper::PeakDetection(int16_t* data, size_t data_length,
+ size_t num_peaks, int fs_mult,
+ size_t* peak_index, int16_t* peak_value) {
+ size_t min_index = 0;
+ size_t max_index = 0;
- for (int i = 0; i <= num_peaks - 1; i++) {
+ for (size_t i = 0; i <= num_peaks - 1; i++) {
if (num_peaks == 1) {
// Single peak. The parabola fit assumes that an extra point is
// available; worst case it gets a zero on the high end of the signal.
@@ -148,7 +148,7 @@
}
void DspHelper::ParabolicFit(int16_t* signal_points, int fs_mult,
- int* peak_index, int16_t* peak_value) {
+ size_t* peak_index, int16_t* peak_value) {
uint16_t fit_index[13];
if (fs_mult == 1) {
fit_index[0] = 0;
@@ -235,16 +235,16 @@
}
}
-int DspHelper::MinDistortion(const int16_t* signal, int min_lag,
- int max_lag, int length,
- int32_t* distortion_value) {
- int best_index = 0;
+size_t DspHelper::MinDistortion(const int16_t* signal, size_t min_lag,
+ size_t max_lag, size_t length,
+ int32_t* distortion_value) {
+ size_t best_index = 0;
int32_t min_distortion = WEBRTC_SPL_WORD32_MAX;
- for (int i = min_lag; i <= max_lag; i++) {
+ for (size_t i = min_lag; i <= max_lag; i++) {
int32_t sum_diff = 0;
const int16_t* data1 = signal;
const int16_t* data2 = signal - i;
- for (int j = 0; j < length; j++) {
+ for (size_t j = 0; j < length; j++) {
sum_diff += WEBRTC_SPL_ABS_W32(data1[j] - data2[j]);
}
// Compare with previous minimum.
@@ -293,15 +293,15 @@
}
int DspHelper::DownsampleTo4kHz(const int16_t* input, size_t input_length,
- int output_length, int input_rate_hz,
+ size_t output_length, int input_rate_hz,
bool compensate_delay, int16_t* output) {
// Set filter parameters depending on input frequency.
// NOTE: The phase delay values are wrong compared to the true phase delay
// of the filters. However, the error is preserved (through the +1 term) for
// consistency.
const int16_t* filter_coefficients; // Filter coefficients.
- int16_t filter_length; // Number of coefficients.
- int16_t filter_delay; // Phase delay in samples.
+ size_t filter_length; // Number of coefficients.
+ size_t filter_delay; // Phase delay in samples.
int16_t factor; // Conversion rate (inFsHz / 8000).
switch (input_rate_hz) {
case 8000: {
@@ -345,9 +345,8 @@
// Returns -1 if input signal is too short; 0 otherwise.
return WebRtcSpl_DownsampleFast(
- &input[filter_length - 1], static_cast<int>(input_length) -
- (filter_length - 1), output, output_length, filter_coefficients,
- filter_length, factor, filter_delay);
+ &input[filter_length - 1], input_length - filter_length + 1, output,
+ output_length, filter_coefficients, filter_length, factor, filter_delay);
}
} // namespace webrtc