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 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 win_slope_Q14 = (1 << 14) / static_cast<int16_t>(win_length); | 138 win_slope_Q14 = (1 << 14) / static_cast<int16_t>(win_length); |
139 } | 139 } |
140 int16_t win_up_Q14 = 0; | 140 int16_t win_up_Q14 = 0; |
141 for (size_t i = 0; i < win_length; i++) { | 141 for (size_t i = 0; i < win_length; i++) { |
142 win_up_Q14 += win_slope_Q14; | 142 win_up_Q14 += win_slope_Q14; |
143 (*output)[channel_ix][i] = | 143 (*output)[channel_ix][i] = |
144 (win_up_Q14 * (*output)[channel_ix][i] + | 144 (win_up_Q14 * (*output)[channel_ix][i] + |
145 ((1 << 14) - win_up_Q14) * expanded[channel_ix][i] + (1 << 13)) >> | 145 ((1 << 14) - win_up_Q14) * expanded[channel_ix][i] + (1 << 13)) >> |
146 14; | 146 14; |
147 } | 147 } |
148 if (fs_hz_ == 48000) { | 148 RTC_DCHECK_GT(win_up_Q14, |
149 RTC_DCHECK_EQ(win_up_Q14, (1 << 14) - 16); | 149 (1 << 14) - 32); // Worst case rouding is a length of 34 |
150 } else { | |
151 RTC_DCHECK_EQ(win_up_Q14, 1 << 14); | |
152 } | |
153 } | 150 } |
154 } else if (last_mode == kModeRfc3389Cng) { | 151 } else if (last_mode == kModeRfc3389Cng) { |
155 RTC_DCHECK_EQ(output->Channels(), 1); // Not adapted for multi-channel yet. | 152 RTC_DCHECK_EQ(output->Channels(), 1); // Not adapted for multi-channel yet. |
156 static const size_t kCngLength = 48; | 153 static const size_t kCngLength = 48; |
157 RTC_DCHECK_LE(8 * fs_mult, kCngLength); | 154 RTC_DCHECK_LE(8 * fs_mult, kCngLength); |
158 int16_t cng_output[kCngLength]; | 155 int16_t cng_output[kCngLength]; |
159 // Reset mute factor and start up fresh. | 156 // Reset mute factor and start up fresh. |
160 external_mute_factor_array[0] = 16384; | 157 external_mute_factor_array[0] = 16384; |
161 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 158 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
162 | 159 |
(...skipping 17 matching lines...) Expand all Loading... |
180 win_slope_Q14 = (1 << 14) / static_cast<int16_t>(win_length); | 177 win_slope_Q14 = (1 << 14) / static_cast<int16_t>(win_length); |
181 } | 178 } |
182 int16_t win_up_Q14 = 0; | 179 int16_t win_up_Q14 = 0; |
183 for (size_t i = 0; i < win_length; i++) { | 180 for (size_t i = 0; i < win_length; i++) { |
184 win_up_Q14 += win_slope_Q14; | 181 win_up_Q14 += win_slope_Q14; |
185 (*output)[0][i] = | 182 (*output)[0][i] = |
186 (win_up_Q14 * (*output)[0][i] + | 183 (win_up_Q14 * (*output)[0][i] + |
187 ((1 << 14) - win_up_Q14) * cng_output[i] + (1 << 13)) >> | 184 ((1 << 14) - win_up_Q14) * cng_output[i] + (1 << 13)) >> |
188 14; | 185 14; |
189 } | 186 } |
190 if (fs_hz_ == 48000) { | 187 RTC_DCHECK_GT(win_up_Q14, |
191 RTC_DCHECK_EQ(win_up_Q14, (1 << 14) - 16); | 188 (1 << 14) - 32); // Worst case rouding is a length of 34 |
192 } else { | |
193 RTC_DCHECK_EQ(win_up_Q14, 1 << 14); | |
194 } | |
195 } else if (external_mute_factor_array[0] < 16384) { | 189 } else if (external_mute_factor_array[0] < 16384) { |
196 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are | 190 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are |
197 // still ramping up from previous muting. | 191 // still ramping up from previous muting. |
198 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). | 192 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). |
199 int increment = 64 / fs_mult; | 193 int increment = 64 / fs_mult; |
200 size_t length_per_channel = length / output->Channels(); | 194 size_t length_per_channel = length / output->Channels(); |
201 for (size_t i = 0; i < length_per_channel; i++) { | 195 for (size_t i = 0; i < length_per_channel; i++) { |
202 for (size_t channel_ix = 0; channel_ix < output->Channels(); | 196 for (size_t channel_ix = 0; channel_ix < output->Channels(); |
203 ++channel_ix) { | 197 ++channel_ix) { |
204 // Scale with mute factor. | 198 // Scale with mute factor. |
205 RTC_DCHECK_LT(channel_ix, output->Channels()); | 199 RTC_DCHECK_LT(channel_ix, output->Channels()); |
206 RTC_DCHECK_LT(i, output->Size()); | 200 RTC_DCHECK_LT(i, output->Size()); |
207 int32_t scaled_signal = (*output)[channel_ix][i] * | 201 int32_t scaled_signal = (*output)[channel_ix][i] * |
208 external_mute_factor_array[channel_ix]; | 202 external_mute_factor_array[channel_ix]; |
209 // Shift 14 with proper rounding. | 203 // Shift 14 with proper rounding. |
210 (*output)[channel_ix][i] = | 204 (*output)[channel_ix][i] = |
211 static_cast<int16_t>((scaled_signal + 8192) >> 14); | 205 static_cast<int16_t>((scaled_signal + 8192) >> 14); |
212 // Increase mute_factor towards 16384. | 206 // Increase mute_factor towards 16384. |
213 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( | 207 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( |
214 16384, external_mute_factor_array[channel_ix] + increment)); | 208 16384, external_mute_factor_array[channel_ix] + increment)); |
215 } | 209 } |
216 } | 210 } |
217 } | 211 } |
218 | 212 |
219 return static_cast<int>(length); | 213 return static_cast<int>(length); |
220 } | 214 } |
221 | 215 |
222 } // namespace webrtc | 216 } // namespace webrtc |
OLD | NEW |