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.18 2008/11/15 14:17:46 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 gsm0610_state_s gsm0610_state_t; 00076 00077 #if defined(__cplusplus) 00078 extern "C" 00079 { 00080 #endif 00081 00082 /*! Initialise a GSM 06.10 encode or decode context. 00083 \param s The GSM 06.10 context 00084 \param packing One of the GSM0610_PACKING_xxx options. 00085 \return A pointer to the GSM 06.10 context, or NULL for error. */ 00086 gsm0610_state_t *gsm0610_init(gsm0610_state_t *s, int packing); 00087 00088 /*! Release a GSM 06.10 encode or decode context. 00089 \param s The GSM 06.10 context 00090 \return 0 for success, else -1. */ 00091 int gsm0610_release(gsm0610_state_t *s); 00092 00093 /*! Set the packing format for a GSM 06.10 encode or decode context. 00094 \param s The GSM 06.10 context 00095 \param packing One of the GSM0610_PACKING_xxx options. 00096 \return 0 for success, else -1. */ 00097 int gsm0610_set_packing(gsm0610_state_t *s, int packing); 00098 00099 /*! Encode a buffer of linear PCM data to GSM 06.10. 00100 \param s The GSM 06.10 context. 00101 \param code The GSM 06.10 data produced. 00102 \param amp The audio sample buffer. 00103 \param len The number of samples in the buffer. 00104 \return The number of bytes of GSM 06.10 data produced. */ 00105 int gsm0610_encode(gsm0610_state_t *s, uint8_t code[], const int16_t amp[], int len); 00106 00107 /*! Decode a buffer of GSM 06.10 data to linear PCM. 00108 \param s The GSM 06.10 context. 00109 \param amp The audio sample buffer. 00110 \param code The GSM 06.10 data. 00111 \param len The number of bytes of GSM 06.10 data to be decoded. 00112 \return The number of samples returned. */ 00113 int gsm0610_decode(gsm0610_state_t *s, int16_t amp[], const uint8_t code[], int len); 00114 00115 int gsm0610_pack_none(uint8_t c[], const gsm0610_frame_t *s); 00116 00117 /*! Pack a pair of GSM 06.10 frames in the format used for wave files (wave type 49). 00118 \param c The buffer for the packed data. This must be at least 65 bytes long. 00119 \param s A pointer to the frames to be packed. 00120 \return The number of bytes generated. */ 00121 int gsm0610_pack_wav49(uint8_t c[], const gsm0610_frame_t *s); 00122 00123 /*! Pack a GSM 06.10 frames in the format used for VoIP. 00124 \param c The buffer for the packed data. This must be at least 33 bytes long. 00125 \param s A pointer to the frame to be packed. 00126 \return The number of bytes generated. */ 00127 int gsm0610_pack_voip(uint8_t c[], const gsm0610_frame_t *s); 00128 00129 int gsm0610_unpack_none(gsm0610_frame_t *s, const uint8_t c[]); 00130 00131 /*! Unpack a pair of GSM 06.10 frames from the format used for wave files (wave type 49). 00132 \param s A pointer to a buffer into which the frames will be packed. 00133 \param c The buffer containing the data to be unpacked. This must be at least 65 bytes long. 00134 \return The number of bytes absorbed. */ 00135 int gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[]); 00136 00137 /*! Unpack a GSM 06.10 frame from the format used for VoIP. 00138 \param s A pointer to a buffer into which the frame will be packed. 00139 \param c The buffer containing the data to be unpacked. This must be at least 33 bytes long. 00140 \return The number of bytes absorbed. */ 00141 int gsm0610_unpack_voip(gsm0610_frame_t *s, const uint8_t c[]); 00142 00143 #if defined(__cplusplus) 00144 } 00145 #endif 00146 00147 #endif 00148 /*- End of include ---------------------------------------------------------*/