Index: webrtc/common_audio/audio_converter_unittest.cc |
diff --git a/webrtc/common_audio/audio_converter_unittest.cc b/webrtc/common_audio/audio_converter_unittest.cc |
index c85b96e28589bbc92ac424879aed402260de0b41..dace0bdccf59b3e612bad16d09aca2fed964192c 100644 |
--- a/webrtc/common_audio/audio_converter_unittest.cc |
+++ b/webrtc/common_audio/audio_converter_unittest.cc |
@@ -13,6 +13,7 @@ |
#include <vector> |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "webrtc/base/arraysize.h" |
#include "webrtc/base/format_macros.h" |
#include "webrtc/base/scoped_ptr.h" |
#include "webrtc/common_audio/audio_converter.h" |
@@ -24,11 +25,11 @@ namespace webrtc { |
typedef rtc::scoped_ptr<ChannelBuffer<float>> ScopedBuffer; |
// Sets the signal value to increase by |data| with every sample. |
-ScopedBuffer CreateBuffer(const std::vector<float>& data, int frames) { |
- const int num_channels = static_cast<int>(data.size()); |
+ScopedBuffer CreateBuffer(const std::vector<float>& data, size_t frames) { |
+ const size_t num_channels = data.size(); |
ScopedBuffer sb(new ChannelBuffer<float>(frames, num_channels)); |
- for (int i = 0; i < num_channels; ++i) |
- for (int j = 0; j < frames; ++j) |
+ for (size_t i = 0; i < num_channels; ++i) |
+ for (size_t j = 0; j < frames; ++j) |
sb->channels()[i][j] = data[i] * j; |
return sb; |
} |
@@ -56,7 +57,7 @@ float ComputeSNR(const ChannelBuffer<float>& ref, |
float mse = 0; |
float variance = 0; |
float mean = 0; |
- for (int i = 0; i < ref.num_channels(); ++i) { |
+ for (size_t i = 0; i < ref.num_channels(); ++i) { |
for (size_t j = 0; j < ref.num_frames() - delay; ++j) { |
float error = ref.channels()[i][j] - test.channels()[i][j + delay]; |
mse += error * error; |
@@ -85,9 +86,9 @@ float ComputeSNR(const ChannelBuffer<float>& ref, |
// Sets the source to a linearly increasing signal for which we can easily |
// generate a reference. Runs the AudioConverter and ensures the output has |
// sufficiently high SNR relative to the reference. |
-void RunAudioConverterTest(int src_channels, |
+void RunAudioConverterTest(size_t src_channels, |
int src_sample_rate_hz, |
- int dst_channels, |
+ size_t dst_channels, |
int dst_sample_rate_hz) { |
const float kSrcLeft = 0.0002f; |
const float kSrcRight = 0.0001f; |
@@ -96,8 +97,8 @@ void RunAudioConverterTest(int src_channels, |
const float dst_left = resampling_factor * kSrcLeft; |
const float dst_right = resampling_factor * kSrcRight; |
const float dst_mono = (dst_left + dst_right) / 2; |
- const int src_frames = src_sample_rate_hz / 100; |
- const int dst_frames = dst_sample_rate_hz / 100; |
+ const size_t src_frames = static_cast<size_t>(src_sample_rate_hz / 100); |
+ const size_t dst_frames = static_cast<size_t>(dst_sample_rate_hz / 100); |
std::vector<float> src_data(1, kSrcLeft); |
if (src_channels == 2) |
@@ -127,8 +128,9 @@ void RunAudioConverterTest(int src_channels, |
static_cast<size_t>( |
PushSincResampler::AlgorithmicDelaySeconds(src_sample_rate_hz) * |
dst_sample_rate_hz); |
- 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); |
+ // SNR reported on the same line later. |
+ printf("(%" PRIuS ", %d Hz) -> (%" PRIuS ", %d Hz) ", |
+ src_channels, src_sample_rate_hz, dst_channels, dst_sample_rate_hz); |
rtc::scoped_ptr<AudioConverter> converter = AudioConverter::Create( |
src_channels, src_frames, dst_channels, dst_frames); |
@@ -141,13 +143,13 @@ void RunAudioConverterTest(int src_channels, |
TEST(AudioConverterTest, ConversionsPassSNRThreshold) { |
const int kSampleRates[] = {8000, 16000, 32000, 44100, 48000}; |
- const int kSampleRatesSize = sizeof(kSampleRates) / sizeof(*kSampleRates); |
- const int kChannels[] = {1, 2}; |
- const int kChannelsSize = sizeof(kChannels) / sizeof(*kChannels); |
- for (int src_rate = 0; src_rate < kSampleRatesSize; ++src_rate) { |
- for (int dst_rate = 0; dst_rate < kSampleRatesSize; ++dst_rate) { |
- for (int src_channel = 0; src_channel < kChannelsSize; ++src_channel) { |
- for (int dst_channel = 0; dst_channel < kChannelsSize; ++dst_channel) { |
+ const size_t kChannels[] = {1, 2}; |
+ for (size_t src_rate = 0; src_rate < arraysize(kSampleRates); ++src_rate) { |
+ for (size_t dst_rate = 0; dst_rate < arraysize(kSampleRates); ++dst_rate) { |
+ for (size_t src_channel = 0; src_channel < arraysize(kChannels); |
+ ++src_channel) { |
+ for (size_t dst_channel = 0; dst_channel < arraysize(kChannels); |
+ ++dst_channel) { |
RunAudioConverterTest(kChannels[src_channel], kSampleRates[src_rate], |
kChannels[dst_channel], kSampleRates[dst_rate]); |
} |