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

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

Issue 1228843002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 int end_factor = 0; 93 int end_factor = 0;
94 // Loop over the channels, starting at the same |factor| each time. 94 // Loop over the channels, starting at the same |factor| each time.
95 for (size_t channel = 0; channel < signal->Channels(); ++channel) { 95 for (size_t channel = 0; channel < signal->Channels(); ++channel) {
96 end_factor = 96 end_factor =
97 RampSignal(&(*signal)[channel][start_index], length, factor, increment); 97 RampSignal(&(*signal)[channel][start_index], length, factor, increment);
98 } 98 }
99 return end_factor; 99 return end_factor;
100 } 100 }
101 101
102 void DspHelper::PeakDetection(int16_t* data, int data_length, 102 void DspHelper::PeakDetection(int16_t* data, size_t data_length,
103 int num_peaks, int fs_mult, 103 size_t num_peaks, int fs_mult,
104 int* peak_index, int16_t* peak_value) { 104 size_t* peak_index, int16_t* peak_value) {
105 int16_t min_index = 0; 105 size_t min_index = 0;
106 int16_t max_index = 0; 106 size_t max_index = 0;
107 107
108 for (int i = 0; i <= num_peaks - 1; i++) { 108 for (size_t i = 0; i <= num_peaks - 1; i++) {
109 if (num_peaks == 1) { 109 if (num_peaks == 1) {
110 // Single peak. The parabola fit assumes that an extra point is 110 // Single peak. The parabola fit assumes that an extra point is
111 // available; worst case it gets a zero on the high end of the signal. 111 // available; worst case it gets a zero on the high end of the signal.
112 // TODO(hlundin): This can potentially get much worse. It breaks the 112 // TODO(hlundin): This can potentially get much worse. It breaks the
113 // API contract, that the length of |data| is |data_length|. 113 // API contract, that the length of |data| is |data_length|.
114 data_length++; 114 data_length++;
115 } 115 }
116 116
117 peak_index[i] = WebRtcSpl_MaxIndexW16(data, data_length - 1); 117 peak_index[i] = WebRtcSpl_MaxIndexW16(data, data_length - 1);
118 118
(...skipping 22 matching lines...) Expand all
141 } 141 }
142 142
143 if (i != num_peaks - 1) { 143 if (i != num_peaks - 1) {
144 memset(&data[min_index], 0, 144 memset(&data[min_index], 0,
145 sizeof(data[0]) * (max_index - min_index + 1)); 145 sizeof(data[0]) * (max_index - min_index + 1));
146 } 146 }
147 } 147 }
148 } 148 }
149 149
150 void DspHelper::ParabolicFit(int16_t* signal_points, int fs_mult, 150 void DspHelper::ParabolicFit(int16_t* signal_points, int fs_mult,
151 int* peak_index, int16_t* peak_value) { 151 size_t* peak_index, int16_t* peak_value) {
152 uint16_t fit_index[13]; 152 uint16_t fit_index[13];
153 if (fs_mult == 1) { 153 if (fs_mult == 1) {
154 fit_index[0] = 0; 154 fit_index[0] = 0;
155 fit_index[1] = 8; 155 fit_index[1] = 8;
156 fit_index[2] = 16; 156 fit_index[2] = 16;
157 } else if (fs_mult == 2) { 157 } else if (fs_mult == 2) {
158 fit_index[0] = 0; 158 fit_index[0] = 0;
159 fit_index[1] = 4; 159 fit_index[1] = 4;
160 fit_index[2] = 8; 160 fit_index[2] = 8;
161 fit_index[3] = 12; 161 fit_index[3] = 12;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 flag++; 228 flag++;
229 lmt += stp; 229 lmt += stp;
230 } 230 }
231 } 231 }
232 } else { 232 } else {
233 *peak_value = signal_points[1]; 233 *peak_value = signal_points[1];
234 *peak_index = *peak_index * 2 * fs_mult; 234 *peak_index = *peak_index * 2 * fs_mult;
235 } 235 }
236 } 236 }
237 237
238 int DspHelper::MinDistortion(const int16_t* signal, int min_lag, 238 size_t DspHelper::MinDistortion(const int16_t* signal, size_t min_lag,
239 int max_lag, int length, 239 size_t max_lag, size_t length,
240 int32_t* distortion_value) { 240 int32_t* distortion_value) {
241 int best_index = 0; 241 size_t best_index = 0;
242 int32_t min_distortion = WEBRTC_SPL_WORD32_MAX; 242 int32_t min_distortion = WEBRTC_SPL_WORD32_MAX;
243 for (int i = min_lag; i <= max_lag; i++) { 243 for (size_t i = min_lag; i <= max_lag; i++) {
244 int32_t sum_diff = 0; 244 int32_t sum_diff = 0;
245 const int16_t* data1 = signal; 245 const int16_t* data1 = signal;
246 const int16_t* data2 = signal - i; 246 const int16_t* data2 = signal - i;
247 for (int j = 0; j < length; j++) { 247 for (size_t j = 0; j < length; j++) {
248 sum_diff += WEBRTC_SPL_ABS_W32(data1[j] - data2[j]); 248 sum_diff += WEBRTC_SPL_ABS_W32(data1[j] - data2[j]);
249 } 249 }
250 // Compare with previous minimum. 250 // Compare with previous minimum.
251 if (sum_diff < min_distortion) { 251 if (sum_diff < min_distortion) {
252 min_distortion = sum_diff; 252 min_distortion = sum_diff;
253 best_index = i; 253 best_index = i;
254 } 254 }
255 } 255 }
256 *distortion_value = min_distortion; 256 *distortion_value = min_distortion;
257 return best_index; 257 return best_index;
(...skipping 28 matching lines...) Expand all
286 286
287 void DspHelper::MuteSignal(int16_t* signal, int mute_slope, size_t length) { 287 void DspHelper::MuteSignal(int16_t* signal, int mute_slope, size_t length) {
288 int32_t factor = (16384 << 6) + 32; 288 int32_t factor = (16384 << 6) + 32;
289 for (size_t i = 0; i < length; i++) { 289 for (size_t i = 0; i < length; i++) {
290 signal[i] = ((factor >> 6) * signal[i] + 8192) >> 14; 290 signal[i] = ((factor >> 6) * signal[i] + 8192) >> 14;
291 factor -= mute_slope; 291 factor -= mute_slope;
292 } 292 }
293 } 293 }
294 294
295 int DspHelper::DownsampleTo4kHz(const int16_t* input, size_t input_length, 295 int DspHelper::DownsampleTo4kHz(const int16_t* input, size_t input_length,
296 int output_length, int input_rate_hz, 296 size_t output_length, int input_rate_hz,
297 bool compensate_delay, int16_t* output) { 297 bool compensate_delay, int16_t* output) {
298 // Set filter parameters depending on input frequency. 298 // Set filter parameters depending on input frequency.
299 // NOTE: The phase delay values are wrong compared to the true phase delay 299 // NOTE: The phase delay values are wrong compared to the true phase delay
300 // of the filters. However, the error is preserved (through the +1 term) for 300 // of the filters. However, the error is preserved (through the +1 term) for
301 // consistency. 301 // consistency.
302 const int16_t* filter_coefficients; // Filter coefficients. 302 const int16_t* filter_coefficients; // Filter coefficients.
303 int16_t filter_length; // Number of coefficients. 303 size_t filter_length; // Number of coefficients.
304 int16_t filter_delay; // Phase delay in samples. 304 size_t filter_delay; // Phase delay in samples.
305 int16_t factor; // Conversion rate (inFsHz / 8000). 305 int16_t factor; // Conversion rate (inFsHz / 8000).
306 switch (input_rate_hz) { 306 switch (input_rate_hz) {
307 case 8000: { 307 case 8000: {
308 filter_length = 3; 308 filter_length = 3;
309 factor = 2; 309 factor = 2;
310 filter_coefficients = kDownsample8kHzTbl; 310 filter_coefficients = kDownsample8kHzTbl;
311 filter_delay = 1 + 1; 311 filter_delay = 1 + 1;
312 break; 312 break;
313 } 313 }
314 case 16000: { 314 case 16000: {
(...skipping 23 matching lines...) Expand all
338 } 338 }
339 } 339 }
340 340
341 if (!compensate_delay) { 341 if (!compensate_delay) {
342 // Disregard delay compensation. 342 // Disregard delay compensation.
343 filter_delay = 0; 343 filter_delay = 0;
344 } 344 }
345 345
346 // Returns -1 if input signal is too short; 0 otherwise. 346 // Returns -1 if input signal is too short; 0 otherwise.
347 return WebRtcSpl_DownsampleFast( 347 return WebRtcSpl_DownsampleFast(
348 &input[filter_length - 1], static_cast<int>(input_length) - 348 &input[filter_length - 1], input_length - filter_length + 1, output,
349 (filter_length - 1), output, output_length, filter_coefficients, 349 output_length, filter_coefficients, filter_length, factor, filter_delay);
350 filter_length, factor, filter_delay);
351 } 350 }
352 351
353 } // namespace webrtc 352 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/dsp_helper.h ('k') | webrtc/modules/audio_coding/neteq/dtmf_tone_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698