niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
kma@webrtc.org | bb966ca | 2012-03-16 16:29:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | * WebRtcSpl_ReverseOrderMultArrayElements() |
| 15 | * WebRtcSpl_ElementwiseVectorMult() |
| 16 | * WebRtcSpl_AddVectorsAndShift() |
| 17 | * WebRtcSpl_AddAffineVectorToVector() |
| 18 | * WebRtcSpl_AffineTransformVector() |
| 19 | * |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "common_audio/signal_processing/include/signal_processing_library.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
pbos@webrtc.org | e4b6064 | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 24 | void WebRtcSpl_ReverseOrderMultArrayElements(int16_t *out, const int16_t *in, |
| 25 | const int16_t *win, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 26 | size_t vector_length, |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 27 | int16_t right_shifts) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 29 | size_t i; |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 30 | int16_t *outptr = out; |
pbos@webrtc.org | e4b6064 | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 31 | const int16_t *inptr = in; |
| 32 | const int16_t *winptr = win; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | for (i = 0; i < vector_length; i++) |
| 34 | { |
Bjorn Volcker | 1ccd8b4 | 2015-03-25 13:29:49 +0100 | [diff] [blame] | 35 | *outptr++ = (int16_t)((*inptr++ * *winptr--) >> right_shifts); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
pbos@webrtc.org | e4b6064 | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 39 | void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 40 | const int16_t *win, size_t vector_length, |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 41 | int16_t right_shifts) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 43 | size_t i; |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 44 | int16_t *outptr = out; |
pbos@webrtc.org | e4b6064 | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 45 | const int16_t *inptr = in; |
| 46 | const int16_t *winptr = win; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | for (i = 0; i < vector_length; i++) |
| 48 | { |
Bjorn Volcker | 1ccd8b4 | 2015-03-25 13:29:49 +0100 | [diff] [blame] | 49 | *outptr++ = (int16_t)((*inptr++ * *winptr++) >> right_shifts); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
pbos@webrtc.org | e4b6064 | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 53 | void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 54 | const int16_t *in2, size_t vector_length, |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 55 | int16_t right_shifts) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 57 | size_t i; |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 58 | int16_t *outptr = out; |
pbos@webrtc.org | e4b6064 | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 59 | const int16_t *in1ptr = in1; |
| 60 | const int16_t *in2ptr = in2; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | for (i = vector_length; i > 0; i--) |
| 62 | { |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 63 | (*outptr++) = (int16_t)(((*in1ptr++) + (*in2ptr++)) >> right_shifts); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
Alessio Bazzica | 1bc995a | 2019-04-15 09:38:24 +0200 | [diff] [blame^] | 67 | void WebRtcSpl_AddAffineVectorToVector(int16_t *out, const int16_t *in, |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 68 | int16_t gain, int32_t add_constant, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 69 | int16_t right_shifts, |
| 70 | size_t vector_length) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 72 | size_t i; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | for (i = 0; i < vector_length; i++) |
| 75 | { |
Bjorn Volcker | affcfb2 | 2015-04-24 08:12:07 +0200 | [diff] [blame] | 76 | out[i] += (int16_t)((in[i] * gain + add_constant) >> right_shifts); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
Alessio Bazzica | 1bc995a | 2019-04-15 09:38:24 +0200 | [diff] [blame^] | 80 | void WebRtcSpl_AffineTransformVector(int16_t *out, const int16_t *in, |
pbos@webrtc.org | b091307 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 81 | int16_t gain, int32_t add_constant, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 82 | int16_t right_shifts, size_t vector_length) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 84 | size_t i; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | for (i = 0; i < vector_length; i++) |
| 87 | { |
Bjorn Volcker | affcfb2 | 2015-04-24 08:12:07 +0200 | [diff] [blame] | 88 | out[i] = (int16_t)((in[i] * gain + add_constant) >> right_shifts); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
| 90 | } |