FreeCalypso > hg > vband-misc
comparison hr-sid/sidgen.c @ 45:5c82f2e56d56
hr-sid: hack created
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 09 Jun 2024 08:57:28 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
44:0b1c4960e5e9 | 45:5c82f2e56d56 |
---|---|
1 /* | |
2 * This program generates a sequence of GSM-HR codec frames in raw packed | |
3 * format (aka TS 101 318) that aims to reverse-engineer the logic of | |
4 * the SID detector in TI Calypso DSP, and maybe later in historical | |
5 * E1 BTS implementations too. | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdint.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <strings.h> | |
13 | |
14 static const uint8_t perfect_sid[14] = { | |
15 0x11, 0x22, 0x33, 0x44, 0xFF, 0xFF, 0xFF, | |
16 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | |
17 }; | |
18 | |
19 static void | |
20 clear_bit(buf, num) | |
21 uint8_t *buf; | |
22 unsigned num; | |
23 { | |
24 unsigned nbyte = num / 8; | |
25 unsigned nbit = num % 8; | |
26 unsigned mask = 0x80 >> nbit; | |
27 | |
28 buf[nbyte] &= ~mask; | |
29 } | |
30 | |
31 static void | |
32 corrupt_class1_bit(buf, num) | |
33 uint8_t *buf; | |
34 unsigned num; | |
35 { | |
36 clear_bit(buf, num + 36); | |
37 } | |
38 | |
39 static void | |
40 corrupt_class2_bit(buf, num) | |
41 uint8_t *buf; | |
42 unsigned num; | |
43 { | |
44 if (num < 8) | |
45 clear_bit(buf, num + 81); | |
46 else | |
47 clear_bit(buf, (num - 8) + 98); | |
48 } | |
49 | |
50 main(argc, argv) | |
51 char **argv; | |
52 { | |
53 FILE *outf; | |
54 uint8_t class1[14], class2[14]; | |
55 unsigned n1, n2; | |
56 | |
57 if (argc != 2) { | |
58 fprintf(stderr, "usage: %s outfile\n", argv[0]); | |
59 exit(1); | |
60 } | |
61 outf = fopen(argv[1], "w"); | |
62 if (!outf) { | |
63 perror(argv[1]); | |
64 exit(1); | |
65 } | |
66 bcopy(perfect_sid, class1, 14); | |
67 for (n1 = 0; n1 < 20; n1++) { | |
68 bcopy(class1, class2, 14); | |
69 for (n2 = 0; n2 < 17; n2++) { | |
70 fwrite(class2, 1, 14, outf); | |
71 corrupt_class2_bit(class2, n2); | |
72 } | |
73 fwrite(class2, 1, 14, outf); | |
74 corrupt_class1_bit(class1, n1); | |
75 } | |
76 fclose(outf); | |
77 exit(0); | |
78 } |