aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2020-05-02 18:05:23 +0300
committerlaforge <laforge@osmocom.org>2020-05-16 20:21:48 +0000
commit4752930972ef727b2f1688fb84b158ed24e1ac09 (patch)
tree9aa5970681dbc44cb7a0089d84836bf77b773b81 /include
parent0a918f028cc9af36dcf997827925355e2b0cad43 (diff)
amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when converted from octet-aligned to bandwidth-efficient mode. It does shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for AMR modes 0, 1, 5, and SID frames because we only remove 6 bits. So old code generated truncated AMR packets for those AMR modes. This patch fixes the length calculation by properly counting bits. Proper bit counting is also bringing us one small step closer to properly handlig multi-frame AMR packets. Change-Id: I0462e054a0adc9080456f3eeea9cab7c229cdb70
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/netif/amr.h38
1 files changed, 26 insertions, 12 deletions
diff --git a/include/osmocom/netif/amr.h b/include/osmocom/netif/amr.h
index 6e37c99..c5a8e28 100644
--- a/include/osmocom/netif/amr.h
+++ b/include/osmocom/netif/amr.h
@@ -78,20 +78,34 @@ static inline void *osmo_amr_get_payload(struct amr_hdr *amrh)
#define AMR_FT_SID 8 /* SID */
#define AMR_FT_MAX 9
-/* AMR voice frame length (in bytes, rounded),
- * See also RFC 3267, chapter 3.6 */
-#define AMR_FT_0_LEN 12 /* 4.75 */
-#define AMR_FT_1_LEN 13 /* 5.15 */
-#define AMR_FT_2_LEN 15 /* 5.90 */
-#define AMR_FT_3_LEN 17 /* 6.70 */
-#define AMR_FT_4_LEN 19 /* 7.40 */
-#define AMR_FT_5_LEN 20 /* 7.95 */
-#define AMR_FT_6_LEN 26 /* 10.2 */
-#define AMR_FT_7_LEN 31 /* 12.2 */
-#define AMR_FT_SID_LEN 5 /* SID */
+/* AMR voice frame length (in bits).
+ * See also RFC 3267, chapter 3.6.
+ *
+ * NOTE: These constants refer to the length of one AMR speech frame-block,
+ * not counting CMR, TOC. */
+#define AMR_FT_0_LEN_BITS 95 /* 4.75 */
+#define AMR_FT_1_LEN_BITS 103 /* 5.15 */
+#define AMR_FT_2_LEN_BITS 118 /* 5.90 */
+#define AMR_FT_3_LEN_BITS 134 /* 6.70 */
+#define AMR_FT_4_LEN_BITS 148 /* 7.40 */
+#define AMR_FT_5_LEN_BITS 159 /* 7.95 */
+#define AMR_FT_6_LEN_BITS 204 /* 10.2 */
+#define AMR_FT_7_LEN_BITS 244 /* 12.2 */
+#define AMR_FT_SID_LEN_BITS 39 /* SID */
-/* NOTE: the above constant refers to the length of one AMR speech frame-block,
+/* AMR voice frame length (in bytes, rounded).
+ *
+ * NOTE: These constants refer to the length of one AMR speech frame-block,
* not counting CMR, TOC. */
+#define AMR_FT_0_LEN ((AMR_FT_0_LEN_BITS+7)/8) /* 4.75 */
+#define AMR_FT_1_LEN ((AMR_FT_1_LEN_BITS+7)/8) /* 5.15 */
+#define AMR_FT_2_LEN ((AMR_FT_2_LEN_BITS+7)/8) /* 5.90 */
+#define AMR_FT_3_LEN ((AMR_FT_3_LEN_BITS+7)/8) /* 6.70 */
+#define AMR_FT_4_LEN ((AMR_FT_4_LEN_BITS+7)/8) /* 7.40 */
+#define AMR_FT_5_LEN ((AMR_FT_5_LEN_BITS+7)/8) /* 7.95 */
+#define AMR_FT_6_LEN ((AMR_FT_6_LEN_BITS+7)/8) /* 10.2 */
+#define AMR_FT_7_LEN ((AMR_FT_7_LEN_BITS+7)/8) /* 12.2 */
+#define AMR_FT_SID_LEN ((AMR_FT_SID_LEN_BITS+7)/8) /* SID */
int osmo_amr_ft_valid(uint8_t amr_ft);
size_t osmo_amr_bytes(uint8_t amr_cmr);