g726.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * g726.h - ITU G.726 codec.
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2006 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 as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
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 G.721/G.723 code which is:
00027  *
00028  * This source code is a product of Sun Microsystems, Inc. and is provided
00029  * for unrestricted use.  Users may copy or modify this source code without
00030  * charge.
00031  *
00032  * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
00033  * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00034  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00035  *
00036  * Sun source code is provided with no support and without any obligation on
00037  * the part of Sun Microsystems, Inc. to assist in its use, correction,
00038  * modification or enhancement.
00039  *
00040  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00041  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
00042  * OR ANY PART THEREOF.
00043  *
00044  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00045  * or profits or other special, indirect and consequential damages, even if
00046  * Sun has been advised of the possibility of such damages.
00047  *
00048  * Sun Microsystems, Inc.
00049  * 2550 Garcia Avenue
00050  * Mountain View, California  94043
00051  *
00052  * $Id: g726.h,v 1.6 2006/05/24 09:19:11 steveu Exp $
00053  */
00054 
00055 /*! \file */
00056 
00057 #if !defined(_G726_H_)
00058 #define _G726_H_
00059 
00060 /*! \page g726_page G.726 encoding and decoding
00061 \section g726_page_sec_1 What does it do?
00062 
00063 The G.726 module is a bit exact implementation of the full ITU G.726 specification.
00064 It supports:
00065     - 16 kbps, 24kbps, 32kbps, and 40kbps operation.
00066     - Tandem adjustment, for interworking with A-law and u-law.
00067     - Annex A support, for use in environments not using A-law or u-law.
00068 
00069 It passes the ITU tests.
00070 
00071 \section g726_page_sec_2 How does it work?
00072 ???.
00073 */
00074 
00075 #define G726_ENCODING_LINEAR    0   /* 16 bit signed linear */
00076 #define G726_ENCODING_ULAW      1   /* u-law */
00077 #define G726_ENCODING_ALAW      2   /* A-law */
00078 
00079 struct g726_state_s;
00080 
00081 typedef int16_t (*g726_decoder_func_t)(struct g726_state_s *s, uint8_t code);
00082 
00083 typedef uint8_t (*g726_encoder_func_t)(struct g726_state_s *s, int16_t amp);
00084 
00085 /*
00086  * The following is the definition of the state structure
00087  * used by the G.726 encoder and decoder to preserve their internal
00088  * state between successive calls.  The meanings of the majority
00089  * of the state structure fields are explained in detail in the
00090  * CCITT Recommendation G.721.  The field names are essentially indentical
00091  * to variable names in the bit level description of the coding algorithm
00092  * included in this Recommendation.
00093  */
00094 typedef struct g726_state_s
00095 {
00096     /*! The bit rate */
00097     int rate;
00098     /*! The external coding, for tandem operation */
00099     int ext_coding;
00100     /*! The number of bits per sample */
00101     int bits_per_sample;
00102     /*! TRUE if the G.726 data is packed */
00103     int packed;
00104 
00105     /*! Locked or steady state step size multiplier. */
00106     int32_t yl;
00107     /*! Unlocked or non-steady state step size multiplier. */
00108     int16_t yu;
00109     /*! int16_t term energy estimate. */
00110     int16_t dms;
00111     /*! Long term energy estimate. */
00112     int16_t dml;
00113     /*! Linear weighting coefficient of 'yl' and 'yu'. */
00114     int16_t ap;
00115     
00116     /*! Coefficients of pole portion of prediction filter. */
00117     int16_t a[2];
00118     /*! Coefficients of zero portion of prediction filter. */
00119     int16_t b[6];
00120     /*! Signs of previous two samples of a partially reconstructed signal. */
00121     int16_t pk[2];
00122     /*! Previous 6 samples of the quantized difference signal represented in
00123         an internal floating point format. */
00124     int16_t dq[6];
00125     /*! Previous 2 samples of the quantized difference signal represented in an
00126         internal floating point format. */
00127     int16_t sr[2];
00128     /*! Delayed tone detect */
00129     int td;
00130     
00131     unsigned int in_buffer;
00132     int in_bits;
00133     unsigned int out_buffer;
00134     int out_bits;
00135 
00136     g726_encoder_func_t enc_func;
00137     g726_decoder_func_t dec_func;
00138 } g726_state_t;
00139 
00140 #ifdef __cplusplus
00141 extern "C" {
00142 #endif
00143 
00144 /*! Initialise a G.726 encode or decode context.
00145     \param s The G.726 context.
00146     \param bit_rate The required bit rate for the ADPCM data.
00147            The valid rates are 16000, 24000, 32000 and 40000.
00148     \param ext_coding The coding used outside G.726.
00149     \param packed TRUE to use packed G.726. Otherwise G.726 will be expected as
00150            one code per octet.
00151     \return A pointer to the G.726 context, or NULL for error. */
00152 g726_state_t *g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packed);
00153 
00154 /*! Free a G.726 encode or decode context.
00155     \param s The G.726 context.
00156     \return 0 for OK. */
00157 int g726_release(g726_state_t *s);
00158 
00159 /*! Decode a buffer of G.726 ADPCM data to linear PCM, a-law or u-law.
00160     \param s The G.726 context.
00161     \param amp
00162     \param g726_data
00163     \param g726_bytes
00164     \return The number of samples returned. */
00165 int g726_decode(g726_state_t *s,
00166                 int16_t amp[],
00167                 const uint8_t g726_data[],
00168                 int g726_bytes);
00169 
00170 /*! Encode a buffer of linear PCM data to G.726 ADPCM.
00171     \param s The G.726 context.
00172     \param g726_data
00173     \param amp
00174     \param samples
00175     \return The number of bytes of G.726 data produced. */
00176 int g726_encode(g726_state_t *s,
00177                 uint8_t g726_data[],
00178                 const int16_t amp[],
00179                 int samples);
00180 
00181 #ifdef __cplusplus
00182 }
00183 #endif
00184 
00185 #endif
00186 /*- End of file ------------------------------------------------------------*/

Generated on Fri Nov 10 09:40:23 2006 for libspandsp by  doxygen 1.5.1