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}
This commit is contained in:
Peter Kasting
2015-08-24 14:52:23 -07:00
parent b594041ec8
commit dce40cf804
471 changed files with 3716 additions and 3499 deletions

View File

@ -14,9 +14,9 @@
namespace webrtc {
void AudioFrameOperations::MonoToStereo(const int16_t* src_audio,
int samples_per_channel,
size_t samples_per_channel,
int16_t* dst_audio) {
for (int i = 0; i < samples_per_channel; i++) {
for (size_t i = 0; i < samples_per_channel; i++) {
dst_audio[2 * i] = src_audio[i];
dst_audio[2 * i + 1] = src_audio[i];
}
@ -41,9 +41,9 @@ int AudioFrameOperations::MonoToStereo(AudioFrame* frame) {
}
void AudioFrameOperations::StereoToMono(const int16_t* src_audio,
int samples_per_channel,
size_t samples_per_channel,
int16_t* dst_audio) {
for (int i = 0; i < samples_per_channel; i++) {
for (size_t i = 0; i < samples_per_channel; i++) {
dst_audio[i] = (src_audio[2 * i] + src_audio[2 * i + 1]) >> 1;
}
}
@ -62,7 +62,7 @@ int AudioFrameOperations::StereoToMono(AudioFrame* frame) {
void AudioFrameOperations::SwapStereoChannels(AudioFrame* frame) {
if (frame->num_channels_ != 2) return;
for (int i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
int16_t temp_data = frame->data_[i];
frame->data_[i] = frame->data_[i + 1];
frame->data_[i + 1] = temp_data;
@ -79,7 +79,7 @@ int AudioFrameOperations::Scale(float left, float right, AudioFrame& frame) {
return -1;
}
for (int i = 0; i < frame.samples_per_channel_; i++) {
for (size_t i = 0; i < frame.samples_per_channel_; i++) {
frame.data_[2 * i] =
static_cast<int16_t>(left * frame.data_[2 * i]);
frame.data_[2 * i + 1] =
@ -92,7 +92,7 @@ int AudioFrameOperations::ScaleWithSat(float scale, AudioFrame& frame) {
int32_t temp_data = 0;
// Ensure that the output result is saturated [-32768, +32767].
for (int i = 0; i < frame.samples_per_channel_ * frame.num_channels_;
for (size_t i = 0; i < frame.samples_per_channel_ * frame.num_channels_;
i++) {
temp_data = static_cast<int32_t>(scale * frame.data_[i]);
if (temp_data < -32768) {

View File

@ -28,14 +28,14 @@ class AudioFrameOperationsTest : public ::testing::Test {
};
void SetFrameData(AudioFrame* frame, int16_t left, int16_t right) {
for (int i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
frame->data_[i] = left;
frame->data_[i + 1] = right;
}
}
void SetFrameData(AudioFrame* frame, int16_t data) {
for (int i = 0; i < frame->samples_per_channel_; i++) {
for (size_t i = 0; i < frame->samples_per_channel_; i++) {
frame->data_[i] = data;
}
}
@ -45,7 +45,7 @@ void VerifyFramesAreEqual(const AudioFrame& frame1, const AudioFrame& frame2) {
EXPECT_EQ(frame1.samples_per_channel_,
frame2.samples_per_channel_);
for (int i = 0; i < frame1.samples_per_channel_ * frame1.num_channels_;
for (size_t i = 0; i < frame1.samples_per_channel_ * frame1.num_channels_;
i++) {
EXPECT_EQ(frame1.data_[i], frame2.data_[i]);
}

View File

@ -95,7 +95,7 @@ int32_t FilePlayerImpl::AudioCodec(CodecInst& audioCodec) const
int32_t FilePlayerImpl::Get10msAudioFromFile(
int16_t* outBuffer,
int& lengthInSamples,
size_t& lengthInSamples,
int frequencyInHz)
{
if(_codec.plfreq == 0)
@ -127,8 +127,7 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
return 0;
}
// One sample is two bytes.
unresampledAudioFrame.samples_per_channel_ =
(uint16_t)lengthInBytes >> 1;
unresampledAudioFrame.samples_per_channel_ = lengthInBytes >> 1;
} else {
// Decode will generate 10 ms of audio data. PlayoutAudioData(..)
@ -156,14 +155,14 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
}
}
int outLen = 0;
size_t outLen = 0;
if(_resampler.ResetIfNeeded(unresampledAudioFrame.sample_rate_hz_,
frequencyInHz, 1))
{
LOG(LS_WARNING) << "Get10msAudioFromFile() unexpected codec.";
// New sampling frequency. Update state.
outLen = frequencyInHz / 100;
outLen = static_cast<size_t>(frequencyInHz / 100);
memset(outBuffer, 0, outLen * sizeof(int16_t));
return 0;
}
@ -177,7 +176,7 @@ int32_t FilePlayerImpl::Get10msAudioFromFile(
if(_scaling != 1.0)
{
for (int i = 0;i < outLen; i++)
for (size_t i = 0;i < outLen; i++)
{
outBuffer[i] = (int16_t)(outBuffer[i] * _scaling);
}

View File

@ -31,7 +31,7 @@ public:
virtual int Get10msAudioFromFile(
int16_t* outBuffer,
int& lengthInSamples,
size_t& lengthInSamples,
int frequencyInHz);
virtual int32_t RegisterModuleFileCallback(FileCallback* callback);
virtual int32_t StartPlayingFile(

View File

@ -62,12 +62,12 @@ class FilePlayerTest : public ::testing::Test {
rtc::Md5Digest checksum;
for (int i = 0; i < output_length_ms / 10; ++i) {
int16_t out[10 * kSampleRateHz / 1000] = {0};
int num_samples;
size_t num_samples;
EXPECT_EQ(0,
player_->Get10msAudioFromFile(out, num_samples, kSampleRateHz));
checksum.Update(out, num_samples * sizeof(out[0]));
if (FLAGS_file_player_output) {
ASSERT_EQ(static_cast<size_t>(num_samples),
ASSERT_EQ(num_samples,
fwrite(out, sizeof(out[0]), num_samples, output_file_));
}
}

View File

@ -156,7 +156,7 @@ int32_t FileRecorderImpl::RecordAudioToFile(
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
tempAudioFrame.samples_per_channel_ =
incomingAudioFrame.samples_per_channel_;
for (uint16_t i = 0;
for (size_t i = 0;
i < (incomingAudioFrame.samples_per_channel_); i++)
{
// Sample value is the average of left and right buffer rounded to
@ -174,7 +174,7 @@ int32_t FileRecorderImpl::RecordAudioToFile(
tempAudioFrame.sample_rate_hz_ = incomingAudioFrame.sample_rate_hz_;
tempAudioFrame.samples_per_channel_ =
incomingAudioFrame.samples_per_channel_;
for (uint16_t i = 0;
for (size_t i = 0;
i < (incomingAudioFrame.samples_per_channel_); i++)
{
// Duplicate sample to both channels
@ -210,7 +210,7 @@ int32_t FileRecorderImpl::RecordAudioToFile(
return -1;
}
} else {
int outLen = 0;
size_t outLen = 0;
_audioResampler.ResetIfNeeded(ptrAudioFrame->sample_rate_hz_,
codec_info_.plfreq,
ptrAudioFrame->num_channels_);