00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * lpc10.h - LPC10 low bit 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: lpc10.h,v 1.17 2008/04/17 14:27:00 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_LPC10_H_) 00029 #define _SPANDSP_LPC10_H_ 00030 00031 /*! \page lpc10_page LPC10 encoding and decoding 00032 \section lpc10_page_sec_1 What does it do? 00033 The LPC10 module implements the US Department of Defense LPC10 00034 codec. This codec produces compressed data at 2400bps. At such 00035 a low rate high fidelity cannot be expected. However, the speech 00036 clarity is quite good, and this codec is unencumbered by patent 00037 or other restrictions. 00038 00039 \section lpc10_page_sec_2 How does it work? 00040 ???. 00041 */ 00042 00043 #define LPC10_SAMPLES_PER_FRAME 180 00044 #define LPC10_BITS_IN_COMPRESSED_FRAME 54 00045 00046 /*! 00047 LPC10 codec unpacked frame. 00048 */ 00049 typedef struct 00050 { 00051 int32_t ipitch; 00052 int32_t irms; 00053 int32_t irc[10]; 00054 } lpc10_frame_t; 00055 00056 /*! 00057 LPC10 codec encoder state descriptor. This defines the state of 00058 a single working instance of the LPC10 encoder. 00059 */ 00060 typedef struct 00061 { 00062 int error_correction; 00063 00064 /* State used only by function high_pass_100hz */ 00065 float z11; 00066 float z21; 00067 float z12; 00068 float z22; 00069 00070 /* State used by function lpc10_analyse */ 00071 float inbuf[LPC10_SAMPLES_PER_FRAME*3]; 00072 float pebuf[LPC10_SAMPLES_PER_FRAME*3]; 00073 float lpbuf[696]; 00074 float ivbuf[312]; 00075 float bias; 00076 int32_t osbuf[10]; /* No initial value necessary */ 00077 int32_t osptr; /* Initial value 1 */ 00078 int32_t obound[3]; 00079 int32_t vwin[3][2]; /* Initial value vwin[2][0] = 307; vwin[2][1] = 462; */ 00080 int32_t awin[3][2]; /* Initial value awin[2][0] = 307; awin[2][1] = 462; */ 00081 int32_t voibuf[4][2]; 00082 float rmsbuf[3]; 00083 float rcbuf[3][10]; 00084 float zpre; 00085 00086 /* State used by function onset */ 00087 float n; 00088 float d__; /* Initial value 1.0f */ 00089 float fpc; /* No initial value necessary */ 00090 float l2buf[16]; 00091 float l2sum1; 00092 int32_t l2ptr1; /* Initial value 1 */ 00093 int32_t l2ptr2; /* Initial value 9 */ 00094 int32_t lasti; /* No initial value necessary */ 00095 int hyst; /* Initial value FALSE */ 00096 00097 /* State used by function lpc10_voicing */ 00098 float dither; /* Initial value 20.0f */ 00099 float snr; 00100 float maxmin; 00101 float voice[3][2]; /* Initial value is probably unnecessary */ 00102 int32_t lbve; 00103 int32_t lbue; 00104 int32_t fbve; 00105 int32_t fbue; 00106 int32_t ofbue; 00107 int32_t sfbue; 00108 int32_t olbue; 00109 int32_t slbue; 00110 00111 /* State used by function dynamic_pitch_tracking */ 00112 float s[60]; 00113 int32_t p[2][60]; 00114 int32_t ipoint; 00115 float alphax; 00116 00117 /* State used by function lpc10_pack */ 00118 int32_t isync; 00119 } lpc10_encode_state_t; 00120 00121 /*! 00122 LPC10 codec decoder state descriptor. This defines the state of 00123 a single working instance of the LPC10 decoder. 00124 */ 00125 typedef struct 00126 { 00127 int error_correction; 00128 00129 /* State used by function decode */ 00130 int32_t iptold; /* Initial value 60 */ 00131 int first; /* Initial value TRUE */ 00132 int32_t ivp2h; 00133 int32_t iovoic; 00134 int32_t iavgp; /* Initial value 60 */ 00135 int32_t erate; 00136 int32_t drc[10][3]; 00137 int32_t dpit[3]; 00138 int32_t drms[3]; 00139 00140 /* State used by function synths */ 00141 float buf[LPC10_SAMPLES_PER_FRAME*2]; 00142 int32_t buflen; /* Initial value LPC10_SAMPLES_PER_FRAME */ 00143 00144 /* State used by function pitsyn */ 00145 int32_t ivoico; /* No initial value necessary as long as first_pitsyn is initially TRUE_ */ 00146 int32_t ipito; /* No initial value necessary as long as first_pitsyn is initially TRUE_ */ 00147 float rmso; /* Initial value 1.0f */ 00148 float rco[10]; /* No initial value necessary as long as first_pitsyn is initially TRUE_ */ 00149 int32_t jsamp; /* Nno initial value necessary as long as first_pitsyn is initially TRUE_ */ 00150 int first_pitsyn; /* Initial value TRUE */ 00151 00152 /* State used by function bsynz */ 00153 int32_t ipo; 00154 float exc[166]; 00155 float exc2[166]; 00156 float lpi[3]; 00157 float hpi[3]; 00158 float rmso_bsynz; 00159 00160 /* State used by function random */ 00161 int32_t j; 00162 int32_t k; 00163 int16_t y[5]; 00164 00165 /* State used by function deemp */ 00166 float dei[2]; 00167 float deo[3]; 00168 } lpc10_decode_state_t; 00169 00170 #if defined(__cplusplus) 00171 extern "C" 00172 { 00173 #endif 00174 00175 /*! Initialise an LPC10e encode context. 00176 \param s The LPC10e context 00177 \param error_correction ??? 00178 \return A pointer to the LPC10e context, or NULL for error. */ 00179 lpc10_encode_state_t *lpc10_encode_init(lpc10_encode_state_t *s, int error_correction); 00180 00181 int lpc10_encode_release(lpc10_encode_state_t *s); 00182 00183 /*! Encode a buffer of linear PCM data to LPC10e. 00184 \param s The LPC10e context. 00185 \param ima_data The LPC10e data produced. 00186 \param amp The audio sample buffer. 00187 \param len The number of samples in the buffer. This must be a multiple of 180, as 00188 this is the number of samples on a frame. 00189 \return The number of bytes of LPC10e data produced. */ 00190 int lpc10_encode(lpc10_encode_state_t *s, uint8_t code[], const int16_t amp[], int len); 00191 00192 /*! Initialise an LPC10e decode context. 00193 \param s The LPC10e context 00194 \param error_correction ??? 00195 \return A pointer to the LPC10e context, or NULL for error. */ 00196 lpc10_decode_state_t *lpc10_decode_init(lpc10_decode_state_t *st, int error_correction); 00197 00198 int lpc10_decode_release(lpc10_decode_state_t *s); 00199 00200 /*! Decode a buffer of LPC10e data to linear PCM. 00201 \param s The LPC10e context. 00202 \param amp The audio sample buffer. 00203 \param code The LPC10e data. 00204 \param len The number of bytes of LPC10e data to be decoded. This must be a multiple of 7, 00205 as each frame is packed into 7 bytes. 00206 \return The number of samples returned. */ 00207 int lpc10_decode(lpc10_decode_state_t *s, int16_t amp[], const uint8_t code[], int len); 00208 00209 00210 #if defined(__cplusplus) 00211 } 00212 #endif 00213 00214 #endif 00215 /*- End of include ---------------------------------------------------------*/