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 // TODO(Bjornv): Change the function parameter order to WebRTC code style. | 13 // TODO(Bjornv): Change the function parameter order to WebRTC code style. |
14 // C version of WebRtcSpl_DownsampleFast() for generic platforms. | 14 // C version of WebRtcSpl_DownsampleFast() for generic platforms. |
15 int WebRtcSpl_DownsampleFastC(const int16_t* data_in, | 15 int WebRtcSpl_DownsampleFastC(const int16_t* data_in, |
16 int data_in_length, | 16 size_t data_in_length, |
17 int16_t* data_out, | 17 int16_t* data_out, |
18 int data_out_length, | 18 size_t data_out_length, |
19 const int16_t* __restrict coefficients, | 19 const int16_t* __restrict coefficients, |
20 int coefficients_length, | 20 size_t coefficients_length, |
21 int factor, | 21 int factor, |
22 int delay) { | 22 size_t delay) { |
23 int i = 0; | 23 size_t i = 0; |
24 int j = 0; | 24 size_t j = 0; |
25 int32_t out_s32 = 0; | 25 int32_t out_s32 = 0; |
26 int endpos = delay + factor * (data_out_length - 1) + 1; | 26 size_t endpos = delay + factor * (data_out_length - 1) + 1; |
27 | 27 |
28 // Return error if any of the running conditions doesn't meet. | 28 // Return error if any of the running conditions doesn't meet. |
29 if (data_out_length <= 0 || coefficients_length <= 0 | 29 if (data_out_length == 0 || coefficients_length == 0 |
30 || data_in_length < endpos) { | 30 || data_in_length < endpos) { |
31 return -1; | 31 return -1; |
32 } | 32 } |
33 | 33 |
34 for (i = delay; i < endpos; i += factor) { | 34 for (i = delay; i < endpos; i += factor) { |
35 out_s32 = 2048; // Round value, 0.5 in Q12. | 35 out_s32 = 2048; // Round value, 0.5 in Q12. |
36 | 36 |
37 for (j = 0; j < coefficients_length; j++) { | 37 for (j = 0; j < coefficients_length; j++) { |
38 out_s32 += coefficients[j] * data_in[i - j]; // Q12. | 38 out_s32 += coefficients[j] * data_in[i - j]; // Q12. |
39 } | 39 } |
40 | 40 |
41 out_s32 >>= 12; // Q0. | 41 out_s32 >>= 12; // Q0. |
42 | 42 |
43 // Saturate and store the output. | 43 // Saturate and store the output. |
44 *data_out++ = WebRtcSpl_SatW32ToW16(out_s32); | 44 *data_out++ = WebRtcSpl_SatW32ToW16(out_s32); |
45 } | 45 } |
46 | 46 |
47 return 0; | 47 return 0; |
48 } | 48 } |
OLD | NEW |