comparison libtwamr/tw_amr.h @ 252:57b4053559ff

libtwamr: beginning of project
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 05 Apr 2024 01:02:23 +0000
parents
children 6b33f3ba4289
comparison
equal deleted inserted replaced
251:946849291027 252:57b4053559ff
1 /*
2 * This header file is the external public interface to libtwamr;
3 * it should be installed in the same system include directory
4 * as <gsm.h> and <gsm_efr.h> for more classic GSM codecs.
5 */
6
7 #ifndef __THEMWI_AMR_H
8 #define __THEMWI_AMR_H
9
10 #include <stdint.h>
11
12 /* AMR definitions that matter for the public interface */
13
14 #define AMR_MAX_PRM 57 /* max. num. of params */
15 #define AMR_IETF_MAX_PL 32 /* max bytes in RFC 4867 frame */
16 #define AMR_IETF_HDR_LEN 6 /* .amr file header bytes */
17 #define AMR_COD_WORDS 250 /* # of words in 3GPP test seq format */
18
19 enum RXFrameType {
20 RX_SPEECH_GOOD = 0,
21 RX_SPEECH_DEGRADED,
22 RX_ONSET,
23 RX_SPEECH_BAD,
24 RX_SID_FIRST,
25 RX_SID_UPDATE,
26 RX_SID_BAD,
27 RX_NO_DATA,
28 RX_N_FRAMETYPES /* number of frame types */
29 };
30
31 enum TXFrameType {
32 TX_SPEECH_GOOD = 0,
33 TX_SID_FIRST,
34 TX_SID_UPDATE,
35 TX_NO_DATA,
36 TX_SPEECH_DEGRADED,
37 TX_SPEECH_BAD,
38 TX_SID_BAD,
39 TX_ONSET,
40 TX_N_FRAMETYPES /* number of frame types */
41 };
42
43 enum Mode {
44 MR475 = 0,
45 MR515,
46 MR59,
47 MR67,
48 MR74,
49 MR795,
50 MR102,
51 MR122,
52 MRDTX
53 };
54
55 #define AMR_FT_NODATA 15
56
57 /* libtwamr encoder and decoder state */
58
59 struct amr_encoder_state; /* opaque to external users */
60 struct amr_decoder_state; /* ditto */
61
62 struct amr_encoder_state *amr_encoder_create(int dtx);
63 struct amr_decoder_state *amr_decoder_create(void);
64
65 /* special freeing functions to deal with extra internal structs */
66 void amr_encoder_free(struct amr_encoder_state *st);
67 void amr_decoder_free(struct amr_decoder_state *st);
68
69 /* reset state to initial */
70 void amr_encoder_reset(struct amr_encoder_state *st);
71 void amr_decoder_reset(struct amr_decoder_state *st);
72
73 /* interface structure for passing frames of codec parameters */
74
75 struct amr_param_frame {
76 uint8_t type;
77 uint8_t mode;
78 int16_t param[AMR_MAX_PRM];
79 };
80
81 /* encoder and decoder main functions */
82
83 void amr_encode_frame(struct amr_encoder_state *st, const int16_t *pcm,
84 struct amr_param_frame *frame);
85
86 void amr_decode_frame(struct amr_decoder_state *st,
87 const struct amr_param_frame *frame, int16_t *pcm);
88
89 /* stateless utility functions: format conversions */
90
91 enum RXFrameType amr_txtype_to_rxtype(enum TXFrameType tx_type);
92
93 unsigned amr_frame_to_ietf(const struct amr_param_frame *frame, uint8_t *bytes);
94 int amr_frame_from_ietf(const uint8_t *bytes, struct amr_param_frame *frame);
95 int amr_ietf_grok_first_octet(uint8_t fo);
96
97 void amr_frame_to_tseq(const struct amr_param_frame *frame, uint16_t *cod);
98 int amr_frame_from_tseq(const uint16_t *cod, int use_rxtype,
99 struct amr_param_frame *frame);
100
101 #endif /* include guard */