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 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: gsm0610.h,v 1.17 2008/04/17 14:27:00 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     /*! Preprocessing */
00083     int16_t z1;
00084     int32_t L_z2;
00085     /*! Pre-emphasis */
00086     int16_t mp;
00087 
00088     /*! Short term delay filter */
00089     int16_t u[8];
00090     int16_t LARpp[2][8];
00091     int16_t j;
00092 
00093     /*! Long term synthesis */
00094     int16_t nrp;
00095     /*! Short term synthesis */
00096     int16_t v[9];
00097     /*! Decoder postprocessing */
00098     int16_t msr;
00099     
00100     /*! Encoder data */
00101     int16_t e[50];
00102 } gsm0610_state_t;
00103 
00104 #if defined(__cplusplus)
00105 extern "C"
00106 {
00107 #endif
00108 
00109 /*! Initialise a GSM 06.10 encode or decode context.
00110     \param s The GSM 06.10 context
00111     \param packing One of the GSM0610_PACKING_xxx options.
00112     \return A pointer to the GSM 06.10 context, or NULL for error. */
00113 gsm0610_state_t *gsm0610_init(gsm0610_state_t *s, int packing);
00114 
00115 /*! Release a GSM 06.10 encode or decode context.
00116     \param s The GSM 06.10 context
00117     \return 0 for success, else -1. */
00118 int gsm0610_release(gsm0610_state_t *s);
00119 
00120 /*! Set the packing format for a GSM 06.10 encode or decode context.
00121     \param s The GSM 06.10 context
00122     \param packing One of the GSM0610_PACKING_xxx options.
00123     \return 0 for success, else -1. */
00124 int gsm0610_set_packing(gsm0610_state_t *s, int packing);
00125 
00126 /*! Encode a buffer of linear PCM data to GSM 06.10.
00127     \param s The GSM 06.10 context.
00128     \param code The GSM 06.10 data produced.
00129     \param amp The audio sample buffer.
00130     \param len The number of samples in the buffer.
00131     \return The number of bytes of GSM 06.10 data produced. */
00132 int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len);
00133 
00134 /*! Decode a buffer of GSM 06.10 data to linear PCM.
00135     \param s The GSM 06.10 context.
00136     \param amp The audio sample buffer.
00137     \param code The GSM 06.10 data.
00138     \param len The number of bytes of GSM 06.10 data to be decoded.
00139     \return The number of samples returned. */
00140 int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len);
00141 
00142 int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s);
00143 
00144 /*! Pack a pair of GSM 06.10 frames in the format used for wave files (wave type 49).
00145     \param c The buffer for the packed data. This must be at least 65 bytes long.
00146     \param s A pointer to the frames to be packed.
00147     \return The number of bytes generated. */
00148 int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s);
00149 
00150 /*! Pack a GSM 06.10 frames in the format used for VoIP.
00151     \param c The buffer for the packed data. This must be at least 33 bytes long.
00152     \param s A pointer to the frame to be packed.
00153     \return The number of bytes generated. */
00154 int gsm0610_pack_voip(uint8_t c[], const gsm0610_frame_t *s);
00155 
00156 int gsm0610_unpack_none(gsm0610_frame_t *s, const uint8_t c[]);
00157 
00158 /*! Unpack a pair of GSM 06.10 frames from the format used for wave files (wave type 49).
00159     \param s A pointer to a buffer into which the frames will be packed.
00160     \param c The buffer containing the data to be unpacked. This must be at least 65 bytes long.
00161     \return The number of bytes absorbed. */
00162 int gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[]);
00163 
00164 /*! Unpack a GSM 06.10 frame from the format used for VoIP.
00165     \param s A pointer to a buffer into which the frame will be packed.
00166     \param c The buffer containing the data to be unpacked. This must be at least 33 bytes long.
00167     \return The number of bytes absorbed. */
00168 int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[]);
00169 
00170 #if defined(__cplusplus)
00171 }
00172 #endif
00173 
00174 #endif
00175 /*- End of include ---------------------------------------------------------*/

Generated on Tue Oct 7 20:25:46 2008 for spandsp by  doxygen 1.5.6