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