vector.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * vector.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 as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025  *
00026  * $Id: vector.h,v 1.3 2005/11/25 14:52:00 steveu Exp $
00027  */
00028 
00029 #if !defined(_VECTOR_H_)
00030 #define _VECTOR_H_
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 static __inline__ int vec_dot_prod(const int16_t *vec1,
00037                                    const int16_t *vec2,
00038                                    int len)
00039 {
00040     int i;
00041     int sum;
00042 
00043     sum = 0;
00044     for (i = 0;  i < len;  i++)
00045         sum += vec1[i]*vec2[i];
00046     return sum;
00047 }
00048 
00049 static __inline__ int vec_norm2(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 
00060 static __inline__ void vec_sar(int16_t *vec, int len, int shift)
00061 {
00062     int i;
00063 
00064     for (i = 0;  i < len;  i++)
00065         vec[i] >>= shift;
00066 }
00067 
00068 static __inline__ int vec_max_bits(const int16_t *vec, int len)
00069 {
00070     int i;
00071     int max;
00072     int v;
00073     int b;
00074 
00075     max = 0;
00076     for (i = 0;  i < len;  i++)
00077     {
00078         v = abs(vec[i]);
00079         if (v > max)
00080             max = v;
00081     }
00082     b = 0;
00083     while (max != 0)
00084     {
00085         b++;
00086         max >>= 1;
00087     }
00088     return b;
00089 }
00090 
00091 #ifdef __cplusplus
00092 }
00093 #endif
00094 
00095 #endif
00096 /*- End of file ------------------------------------------------------------*/

Generated on Fri Nov 10 09:40:24 2006 for libspandsp by  doxygen 1.5.1