annotate libtwamr/tw_amr.h @ 273:0be493a1e0d6

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