Pau Espin Pedrol | 71ed463 | 2022-09-02 18:51:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2019-2022 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | */ |
| 10 | |
| 11 | module AMR_Types { |
| 12 | |
| 13 | import from General_Types all; |
Pau Espin Pedrol | 1a8f8f8 | 2022-09-06 20:25:50 +0200 | [diff] [blame] | 14 | import from Osmocom_Types all; |
Pau Espin Pedrol | 71ed463 | 2022-09-02 18:51:19 +0200 | [diff] [blame] | 15 | |
| 16 | /* AMR voice frame type identifiers |
| 17 | * See also 3GPP TS 26.101, Table 1a: Interpretation of Frame Type, Mode |
| 18 | * Indication and Mode Request fields */ |
| 19 | type enumerated AMRFT { |
| 20 | AMR_FT_0, /* 4.75 */ |
| 21 | AMR_FT_1, /* 5.15 */ |
| 22 | AMR_FT_2, /* 5.90 */ |
| 23 | AMR_FT_3, /* 6.70 */ |
| 24 | AMR_FT_4, /* 7.40 */ |
| 25 | AMR_FT_5, /* 7.95 */ |
| 26 | AMR_FT_6, /* 10.2 */ |
| 27 | AMR_FT_7, /* 12.2 */ |
| 28 | AMR_FT_SID /* SID */ |
| 29 | }; |
| 30 | |
| 31 | /* AMR voice frame length (in bytes, rounded), |
| 32 | * See also RFC 3267, chapter 3.6 */ |
| 33 | const integer c_AMRFT_len[9] := {12, 13, 15, 17, 19, 20, 26, 31, 5}; |
| 34 | |
| 35 | function f_amrft_payload_len(INT4b amr_ft) return integer { |
| 36 | return c_AMRFT_len[amr_ft]; |
| 37 | } |
| 38 | |
Pau Espin Pedrol | 1a8f8f8 | 2022-09-06 20:25:50 +0200 | [diff] [blame] | 39 | type record RTP_AMR_Hdr { |
| 40 | uint4_t cmr, |
| 41 | BIT4 padding1, |
| 42 | BIT1 f, |
| 43 | uint4_t ft, |
| 44 | BIT1 q, |
| 45 | BIT2 padding2 |
| 46 | } with { variant "FIELDORDER(msb)" }; |
| 47 | |
| 48 | template (value) RTP_AMR_Hdr ts_RTP_AMR_Hdr(template (value) uint4_t cmr, |
| 49 | template (value) uint4_t ft, |
| 50 | template (value) BIT1 q := '1'B, |
| 51 | template (value) BIT1 f := '0'B) := { |
| 52 | cmr := cmr, |
| 53 | padding1 := '0000'B, |
| 54 | f := f, |
| 55 | ft := ft, |
| 56 | q := q, |
| 57 | padding2 := '00'B |
| 58 | } |
| 59 | external function enc_RTP_AMR_Hdr(in RTP_AMR_Hdr amr_hdr) return octetstring |
| 60 | with { extension "prototype(convert) encode(RAW)" }; |
| 61 | external function dec_RTP_AMR_Hdr(in octetstring stream) return RTP_AMR_Hdr |
| 62 | with { extension "prototype(convert) decode(RAW)" }; |
| 63 | |
Pau Espin Pedrol | 71ed463 | 2022-09-02 18:51:19 +0200 | [diff] [blame] | 64 | } with { encode "RAW"} |