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 General Public License version 2, as 00014 * 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 General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * 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.7 2007/04/08 08:16:18 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 int32_t vec_dot_prodi16(const int16_t x[], const int16_t y[], int n); 00037 00038 /*! \brief Find the minimum and maximum values in a vector. 00039 \param x The vector to be searched. 00040 \param n The number of elements in the vetor. 00041 \param result A two element vector. The first will receive the 00042 maximum. The second will receive thw minimum. This parameter 00043 may be set to NULL. 00044 \return The absolute maximum value. Since the range of negative numbers 00045 exceeds the range of positive one, the returned integer is longer 00046 than the ones being searched. */ 00047 int32_t vec_min_maxi16(const int16_t x[], int n, int16_t out[]); 00048 00049 static __inline__ int vec_norm2i16(const int16_t *vec, int len) 00050 { 00051 int i; 00052 int sum; 00053 00054 sum = 0; 00055 for (i = 0; i < len; i++) 00056 sum += vec[i]*vec[i]; 00057 return sum; 00058 } 00059 /*- End of function --------------------------------------------------------*/ 00060 00061 static __inline__ void vec_sari16(int16_t *vec, int len, int shift) 00062 { 00063 int i; 00064 00065 for (i = 0; i < len; i++) 00066 vec[i] >>= shift; 00067 } 00068 /*- End of function --------------------------------------------------------*/ 00069 00070 static __inline__ int vec_max_bitsi16(const int16_t *vec, int len) 00071 { 00072 int i; 00073 int max; 00074 int v; 00075 int b; 00076 00077 max = 0; 00078 for (i = 0; i < len; i++) 00079 { 00080 v = abs(vec[i]); 00081 if (v > max) 00082 max = v; 00083 } 00084 b = 0; 00085 while (max != 0) 00086 { 00087 b++; 00088 max >>= 1; 00089 } 00090 return b; 00091 } 00092 /*- End of function --------------------------------------------------------*/ 00093 00094 #if defined(__cplusplus) 00095 } 00096 #endif 00097 00098 #endif 00099 /*- End of file ------------------------------------------------------------*/