1 /* 2 * Copyright (c) 2011 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 12 /* 13 * This file contains the function WebRtcSpl_DownsampleFast(). 14 * The description header can be found in signal_processing_library.h 15 * 16 */ 17 18 #include "signal_processing_library.h" 19 20 int WebRtcSpl_DownsampleFast(WebRtc_Word16 *in_ptr, WebRtc_Word16 in_length, 21 WebRtc_Word16 *out_ptr, WebRtc_Word16 out_length, 22 WebRtc_Word16 *B, WebRtc_Word16 B_length, WebRtc_Word16 factor, 23 WebRtc_Word16 delay) 24 { 25 WebRtc_Word32 o; 26 int i, j; 27 28 WebRtc_Word16 *downsampled_ptr = out_ptr; 29 WebRtc_Word16 *b_ptr; 30 WebRtc_Word16 *x_ptr; 31 WebRtc_Word16 endpos = delay 32 + (WebRtc_Word16)WEBRTC_SPL_MUL_16_16(factor, (out_length - 1)) + 1; 33 34 if (in_length < endpos) 35 { 36 return -1; 37 } 38 39 for (i = delay; i < endpos; i += factor) 40 { 41 b_ptr = &B[0]; 42 x_ptr = &in_ptr[i]; 43 44 o = (WebRtc_Word32)2048; // Round val 45 46 for (j = 0; j < B_length; j++) 47 { 48 o += WEBRTC_SPL_MUL_16_16(*b_ptr++, *x_ptr--); 49 } 50 51 o = WEBRTC_SPL_RSHIFT_W32(o, 12); 52 53 // If output is higher than 32768, saturate it. Same with negative side 54 55 *downsampled_ptr++ = WebRtcSpl_SatW32ToW16(o); 56 } 57 58 return 0; 59 } 60