andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 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.org | abf0cd8 | 2013-05-27 09:49:58 +0000 | [diff] [blame] | 22 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 23 | |
pbos@webrtc.org | bb48e9c | 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, |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 26 | int16_t vector_length, |
| 27 | int16_t right_shifts) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 28 | { |
| 29 | int i; |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 30 | int16_t *outptr = out; |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 31 | const int16_t *inptr = in; |
| 32 | const int16_t *winptr = win; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 33 | for (i = 0; i < vector_length; i++) |
| 34 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 35 | (*outptr++) = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(*inptr++, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 36 | *winptr--, right_shifts); |
| 37 | } |
| 38 | } |
| 39 | |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 40 | void WebRtcSpl_ElementwiseVectorMult(int16_t *out, const int16_t *in, |
| 41 | const int16_t *win, int16_t vector_length, |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 42 | int16_t right_shifts) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 43 | { |
| 44 | int i; |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 45 | int16_t *outptr = out; |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 46 | const int16_t *inptr = in; |
| 47 | const int16_t *winptr = win; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 48 | for (i = 0; i < vector_length; i++) |
| 49 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 50 | (*outptr++) = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(*inptr++, |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 51 | *winptr++, right_shifts); |
| 52 | } |
| 53 | } |
| 54 | |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 55 | void WebRtcSpl_AddVectorsAndShift(int16_t *out, const int16_t *in1, |
| 56 | const int16_t *in2, int16_t vector_length, |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 57 | int16_t right_shifts) |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 58 | { |
| 59 | int i; |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 60 | int16_t *outptr = out; |
pbos@webrtc.org | bb48e9c | 2013-04-10 18:06:57 +0000 | [diff] [blame] | 61 | const int16_t *in1ptr = in1; |
| 62 | const int16_t *in2ptr = in2; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 63 | for (i = vector_length; i > 0; i--) |
| 64 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 65 | (*outptr++) = (int16_t)(((*in1ptr++) + (*in2ptr++)) >> right_shifts); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 69 | void 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.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 72 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 73 | int16_t *inPtr; |
| 74 | int16_t *outPtr; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 75 | int i; |
| 76 | |
| 77 | inPtr = in; |
| 78 | outPtr = out; |
| 79 | for (i = 0; i < vector_length; i++) |
| 80 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 81 | (*outPtr++) += (int16_t)((WEBRTC_SPL_MUL_16_16((*inPtr++), gain) |
| 82 | + (int32_t)add_constant) >> right_shifts); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 86 | void 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.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 89 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 90 | int16_t *inPtr; |
| 91 | int16_t *outPtr; |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 92 | int i; |
| 93 | |
| 94 | inPtr = in; |
| 95 | outPtr = out; |
| 96 | for (i = 0; i < vector_length; i++) |
| 97 | { |
pbos@webrtc.org | 1727dc7 | 2013-04-09 16:40:28 +0000 | [diff] [blame] | 98 | (*outPtr++) = (int16_t)((WEBRTC_SPL_MUL_16_16((*inPtr++), gain) |
| 99 | + (int32_t)add_constant) >> right_shifts); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 100 | } |
| 101 | } |