annotate efr-sid/mk-sid-test2.c @ 52:fd498c6898a8

efr-sid OS#6538: generate TCH UL file for FC testing
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 12 Aug 2024 03:09:13 +0000
parents 0db059f4632d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
2 * This program generates a set of EFR codec frames based on a single input
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
3 * frame (in ETSI cod format) that is expected to be a perfect SID.
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
4 * The output frame set is intended to serve as a unit test for the
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
5 * bit-counting SID classification function; it will contain different
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
6 * extents of bit clearing to produce valid SID, invalid SID and non-SID
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
7 * speech classifications.
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdint.h>
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
13 #include <string.h>
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
14 #include <strings.h>
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <gsm_efr.h>
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "etsi.h"
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
18 #define TOTAL_BITS 244
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
19
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern const uint8_t SID_codeword_bit_idx[95];
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
22 static uint8_t input_frame[ETSI_ENC_NWORDS];
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
23 static FILE *outf;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
24
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static void
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
26 read_input_file(filename)
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 char *filename;
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 FILE *inf;
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 inf = fopen(filename, "r");
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!inf) {
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 perror(filename);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 exit(1);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
36 read_etsi_bits(inf, 0, input_frame, ETSI_ENC_NWORDS, filename);
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fclose(inf);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
40 static void
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
41 emit_out_frame(bits)
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
42 uint8_t *bits;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
43 {
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
44 uint8_t packed_frame[EFR_RTP_FRAME_LEN];
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
45
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
46 bits2frame(bits, packed_frame, "input", 0);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
47 fwrite(packed_frame, 1, EFR_RTP_FRAME_LEN, outf);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
48 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
49
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
50 static void
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
51 emit_1bit_errors()
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
52 {
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
53 uint8_t frame_bits[TOTAL_BITS];
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
54 unsigned n;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
55
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
56 for (n = 0; n < 95; n++) {
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
57 bcopy(input_frame, frame_bits, TOTAL_BITS);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
58 frame_bits[SID_codeword_bit_idx[n]] = 0;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
59 emit_out_frame(frame_bits);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
60 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
61 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
62
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
63 static void
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
64 emit_2bit_errors()
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
65 {
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
66 uint8_t frame_bits[TOTAL_BITS];
50
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
67 unsigned n;
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
68
50
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
69 for (n = 0; n < 48; n++) {
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
70 bcopy(input_frame, frame_bits, TOTAL_BITS);
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
71 frame_bits[SID_codeword_bit_idx[n]] = 0;
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
72 frame_bits[SID_codeword_bit_idx[n + 47]] = 0;
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
73 emit_out_frame(frame_bits);
0db059f4632d efr-sid OS#6538: more sensible 2-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 49
diff changeset
74 }
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
75 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
76
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
77 static void
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
78 emit_15bit_errors()
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
79 {
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
80 uint8_t frame_bits[TOTAL_BITS];
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
81 unsigned i, j;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
82
49
2daadef1e70d efr-sid OS#6538: more sensible 15-bit and 16-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
83 for (i = 0; i < 11; i++) {
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
84 bcopy(input_frame, frame_bits, TOTAL_BITS);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
85 for (j = 0; j < 15; j++)
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
86 frame_bits[SID_codeword_bit_idx[j * 6 + i]] = 0;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
87 emit_out_frame(frame_bits);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
88 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
89 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
90
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
91 static void
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
92 emit_16bit_errors()
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
93 {
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
94 uint8_t frame_bits[TOTAL_BITS];
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
95 unsigned i, j;
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
96
49
2daadef1e70d efr-sid OS#6538: more sensible 15-bit and 16-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
97 for (i = 0; i < 20; i++) {
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
98 bcopy(input_frame, frame_bits, TOTAL_BITS);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
99 for (j = 0; j < 16; j++)
49
2daadef1e70d efr-sid OS#6538: more sensible 15-bit and 16-bit errors
Mychaela Falconia <falcon@freecalypso.org>
parents: 48
diff changeset
100 frame_bits[SID_codeword_bit_idx[j * 5 + i]] = 0;
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
101 emit_out_frame(frame_bits);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
102 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
103 }
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
104
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 main(argc, argv)
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 char **argv;
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (argc != 3) {
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 fprintf(stderr, "usage: %s input.cod output.gsmx\n", argv[0]);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 exit(1);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
112 read_input_file(argv[1]);
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 outf = fopen(argv[2], "w");
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 if (!outf) {
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 perror(argv[2]);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 exit(1);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }
48
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
118 /* emit the perfect, error-free SID first */
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
119 emit_out_frame(input_frame);
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
120 /* now different bit-error possibilities */
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
121 emit_1bit_errors();
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
122 emit_2bit_errors();
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
123 emit_15bit_errors();
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
124 emit_16bit_errors();
3e632126e099 efr-sid: generate efr-sid-test2.gsmx for OS#6538
Mychaela Falconia <falcon@freecalypso.org>
parents: 43
diff changeset
125 /* all done */
43
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 fclose(outf);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 exit(0);
8bfc517fda3b efr-sid: hack created
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }