5
|
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 General Public License version 2, as
|
|
14 * 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 General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * 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.4 2006/10/24 13:45:28 steveu Exp $
|
|
26 */
|
|
27
|
|
28 #if !defined(_VECTOR_INT_H_)
|
|
29 #define _VECTOR_INT_H_
|
|
30
|
|
31 #ifdef __cplusplus
|
|
32 extern "C" {
|
|
33 #endif
|
|
34
|
|
35 int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n);
|
|
36
|
|
37 /*! \brief Find the minimum and maximum values in a vector.
|
|
38 \param x The vector to be searched.
|
|
39 \param n The number of elements in the vetor.
|
|
40 \param result A two element vector. The first will receive the
|
|
41 maximum. The second will receive thw minimum. This parameter
|
|
42 may be set to NULL.
|
|
43 \return The absolute maximum value. Since the range of negative numbers
|
|
44 exceeds the range of positive one, the returned integer is longer
|
|
45 than the ones being searched. */
|
|
46 int32_t vec_min_maxi16(const int16_t x[], int n, int16_t out[]);
|
|
47
|
|
48 static __inline__ int vec_norm2i16(const int16_t *vec, int len)
|
|
49 {
|
|
50 int i;
|
|
51 int sum;
|
|
52
|
|
53 sum = 0;
|
|
54 for (i = 0; i < len; i++)
|
|
55 sum += vec[i]*vec[i];
|
|
56 return sum;
|
|
57 }
|
|
58 /*- End of function --------------------------------------------------------*/
|
|
59
|
|
60 static __inline__ void vec_sari16(int16_t *vec, int len, int shift)
|
|
61 {
|
|
62 int i;
|
|
63
|
|
64 for (i = 0; i < len; i++)
|
|
65 vec[i] >>= shift;
|
|
66 }
|
|
67 /*- End of function --------------------------------------------------------*/
|
|
68
|
|
69 static __inline__ int vec_max_bitsi16(const int16_t *vec, int len)
|
|
70 {
|
|
71 int i;
|
|
72 int max;
|
|
73 int v;
|
|
74 int b;
|
|
75
|
|
76 max = 0;
|
|
77 for (i = 0; i < len; i++)
|
|
78 {
|
|
79 v = abs(vec[i]);
|
|
80 if (v > max)
|
|
81 max = v;
|
|
82 }
|
|
83 b = 0;
|
|
84 while (max != 0)
|
|
85 {
|
|
86 b++;
|
|
87 max >>= 1;
|
|
88 }
|
|
89 return b;
|
|
90 }
|
|
91 /*- End of function --------------------------------------------------------*/
|
|
92
|
|
93 #ifdef __cplusplus
|
|
94 }
|
|
95 #endif
|
|
96
|
|
97 #endif
|
|
98 /*- End of file ------------------------------------------------------------*/
|