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/codecs/cng/webrtc_cng.h" | 11 #include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
| 15 #include "webrtc/base/safe_conversions.h" |
15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 16 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
16 | 17 |
17 namespace webrtc { | 18 namespace webrtc { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const size_t kCngMaxOutsizeOrder = 640; | 22 const size_t kCngMaxOutsizeOrder = 640; |
22 | 23 |
23 // TODO(ossu): Rename the left-over WebRtcCng according to style guide. | 24 // TODO(ossu): Rename the left-over WebRtcCng according to style guide. |
24 void WebRtcCng_K2a16(int16_t* k, int useOrder, int16_t* a); | 25 void WebRtcCng_K2a16(int16_t* k, int useOrder, int16_t* a); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 112 |
112 bool ComfortNoiseDecoder::Generate(rtc::ArrayView<int16_t> out_data, | 113 bool ComfortNoiseDecoder::Generate(rtc::ArrayView<int16_t> out_data, |
113 bool new_period) { | 114 bool new_period) { |
114 int16_t excitation[kCngMaxOutsizeOrder]; | 115 int16_t excitation[kCngMaxOutsizeOrder]; |
115 int16_t low[kCngMaxOutsizeOrder]; | 116 int16_t low[kCngMaxOutsizeOrder]; |
116 int16_t lpPoly[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 117 int16_t lpPoly[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
117 int16_t ReflBetaStd = 26214; /* 0.8 in q15. */ | 118 int16_t ReflBetaStd = 26214; /* 0.8 in q15. */ |
118 int16_t ReflBetaCompStd = 6553; /* 0.2 in q15. */ | 119 int16_t ReflBetaCompStd = 6553; /* 0.2 in q15. */ |
119 int16_t ReflBetaNewP = 19661; /* 0.6 in q15. */ | 120 int16_t ReflBetaNewP = 19661; /* 0.6 in q15. */ |
120 int16_t ReflBetaCompNewP = 13107; /* 0.4 in q15. */ | 121 int16_t ReflBetaCompNewP = 13107; /* 0.4 in q15. */ |
121 int16_t Beta, BetaC, tmp1, tmp2, tmp3; | 122 int16_t Beta, BetaC; /* These are in Q15. */ |
122 int32_t targetEnergy; | 123 int32_t targetEnergy; |
123 int16_t En; | 124 int16_t En; |
124 int16_t temp16; | 125 int16_t temp16; |
125 const size_t num_samples = out_data.size(); | 126 const size_t num_samples = out_data.size(); |
126 | 127 |
127 if (num_samples > kCngMaxOutsizeOrder) { | 128 if (num_samples > kCngMaxOutsizeOrder) { |
128 return false; | 129 return false; |
129 } | 130 } |
130 | 131 |
131 if (new_period) { | 132 if (new_period) { |
132 dec_used_scale_factor_ = dec_target_scale_factor_; | 133 dec_used_scale_factor_ = dec_target_scale_factor_; |
133 Beta = ReflBetaNewP; | 134 Beta = ReflBetaNewP; |
134 BetaC = ReflBetaCompNewP; | 135 BetaC = ReflBetaCompNewP; |
135 } else { | 136 } else { |
136 Beta = ReflBetaStd; | 137 Beta = ReflBetaStd; |
137 BetaC = ReflBetaCompStd; | 138 BetaC = ReflBetaCompStd; |
138 } | 139 } |
139 | 140 |
140 /* Here we use a 0.5 weighting, should possibly be modified to 0.6. */ | 141 /* Calculate new scale factor in Q13 */ |
141 tmp1 = dec_used_scale_factor_ << 2; /* Q13->Q15 */ | 142 dec_used_scale_factor_ = |
142 tmp2 = dec_target_scale_factor_ << 2; /* Q13->Q15 */ | 143 rtc::checked_cast<int16_t>( |
143 tmp3 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(tmp1, Beta, 15); | 144 WEBRTC_SPL_MUL_16_16_RSFT(dec_used_scale_factor_, Beta >> 2, 13) + |
144 tmp3 += (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(tmp2, BetaC, 15); | 145 WEBRTC_SPL_MUL_16_16_RSFT(dec_target_scale_factor_, BetaC >> 2, 13)); |
145 dec_used_scale_factor_ = tmp3 >> 2; /* Q15->Q13 */ | |
146 | 146 |
147 dec_used_energy_ = dec_used_energy_ >> 1; | 147 dec_used_energy_ = dec_used_energy_ >> 1; |
148 dec_used_energy_ += dec_target_energy_ >> 1; | 148 dec_used_energy_ += dec_target_energy_ >> 1; |
149 | 149 |
150 /* Do the same for the reflection coeffs. */ | 150 /* Do the same for the reflection coeffs, albeit in Q15. */ |
151 for (size_t i = 0; i < WEBRTC_CNG_MAX_LPC_ORDER; i++) { | 151 for (size_t i = 0; i < WEBRTC_CNG_MAX_LPC_ORDER; i++) { |
152 dec_used_reflCoefs_[i] = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( | 152 dec_used_reflCoefs_[i] = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( |
153 dec_used_reflCoefs_[i], Beta, 15); | 153 dec_used_reflCoefs_[i], Beta, 15); |
154 dec_used_reflCoefs_[i] += (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( | 154 dec_used_reflCoefs_[i] += (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( |
155 dec_target_reflCoefs_[i], BetaC, 15); | 155 dec_target_reflCoefs_[i], BetaC, 15); |
156 } | 156 } |
157 | 157 |
158 /* Compute the polynomial coefficients. */ | 158 /* Compute the polynomial coefficients. */ |
159 WebRtcCng_K2a16(dec_used_reflCoefs_, WEBRTC_CNG_MAX_LPC_ORDER, lpPoly); | 159 WebRtcCng_K2a16(dec_used_reflCoefs_, WEBRTC_CNG_MAX_LPC_ORDER, lpPoly); |
160 | 160 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 anyptr = any; | 433 anyptr = any; |
434 for (i = 0; i < (m + 2); i++) { | 434 for (i = 0; i < (m + 2); i++) { |
435 *aptr++ = *anyptr++; | 435 *aptr++ = *anyptr++; |
436 } | 436 } |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 } // namespace | 440 } // namespace |
441 | 441 |
442 } // namespace webrtc | 442 } // namespace webrtc |
OLD | NEW |