Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/vector_int_tests.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 15:50:58 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * complex_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.11 2009/04/26 07:00:39 steveu Exp $ | |
26 */ | |
27 | |
28 #if defined(HAVE_CONFIG_H) | |
29 #include "config.h" | |
30 #endif | |
31 | |
32 #include <stdlib.h> | |
33 #include <stdio.h> | |
34 #include <fcntl.h> | |
35 #include <string.h> | |
36 | |
37 #include "spandsp.h" | |
38 | |
39 static int32_t vec_dot_prodi16_dumb(const int16_t x[], const int16_t y[], int n) | |
40 { | |
41 int32_t z; | |
42 int i; | |
43 | |
44 z = 0; | |
45 for (i = 0; i < n; i++) | |
46 z += (int32_t) x[i]*(int32_t) y[i]; | |
47 return z; | |
48 } | |
49 /*- End of function --------------------------------------------------------*/ | |
50 | |
51 static int test_vec_dot_prodi16(void) | |
52 { | |
53 int i; | |
54 int32_t za; | |
55 int32_t zb; | |
56 int16_t x[99]; | |
57 int16_t y[99]; | |
58 | |
59 for (i = 0; i < 99; i++) | |
60 { | |
61 x[i] = rand(); | |
62 y[i] = rand(); | |
63 } | |
64 | |
65 for (i = 1; i < 99; i++) | |
66 { | |
67 za = vec_dot_prodi16(x, y, i); | |
68 zb = vec_dot_prodi16_dumb(x, y, i); | |
69 if (za != zb) | |
70 { | |
71 printf("Tests failed\n"); | |
72 exit(2); | |
73 } | |
74 } | |
75 return 0; | |
76 } | |
77 /*- End of function --------------------------------------------------------*/ | |
78 | |
79 static int32_t vec_min_maxi16_dumb(const int16_t x[], int n, int16_t out[]) | |
80 { | |
81 int i; | |
82 int16_t min; | |
83 int16_t max; | |
84 int16_t temp; | |
85 int32_t z; | |
86 | |
87 max = INT16_MIN; | |
88 min = INT16_MAX; | |
89 for (i = 0; i < n; i++) | |
90 { | |
91 temp = x[i]; | |
92 if (temp > max) | |
93 max = temp; | |
94 /*endif*/ | |
95 if (temp < min) | |
96 min = temp; | |
97 /*endif*/ | |
98 } | |
99 /*endfor*/ | |
100 out[0] = max; | |
101 out[1] = min; | |
102 z = abs(min); | |
103 if (z > max) | |
104 return z; | |
105 return max; | |
106 } | |
107 /*- End of function --------------------------------------------------------*/ | |
108 | |
109 static int test_vec_min_maxi16(void) | |
110 { | |
111 int i; | |
112 int32_t za; | |
113 int32_t zb; | |
114 int16_t x[99]; | |
115 int16_t y[99]; | |
116 int16_t outa[2]; | |
117 int16_t outb[2]; | |
118 | |
119 for (i = 0; i < 99; i++) | |
120 { | |
121 x[i] = rand(); | |
122 y[i] = rand(); | |
123 } | |
124 | |
125 x[42] = -32768; | |
126 za = vec_min_maxi16_dumb(x, 99, outa); | |
127 zb = vec_min_maxi16(x, 99, outb); | |
128 if (za != zb | |
129 || | |
130 outa[0] != outb[0] | |
131 || | |
132 outa[1] != outb[1]) | |
133 { | |
134 printf("Tests failed\n"); | |
135 exit(2); | |
136 } | |
137 return 0; | |
138 } | |
139 /*- End of function --------------------------------------------------------*/ | |
140 | |
141 static int test_vec_circular_dot_prodi16(void) | |
142 { | |
143 int i; | |
144 int j; | |
145 int pos; | |
146 int len; | |
147 int32_t za; | |
148 int32_t zb; | |
149 int16_t x[99]; | |
150 int16_t y[99]; | |
151 | |
152 /* Verify that we can do circular sample buffer "dot" linear coefficient buffer | |
153 operations properly, by doing two sub-dot products. */ | |
154 for (i = 0; i < 99; i++) | |
155 { | |
156 x[i] = rand(); | |
157 y[i] = rand(); | |
158 } | |
159 | |
160 len = 95; | |
161 for (pos = 0; pos < len; pos++) | |
162 { | |
163 za = vec_circular_dot_prodi16(x, y, len, pos); | |
164 zb = 0; | |
165 for (i = 0; i < len; i++) | |
166 { | |
167 j = (pos + i) % len; | |
168 zb += (int32_t) x[j]*(int32_t) y[i]; | |
169 } | |
170 | |
171 if (za != zb) | |
172 { | |
173 printf("Tests failed\n"); | |
174 exit(2); | |
175 } | |
176 } | |
177 return 0; | |
178 } | |
179 /*- End of function --------------------------------------------------------*/ | |
180 | |
181 int main(int argc, char *argv[]) | |
182 { | |
183 test_vec_dot_prodi16(); | |
184 test_vec_min_maxi16(); | |
185 test_vec_circular_dot_prodi16(); | |
186 | |
187 printf("Tests passed.\n"); | |
188 return 0; | |
189 } | |
190 /*- End of function --------------------------------------------------------*/ | |
191 /*- End of file ------------------------------------------------------------*/ |