Line data Source code
1 : /*
2 : * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 : *
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
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
12 :
13 : #include "webrtc/base/checks.h"
14 : #include "webrtc/base/sanitizer.h"
15 :
16 : // TODO(Bjornv): Change the function parameter order to WebRTC code style.
17 : // C version of WebRtcSpl_DownsampleFast() for generic platforms.
18 0 : int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
19 : size_t data_in_length,
20 : int16_t* data_out,
21 : size_t data_out_length,
22 : const int16_t* __restrict coefficients,
23 : size_t coefficients_length,
24 : int factor,
25 : size_t delay) {
26 0 : int16_t* const original_data_out = data_out;
27 0 : size_t i = 0;
28 0 : size_t j = 0;
29 0 : int32_t out_s32 = 0;
30 0 : size_t endpos = delay + factor * (data_out_length - 1) + 1;
31 :
32 : // Return error if any of the running conditions doesn't meet.
33 0 : if (data_out_length == 0 || coefficients_length == 0
34 0 : || data_in_length < endpos) {
35 0 : return -1;
36 : }
37 :
38 0 : rtc_MsanCheckInitialized(coefficients, sizeof(coefficients[0]),
39 : coefficients_length);
40 :
41 0 : for (i = delay; i < endpos; i += factor) {
42 0 : out_s32 = 2048; // Round value, 0.5 in Q12.
43 :
44 0 : for (j = 0; j < coefficients_length; j++) {
45 0 : rtc_MsanCheckInitialized(&data_in[i - j], sizeof(data_in[0]), 1);
46 0 : out_s32 += coefficients[j] * data_in[i - j]; // Q12.
47 : }
48 :
49 0 : out_s32 >>= 12; // Q0.
50 :
51 : // Saturate and store the output.
52 0 : *data_out++ = WebRtcSpl_SatW32ToW16(out_s32);
53 : }
54 :
55 0 : RTC_DCHECK_EQ(original_data_out + data_out_length, data_out);
56 0 : rtc_MsanCheckInitialized(original_data_out, sizeof(original_data_out[0]),
57 : data_out_length);
58 :
59 0 : return 0;
60 : }
|