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/post_decode_vad.h" | 20 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 // static | |
25 const size_t BackgroundNoise::kMaxLpcOrder; | |
Peter Kasting
2015/07/23 19:37:05
Changing the type of this from int to size_t means
hlundin-webrtc
2015/08/10 11:30:00
Acknowledged.
| |
26 | |
24 BackgroundNoise::BackgroundNoise(size_t num_channels) | 27 BackgroundNoise::BackgroundNoise(size_t num_channels) |
25 : num_channels_(num_channels), | 28 : num_channels_(num_channels), |
26 channel_parameters_(new ChannelParameters[num_channels_]), | 29 channel_parameters_(new ChannelParameters[num_channels_]), |
27 mode_(NetEq::kBgnOn) { | 30 mode_(NetEq::kBgnOn) { |
28 Reset(); | 31 Reset(); |
29 } | 32 } |
30 | 33 |
31 BackgroundNoise::~BackgroundNoise() {} | 34 BackgroundNoise::~BackgroundNoise() {} |
32 | 35 |
33 void BackgroundNoise::Reset() { | 36 void BackgroundNoise::Reset() { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } | 146 } |
144 | 147 |
145 const int16_t* BackgroundNoise::FilterState(size_t channel) const { | 148 const int16_t* BackgroundNoise::FilterState(size_t channel) const { |
146 assert(channel < num_channels_); | 149 assert(channel < num_channels_); |
147 return channel_parameters_[channel].filter_state; | 150 return channel_parameters_[channel].filter_state; |
148 } | 151 } |
149 | 152 |
150 void BackgroundNoise::SetFilterState(size_t channel, const int16_t* input, | 153 void BackgroundNoise::SetFilterState(size_t channel, const int16_t* input, |
151 size_t length) { | 154 size_t length) { |
152 assert(channel < num_channels_); | 155 assert(channel < num_channels_); |
153 length = std::min(length, static_cast<size_t>(kMaxLpcOrder)); | 156 length = std::min(length, kMaxLpcOrder); |
154 memcpy(channel_parameters_[channel].filter_state, input, | 157 memcpy(channel_parameters_[channel].filter_state, input, |
155 length * sizeof(int16_t)); | 158 length * sizeof(int16_t)); |
156 } | 159 } |
157 | 160 |
158 int16_t BackgroundNoise::Scale(size_t channel) const { | 161 int16_t BackgroundNoise::Scale(size_t channel) const { |
159 assert(channel < num_channels_); | 162 assert(channel < num_channels_); |
160 return channel_parameters_[channel].scale; | 163 return channel_parameters_[channel].scale; |
161 } | 164 } |
162 int16_t BackgroundNoise::ScaleShift(size_t channel) const { | 165 int16_t BackgroundNoise::ScaleShift(size_t channel) const { |
163 assert(channel < num_channels_); | 166 assert(channel < num_channels_); |
164 return channel_parameters_[channel].scale_shift; | 167 return channel_parameters_[channel].scale_shift; |
165 } | 168 } |
166 | 169 |
167 int32_t BackgroundNoise::CalculateAutoCorrelation( | 170 int32_t BackgroundNoise::CalculateAutoCorrelation( |
168 const int16_t* signal, int length, int32_t* auto_correlation) const { | 171 const int16_t* signal, size_t length, int32_t* auto_correlation) const { |
169 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(signal, length); | 172 int16_t signal_max = WebRtcSpl_MaxAbsValueW16(signal, length); |
170 int correlation_scale = kLogVecLen - | 173 int correlation_scale = kLogVecLen - |
171 WebRtcSpl_NormW32(signal_max * signal_max); | 174 WebRtcSpl_NormW32(signal_max * signal_max); |
172 correlation_scale = std::max(0, correlation_scale); | 175 correlation_scale = std::max(0, correlation_scale); |
173 | 176 |
174 static const int kCorrelationStep = -1; | 177 static const int kCorrelationStep = -1; |
175 WebRtcSpl_CrossCorrelation(auto_correlation, signal, signal, length, | 178 WebRtcSpl_CrossCorrelation(auto_correlation, signal, signal, length, |
176 kMaxLpcOrder + 1, correlation_scale, | 179 kMaxLpcOrder + 1, correlation_scale, |
177 kCorrelationStep); | 180 kCorrelationStep); |
178 | 181 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 | 243 |
241 // Normalize residual_energy to 29 or 30 bits before sqrt. | 244 // Normalize residual_energy to 29 or 30 bits before sqrt. |
242 int16_t norm_shift = WebRtcSpl_NormW32(residual_energy) - 1; | 245 int16_t norm_shift = WebRtcSpl_NormW32(residual_energy) - 1; |
243 if (norm_shift & 0x1) { | 246 if (norm_shift & 0x1) { |
244 norm_shift -= 1; // Even number of shifts required. | 247 norm_shift -= 1; // Even number of shifts required. |
245 } | 248 } |
246 assert(norm_shift >= 0); // Should always be positive. | 249 assert(norm_shift >= 0); // Should always be positive. |
247 residual_energy = residual_energy << norm_shift; | 250 residual_energy = residual_energy << norm_shift; |
248 | 251 |
249 // Calculate scale and shift factor. | 252 // Calculate scale and shift factor. |
250 parameters.scale = WebRtcSpl_SqrtFloor(residual_energy); | 253 parameters.scale = static_cast<int16_t>(WebRtcSpl_SqrtFloor(residual_energy)); |
hlundin-webrtc
2015/08/10 11:30:00
rtc::checked_cast
Peter Kasting
2015/08/17 22:49:46
This shouldn't be necessary, since by definition t
hlundin-webrtc
2015/08/18 07:19:18
That seems like a good idea, if you don't mind.
Peter Kasting
2015/08/18 20:32:07
Actually, I don't think this is safe after all. T
hlundin-webrtc
2015/08/19 07:36:45
I saw the bug and will triage it. Thanks for inves
| |
251 // Add 13 to the |scale_shift_|, since the random numbers table is in | 254 // Add 13 to the |scale_shift_|, since the random numbers table is in |
252 // Q13. | 255 // Q13. |
253 // TODO(hlundin): Move the "13" to where the |scale_shift_| is used? | 256 // TODO(hlundin): Move the "13" to where the |scale_shift_| is used? |
254 parameters.scale_shift = | 257 parameters.scale_shift = |
255 static_cast<int16_t>(13 + ((kLogResidualLength + norm_shift) / 2)); | 258 static_cast<int16_t>(13 + ((kLogResidualLength + norm_shift) / 2)); |
256 | 259 |
257 initialized_ = true; | 260 initialized_ = true; |
258 } | 261 } |
259 | 262 |
260 } // namespace webrtc | 263 } // namespace webrtc |
OLD | NEW |