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 Lesser General Public License version 2.1, 00014 * as 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 Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: g726.h,v 1.26 2009/04/12 09:12:10 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_G726_H_) 00031 #define _SPANDSP_G726_H_ 00032 00033 /*! \page g726_page G.726 encoding and decoding 00034 \section g726_page_sec_1 What does it do? 00035 00036 The G.726 module is a bit exact implementation of the full ITU G.726 specification. 00037 It supports: 00038 - 16 kbps, 24kbps, 32kbps, and 40kbps operation. 00039 - Tandem adjustment, for interworking with A-law and u-law. 00040 - Annex A support, for use in environments not using A-law or u-law. 00041 00042 It passes the ITU tests. 00043 00044 \section g726_page_sec_2 How does it work? 00045 ???. 00046 */ 00047 00048 enum 00049 { 00050 G726_ENCODING_LINEAR = 0, /* Interworking with 16 bit signed linear */ 00051 G726_ENCODING_ULAW, /* Interworking with u-law */ 00052 G726_ENCODING_ALAW /* Interworking with A-law */ 00053 }; 00054 00055 enum 00056 { 00057 G726_PACKING_NONE = 0, 00058 G726_PACKING_LEFT = 1, 00059 G726_PACKING_RIGHT = 2 00060 }; 00061 00062 /*! 00063 G.726 state 00064 */ 00065 typedef struct g726_state_s g726_state_t; 00066 00067 typedef int16_t (*g726_decoder_func_t)(g726_state_t *s, uint8_t code); 00068 00069 typedef uint8_t (*g726_encoder_func_t)(g726_state_t *s, int16_t amp); 00070 00071 #if defined(__cplusplus) 00072 extern "C" 00073 { 00074 #endif 00075 00076 /*! Initialise a G.726 encode or decode context. 00077 \param s The G.726 context. 00078 \param bit_rate The required bit rate for the ADPCM data. 00079 The valid rates are 16000, 24000, 32000 and 40000. 00080 \param ext_coding The coding used outside G.726. 00081 \param packing One of the G.726_PACKING_xxx options. 00082 \return A pointer to the G.726 context, or NULL for error. */ 00083 SPAN_DECLARE(g726_state_t *) g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packing); 00084 00085 /*! Release a G.726 encode or decode context. 00086 \param s The G.726 context. 00087 \return 0 for OK. */ 00088 SPAN_DECLARE(int) g726_release(g726_state_t *s); 00089 00090 /*! Free a G.726 encode or decode context. 00091 \param s The G.726 context. 00092 \return 0 for OK. */ 00093 SPAN_DECLARE(int) g726_free(g726_state_t *s); 00094 00095 /*! Decode a buffer of G.726 ADPCM data to linear PCM, a-law or u-law. 00096 \param s The G.726 context. 00097 \param amp The audio sample buffer. 00098 \param g726_data 00099 \param g726_bytes 00100 \return The number of samples returned. */ 00101 SPAN_DECLARE(int) g726_decode(g726_state_t *s, 00102 int16_t amp[], 00103 const uint8_t g726_data[], 00104 int g726_bytes); 00105 00106 /*! Encode a buffer of linear PCM data to G.726 ADPCM. 00107 \param s The G.726 context. 00108 \param g726_data The G.726 data produced. 00109 \param amp The audio sample buffer. 00110 \param len The number of samples in the buffer. 00111 \return The number of bytes of G.726 data produced. */ 00112 SPAN_DECLARE(int) g726_encode(g726_state_t *s, 00113 uint8_t g726_data[], 00114 const int16_t amp[], 00115 int len); 00116 00117 #if defined(__cplusplus) 00118 } 00119 #endif 00120 00121 #endif 00122 /*- End of file ------------------------------------------------------------*/