Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/src/vector_float.c @ 5:f762bf195c4b
import spandsp-0.0.3
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 16:00:21 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 4:26cd8f1ef0b1 | 5:f762bf195c4b |
|---|---|
| 1 /* | |
| 2 * SpanDSP - a series of DSP components for telephony | |
| 3 * | |
| 4 * vector_float.c - Floating vector arithmetic routines. | |
| 5 * | |
| 6 * Written by Steve Underwood <steveu@coppice.org> | |
| 7 * | |
| 8 * Copyright (C) 2006 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_float.c,v 1.5 2006/11/19 14:07:26 steveu Exp $ | |
| 26 */ | |
| 27 | |
| 28 /*! \file */ | |
| 29 | |
| 30 #ifdef HAVE_CONFIG_H | |
| 31 #include <config.h> | |
| 32 #endif | |
| 33 | |
| 34 #include <inttypes.h> | |
| 35 #include <stdlib.h> | |
| 36 #include <stdio.h> | |
| 37 #include <string.h> | |
| 38 #if defined(HAVE_TGMATH_H) | |
| 39 #include <tgmath.h> | |
| 40 #endif | |
| 41 #if defined(HAVE_MATH_H) | |
| 42 #include <math.h> | |
| 43 #endif | |
| 44 #include <assert.h> | |
| 45 | |
| 46 #include "spandsp/telephony.h" | |
| 47 #include "spandsp/logging.h" | |
| 48 #include "spandsp/vector_float.h" | |
| 49 | |
| 50 void vec_copyf(float z[], const float x[], int n) | |
| 51 { | |
| 52 int i; | |
| 53 | |
| 54 for (i = 0; i < n; i++) | |
| 55 z[i] = x[i]; | |
| 56 } | |
| 57 /*- End of function --------------------------------------------------------*/ | |
| 58 | |
| 59 void vec_copy(double z[], const double x[], int n) | |
| 60 { | |
| 61 int i; | |
| 62 | |
| 63 for (i = 0; i < n; i++) | |
| 64 z[i] = x[i]; | |
| 65 } | |
| 66 /*- End of function --------------------------------------------------------*/ | |
| 67 | |
| 68 #if defined(HAVE_LONG_DOUBLE) | |
| 69 void vec_copyl(long double z[], const long double x[], int n) | |
| 70 { | |
| 71 int i; | |
| 72 | |
| 73 for (i = 0; i < n; i++) | |
| 74 z[i] = x[i]; | |
| 75 } | |
| 76 /*- End of function --------------------------------------------------------*/ | |
| 77 #endif | |
| 78 | |
| 79 void vec_zerof(float z[], int n) | |
| 80 { | |
| 81 int i; | |
| 82 | |
| 83 for (i = 0; i < n; i++) | |
| 84 z[i] = 0.0f; | |
| 85 } | |
| 86 /*- End of function --------------------------------------------------------*/ | |
| 87 | |
| 88 void vec_zero(double z[], int n) | |
| 89 { | |
| 90 int i; | |
| 91 | |
| 92 for (i = 0; i < n; i++) | |
| 93 z[i] = 0.0; | |
| 94 } | |
| 95 /*- End of function --------------------------------------------------------*/ | |
| 96 | |
| 97 #if defined(HAVE_LONG_DOUBLE) | |
| 98 void vec_zerol(long double z[], int n) | |
| 99 { | |
| 100 int i; | |
| 101 | |
| 102 for (i = 0; i < n; i++) | |
| 103 z[i] = 0.0; | |
| 104 } | |
| 105 /*- End of function --------------------------------------------------------*/ | |
| 106 #endif | |
| 107 | |
| 108 void vec_setf(float z[], float x, int n) | |
| 109 { | |
| 110 int i; | |
| 111 | |
| 112 for (i = 0; i < n; i++) | |
| 113 z[i] = x; | |
| 114 } | |
| 115 /*- End of function --------------------------------------------------------*/ | |
| 116 | |
| 117 void vec_set(double z[], double x, int n) | |
| 118 { | |
| 119 int i; | |
| 120 | |
| 121 for (i = 0; i < n; i++) | |
| 122 z[i] = x; | |
| 123 } | |
| 124 /*- End of function --------------------------------------------------------*/ | |
| 125 | |
| 126 #if defined(HAVE_LONG_DOUBLE) | |
| 127 void vec_setl(long double z[], long double x, int n) | |
| 128 { | |
| 129 int i; | |
| 130 | |
| 131 for (i = 0; i < n; i++) | |
| 132 z[i] = x; | |
| 133 } | |
| 134 /*- End of function --------------------------------------------------------*/ | |
| 135 #endif | |
| 136 | |
| 137 void vec_addf(float z[], const float x[], const float y[], int n) | |
| 138 { | |
| 139 int i; | |
| 140 | |
| 141 for (i = 0; i < n; i++) | |
| 142 z[i] = x[i] + y[i]; | |
| 143 } | |
| 144 /*- End of function --------------------------------------------------------*/ | |
| 145 | |
| 146 void vec_add(double z[], const double x[], const double y[], int n) | |
| 147 { | |
| 148 int i; | |
| 149 | |
| 150 for (i = 0; i < n; i++) | |
| 151 z[i] = x[i] + y[i]; | |
| 152 } | |
| 153 /*- End of function --------------------------------------------------------*/ | |
| 154 | |
| 155 void vec_addl(long double z[], const long double x[], const long double y[], int n) | |
| 156 { | |
| 157 int i; | |
| 158 | |
| 159 for (i = 0; i < n; i++) | |
| 160 z[i] = x[i] + y[i]; | |
| 161 } | |
| 162 /*- End of function --------------------------------------------------------*/ | |
| 163 | |
| 164 void vec_scaled_addf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n) | |
| 165 { | |
| 166 int i; | |
| 167 | |
| 168 for (i = 0; i < n; i++) | |
| 169 z[i] = x[i]*x_scale + y[i]*y_scale; | |
| 170 } | |
| 171 /*- End of function --------------------------------------------------------*/ | |
| 172 | |
| 173 void vec_scaled_add(double z[], const double x[], double x_scale, const double y[], double y_scale, int n) | |
| 174 { | |
| 175 int i; | |
| 176 | |
| 177 for (i = 0; i < n; i++) | |
| 178 z[i] = x[i]*x_scale + y[i]*y_scale; | |
| 179 } | |
| 180 /*- End of function --------------------------------------------------------*/ | |
| 181 | |
| 182 #if defined(HAVE_LONG_DOUBLE) | |
| 183 void vec_scaled_addl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n) | |
| 184 { | |
| 185 int i; | |
| 186 | |
| 187 for (i = 0; i < n; i++) | |
| 188 z[i] = x[i]*x_scale + y[i]*y_scale; | |
| 189 } | |
| 190 /*- End of function --------------------------------------------------------*/ | |
| 191 #endif | |
| 192 | |
| 193 void vec_subf(float z[], const float x[], const float y[], int n) | |
| 194 { | |
| 195 int i; | |
| 196 | |
| 197 for (i = 0; i < n; i++) | |
| 198 z[i] = x[i] - y[i]; | |
| 199 } | |
| 200 /*- End of function --------------------------------------------------------*/ | |
| 201 | |
| 202 void vec_sub(double z[], const double x[], const double y[], int n) | |
| 203 { | |
| 204 int i; | |
| 205 | |
| 206 for (i = 0; i < n; i++) | |
| 207 z[i] = x[i] - y[i]; | |
| 208 } | |
| 209 /*- End of function --------------------------------------------------------*/ | |
| 210 | |
| 211 #if defined(HAVE_LONG_DOUBLE) | |
| 212 void vec_subl(long double z[], const long double x[], const long double y[], int n) | |
| 213 { | |
| 214 int i; | |
| 215 | |
| 216 for (i = 0; i < n; i++) | |
| 217 z[i] = x[i] - y[i]; | |
| 218 } | |
| 219 /*- End of function --------------------------------------------------------*/ | |
| 220 #endif | |
| 221 | |
| 222 void vec_scaled_subf(float z[], const float x[], float x_scale, const float y[], float y_scale, int n) | |
| 223 { | |
| 224 int i; | |
| 225 | |
| 226 for (i = 0; i < n; i++) | |
| 227 z[i] = x[i]*x_scale - y[i]*y_scale; | |
| 228 } | |
| 229 /*- End of function --------------------------------------------------------*/ | |
| 230 | |
| 231 void vec_scaled_sub(double z[], const double x[], double x_scale, const double y[], double y_scale, int n) | |
| 232 { | |
| 233 int i; | |
| 234 | |
| 235 for (i = 0; i < n; i++) | |
| 236 z[i] = x[i]*x_scale - y[i]*y_scale; | |
| 237 } | |
| 238 /*- End of function --------------------------------------------------------*/ | |
| 239 | |
| 240 #if defined(HAVE_LONG_DOUBLE) | |
| 241 void vec_scaled_subl(long double z[], const long double x[], long double x_scale, const long double y[], long double y_scale, int n) | |
| 242 { | |
| 243 int i; | |
| 244 | |
| 245 for (i = 0; i < n; i++) | |
| 246 z[i] = x[i]*x_scale - y[i]*y_scale; | |
| 247 } | |
| 248 /*- End of function --------------------------------------------------------*/ | |
| 249 #endif | |
| 250 | |
| 251 void vec_scalar_mulf(float z[], const float x[], float y, int n) | |
| 252 { | |
| 253 int i; | |
| 254 | |
| 255 for (i = 0; i < n; i++) | |
| 256 z[i] = x[i]*y; | |
| 257 } | |
| 258 /*- End of function --------------------------------------------------------*/ | |
| 259 | |
| 260 void vec_scalar_mul(double z[], const double x[], double y, int n) | |
| 261 { | |
| 262 int i; | |
| 263 | |
| 264 for (i = 0; i < n; i++) | |
| 265 z[i] = x[i]*y; | |
| 266 } | |
| 267 /*- End of function --------------------------------------------------------*/ | |
| 268 | |
| 269 #if defined(HAVE_LONG_DOUBLE) | |
| 270 void vec_scalar_mull(long double z[], const long double x[], long double y, int n) | |
| 271 { | |
| 272 int i; | |
| 273 | |
| 274 for (i = 0; i < n; i++) | |
| 275 z[i] = x[i]*y; | |
| 276 } | |
| 277 /*- End of function --------------------------------------------------------*/ | |
| 278 #endif | |
| 279 | |
| 280 float vec_dot_prodf(const float x[], const float y[], int n) | |
| 281 { | |
| 282 int i; | |
| 283 float z; | |
| 284 | |
| 285 z = 0.0f; | |
| 286 for (i = 0; i < n; i++) | |
| 287 z += x[i]*y[i]; | |
| 288 return z; | |
| 289 } | |
| 290 /*- End of function --------------------------------------------------------*/ | |
| 291 | |
| 292 double vec_dot_prod(const double x[], const double y[], int n) | |
| 293 { | |
| 294 int i; | |
| 295 double z; | |
| 296 | |
| 297 z = 0.0; | |
| 298 for (i = 0; i < n; i++) | |
| 299 z += x[i]*y[i]; | |
| 300 return z; | |
| 301 } | |
| 302 /*- End of function --------------------------------------------------------*/ | |
| 303 | |
| 304 #if defined(HAVE_LONG_DOUBLE) | |
| 305 long double vec_dot_prodl(const long double x[], const long double y[], int n) | |
| 306 { | |
| 307 int i; | |
| 308 long double z; | |
| 309 | |
| 310 z = 0.0; | |
| 311 for (i = 0; i < n; i++) | |
| 312 z += x[i]*y[i]; | |
| 313 return z; | |
| 314 } | |
| 315 /*- End of function --------------------------------------------------------*/ | |
| 316 #endif | |
| 317 /*- End of file ------------------------------------------------------------*/ |
