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

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

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 5 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 27 matching lines...) Expand all
38 assert(output->Empty()); 38 assert(output->Empty());
39 // Output should be empty at this point. 39 // Output should be empty at this point.
40 if (length % output->Channels() != 0) { 40 if (length % output->Channels() != 0) {
41 // The length does not match the number of channels. 41 // The length does not match the number of channels.
42 output->Clear(); 42 output->Clear();
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 size_t fs_mult = fs_hz_ / 8000;
hlundin-webrtc 2015/08/10 11:30:01 not size_t
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(static_cast<int32_t>(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());
64 expand_->Process(&expanded); 64 expand_->Process(&expanded);
65 expand_->Reset(); 65 expand_->Reset();
66 66
67 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) {
68 // Adjust muting factor (main muting factor times expand muting factor). 68 // Adjust muting factor (main muting factor times expand muting factor).
69 external_mute_factor_array[channel_ix] = static_cast<int16_t>( 69 external_mute_factor_array[channel_ix] = static_cast<int16_t>(
70 (external_mute_factor_array[channel_ix] * 70 (external_mute_factor_array[channel_ix] *
71 expand_->MuteFactor(channel_ix)) >> 14); 71 expand_->MuteFactor(channel_ix)) >> 14);
72 72
73 int16_t* signal = &(*output)[channel_ix][0]; 73 int16_t* signal = &(*output)[channel_ix][0];
74 size_t length_per_channel = length / output->Channels(); 74 size_t length_per_channel = length / output->Channels();
75 // Find largest absolute value in new data. 75 // Find largest absolute value in new data.
76 int16_t decoded_max = WebRtcSpl_MaxAbsValueW16( 76 int16_t decoded_max =
77 signal, static_cast<int>(length_per_channel)); 77 WebRtcSpl_MaxAbsValueW16(signal, length_per_channel);
78 // Adjust muting factor if needed (to BGN level). 78 // Adjust muting factor if needed (to BGN level).
79 int energy_length = std::min(static_cast<int>(fs_mult * 64), 79 size_t energy_length = std::min(fs_mult * 64, length_per_channel);
80 static_cast<int>(length_per_channel));
81 int scaling = 6 + fs_shift 80 int scaling = 6 + fs_shift
82 - WebRtcSpl_NormW32(decoded_max * decoded_max); 81 - WebRtcSpl_NormW32(decoded_max * decoded_max);
83 scaling = std::max(scaling, 0); // |scaling| should always be >= 0. 82 scaling = std::max(scaling, 0); // |scaling| should always be >= 0.
84 int32_t energy = WebRtcSpl_DotProductWithScale(signal, signal, 83 int32_t energy = WebRtcSpl_DotProductWithScale(signal, signal,
85 energy_length, scaling); 84 energy_length, scaling);
86 int32_t scaled_energy_length = 85 int32_t scaled_energy_length =
87 static_cast<int32_t>(energy_length >> scaling); 86 static_cast<int32_t>(energy_length >> scaling);
88 if (scaled_energy_length > 0) { 87 if (scaled_energy_length > 0) {
89 energy = energy / scaled_energy_length; 88 energy = energy / scaled_energy_length;
90 } else { 89 } else {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 assert(channel_ix < output->Channels()); 136 assert(channel_ix < output->Channels());
138 assert(i < output->Size()); 137 assert(i < output->Size());
139 (*output)[channel_ix][i] = 138 (*output)[channel_ix][i] =
140 static_cast<int16_t>((fraction * (*output)[channel_ix][i] + 139 static_cast<int16_t>((fraction * (*output)[channel_ix][i] +
141 (32 - fraction) * expanded[channel_ix][i] + 8) >> 5); 140 (32 - fraction) * expanded[channel_ix][i] + 8) >> 5);
142 fraction += increment; 141 fraction += increment;
143 } 142 }
144 } 143 }
145 } else if (last_mode == kModeRfc3389Cng) { 144 } else if (last_mode == kModeRfc3389Cng) {
146 assert(output->Channels() == 1); // Not adapted for multi-channel yet. 145 assert(output->Channels() == 1); // Not adapted for multi-channel yet.
147 static const int kCngLength = 32; 146 static const size_t kCngLength = 32;
148 int16_t cng_output[kCngLength]; 147 int16_t cng_output[kCngLength];
149 // Reset mute factor and start up fresh. 148 // Reset mute factor and start up fresh.
150 external_mute_factor_array[0] = 16384; 149 external_mute_factor_array[0] = 16384;
151 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); 150 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder();
152 151
153 if (cng_decoder) { 152 if (cng_decoder) {
154 // Generate long enough for 32kHz. 153 // Generate long enough for 32kHz.
155 if (WebRtcCng_Generate(cng_decoder->CngDecoderInstance(), cng_output, 154 if (WebRtcCng_Generate(cng_decoder->CngDecoderInstance(), cng_output,
156 kCngLength, 0) < 0) { 155 kCngLength, 0) < 0) {
157 // Error returned; set return vector to all zeros. 156 // Error returned; set return vector to all zeros.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min( 194 external_mute_factor_array[channel_ix] = static_cast<int16_t>(std::min(
196 16384, external_mute_factor_array[channel_ix] + increment)); 195 16384, external_mute_factor_array[channel_ix] + increment));
197 } 196 }
198 } 197 }
199 } 198 }
200 199
201 return static_cast<int>(length); 200 return static_cast<int>(length);
202 } 201 }
203 202
204 } // namespace webrtc 203 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698