OLD | NEW |
---|---|
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 |
11 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | 11 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" |
12 | 12 |
13 int WebRtcSpl_AutoCorrelation(const int16_t* in_vector, | 13 int WebRtcSpl_AutoCorrelation(const int16_t* in_vector, |
14 int in_vector_length, | 14 size_t in_vector_length, |
15 int order, | 15 size_t order, |
16 int32_t* result, | 16 int32_t* result, |
17 int* scale) { | 17 int* scale) { |
18 int32_t sum = 0; | 18 int32_t sum = 0; |
19 int i = 0, j = 0; | 19 size_t i = 0, j = 0; |
20 int16_t smax = 0; | 20 int16_t smax = 0; |
21 int scaling = 0; | 21 int scaling = 0; |
22 | 22 |
23 if (order > in_vector_length) { | 23 if (order > in_vector_length) { |
Andrew MacDonald
2015/07/22 19:54:58
assert this instead and return a size_t?
| |
24 /* Undefined */ | 24 /* Undefined */ |
25 return -1; | 25 return -1; |
26 } else if (order < 0) { | |
27 order = in_vector_length; | |
28 } | 26 } |
29 | 27 |
30 // Find the maximum absolute value of the samples. | 28 // Find the maximum absolute value of the samples. |
31 smax = WebRtcSpl_MaxAbsValueW16(in_vector, in_vector_length); | 29 smax = WebRtcSpl_MaxAbsValueW16(in_vector, in_vector_length); |
32 | 30 |
33 // In order to avoid overflow when computing the sum we should scale the | 31 // In order to avoid overflow when computing the sum we should scale the |
34 // samples so that (in_vector_length * smax * smax) will not overflow. | 32 // samples so that (in_vector_length * smax * smax) will not overflow. |
35 if (smax == 0) { | 33 if (smax == 0) { |
36 scaling = 0; | 34 scaling = 0; |
37 } else { | 35 } else { |
(...skipping 19 matching lines...) Expand all Loading... | |
57 sum += (in_vector[j + 2] * in_vector[i + j + 2]) >> scaling; | 55 sum += (in_vector[j + 2] * in_vector[i + j + 2]) >> scaling; |
58 sum += (in_vector[j + 3] * in_vector[i + j + 3]) >> scaling; | 56 sum += (in_vector[j + 3] * in_vector[i + j + 3]) >> scaling; |
59 } | 57 } |
60 for (; j < in_vector_length - i; j++) { | 58 for (; j < in_vector_length - i; j++) { |
61 sum += (in_vector[j] * in_vector[i + j]) >> scaling; | 59 sum += (in_vector[j] * in_vector[i + j]) >> scaling; |
62 } | 60 } |
63 *result++ = sum; | 61 *result++ = sum; |
64 } | 62 } |
65 | 63 |
66 *scale = scaling; | 64 *scale = scaling; |
67 return order + 1; | 65 return (int)(order + 1); |
68 } | 66 } |
OLD | NEW |