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