spandsp 0.0.6
|
00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * vector_int.h 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 */ 00025 00026 #if !defined(_SPANDSP_VECTOR_INT_H_) 00027 #define _SPANDSP_VECTOR_INT_H_ 00028 00029 #if defined(__cplusplus) 00030 extern "C" 00031 { 00032 #endif 00033 00034 static __inline__ void vec_copyi(int z[], const int x[], int n) 00035 { 00036 memcpy(z, x, n*sizeof(z[0])); 00037 } 00038 /*- End of function --------------------------------------------------------*/ 00039 00040 static __inline__ void vec_copyi16(int16_t z[], const int16_t x[], int n) 00041 { 00042 memcpy(z, x, n*sizeof(z[0])); 00043 } 00044 /*- End of function --------------------------------------------------------*/ 00045 00046 static __inline__ void vec_copyi32(int32_t z[], const int32_t x[], int n) 00047 { 00048 memcpy(z, x, n*sizeof(z[0])); 00049 } 00050 /*- End of function --------------------------------------------------------*/ 00051 00052 static __inline__ void vec_zeroi(int z[], int n) 00053 { 00054 memset(z, 0, n*sizeof(z[0])); 00055 } 00056 /*- End of function --------------------------------------------------------*/ 00057 00058 static __inline__ void vec_zeroi16(int16_t z[], int n) 00059 { 00060 memset(z, 0, n*sizeof(z[0])); 00061 } 00062 /*- End of function --------------------------------------------------------*/ 00063 00064 static __inline__ void vec_zeroi32(int32_t z[], int n) 00065 { 00066 memset(z, 0, n*sizeof(z[0])); 00067 } 00068 /*- End of function --------------------------------------------------------*/ 00069 00070 static __inline__ void vec_seti(int z[], int x, int n) 00071 { 00072 int i; 00073 00074 for (i = 0; i < n; i++) 00075 z[i] = x; 00076 } 00077 /*- End of function --------------------------------------------------------*/ 00078 00079 static __inline__ void vec_seti16(int16_t z[], int16_t x, int n) 00080 { 00081 int i; 00082 00083 for (i = 0; i < n; i++) 00084 z[i] = x; 00085 } 00086 /*- End of function --------------------------------------------------------*/ 00087 00088 static __inline__ void vec_seti32(int32_t z[], int32_t x, int n) 00089 { 00090 int i; 00091 00092 for (i = 0; i < n; i++) 00093 z[i] = x; 00094 } 00095 /*- End of function --------------------------------------------------------*/ 00096 00097 /*! \brief Find the dot product of two int16_t vectors. 00098 \param x The first vector. 00099 \param y The first vector. 00100 \param n The number of elements in the vectors. 00101 \return The dot product of the two vectors. */ 00102 SPAN_DECLARE(int32_t) vec_dot_prodi16(const int16_t x[], const int16_t y[], int n); 00103 00104 /*! \brief Find the dot product of two int16_t vectors, where the first is a circular buffer 00105 with an offset for the starting position. 00106 \param x The first vector. 00107 \param y The first vector. 00108 \param n The number of elements in the vectors. 00109 \param pos The starting position in the x vector. 00110 \return The dot product of the two vectors. */ 00111 SPAN_DECLARE(int32_t) vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos); 00112 00113 SPAN_DECLARE(void) vec_lmsi16(const int16_t x[], int16_t y[], int n, int16_t error); 00114 00115 SPAN_DECLARE(void) vec_circular_lmsi16(const int16_t x[], int16_t y[], int n, int pos, int16_t error); 00116 00117 /*! \brief Find the minimum and maximum values in an int16_t vector. 00118 \param x The vector to be searched. 00119 \param n The number of elements in the vector. 00120 \param out A two element vector. The first will receive the 00121 maximum. The second will receive the minimum. This parameter 00122 may be set to NULL. 00123 \return The absolute maximum value. Since the range of negative numbers 00124 exceeds the range of positive one, the returned integer is longer 00125 than the ones being searched. */ 00126 SPAN_DECLARE(int32_t) vec_min_maxi16(const int16_t x[], int n, int16_t out[]); 00127 00128 static __inline__ int vec_norm2i16(const int16_t *vec, int len) 00129 { 00130 int i; 00131 int sum; 00132 00133 sum = 0; 00134 for (i = 0; i < len; i++) 00135 sum += vec[i]*vec[i]; 00136 return sum; 00137 } 00138 /*- End of function --------------------------------------------------------*/ 00139 00140 static __inline__ void vec_sari16(int16_t *vec, int len, int shift) 00141 { 00142 int i; 00143 00144 for (i = 0; i < len; i++) 00145 vec[i] >>= shift; 00146 } 00147 /*- End of function --------------------------------------------------------*/ 00148 00149 static __inline__ int vec_max_bitsi16(const int16_t *vec, int len) 00150 { 00151 int i; 00152 int max; 00153 int v; 00154 int b; 00155 00156 max = 0; 00157 for (i = 0; i < len; i++) 00158 { 00159 v = abs(vec[i]); 00160 if (v > max) 00161 max = v; 00162 } 00163 b = 0; 00164 while (max != 0) 00165 { 00166 b++; 00167 max >>= 1; 00168 } 00169 return b; 00170 } 00171 /*- End of function --------------------------------------------------------*/ 00172 00173 #if defined(__cplusplus) 00174 } 00175 #endif 00176 00177 #endif 00178 /*- End of file ------------------------------------------------------------*/