Prepare to convert various types to size_t.
This makes some behaviorally-invariant changes to make certain code that currently only works correctly with signed types work safely regardless of the signedness of the types in question. This is preparation for a future change that will convert a variety of types to size_t. There are also some formatting changes (e.g. converting "enum hack" usage to real consts) to make it simpler to just change "int" to "size_t" in the future to change the types of those constants. BUG=none R=andrew@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org TBR=ajm Review URL: https://codereview.webrtc.org/1174813003 Cr-Commit-Position: refs/heads/master@{#9413}
This commit is contained in:
@ -404,7 +404,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
|
||||
// Find the maximizing index |i| of the cost function
|
||||
// f[i] = best_correlation[i] / best_distortion[i].
|
||||
int32_t best_ratio = std::numeric_limits<int32_t>::min();
|
||||
int best_index = -1;
|
||||
int best_index = std::numeric_limits<int>::max();
|
||||
for (int i = 0; i < kNumCorrelationCandidates; ++i) {
|
||||
int32_t ratio;
|
||||
if (best_distortion[i] > 0) {
|
||||
@ -549,9 +549,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
|
||||
}
|
||||
|
||||
// Set the 3 lag values.
|
||||
int lag_difference = distortion_lag - correlation_lag;
|
||||
if (lag_difference == 0) {
|
||||
// |distortion_lag| and |correlation_lag| are equal.
|
||||
if (distortion_lag == correlation_lag) {
|
||||
expand_lags_[0] = distortion_lag;
|
||||
expand_lags_[1] = distortion_lag;
|
||||
expand_lags_[2] = distortion_lag;
|
||||
@ -563,7 +561,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
|
||||
// Second lag is the average of the two.
|
||||
expand_lags_[1] = (distortion_lag + correlation_lag) / 2;
|
||||
// Third lag is the average again, but rounding towards |correlation_lag|.
|
||||
if (lag_difference > 0) {
|
||||
if (distortion_lag > correlation_lag) {
|
||||
expand_lags_[2] = (distortion_lag + correlation_lag - 1) / 2;
|
||||
} else {
|
||||
expand_lags_[2] = (distortion_lag + correlation_lag + 1) / 2;
|
||||
@ -691,9 +689,8 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
|
||||
temp_sum += kCoefficients[1] * x1;
|
||||
temp_sum += kCoefficients[2] * x2;
|
||||
temp_sum += kCoefficients[3] * x3;
|
||||
parameters.voice_mix_factor = temp_sum / 4096;
|
||||
parameters.voice_mix_factor = std::min(parameters.voice_mix_factor,
|
||||
static_cast<int16_t>(16384));
|
||||
parameters.voice_mix_factor =
|
||||
static_cast<int16_t>(std::min(temp_sum / 4096, 16384));
|
||||
parameters.voice_mix_factor = std::max(parameters.voice_mix_factor,
|
||||
static_cast<int16_t>(0));
|
||||
} else {
|
||||
|
||||
@ -175,7 +175,7 @@ int Merge::GetExpandedSignal(int* old_length, int* expand_period) {
|
||||
// This is the truncated length.
|
||||
}
|
||||
// This assert should always be true thanks to the if statement above.
|
||||
assert(210 * kMaxSampleRate / 8000 - *old_length >= 0);
|
||||
assert(210 * kMaxSampleRate / 8000 >= *old_length);
|
||||
|
||||
AudioMultiVector expanded_temp(num_channels_);
|
||||
expand_->Process(&expanded_temp);
|
||||
@ -342,7 +342,7 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
|
||||
int start_index = timestamps_per_call_ +
|
||||
static_cast<int>(expand_->overlap_length());
|
||||
start_index = std::max(start_position, start_index);
|
||||
start_index = std::max(start_index - input_length, 0);
|
||||
start_index = (input_length > start_index) ? 0 : (start_index - input_length);
|
||||
// Downscale starting index to 4kHz domain. (fs_mult_ * 2 = fs_hz_ / 4000.)
|
||||
int start_index_downsamp = start_index / (fs_mult_ * 2);
|
||||
|
||||
|
||||
@ -1520,10 +1520,10 @@ int NetEqImpl::DoPreemptiveExpand(int16_t* decoded_buffer,
|
||||
borrowed_samples_per_channel = static_cast<int>(required_samples -
|
||||
decoded_length_per_channel);
|
||||
// Calculate how many of these were already played out.
|
||||
old_borrowed_samples_per_channel = static_cast<int>(
|
||||
borrowed_samples_per_channel - sync_buffer_->FutureLength());
|
||||
old_borrowed_samples_per_channel = std::max(
|
||||
0, old_borrowed_samples_per_channel);
|
||||
const int future_length = static_cast<int>(sync_buffer_->FutureLength());
|
||||
old_borrowed_samples_per_channel =
|
||||
(borrowed_samples_per_channel > future_length) ?
|
||||
(borrowed_samples_per_channel - future_length) : 0;
|
||||
memmove(&decoded_buffer[borrowed_samples_per_channel * num_channels],
|
||||
decoded_buffer,
|
||||
sizeof(int16_t) * decoded_length);
|
||||
|
||||
@ -83,8 +83,10 @@ int Normal::Process(const int16_t* input,
|
||||
scaling = std::max(scaling, 0); // |scaling| should always be >= 0.
|
||||
int32_t energy = WebRtcSpl_DotProductWithScale(signal, signal,
|
||||
energy_length, scaling);
|
||||
if ((energy_length >> scaling) > 0) {
|
||||
energy = energy / (energy_length >> scaling);
|
||||
int32_t scaled_energy_length =
|
||||
static_cast<int32_t>(energy_length >> scaling);
|
||||
if (scaled_energy_length > 0) {
|
||||
energy = energy / scaled_energy_length;
|
||||
} else {
|
||||
energy = 0;
|
||||
}
|
||||
|
||||
@ -450,7 +450,10 @@ int main(int argc, char* argv[]) {
|
||||
CHECK_NOT_NULL(out_file);
|
||||
printf("Output file: %s\n\n", argv[2]);
|
||||
packet_size = atoi(argv[3]);
|
||||
CHECK_NOT_NULL(packet_size);
|
||||
if (packet_size <= 0) {
|
||||
printf("Packet size %d must be positive", packet_size);
|
||||
return -1;
|
||||
}
|
||||
printf("Packet size: %i\n", packet_size);
|
||||
|
||||
// check for stereo
|
||||
|
||||
Reference in New Issue
Block a user