1 /* Verify correctness of the peak routine 2 * Copyright 2004 Phil Karn, KA9Q 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <time.h> 7 8 /* These values should trigger leading/trailing array fragment handling */ 9 #define NSAMP 200002 10 #define OFFSET 1 11 12 int peakval(signed short *,int); 13 int peakval_port(signed short *,int); 14 main()15int main(){ 16 int i,s; 17 int result,rresult; 18 signed short samples[NSAMP]; 19 20 srandom(time(NULL)); 21 22 for(i=0;i<NSAMP;i++){ 23 do { 24 s = random() & 0x0fff; 25 } while(s == 0x8000); 26 samples[i] = s; 27 } 28 samples[5] = 25000; 29 30 rresult = peakval_port(&samples[OFFSET],NSAMP-OFFSET); 31 result = peakval(&samples[OFFSET],NSAMP-OFFSET); 32 if(result == rresult){ 33 printf("OK\n"); 34 } else { 35 printf("peak mismatch: %d != %d\n",result,rresult); 36 } 37 exit(0); 38 } 39