falconia has uploaded this change for review.

View Change

AMR codec: add decoder homing frame const patterns

ETSI-defined decoder homing frames for HRv1 and EFR are already
captured in osmo_gsm620_homing_frame[] and osmo_gsm660_homing_frame[];
now add 3GPP-defined DHFs for AMR, all 8 modes.

These AMR DHFs are useful to have in libosmocodec:

* Future AMR-capable tw-e1abis-mgw will emit DHFs toward the BTS/CCU
during prolonged absence of RTP input - needed because the alternative
of emitting an endless stream of No_Data frames may produce undesirable
effects on Um with some E1 BTS models. If it is desired to bring
tw-e1abis-mgw functionality into mainline Osmocom at some point,
DHF bits need to reside somewhere in libosmo*.

* In future improvements of AMR support in osmo-bts-trx, it may be
likewise desirable to transmit DHFs on Um downlink during the same
conditions of prolonged absence of RTP input.

Change-Id: I1f8f8ec36cc13270a1d1fa633583107317abe894
---
M include/osmocom/codec/codec.h
M src/codec/gsm690.c
2 files changed, 75 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/57/41257/1
diff --git a/include/osmocom/codec/codec.h b/include/osmocom/codec/codec.h
index b697cfb..8ec9e62 100644
--- a/include/osmocom/codec/codec.h
+++ b/include/osmocom/codec/codec.h
@@ -98,6 +98,15 @@
int osmo_amr_sbits_to_param(uint16_t *param, const ubit_t *s_bits,
enum osmo_amr_type mode);

+extern const uint16_t osmo_amr_dhf_4_75[];
+extern const uint16_t osmo_amr_dhf_5_15[];
+extern const uint16_t osmo_amr_dhf_5_90[];
+extern const uint16_t osmo_amr_dhf_6_70[];
+extern const uint16_t osmo_amr_dhf_7_40[];
+extern const uint16_t osmo_amr_dhf_7_95[];
+extern const uint16_t osmo_amr_dhf_10_2[];
+extern const uint16_t osmo_amr_dhf_12_2[];
+
/* SID ternary classification per GSM 06.31 & 06.81 section 6.1.1 */
enum osmo_gsm631_sid_class {
OSMO_GSM631_SID_CLASS_SPEECH = 0,
diff --git a/src/codec/gsm690.c b/src/codec/gsm690.c
index 5730718..fc7e584 100644
--- a/src/codec/gsm690.c
+++ b/src/codec/gsm690.c
@@ -512,6 +512,72 @@
return 0;
}

+/* For each of the 8 modes of AMR codec, there exists a special encoded frame
+ * bit pattern which the speech decoder is required to recognize as a special
+ * decoder homing frame (DHF), as specified in TS 26.090 section 8.4. Bit
+ * patterns of these 8 DHFs are specified in TS 26.073 Tables 9a through 9h
+ * and captured in the following const arrays. Note that the canonical form
+ * of each DHF is an array of codec parameters; in order to emit any of these
+ * DHFs as an RTP payload or a TRAU frame, the application will need to
+ * convert it to s-bits with osmo_amr_param_to_sbits(), followed by
+ * osmo_amr_s_to_d() in the case of RTP output.
+ */
+
+const uint16_t osmo_amr_dhf_4_75[17] = {
+ 0x00F8, 0x009D, 0x001C, 0x0066, 0x0000, 0x0003, 0x0028, 0x000F,
+ 0x0038, 0x0001, 0x000F, 0x0031, 0x0002, 0x0008, 0x000F, 0x0026,
+ 0x0003
+};
+
+const uint16_t osmo_amr_dhf_5_15[19] = {
+ 0x00F8, 0x009D, 0x001C, 0x0066, 0x0000, 0x0003, 0x0037, 0x000F,
+ 0x0000, 0x0003, 0x0005, 0x000F, 0x0037, 0x0003, 0x0037, 0x000F,
+ 0x0023, 0x0003, 0x001F
+};
+
+const uint16_t osmo_amr_dhf_5_90[19] = {
+ 0x00F8, 0x00E3, 0x002F, 0x00BD, 0x0000, 0x0003, 0x0037, 0x000F,
+ 0x0001, 0x0003, 0x000F, 0x0060, 0x00F9, 0x0003, 0x0037, 0x000F,
+ 0x0000, 0x0003, 0x0037
+};
+
+const uint16_t osmo_amr_dhf_6_70[19] = {
+ 0x00F8, 0x00E3, 0x002F, 0x00BD, 0x0002, 0x0007, 0x0000, 0x000F,
+ 0x0098, 0x0007, 0x0061, 0x0060, 0x05C5, 0x0007, 0x0000, 0x000F,
+ 0x0318, 0x0007, 0x0000
+};
+
+const uint16_t osmo_amr_dhf_7_40[19] = {
+ 0x00F8, 0x00E3, 0x002F, 0x00BD, 0x0006, 0x000F, 0x0000, 0x001B,
+ 0x0208, 0x000F, 0x0062, 0x0060, 0x1BA6, 0x000F, 0x0000, 0x001B,
+ 0x0006, 0x000F, 0x0000
+};
+
+const uint16_t osmo_amr_dhf_7_95[23] = {
+ 0x00C2, 0x00E3, 0x002F, 0x00BD, 0x0006, 0x000F, 0x000A, 0x0000,
+ 0x0039, 0x1C08, 0x0007, 0x000A, 0x000B, 0x0063, 0x11A6, 0x000F,
+ 0x0001, 0x0000, 0x0039, 0x09A0, 0x000F, 0x0002, 0x0001
+};
+
+const uint16_t osmo_amr_dhf_10_2[39] = {
+ 0x00F8, 0x00E3, 0x002F, 0x0045, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x001B, 0x0000, 0x0001, 0x0000,
+ 0x0001, 0x0326, 0x00CE, 0x007E, 0x0051, 0x0062, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x015A, 0x0359, 0x0076, 0x0000, 0x001B, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x017C, 0x0215, 0x0038, 0x0030
+};
+
+const uint16_t osmo_amr_dhf_12_2[57] = {
+ 0x0004, 0x002A, 0x00DB, 0x0096, 0x002A, 0x0156, 0x000B, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0036, 0x000B, 0x0000, 0x000F, 0x000E, 0x000C,
+ 0x000D, 0x0000, 0x0001, 0x0005, 0x0007, 0x0001, 0x0008, 0x0024,
+ 0x0000, 0x0001, 0x0000, 0x0005, 0x0006, 0x0001, 0x0002, 0x0004,
+ 0x0007, 0x0004, 0x0002, 0x0003, 0x0036, 0x000B, 0x0000, 0x0002,
+ 0x0004, 0x0000, 0x0003, 0x0006, 0x0001, 0x0007, 0x0006, 0x0005,
+ 0x0000
+};
+
/* See also RFC 4867 ยง3.6, Table 1, Column "Total speech bits" */
static const uint8_t amr_len_by_ft[16] = {
12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0

To view, visit change 41257. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1f8f8ec36cc13270a1d1fa633583107317abe894
Gerrit-Change-Number: 41257
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon@freecalypso.org>