comparison spandsp-0.0.6pre17/src/spandsp/vector_int.h @ 4:26cd8f1ef0b1

import spandsp-0.0.6pre17
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 15:50:58 +0200
parents
children
comparison
equal deleted inserted replaced
3:c6c5a16ce2f2 4:26cd8f1ef0b1
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 * $Id: vector_int.h,v 1.14 2009/01/31 08:48:11 steveu Exp $
26 */
27
28 #if !defined(_SPANDSP_VECTOR_INT_H_)
29 #define _SPANDSP_VECTOR_INT_H_
30
31 #if defined(__cplusplus)
32 extern "C"
33 {
34 #endif
35
36 static __inline__ void vec_copyi(int z[], const int x[], int n)
37 {
38 memcpy(z, x, n*sizeof(z[0]));
39 }
40 /*- End of function --------------------------------------------------------*/
41
42 static __inline__ void vec_copyi16(int16_t z[], const int16_t x[], int n)
43 {
44 memcpy(z, x, n*sizeof(z[0]));
45 }
46 /*- End of function --------------------------------------------------------*/
47
48 static __inline__ void vec_copyi32(int32_t z[], const int32_t x[], int n)
49 {
50 memcpy(z, x, n*sizeof(z[0]));
51 }
52 /*- End of function --------------------------------------------------------*/
53
54 static __inline__ void vec_zeroi(int z[], int n)
55 {
56 memset(z, 0, n*sizeof(z[0]));
57 }
58 /*- End of function --------------------------------------------------------*/
59
60 static __inline__ void vec_zeroi16(int16_t z[], int n)
61 {
62 memset(z, 0, n*sizeof(z[0]));
63 }
64 /*- End of function --------------------------------------------------------*/
65
66 static __inline__ void vec_zeroi32(int32_t z[], int n)
67 {
68 memset(z, 0, n*sizeof(z[0]));
69 }
70 /*- End of function --------------------------------------------------------*/
71
72 static __inline__ void vec_seti(int z[], int x, int n)
73 {
74 int i;
75
76 for (i = 0; i < n; i++)
77 z[i] = x;
78 }
79 /*- End of function --------------------------------------------------------*/
80
81 static __inline__ void vec_seti16(int16_t z[], int16_t x, int n)
82 {
83 int i;
84
85 for (i = 0; i < n; i++)
86 z[i] = x;
87 }
88 /*- End of function --------------------------------------------------------*/
89
90 static __inline__ void vec_seti32(int32_t z[], int32_t x, int n)
91 {
92 int i;
93
94 for (i = 0; i < n; i++)
95 z[i] = x;
96 }
97 /*- End of function --------------------------------------------------------*/
98
99 /*! \brief Find the dot product of two int16_t vectors.
100 \param x The first vector.
101 \param y The first vector.
102 \param n The number of elements in the vectors.
103 \return The dot product of the two vectors. */
104 SPAN_DECLARE(int32_t) vec_dot_prodi16(const int16_t x[], const int16_t y[], int n);
105
106 /*! \brief Find the dot product of two int16_t vectors, where the first is a circular buffer
107 with an offset for the starting position.
108 \param x The first vector.
109 \param y The first vector.
110 \param n The number of elements in the vectors.
111 \param pos The starting position in the x vector.
112 \return The dot product of the two vectors. */
113 SPAN_DECLARE(int32_t) vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos);
114
115 SPAN_DECLARE(void) vec_lmsi16(const int16_t x[], int16_t y[], int n, int16_t error);
116
117 SPAN_DECLARE(void) vec_circular_lmsi16(const int16_t x[], int16_t y[], int n, int pos, int16_t error);
118
119 /*! \brief Find the minimum and maximum values in an int16_t vector.
120 \param x The vector to be searched.
121 \param n The number of elements in the vector.
122 \param out A two element vector. The first will receive the
123 maximum. The second will receive the minimum. This parameter
124 may be set to NULL.
125 \return The absolute maximum value. Since the range of negative numbers
126 exceeds the range of positive one, the returned integer is longer
127 than the ones being searched. */
128 SPAN_DECLARE(int32_t) vec_min_maxi16(const int16_t x[], int n, int16_t out[]);
129
130 static __inline__ int vec_norm2i16(const int16_t *vec, int len)
131 {
132 int i;
133 int sum;
134
135 sum = 0;
136 for (i = 0; i < len; i++)
137 sum += vec[i]*vec[i];
138 return sum;
139 }
140 /*- End of function --------------------------------------------------------*/
141
142 static __inline__ void vec_sari16(int16_t *vec, int len, int shift)
143 {
144 int i;
145
146 for (i = 0; i < len; i++)
147 vec[i] >>= shift;
148 }
149 /*- End of function --------------------------------------------------------*/
150
151 static __inline__ int vec_max_bitsi16(const int16_t *vec, int len)
152 {
153 int i;
154 int max;
155 int v;
156 int b;
157
158 max = 0;
159 for (i = 0; i < len; i++)
160 {
161 v = abs(vec[i]);
162 if (v > max)
163 max = v;
164 }
165 b = 0;
166 while (max != 0)
167 {
168 b++;
169 max >>= 1;
170 }
171 return b;
172 }
173 /*- End of function --------------------------------------------------------*/
174
175 #if defined(__cplusplus)
176 }
177 #endif
178
179 #endif
180 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.