1 /* 2 3 $Log: lpc10.h,v $ 4 Revision 1.3 2008/03/21 13:34:21 robs 5 fix (I hope) [1913986] Error during make of static sox 6 7 Revision 1.2 2007/12/26 16:12:42 robs 8 support out-of-source-build 9 10 Revision 1.1 2007/04/16 21:57:22 rrt 11 LPC-10 support, documentation still to come; I wanted to land the code 12 before 14.0.0 went into test, and I'll be busy tomorrow. 13 14 Not highly tested either, but it's just a format, doesn't interfere 15 with anything else, and I'll get on that case before we go stable. 16 17 * Revision 1.1 1996/08/19 22:47:31 jaf 18 * Initial revision 19 * 20 21 */ 22 23 #ifndef __LPC10_H__ 24 #define __LPC10_H__ 25 26 #include <limits.h> 27 28 /* aliases */ 29 #define analys_ lsx_lpc10_analys_ 30 #define bsynz_ lsx_lpc10_bsynz_ 31 #define chanrd_ lsx_lpc10_chanrd_ 32 #define chanwr_ lsx_lpc10_chanwr_ 33 #define contrl_ lsx_lpc10_contrl_ 34 #define create_lpc10_decoder_state lsx_lpc10_create_decoder_state 35 #define create_lpc10_encoder_state lsx_lpc10_create_encoder_state 36 #define dcbias_ lsx_lpc10_dcbias_ 37 #define decode_ lsx_lpc10_decode_ 38 #define deemp_ lsx_lpc10_deemp_ 39 #define difmag_ lsx_lpc10_difmag_ 40 #define dyptrk_ lsx_lpc10_dyptrk_ 41 #define encode_ lsx_lpc10_encode_ 42 #define energy_ lsx_lpc10_energy_ 43 #define ham84_ lsx_lpc10_ham84_ 44 #define hp100_ lsx_lpc10_hp100_ 45 #define i_nint lsx_lpc10_i_nint 46 #define init_lpc10_decoder_state lsx_lpc10_init_decoder_state 47 #define init_lpc10_encoder_state lsx_lpc10_init_encoder_state 48 #define invert_ lsx_lpc10_invert_ 49 #define irc2pc_ lsx_lpc10_irc2pc_ 50 #define ivfilt_ lsx_lpc10_ivfilt_ 51 #define lpc10_decode lsx_lpc10_decode 52 #define lpc10_encode lsx_lpc10_encode 53 #define lpcini_ lsx_lpc10_lpcini_ 54 #define lpfilt_ lsx_lpc10_lpfilt_ 55 #define median_ lsx_lpc10_median_ 56 #define mload_ lsx_lpc10_mload_ 57 #define onset_ lsx_lpc10_onset_ 58 #define pitsyn_ lsx_lpc10_pitsyn_ 59 #define placea_ lsx_lpc10_placea_ 60 #define placev_ lsx_lpc10_placev_ 61 #define pow_ii lsx_lpc10_pow_ii 62 #define preemp_ lsx_lpc10_preemp_ 63 #define prepro_ lsx_lpc10_prepro_ 64 #define random_ lsx_lpc10_random_ 65 #define rcchk_ lsx_lpc10_rcchk_ 66 #define r_sign lsx_lpc10_r_sign 67 #define synths_ lsx_lpc10_synths_ 68 #define tbdm_ lsx_lpc10_tbdm_ 69 #define voicin_ lsx_lpc10_voicin_ 70 #define vparms_ lsx_lpc10_vparms_ 71 72 #define LPC10_SAMPLES_PER_FRAME 180 73 #define LPC10_BITS_IN_COMPRESSED_FRAME 54 74 75 76 #if defined(SHRT_MAX) && defined(SHRT_MIN) && SHRT_MAX==32767 && SHRT_MIN==(-32768) 77 typedef short INT16; 78 #elif defined(INT_MAX) && defined(INT_MIN) && INT_MAX==32767 && INT_MIN==(-32768) 79 typedef int INT16; 80 #else 81 #error Unable to determine an appropriate definition for INT16. 82 #endif 83 84 #if defined(INT_MAX) && defined(INT_MIN) && INT_MAX==2147483647 && INT_MIN==(-2147483647-1) 85 typedef int INT32; 86 #elif defined(LONG_MAX) && defined(LONG_MIN) && LONG_MAX==2147483647 && LONG_MIN==(-2147483647-1) 87 typedef long INT32; 88 #else 89 #error Unable to determine an appropriate definition for INT32. 90 #endif 91 92 93 /* The initial values for every member of this structure is 0, except 94 where noted in comments. */ 95 96 /* These two lines are copied from f2c.h. There should be a more 97 elegant way of doing this than having the same declarations in two 98 files. */ 99 100 typedef float real; 101 typedef INT32 integer; 102 typedef INT32 logical; 103 typedef INT16 shortint; 104 105 struct lpc10_encoder_state { 106 /* State used only by function hp100 */ 107 real z11; 108 real z21; 109 real z12; 110 real z22; 111 112 /* State used by function analys */ 113 real inbuf[540], pebuf[540]; 114 real lpbuf[696], ivbuf[312]; 115 real bias; 116 integer osbuf[10]; /* no initial value necessary */ 117 integer osptr; /* initial value 1 */ 118 integer obound[3]; 119 integer vwin[6] /* was [2][3] */; /* initial value vwin[4] = 307; vwin[5] = 462; */ 120 integer awin[6] /* was [2][3] */; /* initial value awin[4] = 307; awin[5] = 462; */ 121 integer voibuf[8] /* was [2][4] */; 122 real rmsbuf[3]; 123 real rcbuf[30] /* was [10][3] */; 124 real zpre; 125 126 127 /* State used by function onset */ 128 real n; 129 real d__; /* initial value 1.f */ 130 real fpc; /* no initial value necessary */ 131 real l2buf[16]; 132 real l2sum1; 133 integer l2ptr1; /* initial value 1 */ 134 integer l2ptr2; /* initial value 9 */ 135 integer lasti; /* no initial value necessary */ 136 logical hyst; /* initial value FALSE_ */ 137 138 /* State used by function voicin */ 139 real dither; /* initial value 20.f */ 140 real snr; 141 real maxmin; 142 real voice[6] /* was [2][3] */; /* initial value is probably unnecessary */ 143 integer lbve, lbue, fbve, fbue; 144 integer ofbue, sfbue; 145 integer olbue, slbue; 146 /* Initial values: 147 lbve = 3000; 148 fbve = 3000; 149 fbue = 187; 150 ofbue = 187; 151 sfbue = 187; 152 lbue = 93; 153 olbue = 93; 154 slbue = 93; 155 snr = (real) (fbve / fbue << 6); 156 */ 157 158 /* State used by function dyptrk */ 159 real s[60]; 160 integer p[120] /* was [60][2] */; 161 integer ipoint; 162 real alphax; 163 164 /* State used by function chanwr */ 165 integer isync; 166 167 }; 168 169 170 struct lpc10_decoder_state { 171 172 /* State used by function decode */ 173 integer iptold; /* initial value 60 */ 174 logical first; /* initial value TRUE_ */ 175 integer ivp2h; 176 integer iovoic; 177 integer iavgp; /* initial value 60 */ 178 integer erate; 179 integer drc[30] /* was [3][10] */; 180 integer dpit[3]; 181 integer drms[3]; 182 183 /* State used by function synths */ 184 real buf[360]; 185 integer buflen; /* initial value 180 */ 186 187 /* State used by function pitsyn */ 188 integer ivoico; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ 189 integer ipito; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ 190 real rmso; /* initial value 1.f */ 191 real rco[10]; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ 192 integer jsamp; /* no initial value necessary as long as first_pitsyn is initially TRUE_ */ 193 logical first_pitsyn; /* initial value TRUE_ */ 194 195 /* State used by function bsynz */ 196 integer ipo; 197 real exc[166]; 198 real exc2[166]; 199 real lpi1; 200 real lpi2; 201 real lpi3; 202 real hpi1; 203 real hpi2; 204 real hpi3; 205 real rmso_bsynz; 206 207 /* State used by function random */ 208 integer j; /* initial value 2 */ 209 integer k; /* initial value 5 */ 210 shortint y[5]; /* initial value { -21161,-8478,30892,-10216,16950 } */ 211 212 /* State used by function deemp */ 213 real dei1; 214 real dei2; 215 real deo1; 216 real deo2; 217 real deo3; 218 219 }; 220 221 222 223 /* 224 225 Calling sequence: 226 227 Call create_lpc10_encoder_state(), which returns a pointer to an 228 already initialized lpc10_encoder_state structure. 229 230 lpc10_encode reads indices 0 through (LPC10_SAMPLES_PER_FRAME-1) of 231 array speech[], and writes indices 0 through 232 (LPC10_BITS_IN_COMPRESSED_FRAME-1) of array bits[], and both reads 233 and writes the lpc10_encoder_state structure contents. The 234 lpc10_encoder_state structure should *not* be initialized for every 235 frame of encoded speech. Once at the beginning of execution, done 236 automatically for you by create_lpc10_encoder_state(), is enough. 237 238 init_lpc10_encoder_state() reinitializes the lpc10_encoder_state 239 structure. This might be useful if you are finished processing one 240 sound sample, and want to reuse the same lpc10_encoder_state 241 structure to process another sound sample. There might be other 242 uses as well. 243 244 Note that the comments in the lpc10/lpcenc.c file imply that indices 245 1 through 180 of array speech[] are read. These comments were 246 written for the Fortran version of the code, before it was 247 automatically converted to C by the conversion program f2c. f2c 248 seems to use the convention that the pointers to arrays passed as 249 function arguments point to the first index used in the Fortran 250 code, whatever index that might be (usually 1), and then it modifies 251 the pointer inside of the function, like so: 252 253 if (speech) { 254 --speech; 255 } 256 257 So that the code can access the first value at index 1 and the last 258 at index 180. This makes the translated C code "closer" to the 259 original Fortran code. 260 261 The calling sequence for the decoder is similar to the encoder. The 262 only significant difference is that the array bits[] is read 263 (indices 0 through (LPC10_BITS_IN_COMPRESSED_FRAME-1)), and the 264 array speech[] is written (indices 0 through 265 (LPC10_SAMPLES_PER_FRAME-1)). 266 267 */ 268 269 struct lpc10_encoder_state * create_lpc10_encoder_state (void); 270 void init_lpc10_encoder_state (struct lpc10_encoder_state *st); 271 int lpc10_encode (real *speech, INT32 *bits, struct lpc10_encoder_state *st); 272 273 struct lpc10_decoder_state * create_lpc10_decoder_state (void); 274 void init_lpc10_decoder_state (struct lpc10_decoder_state *st); 275 int lpc10_decode (INT32 *bits, real *speech, struct lpc10_decoder_state *st); 276 277 #endif /* __LPC10_H__ */ 278