comparison efrtest/rec2etsi.c @ 47:89945a3b576e

gsmefr-rec2etsi test program added
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 04:01:13 +0000
parents
children bd832a456339
comparison
equal deleted inserted replaced
46:edd2e20e7090 47:89945a3b576e
1 /*
2 * This program reads in an EFR session recording in our binary format
3 * (presumably obtained by converting from an RTP capture on the network
4 * side or from a Calypso DSP readout on the mobile side) and converts
5 * it into ETSI *.dec format, to be fed to ETSI decoder test program.
6 *
7 * The output from this program is in the local machine's native byte order.
8 */
9
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <strings.h>
15 #include "../libgsmefr/gsm_efr.h"
16 #include "../libtest/binreader.h"
17
18 static void
19 frame2bits(frame, bits)
20 uint8_t *frame;
21 uint16_t *bits;
22 {
23 unsigned nb, byte, mask, bit;
24
25 for (nb = 0; nb < 31; nb++) {
26 byte = *frame++;
27 for (mask = 0x80; mask; mask >>= 1) {
28 if (byte & mask)
29 bit = 1;
30 else
31 bit = 0;
32 *bits++ = bit;
33 }
34 }
35 }
36
37 main(argc, argv)
38 char **argv;
39 {
40 FILE *binf, *outf;
41 uint8_t frame[BINFILE_MAX_FRAME];
42 uint16_t bits[250];
43 int rc;
44
45 if (argc != 3) {
46 fprintf(stderr, "usage: %s input.rec output.dec\n", argv[0]);
47 exit(1);
48 }
49 binf = fopen(argv[1], "r");
50 if (!binf) {
51 perror(argv[1]);
52 exit(1);
53 }
54 outf = fopen(argv[2], "w");
55 if (!outf) {
56 perror(argv[2]);
57 exit(1);
58 }
59 for (;;) {
60 rc = binfile_read_frame(binf, frame);
61 if (rc < 0) {
62 fprintf(stderr, "error: garbage in %s\n", argv[1]);
63 exit(1);
64 }
65 if (!rc)
66 break;
67 if (frame[0] == 0xBF) {
68 bits[3] = 1; /* BFI */
69 bzero(bits + 4, 245 * 2);
70 bits[249] = frame[1] & 1; /* TAF */
71 } else if ((frame[0] & 0xF0) == 0xC0) {
72 frame2bits(frame, bits);
73 bits[248] = EFR_sid_classify(frame);
74 bits[249] = 0; /* TAF */
75 } else {
76 fprintf(stderr,
77 "error: %s is not in EFR codec format\n",
78 argv[1]);
79 exit(1);
80 }
81 fwrite(bits + 3, 2, 247, outf);
82 }
83 fclose(outf);
84 exit(0);
85 }