lpc10.h

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

Generated on Thu Mar 20 17:20:09 2008 for libspandsp by  doxygen 1.5.5