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