| 1 | /* |
| 2 | |
| 3 | $Log$ |
| 4 | Revision 1.15 2004/06/26 03:50:14 markster |
| 5 | Merge source cleanups (bug #1911) |
| 6 | |
| 7 | Revision 1.14 2003/02/12 13:59:15 matteo |
| 8 | mer feb 12 14:56:57 CET 2003 |
| 9 | |
| 10 | Revision 1.1.1.1 2003/02/12 13:59:15 matteo |
| 11 | mer feb 12 14:56:57 CET 2003 |
| 12 | |
| 13 | Revision 1.2 2000/01/05 08:20:39 markster |
| 14 | Some OSS fixes and a few lpc changes to make it actually work |
| 15 | |
| 16 | * Revision 1.2 1996/08/20 20:30:11 jaf |
| 17 | * Removed all static local variables that were SAVE'd in the Fortran |
| 18 | * code, and put them in struct lpc10_encoder_state that is passed as an |
| 19 | * argument. |
| 20 | * |
| 21 | * Removed init function, since all initialization is now done in |
| 22 | * init_lpc10_encoder_state(). |
| 23 | * |
| 24 | * Changed name of function from lpcenc_ to lpc10_encode, simply to make |
| 25 | * all lpc10 functions have more consistent naming with each other. |
| 26 | * |
| 27 | * Revision 1.1 1996/08/19 22:31:48 jaf |
| 28 | * Initial revision |
| 29 | * |
| 30 | |
| 31 | */ |
| 32 | |
| 33 | /* -- translated by f2c (version 19951025). |
| 34 | You must link the resulting object file with the libraries: |
| 35 | -lf2c -lm (in that order) |
| 36 | */ |
| 37 | |
| 38 | #include "f2c.h" |
| 39 | |
| 40 | #ifdef P_R_O_T_O_T_Y_P_E_S |
| 41 | extern int lpcdec_(integer *bits, real *speech); |
| 42 | extern int initlpcdec_(void); |
| 43 | /* comlen contrl_ 12 */ |
| 44 | /*:ref: chanrd_ 14 5 4 4 4 4 4 */ |
| 45 | /*:ref: decode_ 14 7 4 4 4 4 4 6 6 */ |
| 46 | /*:ref: synths_ 14 6 4 4 6 6 6 4 */ |
| 47 | /*:ref: initdecode_ 14 0 */ |
| 48 | /*:ref: initsynths_ 14 0 */ |
| 49 | #endif |
| 50 | |
| 51 | /* Common Block Declarations */ |
| 52 | |
| 53 | extern struct { |
| 54 | integer order, lframe; |
| 55 | logical corrp; |
| 56 | } contrl_; |
| 57 | |
| 58 | #define contrl_1 contrl_ |
| 59 | |
| 60 | /* Table of constant values */ |
| 61 | |
| 62 | static integer c__10 = 10; |
| 63 | |
| 64 | /* ***************************************************************** */ |
| 65 | |
| 66 | /* $Log$ |
| 67 | * Revision 1.15 2004/06/26 03:50:14 markster |
| 68 | * Merge source cleanups (bug #1911) |
| 69 | * |
| 70 | * Revision 1.14 2003/02/12 13:59:15 matteo |
| 71 | * mer feb 12 14:56:57 CET 2003 |
| 72 | * |
| 73 | * Revision 1.1.1.1 2003/02/12 13:59:15 matteo |
| 74 | * mer feb 12 14:56:57 CET 2003 |
| 75 | * |
| 76 | * Revision 1.2 2000/01/05 08:20:39 markster |
| 77 | * Some OSS fixes and a few lpc changes to make it actually work |
| 78 | * |
| 79 | * Revision 1.2 1996/08/20 20:30:11 jaf |
| 80 | * Removed all static local variables that were SAVE'd in the Fortran |
| 81 | * code, and put them in struct lpc10_encoder_state that is passed as an |
| 82 | * argument. |
| 83 | * |
| 84 | * Removed init function, since all initialization is now done in |
| 85 | * init_lpc10_encoder_state(). |
| 86 | * |
| 87 | * Changed name of function from lpcenc_ to lpc10_encode, simply to make |
| 88 | * all lpc10 functions have more consistent naming with each other. |
| 89 | * |
| 90 | * Revision 1.1 1996/08/19 22:31:48 jaf |
| 91 | * Initial revision |
| 92 | * */ |
| 93 | /* Revision 1.1 1996/03/28 00:03:00 jaf */ |
| 94 | /* Initial revision */ |
| 95 | |
| 96 | |
| 97 | /* ***************************************************************** */ |
| 98 | |
| 99 | /* Decode 54 bits to one frame of 180 speech samples. */ |
| 100 | |
| 101 | /* Input: */ |
| 102 | /* BITS - 54 encoded bits, stored 1 per array element. */ |
| 103 | /* Indices 1 through 53 read (SYNC bit ignored). */ |
| 104 | /* Output: */ |
| 105 | /* SPEECH - Speech encoded as real values in the range [-1,+1]. */ |
| 106 | /* Indices 1 through 180 written. */ |
| 107 | |
| 108 | /* This subroutine maintains local state from one call to the next. If */ |
| 109 | /* you want to switch to using a new audio stream for this filter, or */ |
| 110 | /* reinitialize its state for any other reason, call the ENTRY */ |
| 111 | /* INITLPCDEC. */ |
| 112 | |
| 113 | /* Subroutine */ int lpc10_decode(integer *bits, real *speech, |
| 114 | struct lpc10_decoder_state *st) |
| 115 | { |
| 116 | integer irms, voice[2], pitch, ipitv; |
| 117 | extern /* Subroutine */ int decode_(integer *, integer *, integer *, |
| 118 | integer *, integer *, real *, real *, struct lpc10_decoder_state *); |
| 119 | real rc[10]; |
| 120 | extern /* Subroutine */ int chanrd_(integer *, integer *, integer *, |
| 121 | integer *, integer *), synths_(integer *, |
| 122 | integer *, real *, real *, real *, integer *, |
| 123 | struct lpc10_decoder_state *); |
| 124 | integer irc[10], len; |
| 125 | real rms; |
| 126 | |
| 127 | /* $Log$ |
| 128 | * Revision 1.15 2004/06/26 03:50:14 markster |
| 129 | * Merge source cleanups (bug #1911) |
| 130 | * |
| 131 | * Revision 1.14 2003/02/12 13:59:15 matteo |
| 132 | * mer feb 12 14:56:57 CET 2003 |
| 133 | * |
| 134 | * Revision 1.1.1.1 2003/02/12 13:59:15 matteo |
| 135 | * mer feb 12 14:56:57 CET 2003 |
| 136 | * |
| 137 | * Revision 1.2 2000/01/05 08:20:39 markster |
| 138 | * Some OSS fixes and a few lpc changes to make it actually work |
| 139 | * |
| 140 | * Revision 1.2 1996/08/20 20:30:11 jaf |
| 141 | * Removed all static local variables that were SAVE'd in the Fortran |
| 142 | * code, and put them in struct lpc10_encoder_state that is passed as an |
| 143 | * argument. |
| 144 | * |
| 145 | * Removed init function, since all initialization is now done in |
| 146 | * init_lpc10_encoder_state(). |
| 147 | * |
| 148 | * Changed name of function from lpcenc_ to lpc10_encode, simply to make |
| 149 | * all lpc10 functions have more consistent naming with each other. |
| 150 | * |
| 151 | * Revision 1.1 1996/08/19 22:31:48 jaf |
| 152 | * Initial revision |
| 153 | * */ |
| 154 | /* Revision 1.3 1996/03/29 22:03:47 jaf */ |
| 155 | /* Removed definitions for any constants that were no longer used. */ |
| 156 | |
| 157 | /* Revision 1.2 1996/03/26 19:34:33 jaf */ |
| 158 | /* Added comments indicating which constants are not needed in an */ |
| 159 | /* application that uses the LPC-10 coder. */ |
| 160 | |
| 161 | /* Revision 1.1 1996/02/07 14:43:51 jaf */ |
| 162 | /* Initial revision */ |
| 163 | |
| 164 | /* LPC Configuration parameters: */ |
| 165 | /* Frame size, Prediction order, Pitch period */ |
| 166 | /* Arguments */ |
| 167 | /* $Log$ |
| 168 | * Revision 1.15 2004/06/26 03:50:14 markster |
| 169 | * Merge source cleanups (bug #1911) |
| 170 | * |
| 171 | * Revision 1.14 2003/02/12 13:59:15 matteo |
| 172 | * mer feb 12 14:56:57 CET 2003 |
| 173 | * |
| 174 | * Revision 1.1.1.1 2003/02/12 13:59:15 matteo |
| 175 | * mer feb 12 14:56:57 CET 2003 |
| 176 | * |
| 177 | * Revision 1.2 2000/01/05 08:20:39 markster |
| 178 | * Some OSS fixes and a few lpc changes to make it actually work |
| 179 | * |
| 180 | * Revision 1.2 1996/08/20 20:30:11 jaf |
| 181 | * Removed all static local variables that were SAVE'd in the Fortran |
| 182 | * code, and put them in struct lpc10_encoder_state that is passed as an |
| 183 | * argument. |
| 184 | * |
| 185 | * Removed init function, since all initialization is now done in |
| 186 | * init_lpc10_encoder_state(). |
| 187 | * |
| 188 | * Changed name of function from lpcenc_ to lpc10_encode, simply to make |
| 189 | * all lpc10 functions have more consistent naming with each other. |
| 190 | * |
| 191 | * Revision 1.1 1996/08/19 22:31:48 jaf |
| 192 | * Initial revision |
| 193 | * */ |
| 194 | /* Revision 1.3 1996/03/29 22:05:55 jaf */ |
| 195 | /* Commented out the common block variables that are not needed by the */ |
| 196 | /* embedded version. */ |
| 197 | |
| 198 | /* Revision 1.2 1996/03/26 19:34:50 jaf */ |
| 199 | /* Added comments indicating which constants are not needed in an */ |
| 200 | /* application that uses the LPC-10 coder. */ |
| 201 | |
| 202 | /* Revision 1.1 1996/02/07 14:44:09 jaf */ |
| 203 | /* Initial revision */ |
| 204 | |
| 205 | /* LPC Processing control variables: */ |
| 206 | |
| 207 | /* *** Read-only: initialized in setup */ |
| 208 | |
| 209 | /* Files for Speech, Parameter, and Bitstream Input & Output, */ |
| 210 | /* and message and debug outputs. */ |
| 211 | |
| 212 | /* Here are the only files which use these variables: */ |
| 213 | |
| 214 | /* lpcsim.f setup.f trans.f error.f vqsetup.f */ |
| 215 | |
| 216 | /* Many files which use fdebug are not listed, since it is only used in */ |
| 217 | /* those other files conditionally, to print trace statements. */ |
| 218 | /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */ |
| 219 | /* LPC order, Frame size, Quantization rate, Bits per frame, */ |
| 220 | /* Error correction */ |
| 221 | /* Subroutine SETUP is the only place where order is assigned a value, */ |
| 222 | /* and that value is 10. It could increase efficiency 1% or so to */ |
| 223 | /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as |
| 224 | */ |
| 225 | /* a variable in a COMMON block, since it is used in many places in the */ |
| 226 | /* core of the coding and decoding routines. Actually, I take that back. |
| 227 | */ |
| 228 | /* At least when compiling with f2c, the upper bound of DO loops is */ |
| 229 | /* stored in a local variable before the DO loop begins, and then that is |
| 230 | */ |
| 231 | /* compared against on each iteration. */ |
| 232 | /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */ |
| 233 | /* Similarly for quant, which is given a value of 2400 in SETUP. quant */ |
| 234 | /* is used in only a few places, and never in the core coding and */ |
| 235 | /* decoding routines, so it could be eliminated entirely. */ |
| 236 | /* nbits is similar to quant, and is given a value of 54 in SETUP. */ |
| 237 | /* corrp is given a value of .TRUE. in SETUP, and is only used in the */ |
| 238 | /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */ |
| 239 | /* coder significantly whether it is .TRUE. or .FALSE., or whether it is |
| 240 | */ |
| 241 | /* a constant or a variable, since it is only examined once per frame. */ |
| 242 | /* Leaving it as a variable that is set to .TRUE. seems like a good */ |
| 243 | /* idea, since it does enable some error-correction capability for */ |
| 244 | /* unvoiced frames, with no change in the coding rate, and no noticeable |
| 245 | */ |
| 246 | /* quality difference in the decoded speech. */ |
| 247 | /* integer quant, nbits */ |
| 248 | /* *** Read/write: variables for debugging, not needed for LPC algorithm |
| 249 | */ |
| 250 | |
| 251 | /* Current frame, Unstable frames, Output clip count, Max onset buffer, |
| 252 | */ |
| 253 | /* Debug listing detail level, Line count on listing page */ |
| 254 | |
| 255 | /* nframe is not needed for an embedded LPC10 at all. */ |
| 256 | /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */ |
| 257 | /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */ |
| 258 | /* an application, I would recommend removing the call to ERROR in RCCHK, |
| 259 | */ |
| 260 | /* and remove ERROR and nunsfm completely. */ |
| 261 | /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in |
| 262 | */ |
| 263 | /* sread.f. When LPC10 is embedded into an application, one might want */ |
| 264 | /* to cause it to be incremented in a routine that takes the output of */ |
| 265 | /* SYNTHS and sends it to an audio device. It could be optionally */ |
| 266 | /* displayed, for those that might want to know what it is. */ |
| 267 | /* maxosp is never initialized to 0 in SETUP, although it probably should |
| 268 | */ |
| 269 | /* be, and it is updated in subroutine ANALYS. I doubt that its value */ |
| 270 | /* would be of much interest to an application in which LPC10 is */ |
| 271 | /* embedded. */ |
| 272 | /* listl and lincnt are not needed for an embedded LPC10 at all. */ |
| 273 | /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */ |
| 274 | /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */ |
| 275 | /* common /contrl/ quant, nbits */ |
| 276 | /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */ |
| 277 | /* Local variables that need not be saved */ |
| 278 | /* Uncoded speech parameters */ |
| 279 | /* Coded speech parameters */ |
| 280 | /* Others */ |
| 281 | /* Local state */ |
| 282 | /* None */ |
| 283 | /* Parameter adjustments */ |
| 284 | if (bits) { |
| 285 | --bits; |
| 286 | } |
| 287 | if (speech) { |
| 288 | --speech; |
| 289 | } |
| 290 | |
| 291 | /* Function Body */ |
| 292 | |
| 293 | chanrd_(&c__10, &ipitv, &irms, irc, &bits[1]); |
| 294 | decode_(&ipitv, &irms, irc, voice, &pitch, &rms, rc, st); |
| 295 | synths_(voice, &pitch, &rms, rc, &speech[1], &len, st); |
| 296 | return 0; |
| 297 | } /* lpcdec_ */ |