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

@ -163,9 +163,9 @@ int AudioDecoderIlbc::DecodeInternal(const uint8_t* encoded,
SpeechType* speech_type) { SpeechType* speech_type) {
DCHECK_EQ(sample_rate_hz, 8000); DCHECK_EQ(sample_rate_hz, 8000);
int16_t temp_type = 1; // Default is speech. int16_t temp_type = 1; // Default is speech.
int16_t ret = WebRtcIlbcfix_Decode(dec_state_, encoded, int ret = WebRtcIlbcfix_Decode(dec_state_, encoded,
static_cast<int16_t>(encoded_len), decoded, static_cast<int16_t>(encoded_len), decoded,
&temp_type); &temp_type);
*speech_type = ConvertSpeechType(temp_type); *speech_type = ConvertSpeechType(temp_type);
return ret; return ret;
} }
@ -330,11 +330,11 @@ int AudioDecoderOpus::DecodeInternal(const uint8_t* encoded,
SpeechType* speech_type) { SpeechType* speech_type) {
DCHECK_EQ(sample_rate_hz, 48000); DCHECK_EQ(sample_rate_hz, 48000);
int16_t temp_type = 1; // Default is speech. int16_t temp_type = 1; // Default is speech.
int16_t ret = WebRtcOpus_Decode(dec_state_, encoded, int ret = WebRtcOpus_Decode(dec_state_, encoded,
static_cast<int16_t>(encoded_len), decoded, static_cast<int16_t>(encoded_len), decoded,
&temp_type); &temp_type);
if (ret > 0) if (ret > 0)
ret *= static_cast<int16_t>(channels_); // Return total number of samples. ret *= static_cast<int>(channels_); // Return total number of samples.
*speech_type = ConvertSpeechType(temp_type); *speech_type = ConvertSpeechType(temp_type);
return ret; return ret;
} }
@ -352,11 +352,11 @@ int AudioDecoderOpus::DecodeRedundantInternal(const uint8_t* encoded,
DCHECK_EQ(sample_rate_hz, 48000); DCHECK_EQ(sample_rate_hz, 48000);
int16_t temp_type = 1; // Default is speech. int16_t temp_type = 1; // Default is speech.
int16_t ret = WebRtcOpus_DecodeFec(dec_state_, encoded, int ret = WebRtcOpus_DecodeFec(dec_state_, encoded,
static_cast<int16_t>(encoded_len), decoded, static_cast<int16_t>(encoded_len), decoded,
&temp_type); &temp_type);
if (ret > 0) if (ret > 0)
ret *= static_cast<int16_t>(channels_); // Return total number of samples. ret *= static_cast<int>(channels_); // Return total number of samples.
*speech_type = ConvertSpeechType(temp_type); *speech_type = ConvertSpeechType(temp_type);
return ret; return ret;
} }

View File

@ -272,7 +272,7 @@ void DspHelper::CrossFade(const int16_t* input1, const int16_t* input2,
} }
void DspHelper::UnmuteSignal(const int16_t* input, size_t length, void DspHelper::UnmuteSignal(const int16_t* input, size_t length,
int16_t* factor, int16_t increment, int16_t* factor, int increment,
int16_t* output) { int16_t* output) {
uint16_t factor_16b = *factor; uint16_t factor_16b = *factor;
int32_t factor_32b = (static_cast<int32_t>(factor_16b) << 6) + 32; int32_t factor_32b = (static_cast<int32_t>(factor_16b) << 6) + 32;
@ -284,7 +284,7 @@ void DspHelper::UnmuteSignal(const int16_t* input, size_t length,
*factor = factor_16b; *factor = factor_16b;
} }
void DspHelper::MuteSignal(int16_t* signal, int16_t mute_slope, size_t length) { void DspHelper::MuteSignal(int16_t* signal, int mute_slope, size_t length) {
int32_t factor = (16384 << 6) + 32; int32_t factor = (16384 << 6) + 32;
for (size_t i = 0; i < length; i++) { for (size_t i = 0; i < length; i++) {
signal[i] = ((factor >> 6) * signal[i] + 8192) >> 14; signal[i] = ((factor >> 6) * signal[i] + 8192) >> 14;

View File

@ -110,11 +110,11 @@ class DspHelper {
// sample and increases the gain by |increment| (Q20) for each sample. The // sample and increases the gain by |increment| (Q20) for each sample. The
// result is written to |output|. |length| samples are processed. // result is written to |output|. |length| samples are processed.
static void UnmuteSignal(const int16_t* input, size_t length, int16_t* factor, static void UnmuteSignal(const int16_t* input, size_t length, int16_t* factor,
int16_t increment, int16_t* output); int increment, int16_t* output);
// Starts at unity gain and gradually fades out |signal|. For each sample, // Starts at unity gain and gradually fades out |signal|. For each sample,
// the gain is reduced by |mute_slope| (Q14). |length| samples are processed. // the gain is reduced by |mute_slope| (Q14). |length| samples are processed.
static void MuteSignal(int16_t* signal, int16_t mute_slope, size_t length); static void MuteSignal(int16_t* signal, int mute_slope, size_t length);
// Downsamples |input| from |sample_rate_hz| to 4 kHz sample rate. The input // Downsamples |input| from |sample_rate_hz| to 4 kHz sample rate. The input
// has |input_length| samples, and the method will write |output_length| // has |input_length| samples, and the method will write |output_length|

View File

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

View File

@ -72,7 +72,7 @@ class Expand {
void GenerateBackgroundNoise(int16_t* random_vector, void GenerateBackgroundNoise(int16_t* random_vector,
size_t channel, size_t channel,
int16_t mute_slope, int mute_slope,
bool too_many_expands, bool too_many_expands,
size_t num_noise_samples, size_t num_noise_samples,
int16_t* buffer); int16_t* buffer);
@ -113,7 +113,7 @@ class Expand {
AudioVector expand_vector0; AudioVector expand_vector0;
AudioVector expand_vector1; AudioVector expand_vector1;
bool onset; bool onset;
int16_t mute_slope; /* Q20 */ int mute_slope; /* Q20 */
}; };
// Calculate the auto-correlation of |input|, with length |input_length| // Calculate the auto-correlation of |input|, with length |input_length|
@ -123,7 +123,7 @@ class Expand {
void Correlation(const int16_t* input, void Correlation(const int16_t* input,
size_t input_length, size_t input_length,
int16_t* output, int16_t* output,
int16_t* output_scale) const; int* output_scale) const;
void UpdateLagIndex(); void UpdateLagIndex();

View File

@ -314,7 +314,7 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
const int max_corr_length = kMaxCorrelationLength; const int max_corr_length = kMaxCorrelationLength;
int stop_position_downsamp = int stop_position_downsamp =
std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1); std::min(max_corr_length, expand_->max_lag() / (fs_mult_ * 2) + 1);
int16_t correlation_shift = 0; int correlation_shift = 0;
if (expanded_max * input_max > 26843546) { if (expanded_max * input_max > 26843546) {
correlation_shift = 3; correlation_shift = 3;
} }
@ -333,7 +333,7 @@ int16_t Merge::CorrelateAndPeakSearch(int16_t expanded_max, int16_t input_max,
int16_t* correlation_ptr = &correlation16[pad_length]; int16_t* correlation_ptr = &correlation16[pad_length];
int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation, int32_t max_correlation = WebRtcSpl_MaxAbsValueW32(correlation,
stop_position_downsamp); stop_position_downsamp);
int16_t norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation)); int norm_shift = std::max(0, 17 - WebRtcSpl_NormW32(max_correlation));
WebRtcSpl_VectorBitShiftW32ToW16(correlation_ptr, stop_position_downsamp, WebRtcSpl_VectorBitShiftW32ToW16(correlation_ptr, stop_position_downsamp,
correlation, norm_shift); correlation, norm_shift);

View File

@ -1278,7 +1278,7 @@ int NetEqImpl::DecodeLoop(PacketList* packet_list, Operations* operation,
*operation == kPreemptiveExpand); *operation == kPreemptiveExpand);
packet_list->pop_front(); packet_list->pop_front();
size_t payload_length = packet->payload_length; size_t payload_length = packet->payload_length;
int16_t decode_length; int decode_length;
if (packet->sync_packet) { if (packet->sync_packet) {
// Decode to silence with the same frame size as the last decode. // Decode to silence with the same frame size as the last decode.
LOG(LS_VERBOSE) << "Decoding sync-packet: " << LOG(LS_VERBOSE) << "Decoding sync-packet: " <<

View File

@ -111,7 +111,7 @@ int Normal::Process(const int16_t* input,
} }
// If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
int16_t increment = 64 / fs_mult; int increment = static_cast<int>(64 / fs_mult);
for (size_t i = 0; i < length_per_channel; i++) { for (size_t i = 0; i < length_per_channel; i++) {
// Scale with mute factor. // Scale with mute factor.
assert(channel_ix < output->Channels()); assert(channel_ix < output->Channels());
@ -178,7 +178,7 @@ int Normal::Process(const int16_t* input,
// Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are
// still ramping up from previous muting. // still ramping up from previous muting.
// If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
int16_t increment = 64 / fs_mult; int increment = static_cast<int>(64 / fs_mult);
size_t length_per_channel = length / output->Channels(); size_t length_per_channel = length / output->Channels();
for (size_t i = 0; i < length_per_channel; i++) { for (size_t i = 0; i < length_per_channel; i++) {
for (size_t channel_ix = 0; channel_ix < output->Channels(); for (size_t channel_ix = 0; channel_ix < output->Channels();

View File

@ -1561,7 +1561,7 @@ int NetEQTest_encode(int coder,
int useVAD, int useVAD,
int bitrate, int bitrate,
int numChannels) { int numChannels) {
short cdlen = 0; int cdlen = 0;
int16_t* tempdata; int16_t* tempdata;
static int first_cng = 1; static int first_cng = 1;
int16_t tempLen; int16_t tempLen;