blob: 179c36a25c14ce83c520b0ebd771f1ba2d09d1e5 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
kma@webrtc.org551fcc02012-02-07 18:03:11 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
pbos@webrtc.orgaa30bb72013-05-27 09:49:58 +000011#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
kma@webrtc.org551fcc02012-02-07 18:03:11 +000013// TODO(Bjornv): Change the function parameter order to WebRTC code style.
kma@webrtc.org0221b782012-09-08 00:09:26 +000014// C version of WebRtcSpl_DownsampleFast() for generic platforms.
15int WebRtcSpl_DownsampleFastC(const int16_t* data_in,
16 int data_in_length,
17 int16_t* data_out,
18 int data_out_length,
19 const int16_t* __restrict coefficients,
20 int coefficients_length,
21 int factor,
22 int delay) {
kma@webrtc.org551fcc02012-02-07 18:03:11 +000023 int i = 0;
24 int j = 0;
25 int32_t out_s32 = 0;
26 int endpos = delay + factor * (data_out_length - 1) + 1;
niklase@google.com470e71d2011-07-07 08:21:25 +000027
kma@webrtc.org551fcc02012-02-07 18:03:11 +000028 // Return error if any of the running conditions doesn't meet.
29 if (data_out_length <= 0 || coefficients_length <= 0
30 || data_in_length < endpos) {
31 return -1;
32 }
niklase@google.com470e71d2011-07-07 08:21:25 +000033
kma@webrtc.org551fcc02012-02-07 18:03:11 +000034 for (i = delay; i < endpos; i += factor) {
35 out_s32 = 2048; // Round value, 0.5 in Q12.
36
37 for (j = 0; j < coefficients_length; j++) {
38 out_s32 += coefficients[j] * data_in[i - j]; // Q12.
niklase@google.com470e71d2011-07-07 08:21:25 +000039 }
40
kma@webrtc.org551fcc02012-02-07 18:03:11 +000041 out_s32 >>= 12; // Q0.
niklase@google.com470e71d2011-07-07 08:21:25 +000042
kma@webrtc.org551fcc02012-02-07 18:03:11 +000043 // Saturate and store the output.
44 *data_out++ = WebRtcSpl_SatW32ToW16(out_s32);
45 }
niklase@google.com470e71d2011-07-07 08:21:25 +000046
kma@webrtc.org551fcc02012-02-07 18:03:11 +000047 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000048}