root/trunk/libffado/tests/test-bufferops.cpp

Revision 2803, 7.7 kB (checked in by jwoithe, 1 year ago)

Cosmetic: capitalise "L" in "Linux".

"Linux" is a proper noun so it should start with a capital letter. These
changes are almost all within comments.

This patch was originally proposed by pander on the ffado-devel mailing
list. It has been expanded to cover all similar cases to maintain
consistency throughout the source tree.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free FireWire (pro-)audio drivers for Linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "debugmodule/debugmodule.h"
25
26 DECLARE_GLOBAL_DEBUG_MODULE;
27
28 #include "libutil/ByteSwap.h"
29 #include "libstreaming/amdtp/AmdtpBufferOps.h"
30
31 #include "libutil/SystemTimeSource.h"
32 #include "libutil/Time.h"
33
34 #include <inttypes.h>
35
36 // 32M of test data
37 #define NB_QUADLETS (1024 * 1024 * 32)
38 #define NB_TESTS 10
39
40 bool
41 testByteSwap(int nb_quadlets, int nb_tests) {
42     quadlet_t *buffer_1;
43     quadlet_t *buffer_ref;
44     int i=0;
45    
46     ffado_microsecs_t start;
47     ffado_microsecs_t elapsed;
48    
49     setDebugLevel(DEBUG_LEVEL_NORMAL);
50    
51     buffer_1 = new quadlet_t[nb_quadlets];
52     buffer_ref = new quadlet_t[nb_quadlets];
53    
54     printMessage( "Generating test data...\n");
55     for (i=0; i<nb_quadlets; i++) {
56         byte_t tmp = i & 0xFF;
57         buffer_1[i]   = tmp << 24;
58         tmp = (i + 1) & 0xFF;
59         buffer_1[i]   |= tmp << 16;
60         tmp = (i + 2) & 0xFF;
61         buffer_1[i]   |= tmp << 8;
62         tmp = (i + 3) & 0xFF;
63         buffer_1[i]   |= tmp;
64     }
65    
66     // do reference conversion
67    
68     for (i=0; i<nb_quadlets; i++) {
69         buffer_ref[i] = CondSwapToBus32(buffer_1[i]);
70     }
71    
72     printMessage( "Performing byte-swap...\n");
73    
74     int test=0;
75     for (test=0; test<nb_tests; test++) {
76         for (i=0; i<nb_quadlets; i++) {
77             byte_t tmp = i & 0xFF;
78             buffer_1[i]   = tmp << 24;
79             tmp = (i + 1) & 0xFF;
80             buffer_1[i]   |= tmp << 16;
81             tmp = (i + 2) & 0xFF;
82             buffer_1[i]   |= tmp << 8;
83             tmp = (i + 3) & 0xFF;
84             buffer_1[i]   |= tmp;
85         }
86
87         start = Util::SystemTimeSource::getCurrentTimeAsUsecs();
88         byteSwapToBus(buffer_1, nb_quadlets);
89         elapsed = Util::SystemTimeSource::getCurrentTimeAsUsecs() - start;
90         printMessage( " took %" PRI_FFADO_MICROSECS_T "usec...\n", elapsed);
91        
92     }
93
94     // check
95     printMessage( "Checking results...\n");
96     bool all_ok=true;
97     for (i=0; i<nb_quadlets; i++) {
98         if (buffer_1[i] != buffer_ref[i]) {
99             printMessage( " bad result: %08X should be %08X\n",
100                         buffer_1[i], buffer_ref[i]);
101             all_ok=false;
102         } else {
103             //debugOutput(DEBUG_LEVEL_VERBOSE, "good result: %08X should be %08X\n",
104             //            buffer_1[i], buffer_ref[i]);
105         }
106     }
107
108     delete[] buffer_1;
109     delete[] buffer_ref;
110     return all_ok;
111 }
112
113 bool
114 testInt24Label(int nb_quadlets, int nb_tests) {
115     quadlet_t *buffer_1;
116     quadlet_t *buffer_ref;
117     int i=0;
118    
119     ffado_microsecs_t start;
120     ffado_microsecs_t elapsed;
121    
122     setDebugLevel(DEBUG_LEVEL_MESSAGE);
123    
124     buffer_1 = new quadlet_t[nb_quadlets];
125     buffer_ref = new quadlet_t[nb_quadlets];
126    
127     printMessage( "Generating test data...\n");
128     for (i=0; i<nb_quadlets; i++) {
129         byte_t tmp = i & 0xFF;
130         buffer_1[i]   = tmp << 16;
131         tmp = (i + 1) & 0xFF;
132         buffer_1[i]   |= tmp << 8;
133         tmp = (i + 2) & 0xFF;
134         buffer_1[i]   |= tmp;
135     }
136    
137     // do reference conversion
138     for (i=0; i<nb_quadlets; i++) {
139         buffer_ref[i] = buffer_1[i] | 0x40000000;
140     }
141    
142     printMessage( "Performing AMDTP labeling...\n");
143    
144     int test=0;
145     for (test=0; test<nb_tests; test++) {
146         for (i=0; i<nb_quadlets; i++) {
147             byte_t tmp = i & 0xFF;
148             buffer_1[i]   = tmp << 16;
149             tmp = (i + 1) & 0xFF;
150             buffer_1[i]   |= tmp << 8;
151             tmp = (i + 2) & 0xFF;
152             buffer_1[i]   |= tmp;
153         }
154
155         start = Util::SystemTimeSource::getCurrentTimeAsUsecs();
156         convertFromInt24AndLabelAsMBLA(buffer_1, nb_quadlets);
157         elapsed = Util::SystemTimeSource::getCurrentTimeAsUsecs() - start;
158         printMessage( " took %" PRI_FFADO_MICROSECS_T "usec...\n", elapsed);
159     }
160
161     // check
162     printMessage( "Checking results...\n");
163     bool all_ok=true;
164     for (i=0; i<nb_quadlets; i++) {
165         if (buffer_1[i] != buffer_ref[i]) {
166             printMessage( " bad result: %08X should be %08X\n",
167                         buffer_1[i], buffer_ref[i]);
168             all_ok=false;
169         } else {
170             //debugOutput(DEBUG_LEVEL_VERBOSE, "good result: %08X should be %08X\n",
171             //            buffer_1[i], buffer_ref[i]);
172         }
173     }
174
175     delete[] buffer_1;
176     delete[] buffer_ref;
177     return all_ok;
178 }
179
180 bool
181 testFloatLabel(int nb_quadlets, int nb_tests) {
182     quadlet_t *buffer_1;
183     quadlet_t *buffer_ref;
184     quadlet_t *buffer_in;
185     float *buffer_float;
186     int i=0;
187    
188     ffado_microsecs_t start;
189     ffado_microsecs_t elapsed;
190    
191     setDebugLevel(DEBUG_LEVEL_MESSAGE);
192    
193     buffer_1 = new quadlet_t[nb_quadlets];
194     buffer_in = new quadlet_t[nb_quadlets];
195     buffer_ref = new quadlet_t[nb_quadlets];
196     buffer_float = new float[nb_quadlets];
197    
198     printMessage( "Generating test data...\n");
199     for (i=0; i<nb_quadlets; i++) {
200         byte_t tmp = i & 0xFF;
201         buffer_in[i]   = tmp << 16;
202         tmp = (i + 1) & 0xFF;
203         buffer_in[i]   |= tmp << 8;
204         tmp = (i + 2) & 0xFF;
205         buffer_in[i]   |= tmp;
206        
207         // convert to float and normalize
208         buffer_float[i] = (float)(buffer_in[i]);
209         buffer_float[i] /= (float)(0x007FFFFF); // range: 0..2
210         buffer_float[i] -= 1.0; // range: 1..-1
211        
212         // copy to input buffer
213         float *t = &(buffer_float[i]);
214         quadlet_t *v = (quadlet_t *)t;
215         buffer_1[i] = *v;
216     }
217    
218     // do reference conversion
219     for (i=0; i<nb_quadlets; i++) {
220         float v = (buffer_float[i]) * AMDTP_FLOAT_MULTIPLIER;
221         unsigned int tmp = ((int) v);
222         tmp = ( tmp >> 8 ) | 0x40000000;
223         buffer_ref[i] = tmp;
224     }
225    
226     printMessage( "Performing AMDTP labeling...\n");
227    
228     int test=0;
229     for (test=0; test<nb_tests; test++) {
230     for (i=0; i<nb_quadlets; i++) {
231         // copy float to input buffer
232         float *t = &(buffer_float[i]);
233         quadlet_t *v = (quadlet_t *)t;
234         buffer_1[i] = *v;
235     }
236
237         start = Util::SystemTimeSource::getCurrentTimeAsUsecs();
238         convertFromFloatAndLabelAsMBLA(buffer_1, nb_quadlets);
239         elapsed = Util::SystemTimeSource::getCurrentTimeAsUsecs() - start;
240         printMessage( " took %" PRI_FFADO_MICROSECS_T "usec...\n", elapsed);
241     }
242
243     // check
244     printMessage( "Checking results...\n");
245     bool all_ok=true;
246     for (i=0; i<nb_quadlets; i++) {
247         if (buffer_1[i] != buffer_ref[i]) {
248             printMessage( " bad result: %08X should be %08X\n",
249                         buffer_1[i], buffer_ref[i]);
250             all_ok=false;
251         } else {
252             //debugOutput(DEBUG_LEVEL_VERBOSE, "good result: %08X should be %08X\n",
253             //            buffer_1[i], buffer_ref[i]);
254         }
255     }
256
257     delete[] buffer_1;
258     delete[] buffer_ref;
259     delete[] buffer_in;
260     delete[] buffer_float;
261     return all_ok;
262 }
263
264 int
265 main(int argc, char **argv) {
266
267     testByteSwap(NB_QUADLETS, NB_TESTS);
268     testInt24Label(NB_QUADLETS, NB_TESTS);
269     testFloatLabel(NB_QUADLETS, NB_TESTS);
270    
271     return 0;
272 }
Note: See TracBrowser for help on using the browser.