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.25 2009/02/10 13:06:47 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 typedef struct g726_state_s g726_state_t; 00063 00064 typedef int16_t (*g726_decoder_func_t)(g726_state_t *s, uint8_t code); 00065 00066 typedef uint8_t (*g726_encoder_func_t)(g726_state_t *s, int16_t amp); 00067 00068 #if defined(__cplusplus) 00069 extern "C" 00070 { 00071 #endif 00072 00073 /*! Initialise a G.726 encode or decode context. 00074 \param s The G.726 context. 00075 \param bit_rate The required bit rate for the ADPCM data. 00076 The valid rates are 16000, 24000, 32000 and 40000. 00077 \param ext_coding The coding used outside G.726. 00078 \param packing One of the G.726_PACKING_xxx options. 00079 \return A pointer to the G.726 context, or NULL for error. */ 00080 SPAN_DECLARE(g726_state_t *) g726_init(g726_state_t *s, int bit_rate, int ext_coding, int packing); 00081 00082 /*! Release a G.726 encode or decode context. 00083 \param s The G.726 context. 00084 \return 0 for OK. */ 00085 SPAN_DECLARE(int) g726_release(g726_state_t *s); 00086 00087 /*! Free a G.726 encode or decode context. 00088 \param s The G.726 context. 00089 \return 0 for OK. */ 00090 SPAN_DECLARE(int) g726_free(g726_state_t *s); 00091 00092 /*! Decode a buffer of G.726 ADPCM data to linear PCM, a-law or u-law. 00093 \param s The G.726 context. 00094 \param amp The audio sample buffer. 00095 \param g726_data 00096 \param g726_bytes 00097 \return The number of samples returned. */ 00098 SPAN_DECLARE(int) g726_decode(g726_state_t *s, 00099 int16_t amp[], 00100 const uint8_t g726_data[], 00101 int g726_bytes); 00102 00103 /*! Encode a buffer of linear PCM data to G.726 ADPCM. 00104 \param s The G.726 context. 00105 \param g726_data The G.726 data produced. 00106 \param amp The audio sample buffer. 00107 \param len The number of samples in the buffer. 00108 \return The number of bytes of G.726 data produced. */ 00109 SPAN_DECLARE(int) g726_encode(g726_state_t *s, 00110 uint8_t g726_data[], 00111 const int16_t amp[], 00112 int len); 00113 00114 #if defined(__cplusplus) 00115 } 00116 #endif 00117 00118 #endif 00119 /*- End of file ------------------------------------------------------------*/