blob: cbdd3dcbcd5b8bc93998100365df2958ed2e7061 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
kma@webrtc.orgbb966ca2012-03-16 16:29:37 +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
11
12/*
13 * This file contains implementations of the iLBC specific functions
niklase@google.com470e71d2011-07-07 08:21:25 +000014 * WebRtcSpl_ReverseOrderMultArrayElements()
15 * WebRtcSpl_ElementwiseVectorMult()
16 * WebRtcSpl_AddVectorsAndShift()
17 * WebRtcSpl_AddAffineVectorToVector()
18 * WebRtcSpl_AffineTransformVector()
19 *
niklase@google.com470e71d2011-07-07 08:21:25 +000020 */
21
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "common_audio/signal_processing/include/signal_processing_library.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
pbos@webrtc.orge4b60642013-04-10 18:06:57 +000024void WebRtcSpl_ReverseOrderMultArrayElements(int16_t *out, const int16_t *in,
25 const int16_t *win,
Peter Kastingdce40cf2015-08-24 14:52:23 -070026 size_t vector_length,
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000027 int16_t right_shifts)
niklase@google.com470e71d2011-07-07 08:21:25 +000028{
Peter Kastingdce40cf2015-08-24 14:52:23 -070029 size_t i;
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000030 int16_t *outptr = out;
pbos@webrtc.orge4b60642013-04-10 18:06:57 +000031 const int16_t *inptr = in;
32 const int16_t *winptr = win;
niklase@google.com470e71d2011-07-07 08:21:25 +000033 for (i = 0; i < vector_length; i++)
34 {
Bjorn Volcker1ccd8b42015-03-25 13:29:49 +010035 *outptr++ = (int16_t)((*inptr++ * *winptr--) >> right_shifts);
niklase@google.com470e71d2011-07-07 08:21:25 +000036 }
37}
38
pbos@webrtc.orge4b60642013-04-10 18:06:57 +000039void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in,
Peter Kastingdce40cf2015-08-24 14:52:23 -070040 const int16_t *win, size_t vector_length,
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000041 int16_t right_shifts)
niklase@google.com470e71d2011-07-07 08:21:25 +000042{
Peter Kastingdce40cf2015-08-24 14:52:23 -070043 size_t i;
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000044 int16_t *outptr = out;
pbos@webrtc.orge4b60642013-04-10 18:06:57 +000045 const int16_t *inptr = in;
46 const int16_t *winptr = win;
niklase@google.com470e71d2011-07-07 08:21:25 +000047 for (i = 0; i < vector_length; i++)
48 {
Bjorn Volcker1ccd8b42015-03-25 13:29:49 +010049 *outptr++ = (int16_t)((*inptr++ * *winptr++) >> right_shifts);
niklase@google.com470e71d2011-07-07 08:21:25 +000050 }
51}
52
pbos@webrtc.orge4b60642013-04-10 18:06:57 +000053void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1,
Peter Kastingdce40cf2015-08-24 14:52:23 -070054 const int16_t *in2, size_t vector_length,
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000055 int16_t right_shifts)
niklase@google.com470e71d2011-07-07 08:21:25 +000056{
Peter Kastingdce40cf2015-08-24 14:52:23 -070057 size_t i;
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000058 int16_t *outptr = out;
pbos@webrtc.orge4b60642013-04-10 18:06:57 +000059 const int16_t *in1ptr = in1;
60 const int16_t *in2ptr = in2;
niklase@google.com470e71d2011-07-07 08:21:25 +000061 for (i = vector_length; i > 0; i--)
62 {
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000063 (*outptr++) = (int16_t)(((*in1ptr++) + (*in2ptr++)) >> right_shifts);
niklase@google.com470e71d2011-07-07 08:21:25 +000064 }
65}
66
Alessio Bazzica1bc995a2019-04-15 09:38:24 +020067void WebRtcSpl_AddAffineVectorToVector(int16_t *out, const int16_t *in,
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000068 int16_t gain, int32_t add_constant,
Peter Kastingdce40cf2015-08-24 14:52:23 -070069 int16_t right_shifts,
70 size_t vector_length)
niklase@google.com470e71d2011-07-07 08:21:25 +000071{
Peter Kastingdce40cf2015-08-24 14:52:23 -070072 size_t i;
niklase@google.com470e71d2011-07-07 08:21:25 +000073
niklase@google.com470e71d2011-07-07 08:21:25 +000074 for (i = 0; i < vector_length; i++)
75 {
Bjorn Volckeraffcfb22015-04-24 08:12:07 +020076 out[i] += (int16_t)((in[i] * gain + add_constant) >> right_shifts);
niklase@google.com470e71d2011-07-07 08:21:25 +000077 }
78}
79
Alessio Bazzica1bc995a2019-04-15 09:38:24 +020080void WebRtcSpl_AffineTransformVector(int16_t *out, const int16_t *in,
pbos@webrtc.orgb0913072013-04-09 16:40:28 +000081 int16_t gain, int32_t add_constant,
Peter Kastingdce40cf2015-08-24 14:52:23 -070082 int16_t right_shifts, size_t vector_length)
niklase@google.com470e71d2011-07-07 08:21:25 +000083{
Peter Kastingdce40cf2015-08-24 14:52:23 -070084 size_t i;
niklase@google.com470e71d2011-07-07 08:21:25 +000085
niklase@google.com470e71d2011-07-07 08:21:25 +000086 for (i = 0; i < vector_length; i++)
87 {
Bjorn Volckeraffcfb22015-04-24 08:12:07 +020088 out[i] = (int16_t)((in[i] * gain + add_constant) >> right_shifts);
niklase@google.com470e71d2011-07-07 08:21:25 +000089 }
90}