spandsp 3.0.0
vector_int.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * vector_int.h
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#if !defined(_SPANDSP_VECTOR_INT_H_)
27#define _SPANDSP_VECTOR_INT_H_
28
29#if defined(__cplusplus)
30extern "C"
31{
32#endif
33
34static __inline__ void vec_copyi(int z[], const int x[], int n)
35{
36 memcpy(z, x, n*sizeof(z[0]));
37}
38/*- End of function --------------------------------------------------------*/
39
40static __inline__ void vec_copyi16(int16_t z[], const int16_t x[], int n)
41{
42 memcpy(z, x, n*sizeof(z[0]));
43}
44/*- End of function --------------------------------------------------------*/
45
46static __inline__ void vec_copyi32(int32_t z[], const int32_t x[], int n)
47{
48 memcpy(z, x, n*sizeof(z[0]));
49}
50/*- End of function --------------------------------------------------------*/
51
52static __inline__ void vec_movei(int z[], const int x[], int n)
53{
54 memmove(z, x, n*sizeof(z[0]));
55}
56/*- End of function --------------------------------------------------------*/
57
58static __inline__ void vec_movei16(int16_t z[], const int16_t x[], int n)
59{
60 memmove(z, x, n*sizeof(z[0]));
61}
62/*- End of function --------------------------------------------------------*/
63
64static __inline__ void vec_movei32(int32_t z[], const int32_t x[], int n)
65{
66 memmove(z, x, n*sizeof(z[0]));
67}
68/*- End of function --------------------------------------------------------*/
69
70static __inline__ void vec_zeroi(int z[], int n)
71{
72 memset(z, 0, n*sizeof(z[0]));
73}
74/*- End of function --------------------------------------------------------*/
75
76static __inline__ void vec_zeroi16(int16_t z[], int n)
77{
78 memset(z, 0, n*sizeof(z[0]));
79}
80/*- End of function --------------------------------------------------------*/
81
82static __inline__ void vec_zeroi32(int32_t z[], int n)
83{
84 memset(z, 0, n*sizeof(z[0]));
85}
86/*- End of function --------------------------------------------------------*/
87
88static __inline__ void vec_seti(int z[], int x, int n)
89{
90 int i;
91
92 for (i = 0; i < n; i++)
93 z[i] = x;
94}
95/*- End of function --------------------------------------------------------*/
96
97static __inline__ void vec_seti16(int16_t z[], int16_t x, int n)
98{
99 int i;
100
101 for (i = 0; i < n; i++)
102 z[i] = x;
103}
104/*- End of function --------------------------------------------------------*/
105
106static __inline__ void vec_seti32(int32_t z[], int32_t x, int n)
107{
108 int i;
109
110 for (i = 0; i < n; i++)
111 z[i] = x;
112}
113/*- End of function --------------------------------------------------------*/
114
115/*! \brief Find the dot product of two int16_t vectors.
116 \param x The first vector.
117 \param y The first vector.
118 \param n The number of elements in the vectors.
119 \return The dot product of the two vectors. */
120SPAN_DECLARE(int32_t) vec_dot_prodi16(const int16_t x[], const int16_t y[], int n);
121
122/*! \brief Find the dot product of two int16_t vectors, where the first is a circular buffer
123 with an offset for the starting position.
124 \param x The first vector.
125 \param y The first vector.
126 \param n The number of elements in the vectors.
127 \param pos The starting position in the x vector.
128 \return The dot product of the two vectors. */
129SPAN_DECLARE(int32_t) vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos);
130
131SPAN_DECLARE(void) vec_lmsi16(const int16_t x[], int16_t y[], int n, int16_t error);
132
133SPAN_DECLARE(void) vec_circular_lmsi16(const int16_t x[], int16_t y[], int n, int pos, int16_t error);
134
135/*! \brief Find the minimum and maximum values in an int16_t vector.
136 \param x The vector to be searched.
137 \param n The number of elements in the vector.
138 \param out A two element vector. The first will receive the
139 maximum. The second will receive the minimum. This parameter
140 may be set to NULL.
141 \return The absolute maximum value. Since the range of negative numbers
142 exceeds the range of positive one, the returned integer is longer
143 than the ones being searched. */
144SPAN_DECLARE(int32_t) vec_min_maxi16(const int16_t x[], int n, int16_t out[]);
145
146static __inline__ int vec_norm2i16(const int16_t *vec, int len)
147{
148 int i;
149 int sum;
150
151 sum = 0;
152 for (i = 0; i < len; i++)
153 sum += vec[i]*vec[i];
154 return sum;
155}
156/*- End of function --------------------------------------------------------*/
157
158static __inline__ void vec_sari16(int16_t *vec, int len, int shift)
159{
160 int i;
161
162 for (i = 0; i < len; i++)
163 vec[i] >>= shift;
164}
165/*- End of function --------------------------------------------------------*/
166
167static __inline__ int vec_max_bitsi16(const int16_t *vec, int len)
168{
169 int i;
170 int max;
171 int v;
172 int b;
173
174 max = 0;
175 for (i = 0; i < len; i++)
176 {
177 v = abs(vec[i]);
178 if (v > max)
179 max = v;
180 }
181 b = 0;
182 while (max != 0)
183 {
184 b++;
185 max >>= 1;
186 }
187 return b;
188}
189/*- End of function --------------------------------------------------------*/
190
191#if defined(__cplusplus)
192}
193#endif
194
195#endif
196/*- End of file ------------------------------------------------------------*/
int32_t vec_min_maxi16(const int16_t x[], int n, int16_t out[])
Find the minimum and maximum values in an int16_t vector.
Definition: vector_int.c:287
int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n)
Find the dot product of two int16_t vectors.
Definition: vector_int.c:50
int32_t vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos)
Find the dot product of two int16_t vectors, where the first is a circular buffer with an offset for ...
Definition: vector_int.c:261