Index: webrtc/common_audio/wav_file.cc |
diff --git a/webrtc/common_audio/wav_file.cc b/webrtc/common_audio/wav_file.cc |
index a0c792c54a6fab246dd66afca5af860cdb53a7f8..94b834a6ac8fc6ecd1b70ddf7ad4d7e9e5f5a92a 100644 |
--- a/webrtc/common_audio/wav_file.cc |
+++ b/webrtc/common_audio/wav_file.cc |
@@ -23,7 +23,7 @@ namespace webrtc { |
// We write 16-bit PCM WAV files. |
static const WavFormat kWavFormat = kWavFormatPcm; |
-static const int kBytesPerSample = 2; |
+static const size_t kBytesPerSample = 2; |
// Doesn't take ownership of the file handle and won't close it. |
class ReadableWavFile : public ReadableWav { |
@@ -43,7 +43,7 @@ WavReader::WavReader(const std::string& filename) |
ReadableWavFile readable(file_handle_); |
WavFormat format; |
- int bytes_per_sample; |
+ size_t bytes_per_sample; |
CHECK(ReadWavHeader(&readable, &num_channels_, &sample_rate_, &format, |
&bytes_per_sample, &num_samples_)); |
num_samples_remaining_ = num_samples_; |
@@ -60,14 +60,13 @@ size_t WavReader::ReadSamples(size_t num_samples, int16_t* samples) { |
#error "Need to convert samples to big-endian when reading from WAV file" |
#endif |
// There could be metadata after the audio; ensure we don't read it. |
- num_samples = std::min(rtc::checked_cast<uint32_t>(num_samples), |
- num_samples_remaining_); |
+ num_samples = std::min(num_samples, num_samples_remaining_); |
const size_t read = |
fread(samples, sizeof(*samples), num_samples, file_handle_); |
// If we didn't read what was requested, ensure we've reached the EOF. |
CHECK(read == num_samples || feof(file_handle_)); |
CHECK_LE(read, num_samples_remaining_); |
- num_samples_remaining_ -= rtc::checked_cast<uint32_t>(read); |
+ num_samples_remaining_ -= read; |
return read; |
} |
@@ -91,7 +90,7 @@ void WavReader::Close() { |
} |
WavWriter::WavWriter(const std::string& filename, int sample_rate, |
- int num_channels) |
+ size_t num_channels) |
: sample_rate_(sample_rate), |
num_channels_(num_channels), |
num_samples_(0), |
@@ -120,9 +119,8 @@ void WavWriter::WriteSamples(const int16_t* samples, size_t num_samples) { |
const size_t written = |
fwrite(samples, sizeof(*samples), num_samples, file_handle_); |
CHECK_EQ(num_samples, written); |
- num_samples_ += static_cast<uint32_t>(written); |
- CHECK(written <= std::numeric_limits<uint32_t>::max() || |
- num_samples_ >= written); // detect uint32_t overflow |
+ num_samples_ += written; |
+ CHECK(num_samples_ >= written); // detect size_t overflow |
} |
void WavWriter::WriteSamples(const float* samples, size_t num_samples) { |
@@ -149,7 +147,7 @@ void WavWriter::Close() { |
rtc_WavWriter* rtc_WavOpen(const char* filename, |
int sample_rate, |
- int num_channels) { |
+ size_t num_channels) { |
return reinterpret_cast<rtc_WavWriter*>( |
new webrtc::WavWriter(filename, sample_rate, num_channels)); |
} |
@@ -168,7 +166,7 @@ int rtc_WavSampleRate(const rtc_WavWriter* wf) { |
return reinterpret_cast<const webrtc::WavWriter*>(wf)->sample_rate(); |
} |
-int rtc_WavNumChannels(const rtc_WavWriter* wf) { |
+size_t rtc_WavNumChannels(const rtc_WavWriter* wf) { |
return reinterpret_cast<const webrtc::WavWriter*>(wf)->num_channels(); |
} |