| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 mute_factor = WebRtcSpl_SqrtFloor(ratio << 14); | 104 mute_factor = WebRtcSpl_SqrtFloor(ratio << 14); |
| 105 } else { | 105 } else { |
| 106 mute_factor = 16384; // 1.0 in Q14. | 106 mute_factor = 16384; // 1.0 in Q14. |
| 107 } | 107 } |
| 108 if (mute_factor > external_mute_factor_array[channel_ix]) { | 108 if (mute_factor > external_mute_factor_array[channel_ix]) { |
| 109 external_mute_factor_array[channel_ix] = | 109 external_mute_factor_array[channel_ix] = |
| 110 static_cast<int16_t>(std::min(mute_factor, 16384)); | 110 static_cast<int16_t>(std::min(mute_factor, 16384)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). | 113 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). |
| 114 int16_t increment = 64 / fs_mult; | 114 int increment = static_cast<int>(64 / fs_mult); |
| 115 for (size_t i = 0; i < length_per_channel; i++) { | 115 for (size_t i = 0; i < length_per_channel; i++) { |
| 116 // Scale with mute factor. | 116 // Scale with mute factor. |
| 117 assert(channel_ix < output->Channels()); | 117 assert(channel_ix < output->Channels()); |
| 118 assert(i < output->Size()); | 118 assert(i < output->Size()); |
| 119 int32_t scaled_signal = (*output)[channel_ix][i] * | 119 int32_t scaled_signal = (*output)[channel_ix][i] * |
| 120 external_mute_factor_array[channel_ix]; | 120 external_mute_factor_array[channel_ix]; |
| 121 // Shift 14 with proper rounding. | 121 // Shift 14 with proper rounding. |
| 122 (*output)[channel_ix][i] = | 122 (*output)[channel_ix][i] = |
| 123 static_cast<int16_t>((scaled_signal + 8192) >> 14); | 123 static_cast<int16_t>((scaled_signal + 8192) >> 14); |
| 124 // Increase mute_factor towards 16384. | 124 // Increase mute_factor towards 16384. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now | 171 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now |
| 172 // for legacy bit-exactness. | 172 // for legacy bit-exactness. |
| 173 signal[i] = | 173 signal[i] = |
| 174 (fraction * signal[i] + (32 - fraction) * cng_output[i] + 8) >> 5; | 174 (fraction * signal[i] + (32 - fraction) * cng_output[i] + 8) >> 5; |
| 175 fraction += increment; | 175 fraction += increment; |
| 176 } | 176 } |
| 177 } else if (external_mute_factor_array[0] < 16384) { | 177 } else if (external_mute_factor_array[0] < 16384) { |
| 178 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are | 178 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are |
| 179 // still ramping up from previous muting. | 179 // still ramping up from previous muting. |
| 180 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). | 180 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). |
| 181 int16_t increment = 64 / fs_mult; | 181 int increment = static_cast<int>(64 / fs_mult); |
| 182 size_t length_per_channel = length / output->Channels(); | 182 size_t length_per_channel = length / output->Channels(); |
| 183 for (size_t i = 0; i < length_per_channel; i++) { | 183 for (size_t i = 0; i < length_per_channel; i++) { |
| 184 for (size_t channel_ix = 0; channel_ix < output->Channels(); | 184 for (size_t channel_ix = 0; channel_ix < output->Channels(); |
| 185 ++channel_ix) { | 185 ++channel_ix) { |
| 186 // Scale with mute factor. | 186 // Scale with mute factor. |
| 187 assert(channel_ix < output->Channels()); | 187 assert(channel_ix < output->Channels()); |
| 188 assert(i < output->Size()); | 188 assert(i < output->Size()); |
| 189 int32_t scaled_signal = (*output)[channel_ix][i] * | 189 int32_t scaled_signal = (*output)[channel_ix][i] * |
| 190 external_mute_factor_array[channel_ix]; | 190 external_mute_factor_array[channel_ix]; |
| 191 // Shift 14 with proper rounding. | 191 // Shift 14 with proper rounding. |
| 192 (*output)[channel_ix][i] = | 192 (*output)[channel_ix][i] = |
| 193 static_cast<int16_t>((scaled_signal + 8192) >> 14); | 193 static_cast<int16_t>((scaled_signal + 8192) >> 14); |
| 194 // Increase mute_factor towards 16384. | 194 // Increase mute_factor towards 16384. |
| 195 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( | 195 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( |
| 196 16384, external_mute_factor_array[channel_ix] + increment)); | 196 16384, external_mute_factor_array[channel_ix] + increment)); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 return static_cast<int>(length); | 201 return static_cast<int>(length); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace webrtc | 204 } // namespace webrtc |
| OLD | NEW |