Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: webrtc/modules/audio_coding/neteq/normal.cc

Issue 1168753002: Match existing type usage better. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 return 0; 43 return 0;
44 } 44 }
45 output->PushBackInterleaved(input, length); 45 output->PushBackInterleaved(input, length);
46 int16_t* signal = &(*output)[0][0]; 46 int16_t* signal = &(*output)[0][0];
47 47
48 const unsigned fs_mult = fs_hz_ / 8000; 48 const unsigned fs_mult = fs_hz_ / 8000;
49 assert(fs_mult > 0); 49 assert(fs_mult > 0);
50 // fs_shift = log2(fs_mult), rounded down. 50 // fs_shift = log2(fs_mult), rounded down.
51 // Note that |fs_shift| is not "exact" for 48 kHz. 51 // Note that |fs_shift| is not "exact" for 48 kHz.
52 // TODO(hlundin): Investigate this further. 52 // TODO(hlundin): Investigate this further.
53 const int fs_shift = 30 - WebRtcSpl_NormW32(fs_mult); 53 const int fs_shift = 30 - WebRtcSpl_NormW32(static_cast<int32_t>(fs_mult));
54 54
55 // Check if last RecOut call resulted in an Expand. If so, we have to take 55 // Check if last RecOut call resulted in an Expand. If so, we have to take
56 // care of some cross-fading and unmuting. 56 // care of some cross-fading and unmuting.
57 if (last_mode == kModeExpand) { 57 if (last_mode == kModeExpand) {
58 // Generate interpolation data using Expand. 58 // Generate interpolation data using Expand.
59 // First, set Expand parameters to appropriate values. 59 // First, set Expand parameters to appropriate values.
60 expand_->SetParametersForNormalAfterExpand(); 60 expand_->SetParametersForNormalAfterExpand();
61 61
62 // Call Expand. 62 // Call Expand.
63 AudioMultiVector expanded(output->Channels()); 63 AudioMultiVector expanded(output->Channels());
(...skipping 28 matching lines...) Expand all
92 } 92 }
93 93
94 int mute_factor; 94 int mute_factor;
95 if ((energy != 0) && 95 if ((energy != 0) &&
96 (energy > background_noise_.Energy(channel_ix))) { 96 (energy > background_noise_.Energy(channel_ix))) {
97 // Normalize new frame energy to 15 bits. 97 // Normalize new frame energy to 15 bits.
98 scaling = WebRtcSpl_NormW32(energy) - 16; 98 scaling = WebRtcSpl_NormW32(energy) - 16;
99 // We want background_noise_.energy() / energy in Q14. 99 // We want background_noise_.energy() / energy in Q14.
100 int32_t bgn_energy = 100 int32_t bgn_energy =
101 background_noise_.Energy(channel_ix) << (scaling+14); 101 background_noise_.Energy(channel_ix) << (scaling+14);
102 int16_t energy_scaled = energy << scaling; 102 int16_t energy_scaled = static_cast<int16_t>(energy << scaling);
103 int16_t ratio = WebRtcSpl_DivW32W16(bgn_energy, energy_scaled); 103 int32_t ratio = WebRtcSpl_DivW32W16(bgn_energy, energy_scaled);
104 mute_factor = WebRtcSpl_SqrtFloor(static_cast<int32_t>(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] = std::min(mute_factor, 16384); 109 external_mute_factor_array[channel_ix] =
110 static_cast<int16_t>(std::min(mute_factor, 16384));
110 } 111 }
111 112
112 // 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).
113 int16_t increment = 64 / fs_mult; 114 int16_t increment = 64 / fs_mult;
114 for (size_t i = 0; i < length_per_channel; i++) { 115 for (size_t i = 0; i < length_per_channel; i++) {
115 // Scale with mute factor. 116 // Scale with mute factor.
116 assert(channel_ix < output->Channels()); 117 assert(channel_ix < output->Channels());
117 assert(i < output->Size()); 118 assert(i < output->Size());
118 int32_t scaled_signal = (*output)[channel_ix][i] * 119 int32_t scaled_signal = (*output)[channel_ix][i] *
119 external_mute_factor_array[channel_ix]; 120 external_mute_factor_array[channel_ix];
120 // Shift 14 with proper rounding. 121 // Shift 14 with proper rounding.
121 (*output)[channel_ix][i] = (scaled_signal + 8192) >> 14; 122 (*output)[channel_ix][i] =
123 static_cast<int16_t>((scaled_signal + 8192) >> 14);
122 // Increase mute_factor towards 16384. 124 // Increase mute_factor towards 16384.
123 external_mute_factor_array[channel_ix] = 125 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
124 std::min(external_mute_factor_array[channel_ix] + increment, 16384); 126 external_mute_factor_array[channel_ix] + increment, 16384));
125 } 127 }
126 128
127 // Interpolate the expanded data into the new vector. 129 // Interpolate the expanded data into the new vector.
128 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.) 130 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.)
129 assert(fs_shift < 3); // Will always be 0, 1, or, 2. 131 assert(fs_shift < 3); // Will always be 0, 1, or, 2.
130 increment = 4 >> fs_shift; 132 increment = 4 >> fs_shift;
131 int fraction = increment; 133 int fraction = increment;
132 for (size_t i = 0; i < 8 * fs_mult; i++) { 134 for (size_t i = 0; i < 8 * fs_mult; i++) {
133 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 135 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8
134 // now for legacy bit-exactness. 136 // now for legacy bit-exactness.
135 assert(channel_ix < output->Channels()); 137 assert(channel_ix < output->Channels());
136 assert(i < output->Size()); 138 assert(i < output->Size());
137 (*output)[channel_ix][i] = 139 (*output)[channel_ix][i] =
138 (fraction * (*output)[channel_ix][i] + 140 static_cast<int16_t>((fraction * (*output)[channel_ix][i] +
139 (32 - fraction) * expanded[channel_ix][i] + 8) >> 5; 141 (32 - fraction) * expanded[channel_ix][i] + 8) >> 5);
140 fraction += increment; 142 fraction += increment;
141 } 143 }
142 } 144 }
143 } else if (last_mode == kModeRfc3389Cng) { 145 } else if (last_mode == kModeRfc3389Cng) {
144 assert(output->Channels() == 1); // Not adapted for multi-channel yet. 146 assert(output->Channels() == 1); // Not adapted for multi-channel yet.
145 static const int kCngLength = 32; 147 static const int kCngLength = 32;
146 int16_t cng_output[kCngLength]; 148 int16_t cng_output[kCngLength];
147 // Reset mute factor and start up fresh. 149 // Reset mute factor and start up fresh.
148 external_mute_factor_array[0] = 16384; 150 external_mute_factor_array[0] = 16384;
149 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); 151 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder();
(...skipping 30 matching lines...) Expand all
180 size_t length_per_channel = length / output->Channels(); 182 size_t length_per_channel = length / output->Channels();
181 for (size_t i = 0; i < length_per_channel; i++) { 183 for (size_t i = 0; i < length_per_channel; i++) {
182 for (size_t channel_ix = 0; channel_ix < output->Channels(); 184 for (size_t channel_ix = 0; channel_ix < output->Channels();
183 ++channel_ix) { 185 ++channel_ix) {
184 // Scale with mute factor. 186 // Scale with mute factor.
185 assert(channel_ix < output->Channels()); 187 assert(channel_ix < output->Channels());
186 assert(i < output->Size()); 188 assert(i < output->Size());
187 int32_t scaled_signal = (*output)[channel_ix][i] * 189 int32_t scaled_signal = (*output)[channel_ix][i] *
188 external_mute_factor_array[channel_ix]; 190 external_mute_factor_array[channel_ix];
189 // Shift 14 with proper rounding. 191 // Shift 14 with proper rounding.
190 (*output)[channel_ix][i] = (scaled_signal + 8192) >> 14; 192 (*output)[channel_ix][i] =
193 static_cast<int16_t>((scaled_signal + 8192) >> 14);
191 // Increase mute_factor towards 16384. 194 // Increase mute_factor towards 16384.
192 external_mute_factor_array[channel_ix] = 195 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
193 std::min(16384, external_mute_factor_array[channel_ix] + increment); 196 16384, external_mute_factor_array[channel_ix] + increment));
194 } 197 }
195 } 198 }
196 } 199 }
197 200
198 return static_cast<int>(length); 201 return static_cast<int>(length);
199 } 202 }
200 203
201 } // namespace webrtc 204 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_unittest.cc ('k') | webrtc/modules/audio_coding/neteq/statistics_calculator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698