comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/g722.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
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 General Public License version 2, as
14 * 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 General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * 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 * $Id: g722.h,v 1.13 2006/10/24 13:45:28 steveu Exp $
32 */
33
34
35 /*! \file */
36
37 #if !defined(_G722_H_)
38 #define _G722_H_
39
40 /*! \page g722_page G.722 encoding and decoding
41 \section g722_page_sec_1 What does it do?
42 The G.722 module is a bit exact implementation of the ITU G.722 specification for all three
43 specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
44
45 To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
46 support an option for the linear audio to be an 8k samples/second stream. In this mode the
47 codec is considerably faster, and still fully compatible with wideband terminals using G.722.
48
49 \section g722_page_sec_2 How does it work?
50 ???.
51 */
52
53 enum
54 {
55 G722_SAMPLE_RATE_8000 = 0x0001,
56 G722_PACKED = 0x0002
57 };
58
59 typedef struct
60 {
61 /*! TRUE if the operating in the special ITU test mode, with the band split filters
62 disabled. */
63 int itu_test_mode;
64 /*! TRUE if the G.722 data is packed */
65 int packed;
66 /*! TRUE if encode from 8k samples/second */
67 int eight_k;
68 /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
69 int bits_per_sample;
70
71 /*! Signal history for the QMF */
72 int x[24];
73
74 struct
75 {
76 int s;
77 int sp;
78 int sz;
79 int r[3];
80 int a[3];
81 int ap[3];
82 int p[3];
83 int d[7];
84 int b[7];
85 int bp[7];
86 int sg[7];
87 int nb;
88 int det;
89 } band[2];
90
91 unsigned int in_buffer;
92 int in_bits;
93 unsigned int out_buffer;
94 int out_bits;
95 } g722_encode_state_t;
96
97 typedef struct
98 {
99 /*! TRUE if the operating in the special ITU test mode, with the band split filters
100 disabled. */
101 int itu_test_mode;
102 /*! TRUE if the G.722 data is packed */
103 int packed;
104 /*! TRUE if decode to 8k samples/second */
105 int eight_k;
106 /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
107 int bits_per_sample;
108
109 /*! Signal history for the QMF */
110 int x[24];
111
112 struct
113 {
114 int s;
115 int sp;
116 int sz;
117 int r[3];
118 int a[3];
119 int ap[3];
120 int p[3];
121 int d[7];
122 int b[7];
123 int bp[7];
124 int sg[7];
125 int nb;
126 int det;
127 } band[2];
128
129 unsigned int in_buffer;
130 int in_bits;
131 unsigned int out_buffer;
132 int out_bits;
133 } g722_decode_state_t;
134
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138
139 /*! Initialise an G.722 encode context.
140 \param s The G.722 encode context.
141 \param rate The required bit rate for the G.722 data.
142 The valid rates are 64000, 56000 and 48000.
143 \param options
144 \return A pointer to the G.722 encode context, or NULL for error. */
145 g722_encode_state_t *g722_encode_init(g722_encode_state_t *s, int rate, int options);
146
147 int g722_encode_release(g722_encode_state_t *s);
148
149 /*! Encode a buffer of linear PCM data to G.722
150 \param s The G.722 context.
151 \param g722_data The G.722 data produced.
152 \param amp The audio sample buffer.
153 \param len The number of samples in the buffer.
154 \return The number of bytes of G.722 data produced. */
155 int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len);
156
157 /*! Initialise an G.722 decode context.
158 \param s The G.722 decode context.
159 \param rate The bit rate of the G.722 data.
160 The valid rates are 64000, 56000 and 48000.
161 \param options
162 \return A pointer to the G.722 decode context, or NULL for error. */
163 g722_decode_state_t *g722_decode_init(g722_decode_state_t *s, int rate, int options);
164
165 int g722_decode_release(g722_decode_state_t *s);
166
167 /*! Decode a buffer of G.722 data to linear PCM.
168 \param s The G.722 context.
169 \param amp The audio sample buffer.
170 \param g722_data
171 \param len
172 \return The number of samples returned. */
173 int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len);
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.