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

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: refinements 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
65 size_t length_per_channel = length / output->Channels();
66 std::unique_ptr<int16_t[]> signal(new int16_t[length_per_channel]);
66 for (size_t channel_ix = 0; channel_ix < output->Channels(); ++channel_ix) { 67 for (size_t channel_ix = 0; channel_ix < output->Channels(); ++channel_ix) {
67 // Adjust muting factor (main muting factor times expand muting factor). 68 // Adjust muting factor (main muting factor times expand muting factor).
68 external_mute_factor_array[channel_ix] = static_cast<int16_t>( 69 external_mute_factor_array[channel_ix] = static_cast<int16_t>(
69 (external_mute_factor_array[channel_ix] * 70 (external_mute_factor_array[channel_ix] *
70 expand_->MuteFactor(channel_ix)) >> 14); 71 expand_->MuteFactor(channel_ix)) >> 14);
71 72
72 int16_t* signal = &(*output)[channel_ix][0]; 73 (*output)[channel_ix].CopyTo(length_per_channel, 0, signal.get());
73 size_t length_per_channel = length / output->Channels(); 74
74 // Find largest absolute value in new data. 75 // Find largest absolute value in new data.
75 int16_t decoded_max = 76 int16_t decoded_max =
76 WebRtcSpl_MaxAbsValueW16(signal, length_per_channel); 77 WebRtcSpl_MaxAbsValueW16(signal.get(), length_per_channel);
77 // Adjust muting factor if needed (to BGN level). 78 // Adjust muting factor if needed (to BGN level).
78 size_t energy_length = 79 size_t energy_length =
79 std::min(static_cast<size_t>(fs_mult * 64), length_per_channel); 80 std::min(static_cast<size_t>(fs_mult * 64), length_per_channel);
80 int scaling = 6 + fs_shift 81 int scaling = 6 + fs_shift
81 - WebRtcSpl_NormW32(decoded_max * decoded_max); 82 - WebRtcSpl_NormW32(decoded_max * decoded_max);
82 scaling = std::max(scaling, 0); // |scaling| should always be >= 0. 83 scaling = std::max(scaling, 0); // |scaling| should always be >= 0.
83 int32_t energy = WebRtcSpl_DotProductWithScale(signal, signal, 84 int32_t energy = WebRtcSpl_DotProductWithScale(signal.get(), signal.get(),
84 energy_length, scaling); 85 energy_length, scaling);
85 int32_t scaled_energy_length = 86 int32_t scaled_energy_length =
86 static_cast<int32_t>(energy_length >> scaling); 87 static_cast<int32_t>(energy_length >> scaling);
87 if (scaled_energy_length > 0) { 88 if (scaled_energy_length > 0) {
88 energy = energy / scaled_energy_length; 89 energy = energy / scaled_energy_length;
89 } else { 90 } else {
90 energy = 0; 91 energy = 0;
91 } 92 }
92 93
93 int mute_factor; 94 int mute_factor;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 if (cng_decoder) { 154 if (cng_decoder) {
154 // Generate long enough for 32kHz. 155 // Generate long enough for 32kHz.
155 if (!cng_decoder->Generate(cng_output, 0)) { 156 if (!cng_decoder->Generate(cng_output, 0)) {
156 // Error returned; set return vector to all zeros. 157 // Error returned; set return vector to all zeros.
157 memset(cng_output, 0, sizeof(cng_output)); 158 memset(cng_output, 0, sizeof(cng_output));
158 } 159 }
159 } else { 160 } else {
160 // If no CNG instance is defined, just copy from the decoded data. 161 // If no CNG instance is defined, just copy from the decoded data.
161 // (This will result in interpolating the decoded with itself.) 162 // (This will result in interpolating the decoded with itself.)
162 memcpy(cng_output, signal, fs_mult * 8 * sizeof(int16_t)); 163 (*output)[0].CopyTo(fs_mult * 8, 0, cng_output);
163 } 164 }
164 // Interpolate the CNG into the new vector. 165 // Interpolate the CNG into the new vector.
165 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.) 166 // (NB/WB/SWB32/SWB48 8/16/32/48 samples.)
166 assert(fs_shift < 3); // Will always be 0, 1, or, 2. 167 assert(fs_shift < 3); // Will always be 0, 1, or, 2.
167 int16_t increment = 4 >> fs_shift; 168 int16_t increment = 4 >> fs_shift;
168 int16_t fraction = increment; 169 int16_t fraction = increment;
169 for (size_t i = 0; i < static_cast<size_t>(8 * fs_mult); i++) { 170 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 171 // TODO(hlundin): Add 16 instead of 8 for correct rounding. Keeping 8 now
171 // for legacy bit-exactness. 172 // for legacy bit-exactness.
172 signal[i] = 173 (*output)[0][i] = (fraction * (*output)[0][i] +
173 (fraction * signal[i] + (32 - fraction) * cng_output[i] + 8) >> 5; 174 (32 - fraction) * cng_output[i] + 8) >> 5;
174 fraction += increment; 175 fraction += increment;
175 } 176 }
176 } else if (external_mute_factor_array[0] < 16384) { 177 } else if (external_mute_factor_array[0] < 16384) {
177 // 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
178 // still ramping up from previous muting. 179 // 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). 180 // If muted increase by 0.64 for every 20 ms (NB/WB 0.0040/0.0020 in Q14).
180 int increment = 64 / fs_mult; 181 int increment = 64 / fs_mult;
181 size_t length_per_channel = length / output->Channels(); 182 size_t length_per_channel = length / output->Channels();
182 for (size_t i = 0; i < length_per_channel; i++) { 183 for (size_t i = 0; i < length_per_channel; i++) {
183 for (size_t channel_ix = 0; channel_ix < output->Channels(); 184 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( 195 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
195 16384, external_mute_factor_array[channel_ix] + increment)); 196 16384, external_mute_factor_array[channel_ix] + increment));
196 } 197 }
197 } 198 }
198 } 199 }
199 200
200 return static_cast<int>(length); 201 return static_cast<int>(length);
201 } 202 }
202 203
203 } // namespace webrtc 204 } // namespace webrtc
OLDNEW
« webrtc/modules/audio_coding/neteq/dsp_helper.h ('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