2 * SpanDSP - a series of DSP components for telephony
4 * g722.h - The ITU G.722 codec.
6 * Written by Steve Underwood <steveu@coppice.org>
8 * Copyright (C) 2005 Steve Underwood
10 * All rights reserved.
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.
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.
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.
25 * Based on a single channel G.722 codec which is:
27 ***** Copyright (c) CMU 1993 *****
28 * Computer Science, Speech Group
29 * Chengxiang Lu and Alex Hauptmann
35 #if !defined(_SPANDSP_G722_H_)
36 #define _SPANDSP_G722_H_
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.
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.
47 \section g722_page_sec_2 How does it work?
53 G722_SAMPLE_RATE_8000 = 0x0001,
60 typedef struct g722_encode_state_s g722_encode_state_t;
65 typedef struct g722_decode_state_s g722_decode_state_t;
67 #if defined(__cplusplus)
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.
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);
80 /*! Release a G.722 encode context.
81 \param s The G.722 encode context.
83 SPAN_DECLARE(int) g722_encode_release(g722_encode_state_t *s);
85 /*! Free a G.722 encode context.
86 \param s The G.722 encode context.
88 SPAN_DECLARE(int) g722_encode_free(g722_encode_state_t *s);
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);
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.
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);
106 /*! Release a G.722 decode context.
107 \param s The G.722 decode context.
109 SPAN_DECLARE(int) g722_decode_release(g722_decode_state_t *s);
111 /*! Free a G.722 decode context.
112 \param s The G.722 decode context.
114 SPAN_DECLARE(int) g722_decode_free(g722_decode_state_t *s);
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.
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);
124 #if defined(__cplusplus)