Index: webrtc/modules/audio_coding/neteq/normal.cc |
diff --git a/webrtc/modules/audio_coding/neteq/normal.cc b/webrtc/modules/audio_coding/neteq/normal.cc |
index 3dee39a8bc54e0ed2e176b80f64b83e0f9a9d40d..1a7bc68033fb359579bcab83fa74d16949c9e3ec 100644 |
--- a/webrtc/modules/audio_coding/neteq/normal.cc |
+++ b/webrtc/modules/audio_coding/neteq/normal.cc |
@@ -130,23 +130,25 @@ int Normal::Process(const int16_t* input, |
// Interpolate the expanded data into the new vector. |
// (NB/WB/SWB32/SWB48 8/16/32/48 samples.) |
- RTC_DCHECK_LT(fs_shift, 3); // Will always be 0, 1, or, 2. |
- increment = 4 >> fs_shift; |
- int fraction = increment; |
- // Don't interpolate over more samples than what is in output. When this |
- // cap strikes, the interpolation will likely sound worse, but this is an |
- // emergency operation in response to unexpected input. |
- const size_t interp_len_samples = |
- std::min(static_cast<size_t>(8 * fs_mult), output->Size()); |
- for (size_t i = 0; i < interp_len_samples; ++i) { |
- // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 |
- // now for legacy bit-exactness. |
- RTC_DCHECK_LT(channel_ix, output->Channels()); |
- RTC_DCHECK_LT(i, output->Size()); |
+ size_t win_length = samples_per_ms_; |
+ int16_t win_slope_Q14 = default_win_slope_Q14_; |
+ RTC_DCHECK_LT(channel_ix, output->Channels()); |
+ if (win_length > output->Size()) { |
+ win_length = output->Size(); |
+ win_slope_Q14 = (1 << 14) / static_cast<int16_t>(win_length); |
+ } |
+ int16_t win_up_Q14 = 0; |
+ for (size_t i = 0; i < win_length; i++) { |
+ win_up_Q14 += win_slope_Q14; |
(*output)[channel_ix][i] = |
- static_cast<int16_t>((fraction * (*output)[channel_ix][i] + |
- (32 - fraction) * expanded[channel_ix][i] + 8) >> 5); |
- fraction += increment; |
+ (win_up_Q14 * (*output)[channel_ix][i] + |
+ ((1 << 14) - win_up_Q14) * expanded[channel_ix][i] + (1 << 13)) >> |
+ 14; |
+ } |
+ if (fs_hz_ == 48000) { |
+ RTC_DCHECK_EQ(win_up_Q14, (1 << 14) - 16); |
+ } else { |
+ RTC_DCHECK_EQ(win_up_Q14, 1 << 14); |
} |
} |
} else if (last_mode == kModeRfc3389Cng) { |
@@ -171,15 +173,24 @@ int Normal::Process(const int16_t* input, |
} |
// Interpolate the CNG into the new vector. |
// (NB/WB/SWB32/SWB48 8/16/32/48 samples.) |
- RTC_DCHECK_LT(fs_shift, 3); // Will always be 0, 1, or, 2. |
- int16_t increment = 4 >> fs_shift; |
- int16_t fraction = increment; |
- for (size_t i = 0; i < static_cast<size_t>(8 * fs_mult); i++) { |
- // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now |
- // for legacy bit-exactness. |
- (*output)[0][i] = (fraction * (*output)[0][i] + |
- (32 - fraction) * cng_output[i] + 8) >> 5; |
- fraction += increment; |
+ size_t win_length = samples_per_ms_; |
+ int16_t win_slope_Q14 = default_win_slope_Q14_; |
+ if (win_length > kCngLength) { |
+ win_length = kCngLength; |
+ win_slope_Q14 = (1 << 14) / static_cast<int16_t>(win_length); |
+ } |
+ int16_t win_up_Q14 = 0; |
+ for (size_t i = 0; i < win_length; i++) { |
+ win_up_Q14 += win_slope_Q14; |
+ (*output)[0][i] = |
+ (win_up_Q14 * (*output)[0][i] + |
+ ((1 << 14) - win_up_Q14) * cng_output[i] + (1 << 13)) >> |
+ 14; |
+ } |
+ if (fs_hz_ == 48000) { |
+ RTC_DCHECK_EQ(win_up_Q14, (1 << 14) - 16); |
+ } else { |
+ RTC_DCHECK_EQ(win_up_Q14, 1 << 14); |
} |
} else if (external_mute_factor_array[0] < 16384) { |
// Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are |