| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_coding/neteq/background_noise.h" | 11 #include "webrtc/modules/audio_coding/neteq/background_noise.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <string.h> // memcpy | 14 #include <string.h> // memcpy |
| 15 | 15 |
| 16 #include <algorithm> // min, max | 16 #include <algorithm> // min, max |
| 17 | 17 |
| 18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 18 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 19 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" | 19 #include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h" |
| 20 #include "webrtc/modules/audio_coding/neteq/cross_correlation.h" |
| 20 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" | 21 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 const size_t BackgroundNoise::kMaxLpcOrder; | 26 const size_t BackgroundNoise::kMaxLpcOrder; |
| 26 | 27 |
| 27 BackgroundNoise::BackgroundNoise(size_t num_channels) | 28 BackgroundNoise::BackgroundNoise(size_t num_channels) |
| 28 : num_channels_(num_channels), | 29 : num_channels_(num_channels), |
| 29 channel_parameters_(new ChannelParameters[num_channels_]), | 30 channel_parameters_(new ChannelParameters[num_channels_]), |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 assert(channel < num_channels_); | 163 assert(channel < num_channels_); |
| 163 return channel_parameters_[channel].scale; | 164 return channel_parameters_[channel].scale; |
| 164 } | 165 } |
| 165 int16_t BackgroundNoise::ScaleShift(size_t channel) const { | 166 int16_t BackgroundNoise::ScaleShift(size_t channel) const { |
| 166 assert(channel < num_channels_); | 167 assert(channel < num_channels_); |
| 167 return channel_parameters_[channel].scale_shift; | 168 return channel_parameters_[channel].scale_shift; |
| 168 } | 169 } |
| 169 | 170 |
| 170 int32_t BackgroundNoise::CalculateAutoCorrelation( | 171 int32_t BackgroundNoise::CalculateAutoCorrelation( |
| 171 const int16_t* signal, size_t length, int32_t* auto_correlation) const { | 172 const int16_t* signal, size_t length, int32_t* auto_correlation) const { |
| 172 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(signal, length); | |
| 173 int correlation_scale = kLogVecLen - | |
| 174 WebRtcSpl_NormW32(signal_max * signal_max); | |
| 175 correlation_scale = std::max(0, correlation_scale); | |
| 176 | |
| 177 static const int kCorrelationStep = -1; | 173 static const int kCorrelationStep = -1; |
| 178 WebRtcSpl_CrossCorrelation(auto_correlation, signal, signal, length, | 174 const int correlation_scale = |
| 179 kMaxLpcOrder + 1, correlation_scale, | 175 CrossCorrelationWithAutoShift(auto_correlation, signal, signal, length, |
| 180 kCorrelationStep); | 176 kMaxLpcOrder + 1, kCorrelationStep); |
| 181 | 177 |
| 182 // Number of shifts to normalize energy to energy/sample. | 178 // Number of shifts to normalize energy to energy/sample. |
| 183 int energy_sample_shift = kLogVecLen - correlation_scale; | 179 int energy_sample_shift = kLogVecLen - correlation_scale; |
| 184 return auto_correlation[0] >> energy_sample_shift; | 180 return auto_correlation[0] >> energy_sample_shift; |
| 185 } | 181 } |
| 186 | 182 |
| 187 void BackgroundNoise::IncrementEnergyThreshold(size_t channel, | 183 void BackgroundNoise::IncrementEnergyThreshold(size_t channel, |
| 188 int32_t sample_energy) { | 184 int32_t sample_energy) { |
| 189 // TODO(hlundin): Simplify the below threshold update. What this code | 185 // TODO(hlundin): Simplify the below threshold update. What this code |
| 190 // does is simply "threshold += (increment * threshold) >> 16", but due | 186 // does is simply "threshold += (increment * threshold) >> 16", but due |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // Add 13 to the |scale_shift_|, since the random numbers table is in | 249 // Add 13 to the |scale_shift_|, since the random numbers table is in |
| 254 // Q13. | 250 // Q13. |
| 255 // TODO(hlundin): Move the "13" to where the |scale_shift_| is used? | 251 // TODO(hlundin): Move the "13" to where the |scale_shift_| is used? |
| 256 parameters.scale_shift = | 252 parameters.scale_shift = |
| 257 static_cast<int16_t>(13 + ((kLogResidualLength + norm_shift) / 2)); | 253 static_cast<int16_t>(13 + ((kLogResidualLength + norm_shift) / 2)); |
| 258 | 254 |
| 259 initialized_ = true; | 255 initialized_ = true; |
| 260 } | 256 } |
| 261 | 257 |
| 262 } // namespace webrtc | 258 } // namespace webrtc |
| OLD | NEW |