FreeCalypso > hg > vband-misc
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hr-sid/sidgen.c Sun Jun 09 08:57:28 2024 +0000 @@ -0,0 +1,78 @@ +/* + * This program generates a sequence of GSM-HR codec frames in raw packed + * format (aka TS 101 318) that aims to reverse-engineer the logic of + * the SID detector in TI Calypso DSP, and maybe later in historical + * E1 BTS implementations too. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +static const uint8_t perfect_sid[14] = { + 0x11, 0x22, 0x33, 0x44, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static void +clear_bit(buf, num) + uint8_t *buf; + unsigned num; +{ + unsigned nbyte = num / 8; + unsigned nbit = num % 8; + unsigned mask = 0x80 >> nbit; + + buf[nbyte] &= ~mask; +} + +static void +corrupt_class1_bit(buf, num) + uint8_t *buf; + unsigned num; +{ + clear_bit(buf, num + 36); +} + +static void +corrupt_class2_bit(buf, num) + uint8_t *buf; + unsigned num; +{ + if (num < 8) + clear_bit(buf, num + 81); + else + clear_bit(buf, (num - 8) + 98); +} + +main(argc, argv) + char **argv; +{ + FILE *outf; + uint8_t class1[14], class2[14]; + unsigned n1, n2; + + if (argc != 2) { + fprintf(stderr, "usage: %s outfile\n", argv[0]); + exit(1); + } + outf = fopen(argv[1], "w"); + if (!outf) { + perror(argv[1]); + exit(1); + } + bcopy(perfect_sid, class1, 14); + for (n1 = 0; n1 < 20; n1++) { + bcopy(class1, class2, 14); + for (n2 = 0; n2 < 17; n2++) { + fwrite(class2, 1, 14, outf); + corrupt_class2_bit(class2, n2); + } + fwrite(class2, 1, 14, outf); + corrupt_class1_bit(class1, n1); + } + fclose(outf); + exit(0); +}