00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * gsm0610.h - GSM 06.10 full rate speech 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 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 * $Id: gsm0610.h,v 1.15 2008/02/12 12:27:48 steveu Exp $ 00027 */ 00028 00029 #if !defined(_SPANDSP_GSM0610_H_) 00030 #define _SPANDSP_GSM0610_H_ 00031 00032 /*! \page gsm0610_page GSM 06.10 encoding and decoding 00033 \section gsm0610_page_sec_1 What does it do? 00034 00035 The GSM 06.10 module is an version of the widely used GSM FR codec software 00036 available from http://kbs.cs.tu-berlin.de/~jutta/toast.html. This version 00037 was produced since some versions of this codec are not bit exact, or not 00038 very efficient on modern processors. This implementation can use MMX instructions 00039 on Pentium class processors, or alternative methods on other processors. It 00040 passes all the ETSI test vectors. That is, it is a tested bit exact implementation. 00041 00042 This implementation supports encoded data in one of three packing formats: 00043 - Unpacked, with the 76 parameters of a GSM 06.10 code frame each occupying a 00044 separate byte. (note that none of the parameters exceed 8 bits). 00045 - Packed the the 33 byte per frame, used for VoIP, where 4 bits per frame are wasted. 00046 - Packed in WAV49 format, where 2 frames are packed into 65 bytes. 00047 00048 \section gsm0610_page_sec_2 How does it work? 00049 ???. 00050 */ 00051 00052 enum 00053 { 00054 GSM0610_PACKING_NONE, 00055 GSM0610_PACKING_WAV49, 00056 GSM0610_PACKING_VOIP 00057 }; 00058 00059 /*! 00060 GSM 06.10 FR codec unpacked frame. 00061 */ 00062 typedef struct 00063 { 00064 int16_t LARc[8]; 00065 int16_t Nc[4]; 00066 int16_t bc[4]; 00067 int16_t Mc[4]; 00068 int16_t xmaxc[4]; 00069 int16_t xMc[4][13]; 00070 } gsm0610_frame_t; 00071 00072 /*! 00073 GSM 06.10 FR codec state descriptor. This defines the state of 00074 a single working instance of the GSM 06.10 FR encoder or decoder. 00075 */ 00076 typedef struct 00077 { 00078 /*! \brief One of the packing modes */ 00079 int packing; 00080 00081 int16_t dp0[280]; 00082 00083 /*! Preprocessing */ 00084 int16_t z1; 00085 int32_t L_z2; 00086 /*! Pre-emphasis */ 00087 int16_t mp; 00088 00089 /*! Short term delay filter */ 00090 int16_t u[8]; 00091 int16_t LARpp[2][8]; 00092 int16_t j; 00093 00094 /*! Long term synthesis */ 00095 int16_t nrp; 00096 /*! Short term synthesis */ 00097 int16_t v[9]; 00098 /*! Decoder postprocessing */ 00099 int16_t msr; 00100 00101 /*! Encoder data */ 00102 int16_t e[50]; 00103 } gsm0610_state_t; 00104 00105 #if defined(__cplusplus) 00106 extern "C" 00107 { 00108 #endif 00109 00110 /*! Initialise a GSM 06.10 encode or decode context. 00111 \param s The GSM 06.10 context 00112 \param packing One of the GSM0610_PACKING_xxx options. 00113 \return A pointer to the GSM 06.10 context, or NULL for error. */ 00114 gsm0610_state_t *gsm0610_init(gsm0610_state_t *s, int packing); 00115 00116 /*! Release a GSM 06.10 encode or decode context. 00117 \param s The GSM 06.10 context 00118 \return 0 for success, else -1. */ 00119 int gsm0610_release(gsm0610_state_t *s); 00120 00121 /*! Set the packing format for a GSM 06.10 encode or decode context. 00122 \param s The GSM 06.10 context 00123 \param packing One of the GSM0610_PACKING_xxx options. 00124 \return 0 for success, else -1. */ 00125 int gsm0610_set_packing(gsm0610_state_t *s, int packing); 00126 00127 /*! Encode a buffer of linear PCM data to GSM 06.10. 00128 \param s The GSM 06.10 context. 00129 \param code The GSM 06.10 data produced. 00130 \param amp The audio sample buffer. 00131 \param len The number of samples in the buffer. 00132 \return The number of bytes of GSM 06.10 data produced. */ 00133 int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len); 00134 00135 /*! Decode a buffer of GSM 06.10 data to linear PCM. 00136 \param s The GSM 06.10 context. 00137 \param amp The audio sample buffer. 00138 \param code The GSM 06.10 data. 00139 \param len The number of bytes of GSM 06.10 data to be decoded. 00140 \return The number of samples returned. */ 00141 int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len); 00142 00143 int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s); 00144 00145 /*! Pack a pair of GSM 06.10 frames in the format used for wave files (wave type 49). 00146 \param c The buffer for the packed data. This must be at least 65 bytes long. 00147 \param s A pointer to the frames to be packed. 00148 \return The number of bytes generated. */ 00149 int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s); 00150 00151 /*! Pack a GSM 06.10 frames in the format used for VoIP. 00152 \param c The buffer for the packed data. This must be at least 33 bytes long. 00153 \param s A pointer to the frame to be packed. 00154 \return The number of bytes generated. */ 00155 int gsm0610_pack_voip(uint8_t c[], const gsm0610_frame_t *s); 00156 00157 int gsm0610_unpack_none(gsm0610_frame_t *s, const uint8_t c[]); 00158 00159 /*! Unpack a pair of GSM 06.10 frames from the format used for wave files (wave type 49). 00160 \param s A pointer to a buffer into which the frames will be packed. 00161 \param c The buffer containing the data to be unpacked. This must be at least 65 bytes long. 00162 \return The number of bytes absorbed. */ 00163 int gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[]); 00164 00165 /*! Unpack a GSM 06.10 frame from the format used for VoIP. 00166 \param s A pointer to a buffer into which the frame will be packed. 00167 \param c The buffer containing the data to be unpacked. This must be at least 33 bytes long. 00168 \return The number of bytes absorbed. */ 00169 int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[]); 00170 00171 #if defined(__cplusplus) 00172 } 00173 #endif 00174 00175 #endif 00176 /*- End of include ---------------------------------------------------------*/