annotate hr-sid/misorder.c @ 55:f27bc1e17311

fr-sid/goodsp-frame41.gsmx: starting point This 33-byte binary file contains frame #41 from good_sp.cod from GSM 06.32 test sequence set, converted from ETSI *.cod format into our gsmx format. This frame is an example of a real FRv1 SID.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 22 Aug 2024 05:00:08 +0000
parents ee54b9748c09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * swSidDetection() in reid.c in GSM 06.06 source contains a table
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * that identifies the 79 bits of the SID field when they got misordered
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * as a result of decoding in unvoiced mode. That table is given
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * in the form of an array of 18 codec params. We need the same mask
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * of misordered SID field bits in the packed format of TS 101 318.
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * This program performs the conversion.
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdint.h>
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static const int16_t misordered_sid_params[18] = {
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 0x0001, /* R0 */ /* unvoiced */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 0x00ef, /* LPC1 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 0x003e, /* LPC2 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 0x007f, /* LPC3 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 0x0001, /* INT LPC */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 0x0003, /* Mode */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 0x001f, /* Code1_1 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 0x0072, /* Code2_1 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 0x0012, /* GSP0_1 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 0x003f, /* Code1_2 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 0x007f, /* Code2_2 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 0x0008, /* GSP0_2 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 0x007f, /* Code1_3 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 0x007f, /* Code2_3 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 0x0008, /* GSP0_3 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 0x007f, /* Code1_4 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 0x007f, /* Code2_4 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 0x000c, /* GSP0_4 */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 };
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 void
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 pack_ts101318_unvoiced(params, payload)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 const int16_t *params;
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 uint8_t *payload;
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 uint8_t *c = payload;
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 /* unvoiced mode */
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 *c++ = ((params[0] & 0x1F) << 3)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 | ((params[1] >> 8) & 0x7);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 *c++ = params[1] & 0xFF;
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *c++ = ((params[2] >> 1) & 0xFF);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *c++ = ((params[2] & 0x1) << 7)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 | ((params[3] >> 1) & 0x7F);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *c++ = ((params[3] & 0x1) << 7)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 | ((params[4] & 0x1) << 6)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 | ((params[5] & 0x3) << 4)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 | ((params[6] >> 3) & 0xF);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 *c++ = ((params[6] & 0x7) << 5)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 | ((params[7] >> 2) & 0x1F);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *c++ = ((params[7] & 0x3) << 6)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 | ((params[8] & 0x1F) << 1)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 | ((params[9] >> 6) & 0x1);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *c++ = ((params[9] & 0x3F) << 2)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 | ((params[10] >> 5) & 0x3);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 *c++ = ((params[10] & 0x1F) << 3)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 | ((params[11] >> 2) & 0x7);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *c++ = ((params[11] & 0x3) << 6)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 | ((params[12] >> 1) & 0x3F);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 *c++ = ((params[12] & 0x1) << 7)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 | (params[13] & 0x7F);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 *c++ = ((params[14] & 0x1F) << 3)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 | ((params[15] >> 4) & 0x7);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 *c++ = ((params[15] & 0xF) << 4)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 | ((params[16] >> 3) & 0xF);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 *c++ = ((params[16] & 0x7) << 5)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 | (params[17] & 0x1F);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 main(argc, argv)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 char **argv;
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 {
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 uint8_t packed_frame[14];
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 int i;
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 pack_ts101318_unvoiced(misordered_sid_params, packed_frame);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 for (i = 0; i < 14; i++) {
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 printf("0x%02X,", packed_frame[i]);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (i == 6 || i == 13)
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 putchar('\n');
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 else
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 putchar(' ');
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(0);
ee54b9748c09 hr-sid: add conversion of misordered SID field
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }