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

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

Issue 1948483002: Using ring buffer for AudioVector in NetEq. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 24 matching lines...) Expand all
35 } 35 }
36 36
37 assert(output->Empty()); 37 assert(output->Empty());
38 // Output should be empty at this point. 38 // Output should be empty at this point.
39 if (length % output->Channels() != 0) { 39 if (length % output->Channels() != 0) {
40 // The length does not match the number of channels. 40 // The length does not match the number of channels.
41 output->Clear(); 41 output->Clear();
42 return 0; 42 return 0;
43 } 43 }
44 output->PushBackInterleaved(input, length); 44 output->PushBackInterleaved(input, length);
45 int16_t* signal = &(*output)[0][0];
46 45
47 const int fs_mult = fs_hz_ / 8000; 46 const int fs_mult = fs_hz_ / 8000;
48 assert(fs_mult > 0); 47 assert(fs_mult > 0);
49 // fs_shift = log2(fs_mult), rounded down. 48 // fs_shift = log2(fs_mult), rounded down.
50 // Note that |fs_shift| is not "exact" for 48 kHz. 49 // Note that |fs_shift| is not "exact" for 48 kHz.
51 // TODO(hlundin): Investigate this further. 50 // TODO(hlundin): Investigate this further.
52 const int fs_shift = 30 - WebRtcSpl_NormW32(fs_mult); 51 const int fs_shift = 30 - WebRtcSpl_NormW32(fs_mult);
53 52
54 // Check if last RecOut call resulted in an Expand. If so, we have to take 53 // Check if last RecOut call resulted in an Expand. If so, we have to take
55 // care of some cross-fading and unmuting. 54 // care of some cross-fading and unmuting.
56 if (last_mode == kModeExpand) { 55 if (last_mode == kModeExpand) {
57 // Generate interpolation data using Expand. 56 // Generate interpolation data using Expand.
58 // First, set Expand parameters to appropriate values. 57 // First, set Expand parameters to appropriate values.
59 expand_->SetParametersForNormalAfterExpand(); 58 expand_->SetParametersForNormalAfterExpand();
60 59
61 // Call Expand. 60 // Call Expand.
62 AudioMultiVector expanded(output->Channels()); 61 AudioMultiVector expanded(output->Channels());
63 expand_->Process(&expanded); 62 expand_->Process(&expanded);
64 expand_->Reset(); 63 expand_->Reset();
65 64
66 for (size_t channel_ix = 0; channel_ix < output->Channels(); ++channel_ix) { 65 for (size_t channel_ix = 0; channel_ix < output->Channels(); ++channel_ix) {
67 // Adjust muting factor (main muting factor times expand muting factor). 66 // Adjust muting factor (main muting factor times expand muting factor).
68 external_mute_factor_array[channel_ix] = static_cast<int16_t>( 67 external_mute_factor_array[channel_ix] = static_cast<int16_t>(
69 (external_mute_factor_array[channel_ix] * 68 (external_mute_factor_array[channel_ix] *
70 expand_->MuteFactor(channel_ix)) >> 14); 69 expand_->MuteFactor(channel_ix)) >> 14);
71 70
72 int16_t* signal = &(*output)[channel_ix][0];
73 size_t length_per_channel = length / output->Channels(); 71 size_t length_per_channel = length / output->Channels();
72
73 std::unique_ptr<int16_t[]> signal(new int16_t[length_per_channel]);
minyue-webrtc 2016/05/08 06:13:53 will remove definition out of loop.
74 (*output)[channel_ix].CopyTo(length_per_channel, 0, signal.get());
75
74 // Find largest absolute value in new data. 76 // Find largest absolute value in new data.
75 int16_t decoded_max = 77 int16_t decoded_max =
76 WebRtcSpl_MaxAbsValueW16(signal, length_per_channel); 78 WebRtcSpl_MaxAbsValueW16(signal.get(), length_per_channel);
77 // Adjust muting factor if needed (to BGN level). 79 // Adjust muting factor if needed (to BGN level).
78 size_t energy_length = 80 size_t energy_length =
79 std::min(static_cast<size_t>(fs_mult * 64), length_per_channel); 81 std::min(static_cast<size_t>(fs_mult * 64), length_per_channel);
80 int scaling = 6 + fs_shift 82 int scaling = 6 + fs_shift
81 - WebRtcSpl_NormW32(decoded_max * decoded_max); 83 - WebRtcSpl_NormW32(decoded_max * decoded_max);
82 scaling = std::max(scaling, 0); // |scaling| should always be >= 0. 84 scaling = std::max(scaling, 0); // |scaling| should always be >= 0.
83 int32_t energy = WebRtcSpl_DotProductWithScale(signal, signal, 85 int32_t energy = WebRtcSpl_DotProductWithScale(signal.get(), signal.get(),
84 energy_length, scaling); 86 energy_length, scaling);
85 int32_t scaled_energy_length = 87 int32_t scaled_energy_length =
86 static_cast<int32_t>(energy_length >> scaling); 88 static_cast<int32_t>(energy_length >> scaling);
87 if (scaled_energy_length > 0) { 89 if (scaled_energy_length > 0) {
88 energy = energy / scaled_energy_length; 90 energy = energy / scaled_energy_length;
89 } else { 91 } else {
90 energy = 0; 92 energy = 0;
91 } 93 }
92 94
93 int mute_factor; 95 int mute_factor;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 154
153 if (cng_decoder) { 155 if (cng_decoder) {
154 // Generate long enough for 32kHz. 156 // Generate long enough for 32kHz.
155 if (!cng_decoder->Generate(cng_output, 0)) { 157 if (!cng_decoder->Generate(cng_output, 0)) {
156 // Error returned; set return vector to all zeros. 158 // Error returned; set return vector to all zeros.
157 memset(cng_output, 0, sizeof(cng_output)); 159 memset(cng_output, 0, sizeof(cng_output));
158 } 160 }
159 } else { 161 } else {
160 // If no CNG instance is defined, just copy from the decoded data. 162 // If no CNG instance is defined, just copy from the decoded data.
161 // (This will result in interpolating the decoded with itself.) 163 // (This will result in interpolating the decoded with itself.)
162 memcpy(cng_output, signal, fs_mult * 8 * sizeof(int16_t)); 164 (*output)[0].CopyTo(fs_mult * 8, 0, cng_output);
163 } 165 }
164 // Interpolate the CNG into the new vector. 166 // Interpolate the CNG into the new vector.
165 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.) 167 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.)
166 assert(fs_shift < 3); // Will always be 0, 1, or, 2. 168 assert(fs_shift < 3); // Will always be 0, 1, or, 2.
167 int16_t increment = 4 >> fs_shift; 169 int16_t increment = 4 >> fs_shift;
168 int16_t fraction = increment; 170 int16_t fraction = increment;
169 for (size_t i = 0; i < static_cast<size_t>(8 * fs_mult); i++) { 171 for (size_t i = 0; i < static_cast<size_t>(8 * fs_mult); i++) {
170 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now 172 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now
171 // for legacy bit-exactness. 173 // for legacy bit-exactness.
172 signal[i] = 174 (*output)[0][i] = (fraction * (*output)[0][i] +
173 (fraction * signal[i] + (32 - fraction) * cng_output[i] + 8) >> 5; 175 (32 - fraction) * cng_output[i] + 8) >> 5;
174 fraction += increment; 176 fraction += increment;
175 } 177 }
176 } else if (external_mute_factor_array[0] < 16384) { 178 } else if (external_mute_factor_array[0] < 16384) {
177 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are 179 // Previous was neither of Expand, FadeToBGN or RFC3389_CNG, but we are
178 // still ramping up from previous muting. 180 // still ramping up from previous muting.
179 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14). 181 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
180 int increment = 64 / fs_mult; 182 int increment = 64 / fs_mult;
181 size_t length_per_channel = length / output->Channels(); 183 size_t length_per_channel = length / output->Channels();
182 for (size_t i = 0; i < length_per_channel; i++) { 184 for (size_t i = 0; i < length_per_channel; i++) {
183 for (size_t channel_ix = 0; channel_ix < output->Channels(); 185 for (size_t channel_ix = 0; channel_ix < output->Channels();
(...skipping 10 matching lines...) Expand all
194 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( 196 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
195 16384, external_mute_factor_array[channel_ix] + increment)); 197 16384, external_mute_factor_array[channel_ix] + increment));
196 } 198 }
197 } 199 }
198 } 200 }
199 201
200 return static_cast<int>(length); 202 return static_cast<int>(length);
201 } 203 }
202 204
203 } // namespace webrtc 205 } // namespace webrtc
OLDNEW
« webrtc/modules/audio_coding/neteq/merge.cc ('K') | « webrtc/modules/audio_coding/neteq/merge.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698