vector_int.h

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  * $Id: vector_int.h,v 1.13 2008/09/18 13:54:32 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_VECTOR_INT_H_)
00029 #define _SPANDSP_VECTOR_INT_H_
00030 
00031 #if defined(__cplusplus)
00032 extern "C"
00033 {
00034 #endif
00035 
00036 static __inline__ void vec_copyi(int z[], const int x[], int n)
00037 {
00038     memcpy(z, x, n*sizeof(z[0]));
00039 }
00040 /*- End of function --------------------------------------------------------*/
00041 
00042 static __inline__ void vec_copyi16(int16_t z[], const int16_t x[], int n)
00043 {
00044     memcpy(z, x, n*sizeof(z[0]));
00045 }
00046 /*- End of function --------------------------------------------------------*/
00047 
00048 static __inline__ void vec_copyi32(int32_t z[], const int32_t x[], int n)
00049 {
00050     memcpy(z, x, n*sizeof(z[0]));
00051 }
00052 /*- End of function --------------------------------------------------------*/
00053 
00054 static __inline__ void vec_zeroi(int z[], int n)
00055 {
00056     memset(z, 0, n*sizeof(z[0]));
00057 }
00058 /*- End of function --------------------------------------------------------*/
00059 
00060 static __inline__ void vec_zeroi16(int16_t z[], int n)
00061 {
00062     memset(z, 0, n*sizeof(z[0]));
00063 }
00064 /*- End of function --------------------------------------------------------*/
00065 
00066 static __inline__ void vec_zeroi32(int32_t z[], int n)
00067 {
00068     memset(z, 0, n*sizeof(z[0]));
00069 }
00070 /*- End of function --------------------------------------------------------*/
00071 
00072 static __inline__ void vec_seti(int z[], int x, int n)
00073 {
00074     int i;
00075     
00076     for (i = 0;  i < n;  i++)
00077         z[i] = x;
00078 }
00079 /*- End of function --------------------------------------------------------*/
00080 
00081 static __inline__ void vec_seti16(int16_t z[], int16_t x, int n)
00082 {
00083     int i;
00084     
00085     for (i = 0;  i < n;  i++)
00086         z[i] = x;
00087 }
00088 /*- End of function --------------------------------------------------------*/
00089 
00090 static __inline__ void vec_seti32(int32_t z[], int32_t x, int n)
00091 {
00092     int i;
00093     
00094     for (i = 0;  i < n;  i++)
00095         z[i] = x;
00096 }
00097 /*- End of function --------------------------------------------------------*/
00098 
00099 /*! \brief Find the dot product of two int16_t vectors.
00100     \param x The first vector.
00101     \param y The first vector.
00102     \param n The number of elements in the vectors.
00103     \return The dot product of the two vectors. */
00104 int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n);
00105 
00106 /*! \brief Find the dot product of two int16_t vectors, where the first is a circular buffer
00107            with an offset for the starting position.
00108     \param x The first vector.
00109     \param y The first vector.
00110     \param n The number of elements in the vectors.
00111     \param pos The starting position in the x vector.
00112     \return The dot product of the two vectors. */
00113 int32_t vec_circular_dot_prodi16(const int16_t x[], const int16_t y[], int n, int pos);
00114 
00115 void vec_lmsi16(const int16_t x[], int16_t y[], int n, int16_t error);
00116 
00117 void vec_circular_lmsi16(const int16_t x[], int16_t y[], int n, int pos, int16_t error);
00118 
00119 /*! \brief Find the minimum and maximum values in an int16_t vector.
00120     \param x The vector to be searched.
00121     \param n The number of elements in the vector.
00122     \param out A two element vector. The first will receive the 
00123            maximum. The second will receive the minimum. This parameter
00124            may be set to NULL.
00125     \return The absolute maximum value. Since the range of negative numbers
00126             exceeds the range of positive one, the returned integer is longer
00127             than the ones being searched. */
00128 int32_t vec_min_maxi16(const int16_t x[], int n, int16_t out[]);
00129 
00130 static __inline__ int vec_norm2i16(const int16_t *vec, int len)
00131 {
00132     int i;
00133     int sum;
00134 
00135     sum = 0;
00136     for (i = 0;  i < len;  i++)
00137         sum += vec[i]*vec[i];
00138     return sum;
00139 }
00140 /*- End of function --------------------------------------------------------*/
00141 
00142 static __inline__ void vec_sari16(int16_t *vec, int len, int shift)
00143 {
00144     int i;
00145 
00146     for (i = 0;  i < len;  i++)
00147         vec[i] >>= shift;
00148 }
00149 /*- End of function --------------------------------------------------------*/
00150 
00151 static __inline__ int vec_max_bitsi16(const int16_t *vec, int len)
00152 {
00153     int i;
00154     int max;
00155     int v;
00156     int b;
00157 
00158     max = 0;
00159     for (i = 0;  i < len;  i++)
00160     {
00161         v = abs(vec[i]);
00162         if (v > max)
00163             max = v;
00164     }
00165     b = 0;
00166     while (max != 0)
00167     {
00168         b++;
00169         max >>= 1;
00170     }
00171     return b;
00172 }
00173 /*- End of function --------------------------------------------------------*/
00174 
00175 #if defined(__cplusplus)
00176 }
00177 #endif
00178 
00179 #endif
00180 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:50 2008 for spandsp by  doxygen 1.5.6