annotate libgsmefr/params2frame.c @ 242:f081a6850fb5

libgsmfrp: new refined implementation The previous implementation exhibited the following defects, which are now fixed: 1) The last received valid SID was cached forever for the purpose of handling future invalid SIDs - we could have received some valid SID ages ago, then lots of speech or NO_DATA, and if we then get an invalid SID, we would resurrect the last valid SID from ancient history - a bad design. In our new design, we handle invalid SID based on the current state, much like BFI. 2) GSM 06.11 spec says clearly that after the second lost SID (received BFI=1 && TAF=1 in CN state) we need to gradually decrease the output level, rather than jump directly to emitting silence frames - we previously failed to implement such logic. 3) Per GSM 06.12 section 5.2, Xmaxc should be the same in all 4 subframes in a SID frame. What should we do if we receive an otherwise valid SID frame with different Xmaxc? Our previous approach would replicate this Xmaxc oddity in every subsequent generated CN frame, which is rather bad. In our new design, the very first CN frame (which can be seen as a transformation of the SID frame itself) retains the original 4 distinct Xmaxc, but all subsequent CN frames are based on the Xmaxc from the last subframe of the most recent SID.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 09 May 2023 05:16:31 +0000
parents 88468d5b3590
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our EFR_params2frame() packing function.
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include "gsm_efr.h"
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #define EFR_MAGIC 0xC
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 void EFR_params2frame(const int16_t *params, uint8_t *frame)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 {
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 uint8_t *c = frame;
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *c++ = ((EFR_MAGIC & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 | ((params[0] >> 3) & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 *c++ = ((params[0] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 | ((params[1] >> 3) & 0x1F);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 *c++ = ((params[1] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 | ((params[2] >> 4) & 0x1F);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 *c++ = ((params[2] & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 | ((params[3] >> 4) & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 *c++ = ((params[3] & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 | ((params[4] >> 2) & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 *c++ = ((params[4] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 | ((params[5] >> 3) & 0x3F);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *c++ = ((params[5] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 | ((params[6] & 0xF) << 1)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 | ((params[7] >> 3) & 0x1);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *c++ = ((params[7] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 | ((params[8] & 0xF) << 1)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 | ((params[9] >> 3) & 0x1);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 *c++ = ((params[9] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 | ((params[10] & 0xF) << 1)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 | ((params[11] >> 3) & 0x1);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *c++ = ((params[11] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 | ((params[12] & 0x7) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 | ((params[13] >> 1) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 *c++ = ((params[13] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 | ((params[14] & 0x7) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 | ((params[15] & 0x7) << 1)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 | ((params[16] >> 2) & 0x1);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *c++ = ((params[16] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 | ((params[17] & 0x1F) << 1)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 | ((params[18] >> 5) & 0x1);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 *c++ = ((params[18] & 0x1F) << 3)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 | ((params[19] >> 1) & 0x7);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *c++ = ((params[19] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 | ((params[20] & 0xF) << 3)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 | ((params[21] >> 1) & 0x7);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *c++ = ((params[21] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 | ((params[22] & 0xF) << 3)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 | ((params[23] >> 1) & 0x7);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *c++ = ((params[23] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 | ((params[24] & 0xF) << 3)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 | (params[25] & 0x7);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *c++ = ((params[26] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 | ((params[27] & 0x7) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 | ((params[28] >> 1) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *c++ = ((params[28] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 | ((params[29] & 0x7) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 | ((params[30] >> 1) & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *c++ = ((params[30] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 | ((params[31] >> 2) & 0x7F);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 *c++ = ((params[31] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 | ((params[32] & 0xF) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 | ((params[33] >> 2) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 *c++ = ((params[33] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 | ((params[34] & 0xF) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 | ((params[35] >> 2) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 *c++ = ((params[35] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 | ((params[36] & 0xF) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 | ((params[37] >> 2) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 *c++ = ((params[37] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 | ((params[38] & 0x7) << 3)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 | (params[39] & 0x7);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 *c++ = ((params[40] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 | ((params[41] & 0x7) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 | ((params[42] >> 1) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *c++ = ((params[42] & 0x1) << 7)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 | ((params[43] & 0x1F) << 2)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 | ((params[44] >> 4) & 0x3);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 *c++ = ((params[44] & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 | (params[45] & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *c++ = ((params[46] & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 | (params[47] & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 *c++ = ((params[48] & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 | (params[49] & 0xF);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *c++ = ((params[50] & 0xF) << 4)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 | ((params[51] & 0x7) << 1)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 | ((params[52] >> 2) & 0x1);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 *c++ = ((params[52] & 0x3) << 6)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 | ((params[53] & 0x7) << 3)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 | (params[54] & 0x7);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 *c++ = ((params[55] & 0x7) << 5)
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 | (params[56] & 0x1F);
88468d5b3590 libgsmefr: implement frame packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }