comparison spandsp-0.0.3/spandsp-0.0.3/tests/vector_int_tests.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_int_tests.c
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_int_tests.c,v 1.3 2006/11/19 14:07:28 steveu Exp $
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <inttypes.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <fcntl.h>
36 #include <string.h>
37 #if defined(HAVE_TGMATH_H)
38 #include <tgmath.h>
39 #endif
40 #if defined(HAVE_MATH_H)
41 #include <math.h>
42 #endif
43 #include <assert.h>
44 #include <audiofile.h>
45 #include <tiffio.h>
46
47 #include "spandsp.h"
48
49 static int32_t vec_dot_prodi16_dumb(const int16_t x[], const int16_t y[], int n)
50 {
51 int32_t z;
52 int i;
53
54 z = 0;
55 for (i = 0; i < n; i++)
56 z += x[i]*y[i];
57 return z;
58 }
59 /*- End of function --------------------------------------------------------*/
60
61 static int32_t vec_min_maxi16_dumb(const int16_t x[], int n, int16_t out[])
62 {
63 int i;
64 int16_t min;
65 int16_t max;
66 int16_t temp;
67 int32_t z;
68
69 max = INT16_MIN;
70 min = INT16_MAX;
71 for (i = 0; i < n; i++)
72 {
73 temp = x[i];
74 if (temp > max)
75 max = temp;
76 /*endif*/
77 if (temp < min)
78 min = temp;
79 /*endif*/
80 }
81 /*endfor*/
82 out[0] = max;
83 out[1] = min;
84 z = abs(min);
85 if (z > max)
86 return z;
87 return max;
88 }
89 /*- End of function --------------------------------------------------------*/
90
91 int main(int argc, char *argv[])
92 {
93 int i;
94 int32_t za;
95 int32_t zb;
96 int16_t x[99];
97 int16_t y[99];
98 int16_t outa[2];
99 int16_t outb[2];
100
101 for (i = 0; i < 99; i++)
102 {
103 x[i] = rand();
104 y[i] = rand();
105 }
106
107 za = vec_dot_prodi16(x, y, 99);
108 zb = vec_dot_prodi16_dumb(x, y, 99);
109 if (za != zb)
110 {
111 printf("Tests failed\n");
112 exit(2);
113 }
114
115 x[42] = -32768;
116 za = vec_min_maxi16_dumb(x, 99, outa);
117 zb = vec_min_maxi16(x, 99, outb);
118 if (za != zb
119 ||
120 outa[0] != outb[0]
121 ||
122 outa[1] != outb[1])
123 {
124 printf("Tests failed\n");
125 exit(2);
126 }
127 printf("Tests passed.\n");
128 return 0;
129 }
130 /*- End of function --------------------------------------------------------*/
131 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.