FreeCalypso > hg > ice1-trau-tester
annotate ater8/out_frame.c @ 51:db39e8855f3d
ater: implement play-d144
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 25 Sep 2024 05:53:38 +0000 |
parents | ff94d7fc5891 |
children |
rev | line source |
---|---|
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
2 * Here we implement our TRAU-UL bit filling function for HRv1 8 kbit/s format. |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
4 * This code is based (very loosely) on trau_rtp_conv.c in libosmo-abis. |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdbool.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <osmocom/core/bits.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/crc8gen.h> |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
13 #include <osmocom/core/utils.h> |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <osmocom/trau/trau_frame.h> |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
15 #include "../libhr/tw_gsmhr.h" |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "out_frame.h" |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 /* |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
20 * EFR TRAU parity (also used for HR) |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 * |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 * g(x) = x^3 + x^1 + 1 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static const struct osmo_crc8gen_code gsm0860_efr_crc3 = { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 .bits = 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 .poly = 0x3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 .init = 0x0, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 .remainder = 0x7, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 }; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
31 void trau_frame_from_record(const int16_t *rec, struct osmo_trau_frame *tf, |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
32 bool *has_taf) |
22
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
33 { |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
34 uint8_t ts101318[GSMHR_FRAME_LEN_RPF]; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
35 int16_t bfi, sid; |
22
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
36 |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
37 /* payload transformation is straightforward */ |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
38 gsmhr_pack_ts101318(rec, ts101318); |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
39 osmo_pbit2ubit(tf->d_bits, ts101318, 14 * 8); |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
40 osmo_crc8gen_set_bits(&gsm0860_efr_crc3, tf->d_bits, 44, tf->crc_bits); |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
42
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
42 /* transformation of metadata flags is the messy part */ |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
43 bfi = rec[18]; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
44 sid = rec[20]; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
45 switch (sid) { |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
46 case 0: |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
47 if (bfi) { |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
48 tf->xc_bits[1] = 1; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
49 tf->xc_bits[2] = 1; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
50 *has_taf = true; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
51 } else { |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
52 tf->xc_bits[1] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
53 tf->xc_bits[2] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
54 tf->xc_bits[3] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
55 *has_taf = false; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
56 } |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
57 break; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
58 case 1: |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
59 tf->xc_bits[1] = 1; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
60 tf->xc_bits[2] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
61 *has_taf = true; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
62 break; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
63 case 2: |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
64 if (bfi) { |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
65 tf->xc_bits[1] = 1; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
66 tf->xc_bits[2] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
67 *has_taf = true; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
68 } else { |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
69 tf->xc_bits[1] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
70 tf->xc_bits[2] = 0; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
71 tf->xc_bits[3] = 1; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
72 *has_taf = false; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
73 } |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
74 break; |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
75 default: |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
76 OSMO_ASSERT(0); |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
77 } |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
78 /* XC5 is always UFI */ |
ff94d7fc5891
new program itt-ater-8
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
79 tf->xc_bits[4] = rec[19]; |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |