ilbc_specific_functions.c revision c55a96383497a772a307b346368133960b02ad03
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 implementations of the iLBC specific functions
14 * WebRtcSpl_ScaleAndAddVectorsWithRound()
15 * WebRtcSpl_ReverseOrderMultArrayElements()
16 * WebRtcSpl_ElementwiseVectorMult()
17 * WebRtcSpl_AddVectorsAndShift()
18 * WebRtcSpl_AddAffineVectorToVector()
19 * WebRtcSpl_AffineTransformVector()
20 *
21 * The description header can be found in signal_processing_library.h
22 *
23 */
24
25#include "signal_processing_library.h"
26
27void WebRtcSpl_ScaleAndAddVectorsWithRound(WebRtc_Word16 *vector1, WebRtc_Word16 scale1,
28                                           WebRtc_Word16 *vector2, WebRtc_Word16 scale2,
29                                           WebRtc_Word16 right_shifts, WebRtc_Word16 *out,
30                                           WebRtc_Word16 vector_length)
31{
32    int i;
33    WebRtc_Word16 roundVal;
34    roundVal = 1 << right_shifts;
35    roundVal = roundVal >> 1;
36    for (i = 0; i < vector_length; i++)
37    {
38        out[i] = (WebRtc_Word16)((WEBRTC_SPL_MUL_16_16(vector1[i], scale1)
39                + WEBRTC_SPL_MUL_16_16(vector2[i], scale2) + roundVal) >> right_shifts);
40    }
41}
42
43void WebRtcSpl_ReverseOrderMultArrayElements(WebRtc_Word16 *out, G_CONST WebRtc_Word16 *in,
44                                             G_CONST WebRtc_Word16 *win,
45                                             WebRtc_Word16 vector_length,
46                                             WebRtc_Word16 right_shifts)
47{
48    int i;
49    WebRtc_Word16 *outptr = out;
50    G_CONST WebRtc_Word16 *inptr = in;
51    G_CONST WebRtc_Word16 *winptr = win;
52    for (i = 0; i < vector_length; i++)
53    {
54        (*outptr++) = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(*inptr++,
55                                                               *winptr--, right_shifts);
56    }
57}
58
59void WebRtcSpl_ElementwiseVectorMult(WebRtc_Word16 *out, G_CONST WebRtc_Word16 *in,
60                                     G_CONST WebRtc_Word16 *win, WebRtc_Word16 vector_length,
61                                     WebRtc_Word16 right_shifts)
62{
63    int i;
64    WebRtc_Word16 *outptr = out;
65    G_CONST WebRtc_Word16 *inptr = in;
66    G_CONST WebRtc_Word16 *winptr = win;
67    for (i = 0; i < vector_length; i++)
68    {
69        (*outptr++) = (WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(*inptr++,
70                                                               *winptr++, right_shifts);
71    }
72}
73
74void WebRtcSpl_AddVectorsAndShift(WebRtc_Word16 *out, G_CONST WebRtc_Word16 *in1,
75                                  G_CONST WebRtc_Word16 *in2, WebRtc_Word16 vector_length,
76                                  WebRtc_Word16 right_shifts)
77{
78    int i;
79    WebRtc_Word16 *outptr = out;
80    G_CONST WebRtc_Word16 *in1ptr = in1;
81    G_CONST WebRtc_Word16 *in2ptr = in2;
82    for (i = vector_length; i > 0; i--)
83    {
84        (*outptr++) = (WebRtc_Word16)(((*in1ptr++) + (*in2ptr++)) >> right_shifts);
85    }
86}
87
88void WebRtcSpl_AddAffineVectorToVector(WebRtc_Word16 *out, WebRtc_Word16 *in,
89                                       WebRtc_Word16 gain, WebRtc_Word32 add_constant,
90                                       WebRtc_Word16 right_shifts, int vector_length)
91{
92    WebRtc_Word16 *inPtr;
93    WebRtc_Word16 *outPtr;
94    int i;
95
96    inPtr = in;
97    outPtr = out;
98    for (i = 0; i < vector_length; i++)
99    {
100        (*outPtr++) += (WebRtc_Word16)((WEBRTC_SPL_MUL_16_16((*inPtr++), gain)
101                + (WebRtc_Word32)add_constant) >> right_shifts);
102    }
103}
104
105void WebRtcSpl_AffineTransformVector(WebRtc_Word16 *out, WebRtc_Word16 *in,
106                                     WebRtc_Word16 gain, WebRtc_Word32 add_constant,
107                                     WebRtc_Word16 right_shifts, int vector_length)
108{
109    WebRtc_Word16 *inPtr;
110    WebRtc_Word16 *outPtr;
111    int i;
112
113    inPtr = in;
114    outPtr = out;
115    for (i = 0; i < vector_length; i++)
116    {
117        (*outPtr++) = (WebRtc_Word16)((WEBRTC_SPL_MUL_16_16((*inPtr++), gain)
118                + (WebRtc_Word32)add_constant) >> right_shifts);
119    }
120}
121