comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/g726.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 * g726.h - ITU G.726 codec.
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2006 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 G.721/G.723 code which is:
26 *
27 * This source code is a product of Sun Microsystems, Inc. and is provided
28 * for unrestricted use. Users may copy or modify this source code without
29 * charge.
30 *
31 * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
32 * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34 *
35 * Sun source code is provided with no support and without any obligation on
36 * the part of Sun Microsystems, Inc. to assist in its use, correction,
37 * modification or enhancement.
38 *
39 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
41 * OR ANY PART THEREOF.
42 *
43 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44 * or profits or other special, indirect and consequential damages, even if
45 * Sun has been advised of the possibility of such damages.
46 *
47 * Sun Microsystems, Inc.
48 * 2550 Garcia Avenue
49 * Mountain View, California 94043
50 *
51 * $Id: g726.h,v 1.13 2006/11/28 16:59:57 steveu Exp $
52 */
53
54 /*! \file */
55
56 #if !defined(_G726_H_)
57 #define _G726_H_
58
59 /*! \page g726_page G.726 encoding and decoding
60 \section g726_page_sec_1 What does it do?
61
62 The G.726 module is a bit exact implementation of the full ITU G.726 specification.
63 It supports:
64 - 16 kbps, 24kbps, 32kbps, and 40kbps operation.
65 - Tandem adjustment, for interworking with A-law and u-law.
66 - Annex A support, for use in environments not using A-law or u-law.
67
68 It passes the ITU tests.
69
70 \section g726_page_sec_2 How does it work?
71 ???.
72 */
73
74 enum
75 {
76 G726_ENCODING_LINEAR = 0, /* Interworking with 16 bit signed linear */
77 G726_ENCODING_ULAW, /* Interworking with u-law */
78 G726_ENCODING_ALAW /* Interworking with A-law */
79 };
80
81 enum
82 {
83 G726_PACKING_NONE = 0,
84 G726_PACKING_LEFT = 1,
85 G726_PACKING_RIGHT = 2
86 };
87
88 struct g726_state_s;
89
90 typedef int16_t (*g726_decoder_func_t)(struct g726_state_s *s, uint8_t code);
91
92 typedef uint8_t (*g726_encoder_func_t)(struct g726_state_s *s, int16_t amp);
93
94 /*
95 * The following is the definition of the state structure
96 * used by the G.726 encoder and decoder to preserve their internal
97 * state between successive calls. The meanings of the majority
98 * of the state structure fields are explained in detail in the
99 * CCITT Recommendation G.721. The field names are essentially indentical
100 * to variable names in the bit level description of the coding algorithm
101 * included in this Recommendation.
102 */
103 typedef struct g726_state_s
104 {
105 /*! The bit rate */
106 int rate;
107 /*! The external coding, for tandem operation */
108 int ext_coding;
109 /*! The number of bits per sample */
110 unsigned int bits_per_sample;
111 /*! One fo the G.726_PACKING_xxx options */
112 int packing;
113
114 /*! Locked or steady state step size multiplier. */
115 int32_t yl;
116 /*! Unlocked or non-steady state step size multiplier. */
117 int16_t yu;
118 /*! int16_t term energy estimate. */
119 int16_t dms;
120 /*! Long term energy estimate. */
121 int16_t dml;
122 /*! Linear weighting coefficient of 'yl' and 'yu'. */
123 int16_t ap;
124
125 /*! Coefficients of pole portion of prediction filter. */
126 int16_t a[2];
127 /*! Coefficients of zero portion of prediction filter. */
128 int16_t b[6];
129 /*! Signs of previous two samples of a partially reconstructed signal. */
130 int16_t pk[2];
131 /*! Previous 6 samples of the quantized difference signal represented in
132 an internal floating point format. */
133 int16_t dq[6];
134 /*! Previous 2 samples of the quantized difference signal represented in an
135 internal floating point format. */
136 int16_t sr[2];
137 /*! Delayed tone detect */
138 int td;
139
140 bitstream_state_t bs;
141
142 g726_encoder_func_t enc_func;
143 g726_decoder_func_t dec_func;
144 } g726_state_t;
145
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149
150 /*! Initialise a G.726 encode or decode context.
151 \param s The G.726 context.
152 \param bit_rate The required bit rate for the ADPCM data.
153 The valid rates are 16000, 24000, 32000 and 40000.
154 \param ext_coding The coding used outside G.726.
155 \param packing One of the G.726_PACKING_xxx options.
156 \return A pointer to the G.726 context, or NULL for error. */
157 g726_state_t *g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packing);
158
159 /*! Free a G.726 encode or decode context.
160 \param s The G.726 context.
161 \return 0 for OK. */
162 int g726_release(g726_state_t *s);
163
164 /*! Decode a buffer of G.726 ADPCM data to linear PCM, a-law or u-law.
165 \param s The G.726 context.
166 \param amp The audio sample buffer.
167 \param g726_data
168 \param g726_bytes
169 \return The number of samples returned. */
170 int g726_decode(g726_state_t *s,
171 int16_t amp[],
172 const uint8_t g726_data[],
173 int g726_bytes);
174
175 /*! Encode a buffer of linear PCM data to G.726 ADPCM.
176 \param s The G.726 context.
177 \param g726_data The G.726 data produced.
178 \param amp The audio sample buffer.
179 \param len The number of samples in the buffer.
180 \return The number of bytes of G.726 data produced. */
181 int g726_encode(g726_state_t *s,
182 uint8_t g726_data[],
183 const int16_t amp[],
184 int len);
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif
191 /*- End of file ------------------------------------------------------------*/

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