g722.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * g722.h - The ITU G.722 codec.
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2005 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License version 2, as
00014  * published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * Based on a single channel G.722 codec which is:
00026  *
00027  *****    Copyright (c) CMU    1993      *****
00028  * Computer Science, Speech Group
00029  * Chengxiang Lu and Alex Hauptmann
00030  *
00031  * $Id: g722.h,v 1.16 2007/04/08 08:16:17 steveu Exp $
00032  */
00033 
00034 
00035 /*! \file */
00036 
00037 #if !defined(_SPANDSP_G722_H_)
00038 #define _SPANDSP_G722_H_
00039 
00040 /*! \page g722_page G.722 encoding and decoding
00041 \section g722_page_sec_1 What does it do?
00042 The G.722 module is a bit exact implementation of the ITU G.722 specification for all three
00043 specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
00044 
00045 To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
00046 support an option for the linear audio to be an 8k samples/second stream. In this mode the
00047 codec is considerably faster, and still fully compatible with wideband terminals using G.722.
00048 
00049 \section g722_page_sec_2 How does it work?
00050 ???.
00051 */
00052 
00053 enum
00054 {
00055     G722_SAMPLE_RATE_8000 = 0x0001,
00056     G722_PACKED = 0x0002
00057 };
00058 
00059 typedef struct
00060 {
00061     /*! TRUE if the operating in the special ITU test mode, with the band split filters
00062              disabled. */
00063     int itu_test_mode;
00064     /*! TRUE if the G.722 data is packed */
00065     int packed;
00066     /*! TRUE if encode from 8k samples/second */
00067     int eight_k;
00068     /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
00069     int bits_per_sample;
00070 
00071     /*! Signal history for the QMF */
00072     int x[24];
00073 
00074     struct
00075     {
00076         int s;
00077         int sp;
00078         int sz;
00079         int r[3];
00080         int a[3];
00081         int ap[3];
00082         int p[3];
00083         int d[7];
00084         int b[7];
00085         int bp[7];
00086         int sg[7];
00087         int nb;
00088         int det;
00089     } band[2];
00090 
00091     unsigned int in_buffer;
00092     int in_bits;
00093     unsigned int out_buffer;
00094     int out_bits;
00095 } g722_encode_state_t;
00096 
00097 typedef struct
00098 {
00099     /*! TRUE if the operating in the special ITU test mode, with the band split filters
00100              disabled. */
00101     int itu_test_mode;
00102     /*! TRUE if the G.722 data is packed */
00103     int packed;
00104     /*! TRUE if decode to 8k samples/second */
00105     int eight_k;
00106     /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
00107     int bits_per_sample;
00108 
00109     /*! Signal history for the QMF */
00110     int x[24];
00111 
00112     struct
00113     {
00114         int s;
00115         int sp;
00116         int sz;
00117         int r[3];
00118         int a[3];
00119         int ap[3];
00120         int p[3];
00121         int d[7];
00122         int b[7];
00123         int bp[7];
00124         int sg[7];
00125         int nb;
00126         int det;
00127     } band[2];
00128     
00129     unsigned int in_buffer;
00130     int in_bits;
00131     unsigned int out_buffer;
00132     int out_bits;
00133 } g722_decode_state_t;
00134 
00135 #if defined(__cplusplus)
00136 extern "C"
00137 {
00138 #endif
00139 
00140 /*! Initialise an G.722 encode context.
00141     \param s The G.722 encode context.
00142     \param rate The required bit rate for the G.722 data.
00143            The valid rates are 64000, 56000 and 48000.
00144     \param options
00145     \return A pointer to the G.722 encode context, or NULL for error. */
00146 g722_encode_state_t *g722_encode_init(g722_encode_state_t *s, int rate, int options);
00147 
00148 int g722_encode_release(g722_encode_state_t *s);
00149 
00150 /*! Encode a buffer of linear PCM data to G.722
00151     \param s The G.722 context.
00152     \param g722_data The G.722 data produced.
00153     \param amp The audio sample buffer.
00154     \param len The number of samples in the buffer.
00155     \return The number of bytes of G.722 data produced. */
00156 int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len);
00157 
00158 /*! Initialise an G.722 decode context.
00159     \param s The G.722 decode context.
00160     \param rate The bit rate of the G.722 data.
00161            The valid rates are 64000, 56000 and 48000.
00162     \param options
00163     \return A pointer to the G.722 decode context, or NULL for error. */
00164 g722_decode_state_t *g722_decode_init(g722_decode_state_t *s, int rate, int options);
00165 
00166 int g722_decode_release(g722_decode_state_t *s);
00167 
00168 /*! Decode a buffer of G.722 data to linear PCM.
00169     \param s The G.722 context.
00170     \param amp The audio sample buffer.
00171     \param g722_data
00172     \param len
00173     \return The number of samples returned. */
00174 int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len);
00175 
00176 #if defined(__cplusplus)
00177 }
00178 #endif
00179 
00180 #endif

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2