1 /* OpenCP Module Player
2 * copyright (c) '04-'10 Stian Skjelstad <stian@nixia.no>
3 *
4 * Unit-test for "dwmixa.c"
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "config.h"
22 #include "types.h"
23 #include <stdio.h>
24 #include "dwmix.h"
25 #include "dwmixa.h"
26 #include <string.h>
27 #include <stdlib.h>
28 #ifdef I386_ASM
29 #include <unistd.h>
30 #include <sys/mman.h>
31 #include "stuff/pagesize.inc.c"
32 #endif
33
34
35 static int16_t (*amptab)[256]; /* signedness is not fixed here */
36 static int signedout;
37 static uint32_t clipmax;
38
39 static int32_t (*voltabsr)[256];
40
41 static uint8_t (*interpoltabr)[256][2];
42
calcamptab(int32_t amp)43 static void calcamptab(int32_t amp)
44 /* Used by SET
45 * OpenPlayer
46 */
47 {
48 int i;
49
50 amp=3*amp/16;
51
52 for (i=0; i<256; i++)
53 {
54 amptab[0][i]=(amp*i)>>12;
55 amptab[1][i]=(amp*i)>>4;
56 amptab[2][i]=(amp*(signed char)i)<<4;
57 }
58
59 if(amp)
60 clipmax=0x07FFF000/amp;
61 else
62 clipmax=0x07FFF000;
63
64 if (!signedout)
65 for (i=0; i<256; i++)
66 amptab[0][i]^=0x8000;
67 }
68
calcvoltabsr(void)69 static void calcvoltabsr(void)
70 {
71 int i,j;
72 for (i=0; i<=512; i++)
73 for (j=0; j<256; j++)
74 voltabsr[i][j]=(i-256)*(signed char)j;
75 }
76
calcinterpoltabr(void)77 static void calcinterpoltabr(void)
78 {
79 int i,j;
80 for (i=0; i<16; i++)
81 for (j=0; j<256; j++)
82 {
83 interpoltabr[i][j][1]=(i*(signed char)j)>>4;
84 interpoltabr[i][j][0]=(signed char)j-interpoltabr[i][j][1];
85 }
86 }
87
88 static uint8_t test_mixrClip_dst8[34];
89 static uint16_t test_mixrClip_dst16[34];
90 static int32_t test_mixrClip_src[32];
91
92 /*
93 0x00001e50 = 7760 / 2147483647 = 0.00000361353 (less than one in 15bit)
94 1 / 32767 = 0.0000305185
95 */
96
97
98 static const int32_t test_mixrClip_fill_src[32] =
99 {
100 0xfffaf970, 0xffffce5d, 0xffffd792, 0xfffff8cb,
101 0xfffffb87, 0xfffecd1d, 0xfffffc89, 0xffffcc8b,
102 0xfffffdba, 0xffffd018, 0x00000004, 0xffffdb9b,
103 0x0000036d, 0xffffe799, 0x000007f1, 0xffffeddf,
104 0x00000d93, 0xffffee4b, 0x000013be, 0xffffe9cc,
105 0x0000189e, 0xffffe12e, 0x00001c0f, 0xffffd594,
106 0x00001e15, 0xffffd063, 0x00001ed1, 0xffffe258,
107 0x00001e50, 0x000106e0, 0x00001d60, 0x000018e3
108 };
109
110 static const uint8_t test_mixrClip_fill_dst8[34] =
111 {
112 0x55,
113 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
114 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
115 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
116 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
117 0x55
118 };
119
120 static const uint16_t test_mixrClip_fill_dst16[34] =
121 {
122 0x1234,
123 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234,
124 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234,
125 0x1324, 0x1234, 0x1234, 0x1324, 0x1234, 0x1234, 0x1234, 0x1234,
126 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234, 0x1234,
127 0x1234
128 };
129
130 static const uint16_t test_mixrClip_dst16_test1[34] =
131 {
132 0x1234,
133 0x0000, 0x0000, 0x06b7, 0x6a60, 0x7294, 0x0000, 0x759a, 0x0000,
134 0x792d, 0x0000, 0x800b, 0x12d2, 0x8a45, 0x36cb, 0x97d1, 0x499d,
135 0xa8b7, 0x4ae1, 0xbb37, 0x3d64, 0xc9d7, 0x238a, 0xd42a, 0x00bd,
136 0xda3c, 0x0000, 0xdc70, 0x2708, 0xdaed, 0xfffd, 0xd81d, 0xcaa6,
137 0x1234
138 };
139
140 static const uint8_t test_mixrClip_dst8_test2[34] =
141 {
142 0x55,
143 0x00, 0x00, 0x06, 0x6a, 0x72, 0x00, 0x75, 0x00,
144 0x79, 0x00, 0x80, 0x12, 0x8a, 0x36, 0x97, 0x49,
145 0xa8, 0x4a, 0xbb, 0x3d, 0xc9, 0x23, 0xd4, 0x00,
146 0xda, 0x00, 0xdc, 0x27, 0xda, 0xff, 0xd8, 0xca,
147 0x55
148 };
149
150 static const uint16_t test_mixrClip_dst16_test3[34] =
151 {
152 0x1234,
153 0x8000, 0x8000, 0x86b7, 0xea60, 0xf294, 0x8000, 0xf59a, 0x8000,
154 0xf92d, 0x8000, 0x000b, 0x92d2, 0x0a45, 0xb6cb, 0x17d1, 0xc99d,
155 0x28b7, 0xcae1, 0x3b37, 0xbd64, 0x49d7, 0xa38a, 0x542a, 0x80bd,
156 0x5a3c, 0x8000, 0x5c70, 0xa708, 0x5aed, 0x7ffd, 0x581d, 0x4aa6,
157 0x1234
158 };
159
160 static const uint8_t test_mixrClip_dst8_test4[34] =
161 {
162 0x55,
163 0x80, 0x80, 0x86, 0xea, 0xf2, 0x80, 0xf5, 0x80,
164 0xf9, 0x80, 0x00, 0x92, 0x0a, 0xb6, 0x17, 0xc9,
165 0x28, 0xca, 0x3b, 0xbd, 0x49, 0xa3, 0x54, 0x80,
166 0x5a, 0x80, 0x5c, 0xa7, 0x5a, 0x7f, 0x58, 0x4a,
167 0x55
168 };
169
test_mixrClip_fill(void)170 static void test_mixrClip_fill(void)
171 {
172 memcpy(test_mixrClip_src, test_mixrClip_fill_src, sizeof(test_mixrClip_src));
173 memcpy(test_mixrClip_dst8, test_mixrClip_fill_dst8, sizeof(test_mixrClip_dst8));
174 memcpy(test_mixrClip_dst16, test_mixrClip_fill_dst16, sizeof(test_mixrClip_dst16));
175 }
176
test_mixrClip_dump(const uint8_t * t1,const uint16_t * t2)177 static int test_mixrClip_dump(const uint8_t *t1, const uint16_t *t2)
178 {
179 int retval=0;
180 int i;
181 if (memcmp(test_mixrClip_src, test_mixrClip_fill_src, sizeof(test_mixrClip_src)))
182 {
183 retval=1;
184 fprintf(stderr, "src failed\n");
185 fprintf(stderr, "src_expected[]={");
186 for (i=0;i<32;i++)
187 fprintf(stderr, "0x%08x%s", (unsigned)test_mixrClip_fill_src[i], i<31?", ":"");
188 fprintf(stderr, "};\n");
189 fprintf(stderr, "src_result[] ={");
190 for (i=0;i<32;i++)
191 fprintf(stderr, "0x%08x%s", (unsigned)test_mixrClip_src[i], i<31?", ":"");
192 fprintf(stderr, "};\n");
193 }
194 if (memcmp(test_mixrClip_dst8, t1, sizeof(test_mixrClip_dst8)))
195 {
196 retval=1;
197 fprintf(stderr, "dst8 failed\n");
198 fprintf(stderr, "dst8_expected[]={");
199 for (i=0;i<34;i++)
200 fprintf(stderr, "0x%02x%s", t1[i], i<33?", ":"");
201 fprintf(stderr, "}\n");
202 fprintf(stderr, "dst8_result[] ={");
203 for (i=0;i<34;i++)
204 fprintf(stderr, "0x%02x%s", test_mixrClip_dst8[i], i<33?", ":"");
205 fprintf(stderr, "}\n");
206 }
207 if (memcmp(test_mixrClip_dst16, t2, sizeof(test_mixrClip_dst16)))
208 {
209 retval=1;
210 fprintf(stderr, "dst16 failed\n");
211 fprintf(stderr, "dst16_expected[]={");
212 for (i=0;i<34;i++)
213 fprintf(stderr, "0x%04x%s", t2[i], i<33?", ":"");
214 fprintf(stderr, "}\n");
215 fprintf(stderr, "dst16_result[] ={");
216 for (i=0;i<34;i++)
217 fprintf(stderr, "0x%04x%s", test_mixrClip_dst16[i], i<33?", ":"");
218 fprintf(stderr, "}\n");
219 }
220 return retval;
221 }
222
test_mixrClip(void)223 static int test_mixrClip(void)
224 {
225 int retval = 0;
226
227 #define BIT16 1
228 #define BIT8 0
229
230 fprintf(stderr, "mixrClip, unsigned, gain = 1.0, 16 bit\n");
231 signedout=0;
232 calcamptab(65535); /* gain = 1.0 */
233 test_mixrClip_fill();
234 mixrClip(test_mixrClip_dst16+1, test_mixrClip_src, 32, amptab, clipmax, BIT16);
235 retval |= test_mixrClip_dump(test_mixrClip_fill_dst8, test_mixrClip_dst16_test1);
236
237 fprintf(stderr, "mixrClip, unsigned, gain = 1.0, 8 bit\n");
238 //signedout=0;
239 //calcamptab(65535); /* gain = 1.0 */
240 test_mixrClip_fill();
241 mixrClip(test_mixrClip_dst8+1, test_mixrClip_src, 32, amptab, clipmax, BIT8);
242 retval |= test_mixrClip_dump(test_mixrClip_dst8_test2, test_mixrClip_fill_dst16);
243
244 fprintf(stderr, "mixrClip, signed, gain = 1.0, 16 bit\n");
245 signedout=1;
246 calcamptab(65535); /* gain = 1.0 */
247 test_mixrClip_fill();
248 mixrClip(test_mixrClip_dst16+1, test_mixrClip_src, 32, amptab, clipmax, BIT16);
249 retval |= test_mixrClip_dump(test_mixrClip_fill_dst8, test_mixrClip_dst16_test3);
250
251 fprintf(stderr, "mixrClip, signed, gain = 1.0, 8 bit\n");
252 //signedout=1;
253 //calcamptab(65535); /* gain = 1.0 */
254 test_mixrClip_fill();
255 mixrClip(test_mixrClip_dst8+1, test_mixrClip_src, 32, amptab, clipmax, BIT8);
256 retval |= test_mixrClip_dump(test_mixrClip_dst8_test4, test_mixrClip_fill_dst16);
257
258 return retval;
259 }
260
initAsm(void)261 static int initAsm(void)
262 {
263 #ifdef I386_ASM
264 /* Self-modifying code needs access to modify it self */
265 {
266 int fd;
267 char *file=strdup("/tmp/ocpXXXXXX");
268 char *start1, *stop1/*, *start2, *stop2*/;
269 int len1/*, len2*/;
270 fd=mkstemp(file);
271
272 start1=(void *)remap_range1_start;
273 stop1=(void *)remap_range1_stop;
274 /*start2=(void *)remap_range2_start;
275 stop2=(void *)remap_range2_stop;*/
276 #ifdef MIXER_DEBUG
277 fprintf(stderr, "range1: %p - %p\n", start1, stop1);
278 /*fprintf(stderr, "range2: %p - %p\n", start2, stop2);*/
279 #endif
280
281 start1=(char *)(((int)start1)&~(pagesize()-1));
282 /*start2=(char *)(((int)start2)&~(pagesize()-1));*/
283 len1=((stop1-start1)+pagesize()-1)& ~(pagesize()-1);
284 /*len2=((stop2-start2)+pagesize-1)& ~(pagesize()-1);*/
285 #ifdef MIXER_DEBUG
286 fprintf(stderr, "mprot: %p + %08x\n", start1, len1);
287 /*fprintf(stderr, "mprot: %p + %08x\n", start2, len2);*/
288 #endif
289 if (write(fd, start1, len1)!=len1)
290 {
291 #ifdef MIXER_DEBUG
292 fprintf(stderr, "write 1 failed\n");
293 #endif
294 return 1;
295 }
296 /*
297 if (write(fd, start2, len2)!=len2)
298 {
299 #ifdef MIXER_DEBUG
300 fprintf(stderr, "write 2 failed\n");
301 #endif
302 return 0;
303 }*/
304
305 if (mmap(start1, len1, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, fd, 0)==MAP_FAILED)
306 {
307 perror("mmap()");
308 return 1;
309 }
310 /*
311 if (mmap(start2, len2, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, fd, len1)==MAP_FAILED)
312 {
313 perror("mmap()");
314 return 0;
315 }
316 */
317 /*
318 if (mprotect((char *)(((int)remap_range1_start)&~(pagesize()-1)), (((char *)remap_range1_stop-(char *)remap_range1_start)+pagesize()-1)& ~(pagesize()-1), PROT_READ|PROT_WRITE|PROT_EXEC) ||
319 mprotect((char *)(((int)remap_range2_start)&~(pagesize()-1)), (((char *)remap_range2_stop-(char *)remap_range2_start)+pagesize()-1)& ~(pagesize()-1), PROT_READ|PROT_WRITE|PROT_EXEC) )
320 {
321 perror("Couldn't mprotect");
322 return 0;
323 }
324 */
325 #ifdef MIXER_DEBUG
326 fprintf(stderr, "Done ?\n");
327 #endif
328 close(fd);
329 unlink(file);
330 free(file);
331 }
332 #endif
333 return 0;
334 }
335
test_mixrFadeChannel(void)336 static int test_mixrFadeChannel(void)
337 {
338 int16_t samples16[] =
339 {
340 0xef01,
341 0xf012,
342 0x0123,
343 0x1234,
344 0x2345,
345 0x3456,
346 0x4567,
347 0x5678,
348 0x6789,
349 0x789a,
350 0x89ab,
351 0x9abc,
352 0xabcd,
353 0xbcde,
354 0xcdef
355 };
356 int8_t samples8[] =
357 {
358 0x4f,
359 0xc0,
360 0x01,
361 0x12,
362 0x23,
363 0x34,
364 0x45,
365 0x56,
366 0x67,
367 0x89,
368 0x9a,
369 0xab,
370 0xbc,
371 0xcd,
372 0xde,
373 0xef
374 };
375 int32_t fade[2];
376 struct channel dummy;
377
378 int retval = 0;
379
380 mixrSetupAddresses(&voltabsr[256], interpoltabr);
381 calcinterpoltabr();
382 calcvoltabsr();
383
384 fprintf(stderr, "mixrFadeChannel 8 bit 0,0\n");
385
386 fade[0]=0;
387 fade[1]=0;
388 dummy.curvols[0] = 0;
389 dummy.curvols[1] = 0;
390 dummy.samp=samples8;
391 dummy.realsamp.bit8=samples8;
392 dummy.pos=1;
393 dummy.status = MIXRQ_PLAYING;
394 mixrFadeChannel(fade, &dummy);
395 if (dummy.curvols[0])
396 {
397 fprintf(stderr, "c->curvols[0]!=0 (%d)\n", dummy.curvols[0]);
398 retval|=1;
399 }
400 if (dummy.curvols[1])
401 {
402 fprintf(stderr, "c->curvols[1]!=0 (%d)\n", dummy.curvols[1]);
403 retval|=1;
404 }
405 if (dummy.pos!=1)
406 {
407 fprintf(stderr, "c->pos!=1 (%d)\n", dummy.pos);
408 retval|=1;
409 }
410 if (dummy.status!=MIXRQ_PLAYING)
411 {
412 fprintf(stderr, "c->status!=%d (%d)\n", MIXRQ_PLAYING, dummy.status);
413 retval|=1;
414 }
415 if (fade[0]!=0)
416 {
417 fprintf(stderr, "fade[0]!=0 (%d)\n", fade[0]);
418 retval|=1;
419 }
420 if (fade[1]!=0)
421 {
422 fprintf(stderr, "fade[1]!=0 (%d)\n", fade[1]);
423 retval|=1;
424 }
425 fprintf(stderr, "mixrFadeChannel 8 bit 126,90\n");
426
427 fade[0]=1;
428 fade[1]=1;
429 dummy.curvols[0] = 126;
430 dummy.curvols[1] = 90;
431 dummy.samp=samples8;
432 dummy.realsamp.bit8=samples8;
433 dummy.pos=1;
434 dummy.status = MIXRQ_PLAYING;
435 mixrFadeChannel(fade, &dummy);
436 if (dummy.curvols[0])
437 {
438 fprintf(stderr, "c->curvols[0]!=0 (%d)\n", dummy.curvols[0]);
439 retval|=1;
440 }
441 if (dummy.curvols[1])
442 {
443 fprintf(stderr, "c->curvols[1]!=0 (%d)\n", dummy.curvols[1]);
444 retval|=1;
445 }
446 if (dummy.pos!=1)
447 {
448 fprintf(stderr, "c->pos!=1 (%d)\n", dummy.pos);
449 retval|=1;
450 }
451 if (dummy.status!=MIXRQ_PLAYING)
452 {
453 fprintf(stderr, "c->status!=%d (%d)\n", MIXRQ_PLAYING, dummy.status);
454 retval|=1;
455 }
456 if (fade[0]!=-8063)
457 {
458 fprintf(stderr, "fade[0]!=-8063 (%d)\n", fade[0]);
459 retval|=1;
460 }
461 if (fade[1]!=-5759)
462 {
463 fprintf(stderr, "fade[1]!=-5759 (%d)\n", fade[1]);
464 retval|=1;
465 }
466
467 fprintf(stderr, "mixrFadeChannel 8 bit -54,45\n");
468
469 fade[0]=1;
470 fade[1]=1;
471 dummy.curvols[0] = -54;
472 dummy.curvols[1] = 45;
473 dummy.samp=samples8;
474 dummy.realsamp.bit8=samples8;
475 dummy.pos=1;
476 dummy.status = MIXRQ_PLAYING;
477 mixrFadeChannel(fade, &dummy);
478 if (dummy.curvols[0])
479 {
480 fprintf(stderr, "c->curvols[0]!=0 (%d)\n", dummy.curvols[0]);
481 retval|=1;
482 }
483 if (dummy.curvols[1])
484 {
485 fprintf(stderr, "c->curvols[1]!=0 (%d)\n", dummy.curvols[1]);
486 retval|=1;
487 }
488 if (dummy.pos!=1)
489 {
490 fprintf(stderr, "c->pos!=1 (%d)\n", dummy.pos);
491 retval|=1;
492 }
493 if (dummy.status!=MIXRQ_PLAYING)
494 {
495 fprintf(stderr, "c->status!=%d (%d)\n", MIXRQ_PLAYING, dummy.status);
496 retval|=1;
497 }
498 if (fade[0]!=3457)
499 {
500 fprintf(stderr, "fade[0]!=3457 (%d)\n", fade[0]);
501 retval|=1;
502 }
503 if (fade[1]!=-2879)
504 {
505 fprintf(stderr, "fade[1]!=-2879 (%d)\n", fade[1]);
506 retval|=1;
507 }
508
509 fprintf(stderr, "mixrFadeChannel 16 bit 0,0\n");
510
511 fade[0]=0;
512 fade[1]=0;
513 dummy.curvols[0] = 0;
514 dummy.curvols[1] = 0;
515 dummy.samp=(void*)((unsigned long)samples16>>1);
516 dummy.realsamp.bit16=samples16;
517 dummy.pos=1;
518 dummy.status = MIXRQ_PLAYING | MIXRQ_PLAY16BIT;
519 mixrFadeChannel(fade, &dummy);
520 if (dummy.curvols[0])
521 {
522 fprintf(stderr, "c->curvols[0]!=0 (%d)\n", dummy.curvols[0]);
523 retval|=1;
524 }
525 if (dummy.curvols[1])
526 {
527 fprintf(stderr, "c->curvols[1]!=0 (%d)\n", dummy.curvols[1]);
528 retval|=1;
529 }
530 if (dummy.pos!=1)
531 {
532 fprintf(stderr, "c->pos!=1 (%d)\n", dummy.pos);
533 retval|=1;
534 }
535 if (dummy.status!=(MIXRQ_PLAYING|MIXRQ_PLAY16BIT))
536 {
537 fprintf(stderr, "c->status!=%d (%d)\n", MIXRQ_PLAYING|MIXRQ_PLAY16BIT, dummy.status);
538 retval|=1;
539 }
540 if (fade[0]!=0)
541 {
542 fprintf(stderr, "fade[0]!=0 (%d)\n", fade[0]);
543 retval|=1;
544 }
545 if (fade[1]!=0)
546 {
547 fprintf(stderr, "fade[1]!=0 (%d)\n", fade[1]);
548 retval|=1;
549 }
550 fprintf(stderr, "mixrFadeChannel 16 bit 126,90\n");
551
552 fade[0]=1;
553 fade[1]=1;
554 dummy.curvols[0] = 126;
555 dummy.curvols[1] = 90;
556 dummy.samp=(void*)((unsigned long)samples16>>1);
557 dummy.realsamp.bit16=samples16;
558 dummy.pos=1;
559 dummy.status = MIXRQ_PLAYING|MIXRQ_PLAY16BIT;
560 mixrFadeChannel(fade, &dummy);
561 if (dummy.curvols[0])
562 {
563 fprintf(stderr, "c->curvols[0]!=0 (%d)\n", dummy.curvols[0]);
564 retval|=1;
565 }
566 if (dummy.curvols[1])
567 {
568 fprintf(stderr, "c->curvols[1]!=0 (%d)\n", dummy.curvols[1]);
569 retval|=1;
570 }
571 if (dummy.pos!=1)
572 {
573 fprintf(stderr, "c->pos!=1 (%d)\n", dummy.pos);
574 retval|=1;
575 }
576 if (dummy.status!=(MIXRQ_PLAYING|MIXRQ_PLAY16BIT))
577 {
578 fprintf(stderr, "c->status!=%d (%d)\n", MIXRQ_PLAYING|MIXRQ_PLAY16BIT, dummy.status);
579 retval|=1;
580 }
581 if (fade[0]!=-2015)
582 {
583 fprintf(stderr, "fade[0]!=-2015 (%d)\n", fade[0]);
584 retval|=1;
585 }
586 if (fade[1]!=-1439)
587 {
588 fprintf(stderr, "fade[1]!=-1439 (%d)\n", fade[1]);
589 retval|=1;
590 }
591
592 fprintf(stderr, "mixrFadeChannel 16 bit -54,45\n");
593
594 fade[0]=1;
595 fade[1]=1;
596 dummy.curvols[0] = -54;
597 dummy.curvols[1] = 45;
598 dummy.samp=(void*)((unsigned long)samples16>>1);
599 dummy.realsamp.bit16=samples16;
600 dummy.pos=1;
601 dummy.status = MIXRQ_PLAYING|MIXRQ_PLAY16BIT;
602 mixrFadeChannel(fade, &dummy);
603 if (dummy.curvols[0])
604 {
605 fprintf(stderr, "c->curvols[0]!=0 (%d)\n", dummy.curvols[0]);
606 retval|=1;
607 }
608 if (dummy.curvols[1])
609 {
610 fprintf(stderr, "c->curvols[1]!=0 (%d)\n", dummy.curvols[1]);
611 retval|=1;
612 }
613 if (dummy.pos!=1)
614 {
615 fprintf(stderr, "c->pos!=1 (%d)\n", dummy.pos);
616 retval|=1;
617 }
618 if (dummy.status!=(MIXRQ_PLAYING|MIXRQ_PLAY16BIT))
619 {
620 fprintf(stderr, "c->status!=%d (%d)\n", MIXRQ_PLAYING|MIXRQ_PLAY16BIT, dummy.status);
621 retval|=1;
622 }
623 if (fade[0]!=865)
624 {
625 fprintf(stderr, "fade[0]!=865 (%d)\n", fade[0]);
626 retval|=1;
627 }
628 if (fade[1]!=-719)
629 {
630 fprintf(stderr, "fade[1]!=-719 (%d)\n", fade[1]);
631 retval|=1;
632 }
633
634 return retval;
635 }
636
637 int32_t test_mixrFade_buf[22];
638 const int32_t test_mixrFade_test1[22] = {0xfffffd31, 0xfffffd36, 0xfffffd3b, 0xfffffd40, 0xfffffd45, 0xfffffd4a, 0xfffffd4f, 0xfffffd54, 0xfffffd59, 0xfffffd5e, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878, 0x78787878};
639 const int32_t test_mixrFade_test2[22] = {0x00000000, 0x00000029, 0x00000000, 0x00000028, 0x00000000, 0x00000027, 0x00000000, 0x00000026, 0x00000000, 0x00000025, 0x00000000, 0x00000024, 0x00000000, 0x00000023, 0x00000000, 0x00000022, 0x00000000, 0x00000021, 0x00000000, 0x00000020, 0x78787878, 0x78787878};
640
test_mixrFade_fill(void)641 static void test_mixrFade_fill(void)
642 {
643 memset(test_mixrFade_buf, 0x78, sizeof(test_mixrFade_buf));
644 }
645
test_mixrFade_dump(const int32_t * should)646 static int test_mixrFade_dump(const int32_t *should)
647 {
648 int i;
649 if (memcmp(should, test_mixrFade_buf, sizeof(test_mixrFade_buf)))
650 {
651 fprintf(stderr, "buf_expected[] = {\n");
652 for (i=0;i<22;i++)
653 fprintf(stderr, "0x%08x%s", should[i], i!=21?", ":"");
654 fprintf(stderr, "}\n");
655 fprintf(stderr, "buf_result[]= {\n");
656 for (i=0;i<22;i++)
657 fprintf(stderr, "0x%08x%s", test_mixrFade_buf[i], i!=21?", ":"");
658 fprintf(stderr, "}\n");
659 return 1;
660 }
661 return 0;
662 }
663
664
test_mixrFade(void)665 static int test_mixrFade(void)
666 {
667 int retval = 0;
668 int32_t fade[2];
669
670 fprintf(stderr, "mixrFade, mono\n");
671 fade[0]=-719;
672 fade[1]=4;
673 test_mixrFade_fill();
674 mixrFade(test_mixrFade_buf, fade, 10, 0);
675 retval|=test_mixrFade_dump(test_mixrFade_test1);
676 if (fade[0]!=-669)
677 {
678 fprintf(stderr, "fade[0]=%d, should have been -669\n", fade[0]);
679 retval|=1;
680 }
681 if (fade[1]!=4)
682 {
683 fprintf(stderr, "fade[1]=%d, should have been 4\n", fade[1]);
684 retval|=1;
685 }
686
687
688 fprintf(stderr, "mixrFade, stereo\n");
689 fade[0]=0;
690 fade[1]=41;
691 test_mixrFade_fill();
692 mixrFade(test_mixrFade_buf, fade, 10, 1);
693 test_mixrFade_dump(test_mixrFade_test2);
694 if (fade[0]!=0)
695 {
696 fprintf(stderr, "fade[0]=%d, should have been 0\n", fade[0]);
697 retval|=1;
698 }
699 if (fade[1]!=31)
700 {
701 fprintf(stderr, "fade[1]=%d, should have been 31\n", fade[1]);
702 retval|=1;
703 }
704 return retval;
705 }
706
707 static int16_t test_mixrPlayChannel_fill16[] =
708 {
709 0x1010,
710 0x5098,
711 0x7fff,
712 0x49a0,
713 0x0303,
714 0xe103,
715 0xa309,
716 0x8000,
717 0xb243,
718 0xef0c,
719
720 0x0000
721 };
722
723 static int8_t test_mixrPlayChannel_fill8[] =
724 {
725 0x10,
726 0x50,
727 0x7f,
728 0x49,
729 0x03,
730 0xe1,
731 0xa3,
732 0x80,
733 0xb2,
734 0xef,
735
736 0x00
737 };
738
739 static int32_t test_mixrPlayChannel_buf[34];
740 static int32_t fadebuf[2];
741
742 static const int32_t test_mixrPlayChannel_test1[] = {0x010114b1, 0x010112af, 0x0100ead8, 0x0100fd05, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
743 static const int32_t test_mixrPlayChannel_test2[] = {0x010114b1, 0x010114b1, 0x010112af, 0x010112af, 0x0100ead8, 0x0100ead8, 0x0100fd05, 0x0100fd05, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
744 static const int32_t test_mixrPlayChannel_test3[] = {0x010114b1, 0x010112af, 0x0100ead8, 0x0100fd05, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
745 static const int32_t test_mixrPlayChannel_test4[] = {0x010114b1, 0x010114b1, 0x010112af, 0x010112af, 0x0100ead8, 0x0100ead8, 0x0100fd05, 0x0100fd05, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
746 static const int32_t test_mixrPlayChannel_test5[] = {0x0101152f, 0x0101070f, 0x0100e7bf, 0x0100fd7d, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
747 static const int32_t test_mixrPlayChannel_test6[] = {0x0101152f, 0x0101152f, 0x0101070f, 0x0101070f, 0x0100e7bf, 0x0100e7bf, 0x0100fd7d, 0x0100fd7d, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
748 static const int32_t test_mixrPlayChannel_test7[] = {0x0101152f, 0x0101070f, 0x0100e7bf, 0x0100fd7d, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
749 static const int32_t test_mixrPlayChannel_test8[] = {0x0101152f, 0x0101152f, 0x0101070f, 0x0101070f, 0x0100e7bf, 0x0100e7bf, 0x0100fd7d, 0x0100fd7d, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101, 0x01010101};
750 static const int32_t test_mixrPlayChannel_test9[] = {0x010114b1, 0x010112af, 0x0100ead8, 0x01011ec5, 0x010101b2, 0x0100e401, 0x01011142, 0x0100fa39, 0x0100f03f, 0x010101a6, 0x0100ed06, 0x01011c4a, 0x0100fa58, 0x0100e581, 0x010110b0, 0x0100ed06, 0x0100f03f, 0x010101a6, 0x0100e581, 0x01011c4a, 0x0100fa58, 0x0100f03f, 0x010110b0, 0x0100ed06, 0x01011c4a, 0x010101a6, 0x0100e581, 0x010110b0, 0x0100fa58, 0x0100f03f, 0x010101a6, 0x0100ed06, 0x01010101, 0x01010101};
751 static const int32_t test_mixrPlayChannel_test10[] = {0x010114b1, 0x010114b1, 0x010112af, 0x010112af, 0x0100ead8, 0x0100ead8, 0x01011ec5, 0x01011ec5, 0x010101b2, 0x010101b2, 0x0100e401, 0x0100e401, 0x01011142, 0x01011142, 0x0100fa39, 0x0100fa39, 0x0100f03f, 0x0100f03f, 0x010101a6, 0x010101a6, 0x0100ed06, 0x0100ed06, 0x01011c4a, 0x01011c4a, 0x0100fa58, 0x0100fa58, 0x0100e581, 0x0100e581, 0x010110b0, 0x010110b0, 0x0100ed06, 0x0100ed06, 0x01010101, 0x01010101};
752 static const int32_t test_mixrPlayChannel_test11[] = {0x010114b1, 0x010112af, 0x0100ead8, 0x01011ec5, 0x010101b2, 0x0100e401, 0x01011142, 0x0100fa39, 0x0100f03f, 0x010101a6, 0x0100ed06, 0x01011c4a, 0x0100fa58, 0x0100e581, 0x010110b0, 0x0100ed06, 0x0100f03f, 0x010101a6, 0x0100e581, 0x01011c4a, 0x0100fa58, 0x0100f03f, 0x010110b0, 0x0100ed06, 0x01011c4a, 0x010101a6, 0x0100e581, 0x010110b0, 0x0100fa58, 0x0100f03f, 0x010101a6, 0x0100ed06, 0x01010101, 0x01010101};
753 static const int32_t test_mixrPlayChannel_test12[] = {0x010114b1, 0x010114b1, 0x010112af, 0x010112af, 0x0100ead8, 0x0100ead8, 0x01011ec5, 0x01011ec5, 0x010101b2, 0x010101b2, 0x0100e401, 0x0100e401, 0x01011142, 0x01011142, 0x0100fa39, 0x0100fa39, 0x0100f03f, 0x0100f03f, 0x010101a6, 0x010101a6, 0x0100ed06, 0x0100ed06, 0x01011c4a, 0x01011c4a, 0x0100fa58, 0x0100fa58, 0x0100e581, 0x0100e581, 0x010110b0, 0x010110b0, 0x0100ed06, 0x0100ed06, 0x01010101, 0x01010101};
754 static const int32_t test_mixrPlayChannel_test13[] = {0x0101152f, 0x0101070f, 0x0100e7bf, 0x01011e11, 0x0100fbb4, 0x0100e815, 0x0101105e, 0x0100f029, 0x0100f60c, 0x01010138, 0x0100e770, 0x01011722, 0x0100f97c, 0x0100ed74, 0x01010a3e, 0x0100ec2a, 0x0100fa21, 0x0100fe6d, 0x0100e6cb, 0x010112d6, 0x0100f48b, 0x0100f1c0, 0x01010471, 0x0100e95f, 0x01011b00, 0x0100fba2, 0x0100eae0, 0x01010de5, 0x0100ef9a, 0x0100f6b1, 0x0101005c, 0x0100e694, 0x01010101, 0x01010101};
755 static const int32_t test_mixrPlayChannel_test14[] = {0x0101152f, 0x0101152f, 0x0101070f, 0x0101070f, 0x0100e7bf, 0x0100e7bf, 0x01011e11, 0x01011e11, 0x0100fbb4, 0x0100fbb4, 0x0100e815, 0x0100e815, 0x0101105e, 0x0101105e, 0x0100f029, 0x0100f029, 0x0100f60c, 0x0100f60c, 0x01010138, 0x01010138, 0x0100e770, 0x0100e770, 0x01011722, 0x01011722, 0x0100f97c, 0x0100f97c, 0x0100ed74, 0x0100ed74, 0x01010a3e, 0x01010a3e, 0x0100ec2a, 0x0100ec2a, 0x01010101, 0x01010101};
756 static const int32_t test_mixrPlayChannel_test15[] = {0x0101152f, 0x0101070f, 0x0100e7bf, 0x01011e11, 0x0100fbb4, 0x0100e815, 0x0101105e, 0x0100f029, 0x0100f60c, 0x01010138, 0x0100e770, 0x01011722, 0x0100f97c, 0x0100ed74, 0x01010a3e, 0x0100ec2a, 0x0100fa21, 0x0100fe6d, 0x0100e6cb, 0x010112d6, 0x0100f48b, 0x0100f1c0, 0x01010471, 0x0100e95f, 0x01011b00, 0x0100fba2, 0x0100eae0, 0x01010de5, 0x0100ef9a, 0x0100f6b1, 0x0101005c, 0x0100e694, 0x01010101, 0x01010101};
757 static const int32_t test_mixrPlayChannel_test16[] = {0x0101152f, 0x0101152f, 0x0101070f, 0x0101070f, 0x0100e7bf, 0x0100e7bf, 0x01011e11, 0x01011e11, 0x0100fbb4, 0x0100fbb4, 0x0100e815, 0x0100e815, 0x0101105e, 0x0101105e, 0x0100f029, 0x0100f029, 0x0100f60c, 0x0100f60c, 0x01010138, 0x01010138, 0x0100e770, 0x0100e770, 0x01011722, 0x01011722, 0x0100f97c, 0x0100f97c, 0x0100ed74, 0x0100ed74, 0x01010a3e, 0x01010a3e, 0x0100ec2a, 0x0100ec2a, 0x01010101, 0x01010101};
758 static const int32_t test_mixrPlayChannel_test17[] = {0x010114b1, 0x010112af, 0x0100ead8, 0x0100eeb9, 0x0100eb92, 0x0101118b, 0x01011142, 0x0100fa39, 0x0100f03f, 0x0100ed06, 0x010101a6, 0x01011c4a, 0x0100fa58, 0x0100e581, 0x0100e581, 0x010101a6, 0x01011c4a, 0x010101a6, 0x0100e581, 0x0100f03f, 0x0100fa58, 0x01011c4a, 0x010110b0, 0x0100ed06, 0x0100f03f, 0x0100ed06, 0x010110b0, 0x010110b0, 0x0100fa58, 0x0100f03f, 0x0100ed06, 0x010101a6, 0x01010101, 0x01010101};
759 static const int32_t test_mixrPlayChannel_test18[] = {0x010114b1, 0x010114b1, 0x010112af, 0x010112af, 0x0100ead8, 0x0100ead8, 0x0100eeb9, 0x0100eeb9, 0x0100eb92, 0x0100eb92, 0x0101118b, 0x0101118b, 0x01011142, 0x01011142, 0x0100fa39, 0x0100fa39, 0x0100f03f, 0x0100f03f, 0x0100ed06, 0x0100ed06, 0x010101a6, 0x010101a6, 0x01011c4a, 0x01011c4a, 0x0100fa58, 0x0100fa58, 0x0100e581, 0x0100e581, 0x0100e581, 0x0100e581, 0x010101a6, 0x010101a6, 0x01010101, 0x01010101};
760 static const int32_t test_mixrPlayChannel_test19[] = {0x010114b1, 0x010112af, 0x0100ead8, 0x0100eeb9, 0x0100eb92, 0x0101118b, 0x01011142, 0x0100fa39, 0x0100f03f, 0x0100ed06, 0x010101a6, 0x01011c4a, 0x0100fa58, 0x0100e581, 0x0100e581, 0x010101a6, 0x01011c4a, 0x010101a6, 0x0100e581, 0x0100f03f, 0x0100fa58, 0x01011c4a, 0x010110b0, 0x0100ed06, 0x0100f03f, 0x0100ed06, 0x010110b0, 0x010110b0, 0x0100fa58, 0x0100f03f, 0x0100ed06, 0x010101a6, 0x01010101, 0x01010101};
761 static const int32_t test_mixrPlayChannel_test20[] = {0x010114b1, 0x010114b1, 0x010112af, 0x010112af, 0x0100ead8, 0x0100ead8, 0x0100eeb9, 0x0100eeb9, 0x0100eb92, 0x0100eb92, 0x0101118b, 0x0101118b, 0x01011142, 0x01011142, 0x0100fa39, 0x0100fa39, 0x0100f03f, 0x0100f03f, 0x0100ed06, 0x0100ed06, 0x010101a6, 0x010101a6, 0x01011c4a, 0x01011c4a, 0x0100fa58, 0x0100fa58, 0x0100e581, 0x0100e581, 0x0100e581, 0x0100e581, 0x010101a6, 0x010101a6, 0x01010101, 0x01010101};
762 static const int32_t test_mixrPlayChannel_test21[] = {0x0101152f, 0x0101070f, 0x0100e7bf, 0x0100fb61, 0x0100ea30, 0x0101087b, 0x0101105e, 0x0100f029, 0x0100f60c, 0x0100e694, 0x0101005c, 0x01011722, 0x0100f97c, 0x0100ed74, 0x0100eae0, 0x0100fba2, 0x01011a24, 0x0100fe6d, 0x0100e6cb, 0x0100f1c0, 0x0100f3af, 0x010112d6, 0x01010471, 0x0100e95f, 0x0100fafd, 0x0100ec2a, 0x01010a3e, 0x01010de5, 0x0100ef9a, 0x0100f6b1, 0x0100e770, 0x01010138, 0x01010101, 0x01010101};
763 static const int32_t test_mixrPlayChannel_test22[] = {0x0101152f, 0x0101152f, 0x0101070f, 0x0101070f, 0x0100e7bf, 0x0100e7bf, 0x0100fb61, 0x0100fb61, 0x0100ea30, 0x0100ea30, 0x0101087b, 0x0101087b, 0x0101105e, 0x0101105e, 0x0100f029, 0x0100f029, 0x0100f60c, 0x0100f60c, 0x0100e694, 0x0100e694, 0x0101005c, 0x0101005c, 0x01011722, 0x01011722, 0x0100f97c, 0x0100f97c, 0x0100ed74, 0x0100ed74, 0x0100eae0, 0x0100eae0, 0x0100fba2, 0x0100fba2, 0x01010101, 0x01010101};
764 static const int32_t test_mixrPlayChannel_test23[] = {0x0101152f, 0x0101070f, 0x0100e7bf, 0x0100fb61, 0x0100ea30, 0x0101087b, 0x0101105e, 0x0100f029, 0x0100f60c, 0x0100e694, 0x0101005c, 0x01011722, 0x0100f97c, 0x0100ed74, 0x0100eae0, 0x0100fba2, 0x01011a24, 0x0100fe6d, 0x0100e6cb, 0x0100f1c0, 0x0100f3af, 0x010112d6, 0x01010471, 0x0100e95f, 0x0100fafd, 0x0100ec2a, 0x01010a3e, 0x01010de5, 0x0100ef9a, 0x0100f6b1, 0x0100e770, 0x01010138, 0x01010101, 0x01010101};
765 static const int32_t test_mixrPlayChannel_test24[] = {0x0101152f, 0x0101152f, 0x0101070f, 0x0101070f, 0x0100e7bf, 0x0100e7bf, 0x0100fb61, 0x0100fb61, 0x0100ea30, 0x0100ea30, 0x0101087b, 0x0101087b, 0x0101105e, 0x0101105e, 0x0100f029, 0x0100f029, 0x0100f60c, 0x0100f60c, 0x0100e694, 0x0100e694, 0x0101005c, 0x0101005c, 0x01011722, 0x01011722, 0x0100f97c, 0x0100f97c, 0x0100ed74, 0x0100ed74, 0x0100eae0, 0x0100eae0, 0x0100fba2, 0x0100fba2, 0x01010101, 0x01010101};
766
test_mixrPlayChannel_fill(int bit16,struct channel * c,int status)767 static void test_mixrPlayChannel_fill(int bit16, struct channel *c, int status)
768 {
769 memset(c, 0, sizeof(*c));
770 if (bit16)
771 {
772 c->samp=(void*)((unsigned long)test_mixrPlayChannel_fill16>>1);
773 c->realsamp.bit16 = test_mixrPlayChannel_fill16;
774 c->length=10;
775 status|=MIXRQ_PLAY16BIT;
776 } else {
777 c->samp=test_mixrPlayChannel_fill8;
778 c->realsamp.bit8 = test_mixrPlayChannel_fill8;
779 c->length=10;
780 }
781 fadebuf[0]=100;
782 fadebuf[1]=-100;
783 c->status=status | MIXRQ_PLAYING;
784 c->pos=1;
785 c->fpos=0x1234;
786 c->step=0x0002abcd;
787 c->length=10;
788 c->loopstart=2;
789 c->loopend=9;
790 c->replen=7;
791 memset(test_mixrPlayChannel_buf, 1, sizeof(test_mixrPlayChannel_buf));
792 c->curvols[0]=63;
793 c->curvols[1]=63;
794 c->dstvols[0]=55;
795 c->dstvols[1]=55;
796 }
797
test_mixrPlayChannel_dump(struct channel * ch,const int32_t * target,int32_t fadebuf0,int32_t fadebuf1,int status,uint32_t pos,uint32_t fpos,int curvols0,int curvols1)798 static int test_mixrPlayChannel_dump(struct channel *ch, const int32_t *target, int32_t fadebuf0, int32_t fadebuf1, int status, uint32_t pos, uint32_t fpos, int curvols0, int curvols1)
799 {
800 int i;
801 int retval = 0;
802 if (memcmp(target, test_mixrPlayChannel_buf, sizeof(test_mixrPlayChannel_buf)))
803 {
804 fprintf(stderr, "buf_expected[] = {\n");
805 for (i=0;i<34;i++)
806 fprintf(stderr, "%s0x%08x", i?", ":"", target[i]);
807 fprintf(stderr, "\n}\n");
808
809 fprintf(stderr, "buf_result[] = {\n");
810 for (i=0;i<34;i++)
811 fprintf(stderr, "%s0x%08x", i?", ":"", test_mixrPlayChannel_buf[i]);
812 fprintf(stderr, "\n}\n");
813 retval |= 1;
814 }
815 if (fadebuf[0]!=fadebuf0)
816 {
817 fprintf(stderr, "fadebuf[0]=%d (expected %d)\n", fadebuf[0], fadebuf0);
818 retval |= 1;
819 }
820 if (fadebuf[1]!=fadebuf1)
821 {
822 fprintf(stderr, "fadebuf[1]=%d (expected %d)\n", fadebuf[1], fadebuf1);
823 retval |= 1;
824 }
825
826 if (ch->status!=status)
827 {
828 fprintf(stderr, "ch->status=0x%02x (expected 0x%02x)\n", ch->status, status);
829 retval |= 1;
830 }
831 if ((ch->pos!=pos)|(ch->fpos!=fpos))
832 {
833 fprintf(stderr, "ch->pos=0x%08x.%04x (expected 0x%08x.%04x)\n", ch->pos, ch->fpos, pos, fpos);
834 retval |= 1;
835 }
836 if (ch->curvols[0]!=curvols0)
837 {
838 fprintf(stderr, "ch->curvols[0]=0x%02x (expected 0x%02x)\n", ch->curvols[0], curvols0);
839 retval |= 1;
840 }
841 if (ch->curvols[1]!=curvols1)
842 {
843 fprintf(stderr, "ch->curvols[1]=0x%02x (expected 0x%02x)\n", ch->curvols[1], curvols1);
844 retval |= 1;
845 }
846 return retval;
847 }
848
test_mixrPlayChannel(void)849 static int test_mixrPlayChannel(void)
850 {
851 int retval = 0;
852 struct channel ch;
853
854 fprintf (stderr, "mixrPlayChannel, mono, 8 bit\n");
855 test_mixrPlayChannel_fill (0, &ch, 0);
856 mixrPlayChannel (test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
857 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test1, 100, -100, 0, 0x0000000a, 0xc168, 0, 0);
858
859 fprintf(stderr, "mixrPlayChannel, stereo, 8 bit\n");
860 test_mixrPlayChannel_fill(0, &ch, 0);
861 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
862 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test2, 100, -100, 0, 0x0000000a, 0xc168, 0, 0);
863
864 fprintf(stderr, "mixrPlayChannel, mono, 16 bit\n");
865 test_mixrPlayChannel_fill(1, &ch, 0);
866 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
867 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test3, 4820, 4620, MIXRQ_PLAY16BIT, 0x0000000a, 0xc168, 0, 0);
868
869 fprintf(stderr, "mixrPlayChannel, stereo, 16 bit\n");
870 test_mixrPlayChannel_fill(1, &ch, 0);
871 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
872 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test4, 4820, 4620, MIXRQ_PLAY16BIT, 0x0000000a, 0xc168, 0, 0);
873
874 fprintf(stderr, "mixrPlayChannel, mono, 8 bit, interpolate\n");
875 test_mixrPlayChannel_fill(0, &ch, MIXRQ_INTERPOLATE);
876 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
877 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test5, 100, -100, MIXRQ_INTERPOLATE, 0x0000000a, 0xc168, 0, 0);
878
879 fprintf(stderr, "mixrPlayChannel, stereo, 8 bit, interpolate\n");
880 test_mixrPlayChannel_fill(0, &ch, MIXRQ_INTERPOLATE);
881 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
882 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test6, 100, -100, MIXRQ_INTERPOLATE, 0x0000000a, 0xc168, 0, 0);
883
884 fprintf(stderr, "mixrPlayChannel, mono, 16 bit, interpolate\n");
885 test_mixrPlayChannel_fill(1, &ch, MIXRQ_INTERPOLATE);
886 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
887 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test7, 4820, 4620, MIXRQ_INTERPOLATE|MIXRQ_PLAY16BIT, 0x0000000a, 0xc168, 0, 0);
888
889 fprintf(stderr, "mixrPlayChannel, stereo, 16 bit, interpolate\n");
890 test_mixrPlayChannel_fill(1, &ch, MIXRQ_INTERPOLATE);
891 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
892 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test8, 4820, 4620, MIXRQ_INTERPOLATE|MIXRQ_PLAY16BIT, 0x0000000a, 0xc168, 0, 0);
893
894 fprintf(stderr, "mixrPlayChannel, mono, 8 bit, looped\n");
895 test_mixrPlayChannel_fill(0, &ch, MIXRQ_LOOPED);
896 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
897 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test9, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED, 0x00000002, 0x8bd4, 0x37, 0x37);
898
899 fprintf(stderr, "mixrPlayChannel, stereo, 8 bit, looped\n");
900 test_mixrPlayChannel_fill(0, &ch, MIXRQ_LOOPED);
901 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
902 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test10, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED, 0x00000008, 0xcf04, 0x37, 0x37);
903
904 fprintf(stderr, "mixrPlayChannel, mono, 16 bit, looped\n");
905 test_mixrPlayChannel_fill(1, &ch, MIXRQ_LOOPED);
906 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
907 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test11, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PLAY16BIT, 0x00000002, 0x8bd4, 0x37, 0x37);
908
909 fprintf(stderr, "mixrPlayChannel, stereo, 16 bit, looped\n");
910 test_mixrPlayChannel_fill(1, &ch, MIXRQ_LOOPED);
911 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
912 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test12, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PLAY16BIT, 0x00000008, 0xcf04, 0x37, 0x37);
913
914 fprintf(stderr, "mixrPlayChannel, mono, 8 bit, interpolate, looped\n");
915 test_mixrPlayChannel_fill(0, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED);
916 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
917 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test13, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_INTERPOLATE, 0x00000002, 0x8bd4, 0x37, 0x37);
918
919 fprintf(stderr, "mixrPlayChannel, stereo, 8 bit, interpolate, looped\n");
920 test_mixrPlayChannel_fill(0, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED);
921 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
922 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test14, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_INTERPOLATE, 0x00000008, 0xcf04, 0x37, 0x37);
923
924 fprintf(stderr, "mixrPlayChannel, mono, 16 bit, interpolate, looped\n");
925 test_mixrPlayChannel_fill(1, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED);
926 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
927 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test15, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PLAY16BIT|MIXRQ_INTERPOLATE, 0x00000002, 0x8bd4, 0x37, 0x37);
928
929 fprintf(stderr, "mixrPlayChannel, stereo, 16 bit, interpolate, looped\n");
930 test_mixrPlayChannel_fill(1, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED);
931 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
932 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test16, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PLAY16BIT|MIXRQ_INTERPOLATE, 0x00000008, 0xcf04, 0x37, 0x37);
933
934 fprintf(stderr, "mixrPlayChannel, mono, 8 bit, ping-pong looped\n");
935 test_mixrPlayChannel_fill(0, &ch, MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
936 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
937 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test17, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP, 0x00000002, 0x8bd4, 0x37, 0x37);
938
939 fprintf(stderr, "mixrPlayChannel, stereo, 8 bit, ping-pong looped\n");
940 test_mixrPlayChannel_fill(0, &ch, MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
941 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
942 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test18, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP, 0x00000002, 0x30fc, 0x37, 0x37);
943
944 fprintf(stderr, "mixrPlayChannel, mono, 16 bit, ping-pong looped\n");
945 test_mixrPlayChannel_fill(1, &ch, MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
946 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
947 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test19, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PLAY16BIT|MIXRQ_PINGPONGLOOP, 0x00000002, 0x8bd4, 0x37, 0x37);
948
949 fprintf(stderr, "mixrPlayChannel, stereo, 16 bit, ping-pong looped\n");
950 test_mixrPlayChannel_fill(1, &ch, MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
951 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
952 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test20, 100, -100, MIXRQ_PLAYING|MIXRQ_LOOPED|MIXRQ_PLAY16BIT|MIXRQ_PINGPONGLOOP, 0x00000002, 0x30fc, 0x37, 0x37);
953
954
955 fprintf(stderr, "mixrPlayChannel, mono, 8 bit, interpolate, ping-pong looped\n");
956 test_mixrPlayChannel_fill(0, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
957 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
958 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test21, 100, -100, MIXRQ_PLAYING|MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP, 0x00000002, 0x8bd4, 0x37, 0x37);
959
960 fprintf(stderr, "mixrPlayChannel, stereo, 8 bit, interpolate, ping-pong looped\n");
961 test_mixrPlayChannel_fill(0, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
962 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
963 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test22, 100, -100, MIXRQ_PLAYING|MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP, 0x00000002, 0x30fc, 0x37, 0x37);
964
965 fprintf(stderr, "mixrPlayChannel, mono, 16 bit, interpolate, ping-pong looped\n");
966 test_mixrPlayChannel_fill(1, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
967 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 32, &ch, 0);
968 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test23, 100, -100, MIXRQ_PLAYING|MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PLAY16BIT|MIXRQ_PINGPONGLOOP, 0x00000002, 0x8bd4, 0x37, 0x37);
969
970 fprintf(stderr, "mixrPlayChannel, stereo, 16 bit, interpolate, ping-pong looped\n");
971 test_mixrPlayChannel_fill(1, &ch, MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PINGPONGLOOP);
972 mixrPlayChannel(test_mixrPlayChannel_buf, fadebuf, 16, &ch, 1);
973 retval |= test_mixrPlayChannel_dump (&ch, test_mixrPlayChannel_test24, 100, -100, MIXRQ_PLAYING|MIXRQ_INTERPOLATE|MIXRQ_LOOPED|MIXRQ_PLAY16BIT|MIXRQ_PINGPONGLOOP, 0x00000002, 0x30fc, 0x37, 0x37);
974
975 return retval;
976 }
977
main(int argc,char * argv[])978 int main(int argc, char *argv[])
979 {
980 int retval=0;
981
982 if (initAsm())
983 return 1;
984
985 amptab=malloc(sizeof(int16_t)*3*256+sizeof(int32_t)); /* PADDING since assembler indexes some bytes beyond tab and ignores upper bits */ /*new short [3][256];*/
986
987 voltabsr=malloc(sizeof(uint32_t)*513*256);
988
989 interpoltabr=malloc(sizeof(uint8_t)*16*256*2);
990
991 retval |= test_mixrClip();
992
993 retval |= test_mixrFadeChannel();
994
995 retval |= test_mixrFade();
996
997 retval |= test_mixrPlayChannel();
998
999 free(amptab);
1000
1001 return retval;
1002 }
1003