Reland "Upconvert various types to int.", neteq portion.

This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24.  Specifically, the
files in webrtc/modules/audio_coding/neteq/ are relanded.

The original commit message is below:

Upconvert various types to int.

Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t.

Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C."

This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t).  Other locations will be converted to size_t in a separate change.

BUG=none
TBR=kwiberg

Review URL: https://codereview.webrtc.org/1181073002

Cr-Commit-Position: refs/heads/master@{#9427}
This commit is contained in:
Peter Kasting
2015-06-11 19:57:18 -07:00
parent bc440d5651
commit 36b7cc3264
9 changed files with 44 additions and 46 deletions

View File

@ -239,14 +239,12 @@ int Expand::Process(AudioMultiVector* output) {
if (consecutive_expands_ == 3) {
// Let the mute factor decrease from 1.0 to 0.95 in 6.25 ms.
// mute_slope = 0.0010 / fs_mult in Q20.
parameters.mute_slope = std::max(parameters.mute_slope,
static_cast<int16_t>(1049 / fs_mult));
parameters.mute_slope = std::max(parameters.mute_slope, 1049 / fs_mult);
}
if (consecutive_expands_ == 7) {
// Let the mute factor decrease from 1.0 to 0.90 in 6.25 ms.
// mute_slope = 0.0020 / fs_mult in Q20.
parameters.mute_slope = std::max(parameters.mute_slope,
static_cast<int16_t>(2097 / fs_mult));
parameters.mute_slope = std::max(parameters.mute_slope, 2097 / fs_mult);
}
// Mute segment according to slope value.
@ -368,7 +366,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
InitializeForAnExpandPeriod();
// Calculate correlation in downsampled domain (4 kHz sample rate).
int16_t correlation_scale;
int correlation_scale;
int correlation_length = 51; // TODO(hlundin): Legacy bit-exactness.
// If it is decided to break bit-exactness |correlation_length| should be
// initialized to the return value of Correlation().
@ -445,7 +443,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
correlation_length + start_index + correlation_lags - 1);
correlation_scale = ((31 - WebRtcSpl_NormW32(signal_max * signal_max))
+ (31 - WebRtcSpl_NormW32(correlation_length))) - 31;
correlation_scale = std::max(static_cast<int16_t>(0), correlation_scale);
correlation_scale = std::max(0, correlation_scale);
// Calculate the correlation, store in |correlation_vector2|.
WebRtcSpl_CrossCorrelation(
@ -472,7 +470,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
// Calculate the correlation coefficient between the two portions of the
// signal.
int16_t corr_coefficient;
int32_t corr_coefficient;
if ((energy1 > 0) && (energy2 > 0)) {
int energy1_scale = std::max(16 - WebRtcSpl_NormW32(energy1), 0);
int energy2_scale = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
@ -481,17 +479,17 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
// If sum is odd, add 1 to make it even.
energy1_scale += 1;
}
int16_t scaled_energy1 = energy1 >> energy1_scale;
int16_t scaled_energy2 = energy2 >> energy2_scale;
int16_t sqrt_energy_product = WebRtcSpl_SqrtFloor(
scaled_energy1 * scaled_energy2);
int32_t scaled_energy1 = energy1 >> energy1_scale;
int32_t scaled_energy2 = energy2 >> energy2_scale;
int16_t sqrt_energy_product = static_cast<int16_t>(
WebRtcSpl_SqrtFloor(scaled_energy1 * scaled_energy2));
// Calculate max_correlation / sqrt(energy1 * energy2) in Q14.
int cc_shift = 14 - (energy1_scale + energy2_scale) / 2;
max_correlation = WEBRTC_SPL_SHIFT_W32(max_correlation, cc_shift);
corr_coefficient = WebRtcSpl_DivW32W16(max_correlation,
sqrt_energy_product);
corr_coefficient = std::min(static_cast<int16_t>(16384),
corr_coefficient); // Cap at 1.0 in Q14.
// Cap at 1.0 in Q14.
corr_coefficient = std::min(16384, corr_coefficient);
} else {
corr_coefficient = 0;
}
@ -512,8 +510,8 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
if ((energy1 / 4 < energy2) && (energy1 > energy2 / 4)) {
// Energy constraint fulfilled. Use both vectors and scale them
// accordingly.
int16_t scaled_energy2 = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
int16_t scaled_energy1 = scaled_energy2 - 13;
int32_t scaled_energy2 = std::max(16 - WebRtcSpl_NormW32(energy2), 0);
int32_t scaled_energy1 = scaled_energy2 - 13;
// Calculate scaled_energy1 / scaled_energy2 in Q13.
int32_t energy_ratio = WebRtcSpl_DivW32W16(
WEBRTC_SPL_SHIFT_W32(energy1, -scaled_energy1),
@ -682,7 +680,8 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
// voice_mix_factor = 0;
if (corr_coefficient > 7875) {
int16_t x1, x2, x3;
x1 = corr_coefficient; // |corr_coefficient| is in Q14.
// |corr_coefficient| is in Q14.
x1 = static_cast<int16_t>(corr_coefficient);
x2 = (x1 * x1) >> 14; // Shift 14 to keep result in Q14.
x3 = (x1 * x2) >> 14;
static const int kCoefficients[4] = { -5179, 19931, -16422, 5776 };
@ -709,7 +708,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
// the division.
// Shift the denominator from Q13 to Q5 before the division. The result of
// the division will then be in Q20.
int16_t temp_ratio = WebRtcSpl_DivW32W16(
int temp_ratio = WebRtcSpl_DivW32W16(
(slope - 8192) << 12,
static_cast<int16_t>((distortion_lag * slope) >> 8));
if (slope > 14746) {
@ -730,8 +729,7 @@ void Expand::AnalyzeSignal(int16_t* random_vector) {
// Make sure the mute factor decreases from 1.0 to 0.9 in no more than
// 6.25 ms.
// mute_slope >= 0.005 / fs_mult in Q20.
parameters.mute_slope = std::max(static_cast<int16_t>(5243 / fs_mult),
parameters.mute_slope);
parameters.mute_slope = std::max(5243 / fs_mult, parameters.mute_slope);
} else if (slope > 8028) {
parameters.mute_slope = 0;
}
@ -755,7 +753,7 @@ Expand::ChannelParameters::ChannelParameters()
void Expand::Correlation(const int16_t* input,
size_t input_length,
int16_t* output,
int16_t* output_scale) const {
int* output_scale) const {
// Set parameters depending on sample rate.
const int16_t* filter_coefficients;
int16_t num_coefficients;
@ -844,7 +842,7 @@ Expand* ExpandFactory::Create(BackgroundNoise* background_noise,
// TODO(turajs): This can be moved to BackgroundNoise class.
void Expand::GenerateBackgroundNoise(int16_t* random_vector,
size_t channel,
int16_t mute_slope,
int mute_slope,
bool too_many_expands,
size_t num_noise_samples,
int16_t* buffer) {
@ -887,7 +885,7 @@ void Expand::GenerateBackgroundNoise(int16_t* random_vector,
bgn_mute_factor > 0) {
// Fade BGN to zero.
// Calculate muting slope, approximately -2^18 / fs_hz.
int16_t mute_slope;
int mute_slope;
if (fs_hz_ == 8000) {
mute_slope = -32;
} else if (fs_hz_ == 16000) {