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