Added Realtime Text (RFC 4103) without having tied it to the phone software yet
[firmerware] / src / codec / spandsp / src / spandsp / g722.h
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * g722.h - The ITU G.722 codec.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2005 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * Based on a single channel G.722 codec which is:
26  *
27  *****    Copyright (c) CMU    1993      *****
28  * Computer Science, Speech Group
29  * Chengxiang Lu and Alex Hauptmann
30  */
31
32
33 /*! \file */
34
35 #if !defined(_SPANDSP_G722_H_)
36 #define _SPANDSP_G722_H_
37
38 /*! \page g722_page G.722 encoding and decoding
39 \section g722_page_sec_1 What does it do?
40 The G.722 module is a bit exact implementation of the ITU G.722 specification for all three
41 specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
42
43 To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
44 support an option for the linear audio to be an 8k samples/second stream. In this mode the
45 codec is considerably faster, and still fully compatible with wideband terminals using G.722.
46
47 \section g722_page_sec_2 How does it work?
48 ???.
49 */
50
51 enum
52 {
53     G722_SAMPLE_RATE_8000 = 0x0001,
54     G722_PACKED = 0x0002
55 };
56
57 /*!
58     G.722 encode state
59  */
60 typedef struct g722_encode_state_s g722_encode_state_t;
61
62 /*!
63     G.722 decode state
64  */
65 typedef struct g722_decode_state_s g722_decode_state_t;
66
67 #if defined(__cplusplus)
68 extern "C"
69 {
70 #endif
71
72 /*! Initialise an G.722 encode context.
73     \param s The G.722 encode context.
74     \param rate The required bit rate for the G.722 data.
75            The valid rates are 64000, 56000 and 48000.
76     \param options
77     \return A pointer to the G.722 encode context, or NULL for error. */
78 SPAN_DECLARE(g722_encode_state_t *) g722_encode_init(g722_encode_state_t *s, int rate, int options);
79
80 /*! Release a G.722 encode context.
81     \param s The G.722 encode context.
82     \return 0 for OK. */
83 SPAN_DECLARE(int) g722_encode_release(g722_encode_state_t *s);
84
85 /*! Free a G.722 encode context.
86     \param s The G.722 encode context.
87     \return 0 for OK. */
88 SPAN_DECLARE(int) g722_encode_free(g722_encode_state_t *s);
89
90 /*! Encode a buffer of linear PCM data to G.722
91     \param s The G.722 context.
92     \param g722_data The G.722 data produced.
93     \param amp The audio sample buffer.
94     \param len The number of samples in the buffer.
95     \return The number of bytes of G.722 data produced. */
96 SPAN_DECLARE(int) g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len);
97
98 /*! Initialise an G.722 decode context.
99     \param s The G.722 decode context.
100     \param rate The bit rate of the G.722 data.
101            The valid rates are 64000, 56000 and 48000.
102     \param options
103     \return A pointer to the G.722 decode context, or NULL for error. */
104 SPAN_DECLARE(g722_decode_state_t *) g722_decode_init(g722_decode_state_t *s, int rate, int options);
105
106 /*! Release a G.722 decode context.
107     \param s The G.722 decode context.
108     \return 0 for OK. */
109 SPAN_DECLARE(int) g722_decode_release(g722_decode_state_t *s);
110
111 /*! Free a G.722 decode context.
112     \param s The G.722 decode context.
113     \return 0 for OK. */
114 SPAN_DECLARE(int) g722_decode_free(g722_decode_state_t *s);
115
116 /*! Decode a buffer of G.722 data to linear PCM.
117     \param s The G.722 context.
118     \param amp The audio sample buffer.
119     \param g722_data
120     \param len
121     \return The number of samples returned. */
122 SPAN_DECLARE(int) g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len);
123
124 #if defined(__cplusplus)
125 }
126 #endif
127
128 #endif