]> mj.ucw.cz Git - home-hw.git/blob - ir-remote/decode.c
Merge branch 'master' of ssh://git.ucw.cz/home/mj/GIT/home-hw
[home-hw.git] / ir-remote / decode.c
1 #include <ucw/lib.h>
2 #include <ucw/fastbuf.h>
3 #include <ucw/unaligned.h>
4
5 #include <stdio.h>
6
7 int main(void)
8 {
9         struct fastbuf *f = bfdopen_shared(0, 4096);
10
11         byte hdr[48];
12         breadb(f, hdr, sizeof(hdr));
13
14         uint i = 0;
15         int last = -1;
16         uint lasti = 0;
17         for (;;) {
18                 byte x[2];
19                 if (!bread(f, x, 2))
20                         break;
21                 int a = (s16) get_u16_le(x);
22                 int boo = (a >= 8000);
23                 if (boo != last) {
24                         if (last >= 0) {
25                                 uint len = i - lasti;
26 #if 0
27                                 printf("%d\t%d\t%6.3f\n", last, len, (double)len / 44100 * 1000);
28 #else
29                                 if (!last) {
30                                         if (len > 2000) {
31                                                 putchar('\n');
32                                         } else if (len >= 26 && len <= 32) {
33                                         } else {
34                                                 printf("<%d>", len);
35                                         }
36                                 } else {
37                                         if (len >= 18 && len <= 24) {
38                                                 putchar('0');
39                                         } else if (len >= 68 && len <= 72) {
40                                                 putchar('1');
41                                         } else if (len >= 194 && len <= 200) {
42                                                 putchar('^');
43                                         } else {
44                                                 printf("[%d]", len);
45                                         }
46                                 }
47 #endif
48                         }
49                         last = boo;
50                         lasti = i;
51                 }
52                 i++;
53         }
54         putchar('\n');
55 }