osmo-sdr/utils/check_ctr.c @ master
1 |
/* utility to check a recorded WAV file in fgpa.test_mode=1 for
|
---|---|
2 |
* discontinuities in the counter increment/decrements */
|
3 |
|
4 |
#include <stdio.h>
|
5 |
#include <stdint.h>
|
6 |
#include <unistd.h>
|
7 |
#include <fcntl.h>
|
8 |
#include <stdlib.h>
|
9 |
|
10 |
#include <sys/types.h>
|
11 |
#include <sys/stat.h>
|
12 |
#include <sys/mman.h>
|
13 |
|
14 |
#define STEP 1
|
15 |
|
16 |
static int check_continuity(uint16_t *samples, uint32_t size) |
17 |
{
|
18 |
uint16_t *end = samples + size/sizeof(uint16_t); |
19 |
uint16_t *cur; |
20 |
int inited = 0; |
21 |
uint16_t last_i, last_q; |
22 |
|
23 |
for (cur = samples; cur < end; cur += 2) { |
24 |
if (!inited) { |
25 |
last_i = cur[0]; |
26 |
last_q = cur[1]; |
27 |
printf("initial I=%04x, Q=%04x\n", |
28 |
last_i, last_q); |
29 |
inited = 1; |
30 |
continue; |
31 |
}
|
32 |
|
33 |
if (cur[0] != (uint16_t)(last_i - STEP) || |
34 |
cur[1] != (uint16_t)(last_q + STEP)) { |
35 |
fprintf(stderr, "Disocntinuity at %u: " |
36 |
"I=%04x/%04x Q=%04x/%04x\n", |
37 |
cur - samples, last_i, cur[0], |
38 |
last_q, cur[1]); |
39 |
}
|
40 |
|
41 |
last_i = cur[0]; |
42 |
last_q = cur[1]; |
43 |
}
|
44 |
|
45 |
return 0; |
46 |
}
|
47 |
|
48 |
int main(int argc, char **argv) |
49 |
{
|
50 |
struct stat st; |
51 |
int fd; |
52 |
void *map; |
53 |
uint16_t *samples; |
54 |
|
55 |
if (argc < 2) { |
56 |
fprintf(stderr, "You have to specify a wave file name\n"); |
57 |
exit(2); |
58 |
}
|
59 |
|
60 |
fd = open(argv[1], O_RDONLY); |
61 |
if (fd < 0) { |
62 |
perror("opening file"); |
63 |
exit(2); |
64 |
}
|
65 |
|
66 |
if (fstat(fd, &st) < 0) { |
67 |
perror("stat"); |
68 |
exit(1); |
69 |
}
|
70 |
|
71 |
map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); |
72 |
if (!map) { |
73 |
perror("mmap"); |
74 |
exit(1); |
75 |
}
|
76 |
|
77 |
if (memcmp(map, "RIFF", 4)) { |
78 |
fprintf(stderr, "Doeesn't look like a WAV file\n"); |
79 |
exit(1); |
80 |
}
|
81 |
|
82 |
samples = (uint16_t *)(map + 0x44); |
83 |
check_continuity(samples, st.st_size-0x44); |
84 |
|
85 |
exit(0); |
86 |
}
|