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-Commit-Position: refs/heads/master@{#9768}
diff --git a/webrtc/voice_engine/utility_unittest.cc b/webrtc/voice_engine/utility_unittest.cc
index a5dd70b..5f02f51 100644
--- a/webrtc/voice_engine/utility_unittest.cc
+++ b/webrtc/voice_engine/utility_unittest.cc
@@ -11,6 +11,7 @@
#include <math.h>
#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/format_macros.h"
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/voice_engine/utility.h"
@@ -53,7 +54,7 @@
frame->num_channels_ = 1;
frame->sample_rate_hz_ = sample_rate_hz;
frame->samples_per_channel_ = sample_rate_hz / 100;
- for (int i = 0; i < frame->samples_per_channel_; i++) {
+ for (size_t i = 0; i < frame->samples_per_channel_; i++) {
frame->data_[i] = static_cast<int16_t>(data * i);
}
}
@@ -71,7 +72,7 @@
frame->num_channels_ = 2;
frame->sample_rate_hz_ = sample_rate_hz;
frame->samples_per_channel_ = sample_rate_hz / 100;
- for (int i = 0; i < frame->samples_per_channel_; i++) {
+ for (size_t i = 0; i < frame->samples_per_channel_; i++) {
frame->data_[i * 2] = static_cast<int16_t>(left * i);
frame->data_[i * 2 + 1] = static_cast<int16_t>(right * i);
}
@@ -92,14 +93,14 @@
// |test_frame|. It allows for up to a |max_delay| in samples between the
// signals to compensate for the resampling delay.
float ComputeSNR(const AudioFrame& ref_frame, const AudioFrame& test_frame,
- int max_delay) {
+ size_t max_delay) {
VerifyParams(ref_frame, test_frame);
float best_snr = 0;
- int best_delay = 0;
- for (int delay = 0; delay <= max_delay; delay++) {
+ size_t best_delay = 0;
+ for (size_t delay = 0; delay <= max_delay; delay++) {
float mse = 0;
float variance = 0;
- for (int i = 0; i < ref_frame.samples_per_channel_ *
+ for (size_t i = 0; i < ref_frame.samples_per_channel_ *
ref_frame.num_channels_ - delay; i++) {
int error = ref_frame.data_[i] - test_frame.data_[i + delay];
mse += error * error;
@@ -113,15 +114,15 @@
best_delay = delay;
}
}
- printf("SNR=%.1f dB at delay=%d\n", best_snr, best_delay);
+ printf("SNR=%.1f dB at delay=%" PRIuS "\n", best_snr, best_delay);
return best_snr;
}
void VerifyFramesAreEqual(const AudioFrame& ref_frame,
const AudioFrame& test_frame) {
VerifyParams(ref_frame, test_frame);
- for (int i = 0; i < ref_frame.samples_per_channel_ * ref_frame.num_channels_;
- i++) {
+ for (size_t i = 0;
+ i < ref_frame.samples_per_channel_ * ref_frame.num_channels_; i++) {
EXPECT_EQ(ref_frame.data_[i], test_frame.data_[i]);
}
}
@@ -161,9 +162,10 @@
// The sinc resampler has a known delay, which we compute here. Multiplying by
// two gives us a crude maximum for any resampling, as the old resampler
// typically (but not always) has lower delay.
- static const int kInputKernelDelaySamples = 16;
- const int max_delay = static_cast<double>(dst_sample_rate_hz)
- / src_sample_rate_hz * kInputKernelDelaySamples * dst_channels * 2;
+ static const size_t kInputKernelDelaySamples = 16;
+ const size_t max_delay = static_cast<size_t>(
+ static_cast<double>(dst_sample_rate_hz) / src_sample_rate_hz *
+ kInputKernelDelaySamples * dst_channels * 2);
printf("(%d, %d Hz) -> (%d, %d Hz) ", // SNR reported on the same line later.
src_channels, src_sample_rate_hz, dst_channels, dst_sample_rate_hz);
if (function == TestRemixAndResample) {