spandsp 0.0.6

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)
30 extern "C"
31{
32#endif
33
34 static __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
40 static __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
46 static __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
52 static __inline__ void vec_zeroi(int z[], int n)
53{
54 memset(z, 0, n*sizeof(z[0]));
55}
56/*- End of function --------------------------------------------------------*/
57
58 static __inline__ void vec_zeroi16(int16_t z[], int n)
59{
60 memset(z, 0, n*sizeof(z[0]));
61}
62/*- End of function --------------------------------------------------------*/
63
64 static __inline__ void vec_zeroi32(int32_t z[], int n)
65{
66 memset(z, 0, n*sizeof(z[0]));
67}
68/*- End of function --------------------------------------------------------*/
69
70 static __inline__ void vec_seti(int z[], int x, int n)
71{
72 int i;
73
74 for (i = 0; i < n; i++)
75 z[i] = x;
76}
77/*- End of function --------------------------------------------------------*/
78
79 static __inline__ void vec_seti16(int16_t z[], int16_t x, int n)
80{
81 int i;
82
83 for (i = 0; i < n; i++)
84 z[i] = x;
85}
86/*- End of function --------------------------------------------------------*/
87
88 static __inline__ void vec_seti32(int32_t z[], int32_t 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
97/*! \brief Find the dot product of two int16_t vectors.
98 \param x The first vector.
99 \param y The first vector.
100 \param n The number of elements in the vectors.
101 \return The dot product of the two vectors. */
102SPAN_DECLARE(int32_t) vec_dot_prodi16(const int16_t x[], const int16_t y[], int n);
103
104/*! \brief Find the dot product of two int16_t vectors, where the first is a circular buffer
105 with an offset for the starting position.
106 \param x The first vector.
107 \param y The first vector.
108 \param n The number of elements in the vectors.
109 \param pos The starting position in the x vector.
110 \return The dot product of the two vectors. */
111SPAN_DECLARE(int32_t) vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos);
112
113SPAN_DECLARE(void) vec_lmsi16(const int16_t x[], int16_t y[], int n, int16_t error);
114
115SPAN_DECLARE(void) vec_circular_lmsi16(const int16_t x[], int16_t y[], int n, int pos, int16_t error);
116
117/*! \brief Find the minimum and maximum values in an int16_t vector.
118 \param x The vector to be searched.
119 \param n The number of elements in the vector.
120 \param out A two element vector. The first will receive the
121 maximum. The second will receive the minimum. This parameter
122 may be set to NULL.
123 \return The absolute maximum value. Since the range of negative numbers
124 exceeds the range of positive one, the returned integer is longer
125 than the ones being searched. */
126SPAN_DECLARE(int32_t) vec_min_maxi16(const int16_t x[], int n, int16_t out[]);
127
128 static __inline__ int vec_norm2i16(const int16_t *vec, int len)
129{
130 int i;
131 int sum;
132
133 sum = 0;
134 for (i = 0; i < len; i++)
135 sum += vec[i]*vec[i];
136 return sum;
137}
138/*- End of function --------------------------------------------------------*/
139
140 static __inline__ void vec_sari16(int16_t *vec, int len, int shift)
141{
142 int i;
143
144 for (i = 0; i < len; i++)
145 vec[i] >>= shift;
146}
147/*- End of function --------------------------------------------------------*/
148
149 static __inline__ int vec_max_bitsi16(const int16_t *vec, int len)
150{
151 int i;
152 int max;
153 int v;
154 int b;
155
156 max = 0;
157 for (i = 0; i < len; i++)
158 {
159 v = abs(vec[i]);
160 if (v > max)
161 max = v;
162 }
163 b = 0;
164 while (max != 0)
165 {
166 b++;
167 max >>= 1;
168 }
169 return b;
170}
171/*- End of function --------------------------------------------------------*/
172
173#if defined(__cplusplus)
174}
175#endif
176
177#endif
178/*- End of file ------------------------------------------------------------*/