gsm0610.h

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, as
00014  * 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 General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: gsm0610.h,v 1.10 2007/04/08 08:16:18 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_GSM0610_H_)
00029 #define _SPANDSP_GSM0610_H_
00030 
00031 /*! \page gsm0610_page GSM 06.10 encoding and decoding
00032 \section gsm0610_page_sec_1 What does it do?
00033 
00034 The GSM 06.10 module is an version of the widely used GSM FR codec software
00035 available from http://kbs.cs.tu-berlin.de/~jutta/toast.html. This version
00036 was produced since some versions of this codec are not bit exact, or not
00037 very efficient on modern processors. This implementation can use MMX instructions
00038 on Pentium class processors, or alternative methods on other processors. It
00039 passes all the ETSI test vectors. That is, it is a tested bit exact implementation.
00040 
00041 This implementation supports encoded data in one of three packing formats:
00042     - Unpacked, with the 76 parameters of a GSM 06.10 code frame each occupying a
00043       separate byte. (note that none of the parameters exceed 8 bits).
00044     - Packed the the 33 byte per frame, used for VoIP, where 4 bits per frame are wasted.
00045     - Packed in WAV49 format, where 2 frames are packed into 65 bytes.
00046 
00047 \section gsm0610_page_sec_2 How does it work?
00048 ???.
00049 */
00050 
00051 enum
00052 {
00053     GSM0610_PACKING_NONE,
00054     GSM0610_PACKING_WAV49,
00055     GSM0610_PACKING_VOIP
00056 };
00057 
00058 /*!
00059     GSM 06.10 FR codec unpacked frame.
00060 */
00061 typedef struct
00062 {
00063     int16_t LARc[8];
00064     int16_t Nc[4];
00065     int16_t bc[4];
00066     int16_t Mc[4];
00067     int16_t xmaxc[4];
00068     int16_t xMc[4][13];
00069 } gsm0610_frame_t;
00070 
00071 /*!
00072     GSM 06.10 FR codec state descriptor. This defines the state of
00073     a single working instance of the GSM 06.10 FR encoder or decoder.
00074 */
00075 typedef struct
00076 {
00077     /*! \brief One of the packing modes */
00078     int packing;
00079 
00080     int16_t dp0[280];
00081 
00082     int16_t z1;         /* preprocessing,   Offset_com. */
00083     int32_t L_z2;       /*                  Offset_com. */
00084     int16_t mp;         /*                  Preemphasis */
00085 
00086     int16_t u[8];       /* short_term_delay_filter */
00087     int16_t LARpp[2][8];
00088     int16_t j;
00089 
00090     int16_t nrp;        /* long term synthesis */
00091     int16_t v[9];       /* short term synthesis */
00092     int16_t msr;        /* decoder postprocessing */
00093 
00094     int16_t e[50];      /* encoder */
00095     uint8_t     frame_index;
00096     uint8_t     frame_chain;
00097 } gsm0610_state_t;
00098 
00099 #if defined(__cplusplus)
00100 extern "C"
00101 {
00102 #endif
00103 
00104 /*! Initialise a GSM 06.10 encode or decode context.
00105     \param s The GSM 06.10 context
00106     \param packing One of the GSM0610_PACKING_xxx options.
00107     \return A pointer to the GSM 06.10 context, or NULL for error. */
00108 gsm0610_state_t *gsm0610_init(gsm0610_state_t *s, int packing);
00109 
00110 int gsm0610_release(gsm0610_state_t *s);
00111 
00112 /*! Encode a buffer of linear PCM data to GSM 06.10.
00113     \param s The GSM 06.10 context.
00114     \param ima_data The GSM 06.10 data produced.
00115     \param amp The audio sample buffer.
00116     \param len The number of samples in the buffer.
00117     \return The number of bytes of GSM 06.10 data produced. */
00118 int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int quant);
00119 
00120 /*! Decode a buffer of GSM 06.10 data to linear PCM.
00121     \param s The GSM 06.10 context.
00122     \param amp The audio sample buffer.
00123     \param code The GSM 06.10 data.
00124     \param quant The number of frames of GSM 06.10 data to be decoded.
00125     \return The number of samples returned. */
00126 int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int quant);
00127 
00128 int gsm0610_pack_none(uint8_t c[], gsm0610_frame_t *s);
00129 
00130 int gsm0610_pack_wav49(uint8_t c[], gsm0610_frame_t *s, int half);
00131 
00132 int gsm0610_pack_voip(uint8_t c[], gsm0610_frame_t *s);
00133 
00134 int gsm0610_unpack_none(gsm0610_frame_t *s, const uint8_t c[]);
00135 
00136 int gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[], int half);
00137 
00138 int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[]);
00139 
00140 #if defined(__cplusplus)
00141 }
00142 #endif
00143 
00144 #endif
00145 /*- End of include ---------------------------------------------------------*/

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2