blob: 4a1a7d61aa59c867e5ca3cf0a4b21114d1ff382f [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
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
12/*
13 * This file contains implementations of the iLBC specific functions
14 * WebRtcSpl_ReverseOrderMultArrayElements()
15 * WebRtcSpl_ElementwiseVectorMult()
16 * WebRtcSpl_AddVectorsAndShift()
17 * WebRtcSpl_AddAffineVectorToVector()
18 * WebRtcSpl_AffineTransformVector()
19 *
20 */
21
pbos@webrtc.orgabf0cd82013-05-27 09:49:58 +000022#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000023
pbos@webrtc.orgbb48e9c2013-04-10 18:06:57 +000024void WebRtcSpl_ReverseOrderMultArrayElements(int16_t *out, const int16_t *in,
25 const int16_t *win,
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000026 int16_t vector_length,
27 int16_t right_shifts)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000028{
29 int i;
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000030 int16_t *outptr = out;
pbos@webrtc.orgbb48e9c2013-04-10 18:06:57 +000031 const int16_t *inptr = in;
32 const int16_t *winptr = win;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000033 for (i = 0; i < vector_length; i++)
34 {
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000035 (*outptr++) = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(*inptr++,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000036 *winptr--, right_shifts);
37 }
38}
39
pbos@webrtc.orgbb48e9c2013-04-10 18:06:57 +000040void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in,
41 const int16_t *win, int16_t vector_length,
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000042 int16_t right_shifts)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000043{
44 int i;
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000045 int16_t *outptr = out;
pbos@webrtc.orgbb48e9c2013-04-10 18:06:57 +000046 const int16_t *inptr = in;
47 const int16_t *winptr = win;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000048 for (i = 0; i < vector_length; i++)
49 {
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000050 (*outptr++) = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(*inptr++,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000051 *winptr++, right_shifts);
52 }
53}
54
pbos@webrtc.orgbb48e9c2013-04-10 18:06:57 +000055void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1,
56 const int16_t *in2, int16_t vector_length,
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000057 int16_t right_shifts)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000058{
59 int i;
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000060 int16_t *outptr = out;
pbos@webrtc.orgbb48e9c2013-04-10 18:06:57 +000061 const int16_t *in1ptr = in1;
62 const int16_t *in2ptr = in2;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000063 for (i = vector_length; i > 0; i--)
64 {
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000065 (*outptr++) = (int16_t)(((*in1ptr++) + (*in2ptr++)) >> right_shifts);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000066 }
67}
68
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000069void WebRtcSpl_AddAffineVectorToVector(int16_t *out, int16_t *in,
70 int16_t gain, int32_t add_constant,
71 int16_t right_shifts, int vector_length)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000072{
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000073 int16_t *inPtr;
74 int16_t *outPtr;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000075 int i;
76
77 inPtr = in;
78 outPtr = out;
79 for (i = 0; i < vector_length; i++)
80 {
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000081 (*outPtr++) += (int16_t)((WEBRTC_SPL_MUL_16_16((*inPtr++), gain)
82 + (int32_t)add_constant) >> right_shifts);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000083 }
84}
85
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000086void WebRtcSpl_AffineTransformVector(int16_t *out, int16_t *in,
87 int16_t gain, int32_t add_constant,
88 int16_t right_shifts, int vector_length)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000089{
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000090 int16_t *inPtr;
91 int16_t *outPtr;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000092 int i;
93
94 inPtr = in;
95 outPtr = out;
96 for (i = 0; i < vector_length; i++)
97 {
pbos@webrtc.org1727dc72013-04-09 16:40:28 +000098 (*outPtr++) = (int16_t)((WEBRTC_SPL_MUL_16_16((*inPtr++), gain)
99 + (int32_t)add_constant) >> right_shifts);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000100 }
101}