Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Typedefs | Functions
f2c.h File Reference
#include "lpc10.h"
Include dependency graph for f2c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  alist
 
struct  cilist
 
struct  cllist
 
struct  complex
 
struct  doublecomplex
 
struct  icilist
 
struct  inlist
 
union  Multitype
 
struct  Namelist
 
struct  olist
 
struct  Vardesc
 

Macros

#define abs(x)   ((x) >= 0 ? (x) : -(x))
 
#define dabs(x)   (doublereal)abs(x)
 
#define dmax(a, b)   (doublereal)max(a,b)
 
#define dmin(a, b)   (doublereal)min(a,b)
 
#define Extern   extern
 
#define F2C_proc_par_types   1
 
#define FALSE_   (0)
 
#define max(a, b)   ((a) >= (b) ? (a) : (b))
 
#define min(a, b)   ((a) <= (b) ? (a) : (b))
 
#define TRUE_   (1)
 
#define VOID   void
 

Typedefs

typedef char * address
 
typedef VOID C_f
 
typedef VOID(* C_fp) (VOID)
 
typedef doublereal(* D_fp) (VOID)
 
typedef double doublereal
 
typedef doublereal E_f
 
typedef doublereal(*)(* E_fp) (VOID)
 
typedef long int flag
 
typedef long int ftnint
 
typedef long int ftnlen
 
typedef VOID H_f
 
typedef VOID(* H_fp) (VOID)
 
typedef integer(* I_fp) (VOID)
 
typedef char integer1
 
typedef shortint(* J_fp) (VOID)
 
typedef shortlogical(* K_fp) (VOID)
 
typedef logical(* L_fp) (VOID)
 
typedef char logical1
 
typedef union Multitype Multitype
 
typedef struct Namelist Namelist
 
typedef real(* R_fp) (VOID)
 
typedef int(* S_fp) (VOID)
 
typedef short int shortlogical
 
typedef int(* U_fp) (VOID)
 
typedef struct Vardesc Vardesc
 
typedef VOID Z_f
 
typedef VOID(* Z_fp) (VOID)
 

Functions

int bsynz_ (real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st)
 
int chanrd_ (integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits)
 
int chanwr_ (integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st)
 
int chanwr_0_ (int n__, integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st)
 
int dcbias_ (integer *len, real *speech, real *sigout)
 
int decode_ (integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st)
 
int deemp_ (real *x, integer *n, struct lpc10_decoder_state *st)
 
int difmag_ (real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr)
 
int dyptrk_ (real *amdf, integer *ltau, integer *minptr, integer *voice, integer *pitch, integer *midx, struct lpc10_encoder_state *st)
 
int encode_ (integer *voice, integer *pitch, real *rms, real *rc, integer *ipitch, integer *irms, integer *irc)
 
int energy_ (integer *len, real *speech, real *rms)
 
int ham84_ (integer *input, integer *output, integer *errcnt)
 
int hp100_ (real *speech, integer *start, integer *end, struct lpc10_encoder_state *st)
 
integer i_nint (real *x)
 
int inithp100_ (void)
 
int initlpcdec_ (void)
 
int initlpcenc_ (void)
 
int invert_ (integer *order, real *phi, real *psi, real *rc)
 
int irc2pc_ (real *rc, real *pc, integer *order, real *gprime, real *g2pass)
 
int ivfilt_ (real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc)
 
int lpcdec_ (integer *bits, real *speech)
 
int lpcenc_ (real *speech, integer *bits)
 
int lpfilt_ (real *inbuf, real *lpbuf, integer *len, integer *nsamp)
 
integer median_ (integer *d1, integer *d2, integer *d3)
 
int mload_ (integer *order, integer *awins, integer *awinf, real *speech, real *phi, real *psi)
 
int onset_ (real *pebuf, integer *osbuf, integer *osptr, integer *oslen, integer *sbufl, integer *sbufh, integer *lframe, struct lpc10_encoder_state *st)
 
int pitsyn_ (integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st)
 
int placea_ (integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin)
 
int placev_ (integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh)
 
integer pow_ii (integer *ap, integer *bp)
 
int preemp_ (real *inbuf, real *pebuf, integer *nsamp, real *coef, real *z__)
 
int prepro_ (real *speech, integer *length, struct lpc10_encoder_state *st)
 
double r_sign (real *a, real *b)
 
integer random_ (struct lpc10_decoder_state *st)
 
int rcchk_ (integer *order, real *rc1f, real *rc2f)
 
int synths_ (integer *voice, integer *pitch, real *rms, real *rc, real *speech, integer *k, struct lpc10_decoder_state *st)
 
int tbdm_ (real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau)
 
int voicin_ (integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd, integer *mintau, real *ivrc, integer *obound, integer *voibuf, integer *af, struct lpc10_encoder_state *st)
 
int vparms_ (integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__)
 

Macro Definition Documentation

◆ abs

#define abs (   x)    ((x) >= 0 ? (x) : -(x))

◆ dabs

#define dabs (   x)    (doublereal)abs(x)

Definition at line 196 of file f2c.h.

◆ dmax

#define dmax (   a,
  b 
)    (doublereal)max(a,b)

Definition at line 200 of file f2c.h.

Referenced by P4().

◆ dmin

#define dmin (   a,
  b 
)    (doublereal)min(a,b)

Definition at line 199 of file f2c.h.

◆ Extern

#define Extern   extern

Definition at line 72 of file f2c.h.

◆ F2C_proc_par_types

#define F2C_proc_par_types   1

Definition at line 204 of file f2c.h.

◆ FALSE_

#define FALSE_   (0)

Definition at line 68 of file f2c.h.

Referenced by decode_(), init_lpc10_encoder_state(), onset_(), pitsyn_(), placea_(), and placev_().

◆ max

#define max (   a,
  b 
)    ((a) >= (b) ? (a) : (b))

◆ min

#define min (   a,
  b 
)    ((a) <= (b) ? (a) : (b))

◆ TRUE_

#define TRUE_   (1)

Definition at line 67 of file f2c.h.

Referenced by init_lpc10_decoder_state(), lpcini_(), onset_(), pitsyn_(), placea_(), and placev_().

◆ VOID

#define VOID   void

Definition at line 163 of file f2c.h.

Typedef Documentation

◆ address

typedef char* address

Definition at line 59 of file f2c.h.

◆ C_f

typedef VOID C_f

Definition at line 231 of file f2c.h.

◆ C_fp

typedef VOID(* C_fp) (VOID)

Definition at line 223 of file f2c.h.

◆ D_fp

typedef doublereal(* D_fp) (VOID)

Definition at line 222 of file f2c.h.

◆ doublereal

typedef double doublereal

barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."

  • From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition)

Definition at line 50 of file f2c.h.

◆ E_f

typedef doublereal E_f

Definition at line 234 of file f2c.h.

◆ E_fp

typedef doublereal(*)(* E_fp) (VOID)

Definition at line 222 of file f2c.h.

◆ flag

typedef long int flag

Definition at line 83 of file f2c.h.

◆ ftnint

typedef long int ftnint

Definition at line 85 of file f2c.h.

◆ ftnlen

typedef long int ftnlen

Definition at line 84 of file f2c.h.

◆ H_f

typedef VOID H_f

Definition at line 232 of file f2c.h.

◆ H_fp

typedef VOID(* H_fp) (VOID)

Definition at line 227 of file f2c.h.

◆ I_fp

typedef integer(* I_fp) (VOID)

Definition at line 220 of file f2c.h.

◆ integer1

typedef char integer1

Definition at line 64 of file f2c.h.

◆ J_fp

typedef shortint(* J_fp) (VOID)

Definition at line 219 of file f2c.h.

◆ K_fp

typedef shortlogical(* K_fp) (VOID)

Definition at line 226 of file f2c.h.

◆ L_fp

typedef logical(* L_fp) (VOID)

Definition at line 225 of file f2c.h.

◆ logical1

typedef char logical1

Definition at line 63 of file f2c.h.

◆ Multitype

typedef union Multitype Multitype

Definition at line 176 of file f2c.h.

◆ Namelist

typedef struct Namelist Namelist

Definition at line 193 of file f2c.h.

◆ R_fp

typedef real(* R_fp) (VOID)

Definition at line 221 of file f2c.h.

◆ S_fp

typedef int(* S_fp) (VOID)

Definition at line 228 of file f2c.h.

◆ shortlogical

typedef short int shortlogical

Definition at line 62 of file f2c.h.

◆ U_fp

typedef int(* U_fp) (VOID)

Definition at line 218 of file f2c.h.

◆ Vardesc

typedef struct Vardesc Vardesc

Definition at line 186 of file f2c.h.

◆ Z_f

typedef VOID Z_f

Definition at line 233 of file f2c.h.

◆ Z_fp

typedef VOID(* Z_fp) (VOID)

Definition at line 224 of file f2c.h.

Function Documentation

◆ bsynz_()

int bsynz_ ( real coef,
integer ip,
integer iv,
real sout,
real rms,
real ratio,
real g2pass,
struct lpc10_decoder_state st 
)

Definition at line 122 of file bsynz.c.

References contrl_1, lpc10_decoder_state::exc, lpc10_decoder_state::exc2, lpc10_decoder_state::hpi1, lpc10_decoder_state::hpi2, lpc10_decoder_state::hpi3, lpc10_decoder_state::ipo, lpc10_decoder_state::lpi1, lpc10_decoder_state::lpi2, lpc10_decoder_state::lpi3, min, random_(), and lpc10_decoder_state::rmso_bsynz.

Referenced by synths_().

125 {
126  /* Initialized data */
127 
128  integer *ipo;
129  real *rmso;
130  static integer kexc[25] = { 8,-16,26,-48,86,-162,294,-502,718,-728,184,
131  672,-610,-672,184,728,718,502,294,162,86,48,26,16,8 };
132  real *exc;
133  real *exc2;
134  real *lpi1;
135  real *lpi2;
136  real *lpi3;
137  real *hpi1;
138  real *hpi2;
139  real *hpi3;
140 
141  /* System generated locals */
142  integer i__1, i__2;
143  real r__1, r__2;
144 
145  /* Builtin functions */
146  double sqrt(doublereal);
147 
148  /* Local variables */
149  real gain, xssq;
150  integer i__, j, k;
151  real noise[166], pulse;
152  integer px;
153  real sscale;
154  extern integer random_(struct lpc10_decoder_state *);
155  real xy, sum, ssq;
156  real lpi0, hpi0;
157 
158 /* $Log$
159  * Revision 1.15 2004/06/26 03:50:14 markster
160  * Merge source cleanups (bug #1911)
161  *
162  * Revision 1.14 2003/02/12 13:59:14 matteo
163  * mer feb 12 14:56:57 CET 2003
164  *
165  * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
166  * mer feb 12 14:56:57 CET 2003
167  *
168  * Revision 1.2 2000/01/05 08:20:39 markster
169  * Some OSS fixes and a few lpc changes to make it actually work
170  *
171  * Revision 1.2 1996/08/20 20:18:55 jaf
172  * Removed all static local variables that were SAVE'd in the Fortran
173  * code, and put them in struct lpc10_decoder_state that is passed as an
174  * argument.
175  *
176  * Removed init function, since all initialization is now done in
177  * init_lpc10_decoder_state().
178  *
179  * Revision 1.1 1996/08/19 22:32:58 jaf
180  * Initial revision
181  * */
182 /* Revision 1.3 1996/03/29 22:03:47 jaf */
183 /* Removed definitions for any constants that were no longer used. */
184 
185 /* Revision 1.2 1996/03/26 19:34:33 jaf */
186 /* Added comments indicating which constants are not needed in an */
187 /* application that uses the LPC-10 coder. */
188 
189 /* Revision 1.1 1996/02/07 14:43:51 jaf */
190 /* Initial revision */
191 
192 /* LPC Configuration parameters: */
193 /* Frame size, Prediction order, Pitch period */
194 /* Arguments */
195 /* $Log$
196  * Revision 1.15 2004/06/26 03:50:14 markster
197  * Merge source cleanups (bug #1911)
198  *
199  * Revision 1.14 2003/02/12 13:59:14 matteo
200  * mer feb 12 14:56:57 CET 2003
201  *
202  * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
203  * mer feb 12 14:56:57 CET 2003
204  *
205  * Revision 1.2 2000/01/05 08:20:39 markster
206  * Some OSS fixes and a few lpc changes to make it actually work
207  *
208  * Revision 1.2 1996/08/20 20:18:55 jaf
209  * Removed all static local variables that were SAVE'd in the Fortran
210  * code, and put them in struct lpc10_decoder_state that is passed as an
211  * argument.
212  *
213  * Removed init function, since all initialization is now done in
214  * init_lpc10_decoder_state().
215  *
216  * Revision 1.1 1996/08/19 22:32:58 jaf
217  * Initial revision
218  * */
219 /* Revision 1.3 1996/03/29 22:05:55 jaf */
220 /* Commented out the common block variables that are not needed by the */
221 /* embedded version. */
222 
223 /* Revision 1.2 1996/03/26 19:34:50 jaf */
224 /* Added comments indicating which constants are not needed in an */
225 /* application that uses the LPC-10 coder. */
226 
227 /* Revision 1.1 1996/02/07 14:44:09 jaf */
228 /* Initial revision */
229 
230 /* LPC Processing control variables: */
231 
232 /* *** Read-only: initialized in setup */
233 
234 /* Files for Speech, Parameter, and Bitstream Input & Output, */
235 /* and message and debug outputs. */
236 
237 /* Here are the only files which use these variables: */
238 
239 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
240 
241 /* Many files which use fdebug are not listed, since it is only used in */
242 /* those other files conditionally, to print trace statements. */
243 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
244 /* LPC order, Frame size, Quantization rate, Bits per frame, */
245 /* Error correction */
246 /* Subroutine SETUP is the only place where order is assigned a value, */
247 /* and that value is 10. It could increase efficiency 1% or so to */
248 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
249 */
250 /* a variable in a COMMON block, since it is used in many places in the */
251 /* core of the coding and decoding routines. Actually, I take that back.
252 */
253 /* At least when compiling with f2c, the upper bound of DO loops is */
254 /* stored in a local variable before the DO loop begins, and then that is
255 */
256 /* compared against on each iteration. */
257 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
258 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
259 /* is used in only a few places, and never in the core coding and */
260 /* decoding routines, so it could be eliminated entirely. */
261 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
262 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
263 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
264 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
265 */
266 /* a constant or a variable, since it is only examined once per frame. */
267 /* Leaving it as a variable that is set to .TRUE. seems like a good */
268 /* idea, since it does enable some error-correction capability for */
269 /* unvoiced frames, with no change in the coding rate, and no noticeable
270 */
271 /* quality difference in the decoded speech. */
272 /* integer quant, nbits */
273 /* *** Read/write: variables for debugging, not needed for LPC algorithm
274 */
275 
276 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
277 */
278 /* Debug listing detail level, Line count on listing page */
279 
280 /* nframe is not needed for an embedded LPC10 at all. */
281 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
282 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
283 /* an application, I would recommend removing the call to ERROR in RCCHK,
284 */
285 /* and remove ERROR and nunsfm completely. */
286 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
287 */
288 /* sread.f. When LPC10 is embedded into an application, one might want */
289 /* to cause it to be incremented in a routine that takes the output of */
290 /* SYNTHS and sends it to an audio device. It could be optionally */
291 /* displayed, for those that might want to know what it is. */
292 /* maxosp is never initialized to 0 in SETUP, although it probably should
293 */
294 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
295 /* would be of much interest to an application in which LPC10 is */
296 /* embedded. */
297 /* listl and lincnt are not needed for an embedded LPC10 at all. */
298 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
299 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
300 /* common /contrl/ quant, nbits */
301 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
302 /* Function return value definitions */
303 /* Parameters/constants */
304 /* KEXC is not a Fortran PARAMETER, but it is an array initialized
305 */
306 /* with a DATA statement that is never modified. */
307 /* Local variables that need not be saved */
308 /* NOISE is declared with range (1:MAXPIT+MAXORD), but only indices
309 */
310 /* ORDER+1 through ORDER+IP are ever used, and I think that IP */
311 /* .LE. MAXPIT. Why not declare it to be in the range (1:MAXPIT) */
312 /* and use that range? */
313 /* Local state */
314 /* I believe that only indices 1 through ORDER of EXC need to be */
315 /* saved from one invocation to the next, but we may as well save */
316 /* the whole array. */
317 /* None of these local variables were given initial values in the */
318 /* original code. I'm guessing that 0 is a reasonable initial */
319 /* value for all of them. */
320  /* Parameter adjustments */
321  if (coef) {
322  --coef;
323  }
324  if (sout) {
325  --sout;
326  }
327 
328  /* Function Body */
329  ipo = &(st->ipo);
330  exc = &(st->exc[0]);
331  exc2 = &(st->exc2[0]);
332  lpi1 = &(st->lpi1);
333  lpi2 = &(st->lpi2);
334  lpi3 = &(st->lpi3);
335  hpi1 = &(st->hpi1);
336  hpi2 = &(st->hpi2);
337  hpi3 = &(st->hpi3);
338  rmso = &(st->rmso_bsynz);
339 
340 /* MAXPIT+MAXORD=166 */
341 /* Calculate history scale factor XY and scale filter state */
342 /* Computing MIN */
343  r__1 = *rmso / (*rms + 1e-6f);
344  xy = min(r__1,8.f);
345  *rmso = *rms;
346  i__1 = contrl_1.order;
347  for (i__ = 1; i__ <= i__1; ++i__) {
348  exc2[i__ - 1] = exc2[*ipo + i__ - 1] * xy;
349  }
350  *ipo = *ip;
351  if (*iv == 0) {
352 /* Generate white noise for unvoiced */
353  i__1 = *ip;
354  for (i__ = 1; i__ <= i__1; ++i__) {
355  exc[contrl_1.order + i__ - 1] = (real) (random_(st) / 64);
356  }
357 /* Impulse doublet excitation for plosives */
358 /* (RANDOM()+32768) is in the range 0 to 2**16-1. Therefore the
359  */
360 /* following expression should be evaluated using integers with
361 at */
362 /* least 32 bits (16 isn't enough), and PX should be in the rang
363 e */
364 /* ORDER+1+0 through ORDER+1+(IP-2) .EQ. ORDER+IP-1. */
365  px = (random_(st) + 32768) * (*ip - 1) / 65536 + contrl_1.order + 1;
366  r__1 = *ratio / 4 * 1.f;
367  pulse = r__1 * 342;
368  if (pulse > 2e3f) {
369  pulse = 2e3f;
370  }
371  exc[px - 1] += pulse;
372  exc[px] -= pulse;
373 /* Load voiced excitation */
374  } else {
375  sscale = (real)sqrt((real) (*ip)) / 6.928f;
376  i__1 = *ip;
377  for (i__ = 1; i__ <= i__1; ++i__) {
378  exc[contrl_1.order + i__ - 1] = 0.f;
379  if (i__ <= 25) {
380  exc[contrl_1.order + i__ - 1] = sscale * kexc[i__ - 1];
381  }
382  lpi0 = exc[contrl_1.order + i__ - 1];
383  r__2 = exc[contrl_1.order + i__ - 1] * .125f + *lpi1 * .75f;
384  r__1 = r__2 + *lpi2 * .125f;
385  exc[contrl_1.order + i__ - 1] = r__1 + *lpi3 * 0.f;
386  *lpi3 = *lpi2;
387  *lpi2 = *lpi1;
388  *lpi1 = lpi0;
389  }
390  i__1 = *ip;
391  for (i__ = 1; i__ <= i__1; ++i__) {
392  noise[contrl_1.order + i__ - 1] = random_(st) * 1.f / 64;
393  hpi0 = noise[contrl_1.order + i__ - 1];
394  r__2 = noise[contrl_1.order + i__ - 1] * -.125f + *hpi1 * .25f;
395  r__1 = r__2 + *hpi2 * -.125f;
396  noise[contrl_1.order + i__ - 1] = r__1 + *hpi3 * 0.f;
397  *hpi3 = *hpi2;
398  *hpi2 = *hpi1;
399  *hpi1 = hpi0;
400  }
401  i__1 = *ip;
402  for (i__ = 1; i__ <= i__1; ++i__) {
403  exc[contrl_1.order + i__ - 1] += noise[contrl_1.order + i__ - 1];
404  }
405  }
406 /* Synthesis filters: */
407 /* Modify the excitation with all-zero filter 1 + G*SUM */
408  xssq = 0.f;
409  i__1 = *ip;
410  for (i__ = 1; i__ <= i__1; ++i__) {
411  k = contrl_1.order + i__;
412  sum = 0.f;
413  i__2 = contrl_1.order;
414  for (j = 1; j <= i__2; ++j) {
415  sum += coef[j] * exc[k - j - 1];
416  }
417  sum *= *g2pass;
418  exc2[k - 1] = sum + exc[k - 1];
419  }
420 /* Synthesize using the all pole filter 1 / (1 - SUM) */
421  i__1 = *ip;
422  for (i__ = 1; i__ <= i__1; ++i__) {
423  k = contrl_1.order + i__;
424  sum = 0.f;
425  i__2 = contrl_1.order;
426  for (j = 1; j <= i__2; ++j) {
427  sum += coef[j] * exc2[k - j - 1];
428  }
429  exc2[k - 1] = sum + exc2[k - 1];
430  xssq += exc2[k - 1] * exc2[k - 1];
431  }
432 /* Save filter history for next epoch */
433  i__1 = contrl_1.order;
434  for (i__ = 1; i__ <= i__1; ++i__) {
435  exc[i__ - 1] = exc[*ip + i__ - 1];
436  exc2[i__ - 1] = exc2[*ip + i__ - 1];
437  }
438 /* Apply gain to match RMS */
439  r__1 = *rms * *rms;
440  ssq = r__1 * *ip;
441  gain = (real)sqrt(ssq / xssq);
442  i__1 = *ip;
443  for (i__ = 1; i__ <= i__1; ++i__) {
444  sout[i__] = gain * exc2[contrl_1.order + i__ - 1];
445  }
446  return 0;
447 } /* bsynz_ */
real exc[166]
Definition: lpc10.h:176
double doublereal
Definition: f2c.h:50
#define contrl_1
Definition: bsynz.c:50
real exc2[166]
Definition: lpc10.h:177
float real
Definition: lpc10.h:79
integer random_(struct lpc10_decoder_state *st)
Definition: random.c:93
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80

◆ chanrd_()

int chanrd_ ( integer order,
integer ipitv,
integer irms,
integer irc,
integer ibits 
)

Definition at line 229 of file chanwr.c.

References chanwr_0_(), and NULL.

Referenced by lpc10_decode().

231 {
232  return chanwr_0_(1, order, ipitv, irms, irc, ibits, NULL);
233  }
#define NULL
Definition: resample.c:96
integer order
Definition: analys.c:66
int chanwr_0_(int n__, integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st)
Definition: chanwr.c:132

◆ chanwr_()

int chanwr_ ( integer order,
integer ipitv,
integer irms,
integer irc,
integer ibits,
struct lpc10_encoder_state st 
)

Definition at line 223 of file chanwr.c.

References chanwr_0_().

Referenced by lpc10_encode().

225 {
226  return chanwr_0_(0, order, ipitv, irms, irc, ibits, st);
227  }
integer order
Definition: analys.c:66
int chanwr_0_(int n__, integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st)
Definition: chanwr.c:132

◆ chanwr_0_()

int chanwr_0_ ( int  n__,
integer order,
integer ipitv,
integer irms,
integer irc,
integer ibits,
struct lpc10_encoder_state st 
)

Definition at line 132 of file chanwr.c.

References lpc10_encoder_state::isync, and order.

Referenced by chanrd_(), and chanwr_().

135 {
136  /* Initialized data */
137 
138  integer *isync;
139  static integer bit[10] = { 2,4,8,8,8,8,16,16,16,16 };
140  static integer iblist[53] = { 13,12,11,1,2,13,12,11,1,2,13,10,11,2,1,10,
141  13,12,11,10,2,13,12,11,10,2,1,12,7,6,1,10,9,8,7,4,6,9,8,7,5,1,9,8,
142  4,6,1,5,9,8,7,5,6 };
143 
144  /* System generated locals */
145  integer i__1;
146 
147  /* Local variables */
148  integer itab[13], i__;
149 
150 /* Arguments */
151 /* Parameters/constants */
152 /* These arrays are not Fortran PARAMETER's, but they are defined */
153 /* by DATA statements below, and their contents are never altered.
154 */
155 /* Local variables that need not be saved */
156 /* Local state */
157 /* ISYNC is only used by CHANWR, not by ENTRY CHANRD. */
158 
159  /* Parameter adjustments */
160  --irc;
161  --ibits;
162 
163  /* Function Body */
164  switch(n__) {
165  case 1: goto L_chanrd;
166  }
167 
168  isync = &(st->isync);
169 
170 /* ***********************************************************************
171  */
172 /* Place quantized parameters into bitstream */
173 /* ***********************************************************************
174  */
175 /* Place parameters into ITAB */
176  itab[0] = *ipitv;
177  itab[1] = *irms;
178  itab[2] = 0;
179  i__1 = *order;
180  for (i__ = 1; i__ <= i__1; ++i__) {
181  itab[i__ + 2] = irc[*order + 1 - i__] & 32767;
182  }
183 /* Put 54 bits into IBITS array */
184  for (i__ = 1; i__ <= 53; ++i__) {
185  ibits[i__] = itab[iblist[i__ - 1] - 1] & 1;
186  itab[iblist[i__ - 1] - 1] /= 2;
187  }
188  ibits[54] = *isync & 1;
189  *isync = 1 - *isync;
190  return 0;
191 /* ***********************************************************************
192  */
193 /* Reconstruct parameters from bitstream */
194 /* ***********************************************************************
195  */
196 
197 L_chanrd:
198 /* Reconstruct ITAB */
199  for (i__ = 1; i__ <= 13; ++i__) {
200  itab[i__ - 1] = 0;
201  }
202  for (i__ = 1; i__ <= 53; ++i__) {
203  itab[iblist[54 - i__ - 1] - 1] = (itab[iblist[54 - i__ - 1] - 1] << 1)
204  + ibits[54 - i__];
205  }
206 /* Sign extend RC's */
207  i__1 = *order;
208  for (i__ = 1; i__ <= i__1; ++i__) {
209  if ((itab[i__ + 2] & bit[i__ - 1]) != 0) {
210  itab[i__ + 2] -= bit[i__ - 1] << 1;
211  }
212  }
213 /* Restore variables */
214  *ipitv = itab[0];
215  *irms = itab[1];
216  i__1 = *order;
217  for (i__ = 1; i__ <= i__1; ++i__) {
218  irc[i__] = itab[*order + 4 - i__ - 1];
219  }
220  return 0;
221 } /* chanwr_ */
integer order
Definition: analys.c:66
integer isync
Definition: lpc10.h:144
INT32 integer
Definition: lpc10.h:80

◆ dcbias_()

int dcbias_ ( integer len,
real speech,
real sigout 
)

Definition at line 79 of file dcbias.c.

References len().

Referenced by analys_().

80 {
81  /* System generated locals */
82  integer i__1;
83 
84  /* Local variables */
85  real bias;
86  integer i__;
87 
88 /* Arguments */
89 /* Local variables that need not be saved */
90  /* Parameter adjustments */
91  --sigout;
92  --speech;
93 
94  /* Function Body */
95  bias = 0.f;
96  i__1 = *len;
97  for (i__ = 1; i__ <= i__1; ++i__) {
98  bias += speech[i__];
99  }
100  bias /= *len;
101  i__1 = *len;
102  for (i__ = 1; i__ <= i__1; ++i__) {
103  sigout[i__] = speech[i__] - bias;
104  }
105  return 0;
106 } /* dcbias_ */
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ decode_()

int decode_ ( integer ipitv,
integer irms,
integer irc,
integer voice,
integer pitch,
real rms,
real rc,
struct lpc10_decoder_state st 
)

Definition at line 147 of file lpc10/decode.c.

References abs, c__2, contrl_1, lpc10_decoder_state::dpit, lpc10_decoder_state::drc, lpc10_decoder_state::drms, lpc10_decoder_state::erate, FALSE_, lpc10_decoder_state::first, first, ham84_(), lpc10_decoder_state::iavgp, lpc10_decoder_state::iovoic, lpc10_decoder_state::iptold, lpc10_decoder_state::ivp2h, median_(), and pow_ii().

Referenced by lpc10_decode().

150 {
151  /* Initialized data */
152 
153  logical *first;
154  static integer ethrs = 2048;
155  static integer ethrs1 = 128;
156  static integer ethrs2 = 1024;
157  static integer ethrs3 = 2048;
158  static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,
159  25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,
160  24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,
161  3641 };
162  static real corth[32] /* was [4][8] */ = { 32767.f,10.f,5.f,0.f,
163  32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,
164  11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,
165  3.2f,0.f };
166  static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,
167  20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,
168  3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,
169  100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,
170  3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,
171  3,3,3,3,1,3,3,3,1,3,1,1,1 };
172  static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
173  384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
174  92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
175  14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
176  static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,
177  96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,
178  127 };
179  static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,
180  .3828f };
181  integer *ivp2h;
182  static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }
183  ;
184  static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };
185  static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };
186  static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };
187  static integer bit[5] = { 2,4,8,16,32 };
188  integer *iovoic;
189  integer *iavgp;
190  integer *iptold;
191  integer *erate;
192  integer *drc;
193  integer *dpit;
194  integer *drms;
195 
196  /* System generated locals */
197  integer i__1, i__2;
198 
199  /* Builtin functions */
201 
202  /* Local variables */
203  extern /* Subroutine */ int ham84_(integer *, integer *, integer *);
204  integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;
205  extern integer median_(integer *, integer *, integer *);
206  integer ishift, errcnt, lsb;
207 
208 /* $Log$
209  * Revision 1.16 2004/06/26 03:50:14 markster
210  * Merge source cleanups (bug #1911)
211  *
212  * Revision 1.15 2003/09/19 01:20:22 markster
213  * Code cleanups (bug #66)
214  *
215  * Revision 1.2 2003/09/19 01:20:22 markster
216  * Code cleanups (bug #66)
217  *
218  * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
219  * mer feb 12 14:56:57 CET 2003
220  *
221  * Revision 1.2 2000/01/05 08:20:39 markster
222  * Some OSS fixes and a few lpc changes to make it actually work
223  *
224  * Revision 1.2 1996/08/20 20:22:39 jaf
225  * Removed all static local variables that were SAVE'd in the Fortran
226  * code, and put them in struct lpc10_decoder_state that is passed as an
227  * argument.
228  *
229  * Removed init function, since all initialization is now done in
230  * init_lpc10_decoder_state().
231  *
232  * Revision 1.1 1996/08/19 22:32:38 jaf
233  * Initial revision
234  * */
235 /* Revision 1.3 1996/03/29 22:03:47 jaf */
236 /* Removed definitions for any constants that were no longer used. */
237 
238 /* Revision 1.2 1996/03/26 19:34:33 jaf */
239 /* Added comments indicating which constants are not needed in an */
240 /* application that uses the LPC-10 coder. */
241 
242 /* Revision 1.1 1996/02/07 14:43:51 jaf */
243 /* Initial revision */
244 
245 /* LPC Configuration parameters: */
246 /* Frame size, Prediction order, Pitch period */
247 /* Arguments */
248 /* $Log$
249  * Revision 1.16 2004/06/26 03:50:14 markster
250  * Merge source cleanups (bug #1911)
251  *
252  * Revision 1.15 2003/09/19 01:20:22 markster
253  * Code cleanups (bug #66)
254  *
255  * Revision 1.2 2003/09/19 01:20:22 markster
256  * Code cleanups (bug #66)
257  *
258  * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
259  * mer feb 12 14:56:57 CET 2003
260  *
261  * Revision 1.2 2000/01/05 08:20:39 markster
262  * Some OSS fixes and a few lpc changes to make it actually work
263  *
264  * Revision 1.2 1996/08/20 20:22:39 jaf
265  * Removed all static local variables that were SAVE'd in the Fortran
266  * code, and put them in struct lpc10_decoder_state that is passed as an
267  * argument.
268  *
269  * Removed init function, since all initialization is now done in
270  * init_lpc10_decoder_state().
271  *
272  * Revision 1.1 1996/08/19 22:32:38 jaf
273  * Initial revision
274  * */
275 /* Revision 1.3 1996/03/29 22:05:55 jaf */
276 /* Commented out the common block variables that are not needed by the */
277 /* embedded version. */
278 
279 /* Revision 1.2 1996/03/26 19:34:50 jaf */
280 /* Added comments indicating which constants are not needed in an */
281 /* application that uses the LPC-10 coder. */
282 
283 /* Revision 1.1 1996/02/07 14:44:09 jaf */
284 /* Initial revision */
285 
286 /* LPC Processing control variables: */
287 
288 /* *** Read-only: initialized in setup */
289 
290 /* Files for Speech, Parameter, and Bitstream Input & Output, */
291 /* and message and debug outputs. */
292 
293 /* Here are the only files which use these variables: */
294 
295 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
296 
297 /* Many files which use fdebug are not listed, since it is only used in */
298 /* those other files conditionally, to print trace statements. */
299 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
300 /* LPC order, Frame size, Quantization rate, Bits per frame, */
301 /* Error correction */
302 /* Subroutine SETUP is the only place where order is assigned a value, */
303 /* and that value is 10. It could increase efficiency 1% or so to */
304 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
305 */
306 /* a variable in a COMMON block, since it is used in many places in the */
307 /* core of the coding and decoding routines. Actually, I take that back.
308 */
309 /* At least when compiling with f2c, the upper bound of DO loops is */
310 /* stored in a local variable before the DO loop begins, and then that is
311 */
312 /* compared against on each iteration. */
313 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
314 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
315 /* is used in only a few places, and never in the core coding and */
316 /* decoding routines, so it could be eliminated entirely. */
317 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
318 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
319 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
320 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
321 */
322 /* a constant or a variable, since it is only examined once per frame. */
323 /* Leaving it as a variable that is set to .TRUE. seems like a good */
324 /* idea, since it does enable some error-correction capability for */
325 /* unvoiced frames, with no change in the coding rate, and no noticeable
326 */
327 /* quality difference in the decoded speech. */
328 /* integer quant, nbits */
329 /* *** Read/write: variables for debugging, not needed for LPC algorithm
330 */
331 
332 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
333 */
334 /* Debug listing detail level, Line count on listing page */
335 
336 /* nframe is not needed for an embedded LPC10 at all. */
337 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
338 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
339 /* an application, I would recommend removing the call to ERROR in RCCHK,
340 */
341 /* and remove ERROR and nunsfm completely. */
342 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
343 */
344 /* sread.f. When LPC10 is embedded into an application, one might want */
345 /* to cause it to be incremented in a routine that takes the output of */
346 /* SYNTHS and sends it to an audio device. It could be optionally */
347 /* displayed, for those that might want to know what it is. */
348 /* maxosp is never initialized to 0 in SETUP, although it probably should
349 */
350 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
351 /* would be of much interest to an application in which LPC10 is */
352 /* embedded. */
353 /* listl and lincnt are not needed for an embedded LPC10 at all. */
354 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
355 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
356 /* common /contrl/ quant, nbits */
357 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
358 /* Function return value definitions */
359 
360 /* Parameters/constants */
361 
362 /* The variables below that are not Fortran PARAMETER's are */
363 /* initialized with DATA statements, and then never modified. */
364 /* The following are used regardless of CORRP's value. */
365 
366 /* DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */
367 
368 /* The following are used only if CORRP is .TRUE. */
369 
370 /* ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */
371 
372 /* Local variables that need not be saved */
373 
374 /* The following are used regardless of CORRP's value */
375 /* The following are used only if CORRP is .TRUE. */
376 
377 /* Local state */
378 
379 /* The following are used regardless of CORRP's value */
380 /* The following are used only if CORRP is .TRUE. */
381 /* I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */
382 /* and DRMS. They should be checked to see if they are reasonable.
383 */
384 /* I'm also guessing for ERATE, but I think 0 is the right initial
385 */
386 /* value. */
387  /* Parameter adjustments */
388  if (irc) {
389  --irc;
390  }
391  if (voice) {
392  --voice;
393  }
394  if (rc) {
395  --rc;
396  }
397 
398  /* Function Body */
399 
400  iptold = &(st->iptold);
401  first = &(st->first);
402  ivp2h = &(st->ivp2h);
403  iovoic = &(st->iovoic);
404  iavgp = &(st->iavgp);
405  erate = &(st->erate);
406  drc = &(st->drc[0]);
407  dpit = &(st->dpit[0]);
408  drms = &(st->drms[0]);
409 
410 /* DATA statements for "constants" defined above. */
411 /* IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) */
412 /* 800 FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) */
413 /* If no error correction, do pitch and voicing then jump to decode */
414  i4 = detau[*ipitv];
415  if (! contrl_1.corrp) {
416  voice[1] = 1;
417  voice[2] = 1;
418  if (*ipitv <= 1) {
419  voice[1] = 0;
420  }
421  if (*ipitv == 0 || *ipitv == 2) {
422  voice[2] = 0;
423  }
424  *pitch = i4;
425  if (*pitch <= 4) {
426  *pitch = *iptold;
427  }
428  if (voice[1] == 1 && voice[2] == 1) {
429  *iptold = *pitch;
430  }
431  if (voice[1] != voice[2]) {
432  *pitch = *iptold;
433  }
434  goto L900;
435  }
436 /* Do error correction pitch and voicing */
437  if (i4 > 4) {
438  dpit[0] = i4;
439  ivoic = 2;
440  *iavgp = (*iavgp * 15 + i4 + 8) / 16;
441  } else {
442  ivoic = i4;
443  dpit[0] = *iavgp;
444  }
445  drms[0] = *irms;
446  i__1 = contrl_1.order;
447  for (i__ = 1; i__ <= i__1; ++i__) {
448  drc[i__ * 3 - 3] = irc[i__];
449  }
450 /* Determine index to IVTAB from V/UV decision */
451 /* If error rate is high then use alternate table */
452  index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;
453  i1 = ivtab[index - 1];
454  ipit = i1 & 3;
455  icorf = i1 / 8;
456  if (*erate < ethrs) {
457  icorf /= 64;
458  }
459 /* Determine error rate: 4=high 1=low */
460  ixcor = 4;
461  if (*erate < ethrs3) {
462  ixcor = 3;
463  }
464  if (*erate < ethrs2) {
465  ixcor = 2;
466  }
467  if (*erate < ethrs1) {
468  ixcor = 1;
469  }
470 /* Voice/unvoice decision determined from bits 0 and 1 of IVTAB */
471  voice[1] = icorf / 2 & 1;
472  voice[2] = icorf & 1;
473 /* Skip decoding on first frame because present data not yet available */
474  if (*first) {
475  *first = FALSE_;
476 /* Assign PITCH a "default" value on the first call, since */
477 /* otherwise it would be left uninitialized. The two lines
478 */
479 /* below were copied from above, since it seemed like a */
480 /* reasonable thing to do for the first call. */
481  *pitch = i4;
482  if (*pitch <= 4) {
483  *pitch = *iptold;
484  }
485  goto L500;
486  }
487 /* If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). */
488 /* Determine error rate and correct errors using a Hamming 8,4 code */
489 /* during transition or unvoiced frame. If IOUT is negative, */
490 /* more than 1 error occurred, use previous frame's parameters. */
491  if ((icorf & bit[3]) != 0) {
492  errcnt = 0;
493  lsb = drms[1] & 1;
494  index = (drc[22] << 4) + drms[1] / 2;
495  ham84_(&index, &iout, &errcnt);
496  drms[1] = drms[2];
497  if (iout >= 0) {
498  drms[1] = (iout << 1) + lsb;
499  }
500  for (i__ = 1; i__ <= 4; ++i__) {
501  if (i__ == 1) {
502  i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);
503  } else {
504  i1 = drc[(9 - i__) * 3 - 2] & 15;
505  }
506  i2 = drc[(5 - i__) * 3 - 2] & 31;
507  lsb = i2 & 1;
508  index = (i1 << 4) + i2 / 2;
509  ham84_(&index, &iout, &errcnt);
510  if (iout >= 0) {
511  iout = (iout << 1) + lsb;
512  if ((iout & 16) == 16) {
513  iout += -32;
514  }
515  } else {
516  iout = drc[(5 - i__) * 3 - 1];
517  }
518  drc[(5 - i__) * 3 - 2] = iout;
519  }
520 /* Determine error rate */
521  *erate = (integer)(*erate * .96875f + errcnt * 102);
522  }
523 /* Get unsmoothed RMS, RC's, and PITCH */
524  *irms = drms[1];
525  i__1 = contrl_1.order;
526  for (i__ = 1; i__ <= i__1; ++i__) {
527  irc[i__] = drc[i__ * 3 - 2];
528  }
529  if (ipit == 1) {
530  dpit[1] = dpit[2];
531  }
532  if (ipit == 3) {
533  dpit[1] = dpit[0];
534  }
535  *pitch = dpit[1];
536 /* If bit 2 of ICORF is set then smooth RMS and RC's, */
537  if ((icorf & bit[1]) != 0) {
538  if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3]
539  && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[
540  ixcor + 3]) {
541  *irms = median_(&drms[2], &drms[1], drms);
542  }
543  for (i__ = 1; i__ <= 6; ++i__) {
544  if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))
545  >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *
546  3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[
547  ixcor + ((i__ + 2) << 2) - 5]) {
548  irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[
549  i__ * 3 - 3]);
550  }
551  }
552  }
553 /* If bit 3 of ICORF is set then smooth pitch */
554  if ((icorf & bit[2]) != 0) {
555  if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1]
556  && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[
557  ixcor - 1]) {
558  *pitch = median_(&dpit[2], &dpit[1], dpit);
559  }
560  }
561 /* If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with */
562 /* values so that after quantization bias is removed in decode */
563 /* the values will be zero. */
564 L500:
565  if ((icorf & bit[4]) != 0) {
566  i__1 = contrl_1.order;
567  for (i__ = 5; i__ <= i__1; ++i__) {
568  irc[i__] = zrc[i__ - 1];
569  }
570  }
571 /* House keeping - one frame delay */
572  *iovoic = ivoic;
573  *ivp2h = voice[2];
574  dpit[2] = dpit[1];
575  dpit[1] = dpit[0];
576  drms[2] = drms[1];
577  drms[1] = drms[0];
578  i__1 = contrl_1.order;
579  for (i__ = 1; i__ <= i__1; ++i__) {
580  drc[i__ * 3 - 1] = drc[i__ * 3 - 2];
581  drc[i__ * 3 - 2] = drc[i__ * 3 - 3];
582  }
583 L900:
584 /* IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) */
585 /* 801 FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) */
586 /* Decode RMS */
587  *irms = rmst[(31 - *irms) * 2];
588 /* Decode RC(1) and RC(2) from log-area-ratios */
589 /* Protect from illegal coded value (-16) caused by bit errors */
590  for (i__ = 1; i__ <= 2; ++i__) {
591  i2 = irc[i__];
592  i1 = 0;
593  if (i2 < 0) {
594  i1 = 1;
595  i2 = -i2;
596  if (i2 > 15) {
597  i2 = 0;
598  }
599  }
600  i2 = detab7[i2 * 2];
601  if (i1 == 1) {
602  i2 = -i2;
603  }
604  ishift = 15 - nbit[i__ - 1];
605  irc[i__] = i2 * pow_ii(&c__2, &ishift);
606  }
607 /* Decode RC(3)-RC(10) to sign plus 14 bits */
608  i__1 = contrl_1.order;
609  for (i__ = 3; i__ <= i__1; ++i__) {
610  i2 = irc[i__];
611  ishift = 15 - nbit[i__ - 1];
612  i2 *= pow_ii(&c__2, &ishift);
613  i2 += qb[i__ - 3];
614  irc[i__] = (integer)(i2 * descl[i__ - 3] + deadd[i__ - 3]);
615  }
616 /* IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) */
617 /* 811 FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) */
618 /* Scale RMS and RC's to reals */
619  *rms = (real) (*irms);
620  i__1 = contrl_1.order;
621  for (i__ = 1; i__ <= i__1; ++i__) {
622  rc[i__] = irc[i__] / 16384.f;
623  }
624  return 0;
625 } /* decode_ */
integer erate
Definition: lpc10.h:157
integer iavgp
Definition: lpc10.h:156
logical first
Definition: lpc10.h:153
integer iptold
Definition: lpc10.h:152
static integer c__2
Definition: lpc10/decode.c:58
#define contrl_1
Definition: lpc10/decode.c:54
integer drms[3]
Definition: lpc10.h:160
integer iovoic
Definition: lpc10.h:155
integer drc[30]
Definition: lpc10.h:158
integer pow_ii(integer *ap, integer *bp)
Definition: f2clib.c:30
integer dpit[3]
Definition: lpc10.h:159
integer median_(integer *d1, integer *d2, integer *d3)
Definition: median.c:69
float real
Definition: lpc10.h:79
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
integer ivp2h
Definition: lpc10.h:154
#define abs(x)
Definition: f2c.h:195
int ham84_(integer *input, integer *output, integer *errcnt)
Definition: ham84.c:85
INT32 logical
Definition: lpc10.h:81
INT32 integer
Definition: lpc10.h:80
#define FALSE_
Definition: f2c.h:68

◆ deemp_()

int deemp_ ( real x,
integer n,
struct lpc10_decoder_state st 
)

Definition at line 106 of file deemp.c.

References lpc10_decoder_state::dei1, lpc10_decoder_state::dei2, lpc10_decoder_state::deo1, lpc10_decoder_state::deo2, and lpc10_decoder_state::deo3.

Referenced by synths_().

107 {
108  /* Initialized data */
109 
110  real *dei1;
111  real *dei2;
112  real *deo1;
113  real *deo2;
114  real *deo3;
115 
116  /* System generated locals */
117  integer i__1;
118  real r__1;
119 
120  /* Local variables */
121  integer k;
122  real dei0;
123 
124 /* Arguments */
125 /* Local variables that need not be saved */
126 /* Local state */
127 /* All of the locals saved below were not given explicit initial */
128 /* values in the original code. I think 0 is a safe choice. */
129  /* Parameter adjustments */
130  if (x) {
131  --x;
132  }
133 
134  /* Function Body */
135 
136  dei1 = &(st->dei1);
137  dei2 = &(st->dei2);
138  deo1 = &(st->deo1);
139  deo2 = &(st->deo2);
140  deo3 = &(st->deo3);
141 
142  i__1 = *n;
143  for (k = 1; k <= i__1; ++k) {
144  dei0 = x[k];
145  r__1 = x[k] - *dei1 * 1.9998f + *dei2;
146  x[k] = r__1 + *deo1 * 2.5f - *deo2 * 2.0925f + *deo3 * .585f;
147  *dei2 = *dei1;
148  *dei1 = dei0;
149  *deo3 = *deo2;
150  *deo2 = *deo1;
151  *deo1 = x[k];
152  }
153  return 0;
154 } /* deemp_ */
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ difmag_()

int difmag_ ( real speech,
integer lpita,
integer tau,
integer ltau,
integer maxlag,
real amdf,
integer minptr,
integer maxptr 
)

Definition at line 90 of file difmag.c.

References abs.

Referenced by tbdm_().

93 {
94  /* System generated locals */
95  integer i__1, i__2;
96  real r__1;
97 
98  /* Local variables */
99  integer i__, j, n1, n2;
100  real sum;
101 
102 /* Arguments */
103 /* Local variables that need not be saved */
104 /* Local state */
105 /* None */
106  /* Parameter adjustments */
107  --amdf;
108  --tau;
109  --speech;
110 
111  /* Function Body */
112  *minptr = 1;
113  *maxptr = 1;
114  i__1 = *ltau;
115  for (i__ = 1; i__ <= i__1; ++i__) {
116  n1 = (*maxlag - tau[i__]) / 2 + 1;
117  n2 = n1 + *lpita - 1;
118  sum = 0.f;
119  i__2 = n2;
120  for (j = n1; j <= i__2; j += 4) {
121  sum += (r__1 = speech[j] - speech[j + tau[i__]], abs(r__1));
122  }
123  amdf[i__] = sum;
124  if (amdf[i__] < amdf[*minptr]) {
125  *minptr = i__;
126  }
127  if (amdf[i__] > amdf[*maxptr]) {
128  *maxptr = i__;
129  }
130  }
131  return 0;
132 } /* difmag_ */
float real
Definition: lpc10.h:79
#define abs(x)
Definition: f2c.h:195
INT32 integer
Definition: lpc10.h:80

◆ dyptrk_()

int dyptrk_ ( real amdf,
integer ltau,
integer minptr,
integer voice,
integer pitch,
integer midx,
struct lpc10_encoder_state st 
)

Definition at line 129 of file dyptrk.c.

References lpc10_encoder_state::alphax, lpc10_encoder_state::ipoint, lpc10_encoder_state::p, and lpc10_encoder_state::s.

Referenced by analys_().

132 {
133  /* Initialized data */
134 
135  real *s;
136  integer *p;
137  integer *ipoint;
138  real *alphax;
139 
140  /* System generated locals */
141  integer i__1;
142 
143  /* Local variables */
144  integer pbar;
145  real sbar;
146  integer iptr, i__, j;
147  real alpha, minsc, maxsc;
148 
149 /* Arguments */
150 /* $Log$
151  * Revision 1.15 2004/06/26 03:50:14 markster
152  * Merge source cleanups (bug #1911)
153  *
154  * Revision 1.14 2003/02/12 13:59:15 matteo
155  * mer feb 12 14:56:57 CET 2003
156  *
157  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
158  * mer feb 12 14:56:57 CET 2003
159  *
160  * Revision 1.2 2000/01/05 08:20:39 markster
161  * Some OSS fixes and a few lpc changes to make it actually work
162  *
163  * Revision 1.2 1996/08/20 20:25:29 jaf
164  * Removed all static local variables that were SAVE'd in the Fortran
165  * code, and put them in struct lpc10_encoder_state that is passed as an
166  * argument.
167  *
168  * Removed init function, since all initialization is now done in
169  * init_lpc10_encoder_state().
170  *
171  * Revision 1.1 1996/08/19 22:32:26 jaf
172  * Initial revision
173  * */
174 /* Revision 1.3 1996/03/29 22:05:55 jaf */
175 /* Commented out the common block variables that are not needed by the */
176 /* embedded version. */
177 
178 /* Revision 1.2 1996/03/26 19:34:50 jaf */
179 /* Added comments indicating which constants are not needed in an */
180 /* application that uses the LPC-10 coder. */
181 
182 /* Revision 1.1 1996/02/07 14:44:09 jaf */
183 /* Initial revision */
184 
185 /* LPC Processing control variables: */
186 
187 /* *** Read-only: initialized in setup */
188 
189 /* Files for Speech, Parameter, and Bitstream Input & Output, */
190 /* and message and debug outputs. */
191 
192 /* Here are the only files which use these variables: */
193 
194 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
195 
196 /* Many files which use fdebug are not listed, since it is only used in */
197 /* those other files conditionally, to print trace statements. */
198 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
199 /* LPC order, Frame size, Quantization rate, Bits per frame, */
200 /* Error correction */
201 /* Subroutine SETUP is the only place where order is assigned a value, */
202 /* and that value is 10. It could increase efficiency 1% or so to */
203 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
204 */
205 /* a variable in a COMMON block, since it is used in many places in the */
206 /* core of the coding and decoding routines. Actually, I take that back.
207 */
208 /* At least when compiling with f2c, the upper bound of DO loops is */
209 /* stored in a local variable before the DO loop begins, and then that is
210 */
211 /* compared against on each iteration. */
212 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
213 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
214 /* is used in only a few places, and never in the core coding and */
215 /* decoding routines, so it could be eliminated entirely. */
216 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
217 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
218 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
219 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
220 */
221 /* a constant or a variable, since it is only examined once per frame. */
222 /* Leaving it as a variable that is set to .TRUE. seems like a good */
223 /* idea, since it does enable some error-correction capability for */
224 /* unvoiced frames, with no change in the coding rate, and no noticeable
225 */
226 /* quality difference in the decoded speech. */
227 /* integer quant, nbits */
228 /* *** Read/write: variables for debugging, not needed for LPC algorithm
229 */
230 
231 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
232 */
233 /* Debug listing detail level, Line count on listing page */
234 
235 /* nframe is not needed for an embedded LPC10 at all. */
236 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
237 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
238 /* an application, I would recommend removing the call to ERROR in RCCHK,
239 */
240 /* and remove ERROR and nunsfm completely. */
241 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
242 */
243 /* sread.f. When LPC10 is embedded into an application, one might want */
244 /* to cause it to be incremented in a routine that takes the output of */
245 /* SYNTHS and sends it to an audio device. It could be optionally */
246 /* displayed, for those that might want to know what it is. */
247 /* maxosp is never initialized to 0 in SETUP, although it probably should
248 */
249 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
250 /* would be of much interest to an application in which LPC10 is */
251 /* embedded. */
252 /* listl and lincnt are not needed for an embedded LPC10 at all. */
253 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
254 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
255 /* common /contrl/ quant, nbits */
256 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
257 /* Parameters/constants */
258 /* Local variables that need not be saved */
259 /* Note that PATH is only used for debugging purposes, and can be */
260 /* removed. */
261 /* Local state */
262 /* It would be a bit more "general" to define S(LTAU), if Fortran */
263 /* allows the argument of a function to be used as the dimension of
264 */
265 /* a local array variable. */
266 /* IPOINT is always in the range 0 to DEPTH-1. */
267 /* WARNING! */
268 
269 /* In the original version of this subroutine, IPOINT, ALPHAX, */
270 /* every element of S, and potentially any element of P with the */
271 /* second index value .NE. IPTR were read without being given */
272 /* initial values (all indices of P with second index equal to */
273 /* IPTR are all written before being read in this subroutine). */
274 
275 /* From examining the code carefully, it appears that all of these
276 */
277 /* should be saved from one invocation to the next. */
278 
279 /* I've run lpcsim with the "-l 6" option to see all of the */
280 /* debugging information that is printed out by this subroutine */
281 /* below, and it appears that S, P, IPOINT, and ALPHAX are all */
282 /* initialized to 0 (these initial values would likely be different
283 */
284 /* on different platforms, compilers, etc.). Given that the output
285 */
286 /* of the coder sounds reasonable, I'm going to initialize these */
287 /* variables to 0 explicitly. */
288 
289  s = &(st->s[0]);
290  p = &(st->p[0]);
291  ipoint = &(st->ipoint);
292  alphax = &(st->alphax);
293 
294 
295  /* Parameter adjustments */
296  if (amdf) {
297  --amdf;
298  }
299 
300  /* Function Body */
301 
302 /* Calculate the confidence factor ALPHA, used as a threshold slope in
303 */
304 /* SEESAW. If unvoiced, set high slope so that every point in P array
305 */
306 /* is marked as a potential pitch frequency. A scaled up version (ALPHAX
307 )*/
308 /* is used to maintain arithmetic precision. */
309  if (*voice == 1) {
310  *alphax = *alphax * .75f + amdf[*minptr] / 2.f;
311  } else {
312  *alphax *= .984375f;
313  }
314  alpha = *alphax / 16;
315  if (*voice == 0 && *alphax < 128.f) {
316  alpha = 8.f;
317  }
318 /* SEESAW: Construct a pitch pointer array and intermediate winner functio
319 n*/
320 /* Left to right pass: */
321  iptr = *ipoint + 1;
322  p[iptr * 60 - 60] = 1;
323  i__ = 1;
324  pbar = 1;
325  sbar = s[0];
326  i__1 = *ltau;
327  for (i__ = 1; i__ <= i__1; ++i__) {
328  sbar += alpha;
329  if (sbar < s[i__ - 1]) {
330  s[i__ - 1] = sbar;
331  p[i__ + iptr * 60 - 61] = pbar;
332  } else {
333  sbar = s[i__ - 1];
334  p[i__ + iptr * 60 - 61] = i__;
335  pbar = i__;
336  }
337  }
338 /* Right to left pass: */
339  i__ = pbar - 1;
340  sbar = s[i__];
341  while(i__ >= 1) {
342  sbar += alpha;
343  if (sbar < s[i__ - 1]) {
344  s[i__ - 1] = sbar;
345  p[i__ + iptr * 60 - 61] = pbar;
346  } else {
347  pbar = p[i__ + iptr * 60 - 61];
348  i__ = pbar;
349  sbar = s[i__ - 1];
350  }
351  --i__;
352  }
353 /* Update S using AMDF */
354 /* Find maximum, minimum, and location of minimum */
355  s[0] += amdf[1] / 2;
356  minsc = s[0];
357  maxsc = minsc;
358  *midx = 1;
359  i__1 = *ltau;
360  for (i__ = 2; i__ <= i__1; ++i__) {
361  s[i__ - 1] += amdf[i__] / 2;
362  if (s[i__ - 1] > maxsc) {
363  maxsc = s[i__ - 1];
364  }
365  if (s[i__ - 1] < minsc) {
366  *midx = i__;
367  minsc = s[i__ - 1];
368  }
369  }
370 /* Subtract MINSC from S to prevent overflow */
371  i__1 = *ltau;
372  for (i__ = 1; i__ <= i__1; ++i__) {
373  s[i__ - 1] -= minsc;
374  }
375  maxsc -= minsc;
376 /* Use higher octave pitch if significant null there */
377  j = 0;
378  for (i__ = 20; i__ <= 40; i__ += 10) {
379  if (*midx > i__) {
380  if (s[*midx - i__ - 1] < maxsc / 4) {
381  j = i__;
382  }
383  }
384  }
385  *midx -= j;
386 /* TRACE: look back two frames to find minimum cost pitch estimate */
387  j = *ipoint;
388  *pitch = *midx;
389  for (i__ = 1; i__ <= 2; ++i__) {
390  j = j % 2 + 1;
391  *pitch = p[*pitch + j * 60 - 61];
392  }
393 
394 /* The following statement subtracts one from IPOINT, mod DEPTH. I
395 */
396 /* think the author chose to add DEPTH-1, instead of subtracting 1,
397 */
398 /* because then it will work even if MOD doesn't work as desired on
399 */
400 /* negative arguments. */
401 
402  *ipoint = (*ipoint + 1) % 2;
403  return 0;
404 } /* dyptrk_ */
integer p[120]
Definition: lpc10.h:139
float real
Definition: lpc10.h:79
real s[60]
Definition: lpc10.h:138
integer ipoint
Definition: lpc10.h:140
INT32 integer
Definition: lpc10.h:80

◆ encode_()

int encode_ ( integer voice,
integer pitch,
real rms,
real rc,
integer ipitch,
integer irms,
integer irc 
)

Definition at line 111 of file encode.c.

References c__2, contrl_1, max, min, and pow_ii().

Referenced by lpc10_encode().

113 {
114  /* Initialized data */
115 
116  static integer enctab[16] = { 0,7,11,12,13,10,6,1,14,9,5,2,3,4,8,15 };
117  static integer entau[60] = { 19,11,27,25,29,21,23,22,30,14,15,7,39,38,46,
118  42,43,41,45,37,53,49,51,50,54,52,60,56,58,26,90,88,92,84,86,82,83,
119  81,85,69,77,73,75,74,78,70,71,67,99,97,113,112,114,98,106,104,108,
120  100,101,76 };
121  static integer enadd[8] = { 1920,-768,2432,1280,3584,1536,2816,-1152 };
122  static real enscl[8] = { .0204f,.0167f,.0145f,.0147f,.0143f,.0135f,.0125f,
123  .0112f };
124  static integer enbits[8] = { 6,5,4,4,4,4,3,3 };
125  static integer entab6[64] = { 0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,
126  3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,9,9,
127  9,10,10,11,11,12,13,14,15 };
128  static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
129  384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
130  92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
131  14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
132 
133  /* System generated locals */
134  integer i__1, i__2;
135 
136  /* Builtin functions */
138 
139  /* Local variables */
140  integer idel, nbit, i__, j, i2, i3, mrk;
141 
142 /* $Log$
143  * Revision 1.15 2004/06/26 03:50:14 markster
144  * Merge source cleanups (bug #1911)
145  *
146  * Revision 1.14 2003/02/12 13:59:15 matteo
147  * mer feb 12 14:56:57 CET 2003
148  *
149  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
150  * mer feb 12 14:56:57 CET 2003
151  *
152  * Revision 1.2 2000/01/05 08:20:39 markster
153  * Some OSS fixes and a few lpc changes to make it actually work
154  *
155  * Revision 1.1 1996/08/19 22:32:21 jaf
156  * Initial revision
157  * */
158 /* Revision 1.3 1996/03/29 22:03:47 jaf */
159 /* Removed definitions for any constants that were no longer used. */
160 
161 /* Revision 1.2 1996/03/26 19:34:33 jaf */
162 /* Added comments indicating which constants are not needed in an */
163 /* application that uses the LPC-10 coder. */
164 
165 /* Revision 1.1 1996/02/07 14:43:51 jaf */
166 /* Initial revision */
167 
168 /* LPC Configuration parameters: */
169 /* Frame size, Prediction order, Pitch period */
170 /* Arguments */
171 /* $Log$
172  * Revision 1.15 2004/06/26 03:50:14 markster
173  * Merge source cleanups (bug #1911)
174  *
175  * Revision 1.14 2003/02/12 13:59:15 matteo
176  * mer feb 12 14:56:57 CET 2003
177  *
178  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
179  * mer feb 12 14:56:57 CET 2003
180  *
181  * Revision 1.2 2000/01/05 08:20:39 markster
182  * Some OSS fixes and a few lpc changes to make it actually work
183  *
184  * Revision 1.1 1996/08/19 22:32:21 jaf
185  * Initial revision
186  * */
187 /* Revision 1.3 1996/03/29 22:05:55 jaf */
188 /* Commented out the common block variables that are not needed by the */
189 /* embedded version. */
190 
191 /* Revision 1.2 1996/03/26 19:34:50 jaf */
192 /* Added comments indicating which constants are not needed in an */
193 /* application that uses the LPC-10 coder. */
194 
195 /* Revision 1.1 1996/02/07 14:44:09 jaf */
196 /* Initial revision */
197 
198 /* LPC Processing control variables: */
199 
200 /* *** Read-only: initialized in setup */
201 
202 /* Files for Speech, Parameter, and Bitstream Input & Output, */
203 /* and message and debug outputs. */
204 
205 /* Here are the only files which use these variables: */
206 
207 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
208 
209 /* Many files which use fdebug are not listed, since it is only used in */
210 /* those other files conditionally, to print trace statements. */
211 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
212 /* LPC order, Frame size, Quantization rate, Bits per frame, */
213 /* Error correction */
214 /* Subroutine SETUP is the only place where order is assigned a value, */
215 /* and that value is 10. It could increase efficiency 1% or so to */
216 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
217 */
218 /* a variable in a COMMON block, since it is used in many places in the */
219 /* core of the coding and decoding routines. Actually, I take that back.
220 */
221 /* At least when compiling with f2c, the upper bound of DO loops is */
222 /* stored in a local variable before the DO loop begins, and then that is
223 */
224 /* compared against on each iteration. */
225 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
226 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
227 /* is used in only a few places, and never in the core coding and */
228 /* decoding routines, so it could be eliminated entirely. */
229 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
230 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
231 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
232 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
233 */
234 /* a constant or a variable, since it is only examined once per frame. */
235 /* Leaving it as a variable that is set to .TRUE. seems like a good */
236 /* idea, since it does enable some error-correction capability for */
237 /* unvoiced frames, with no change in the coding rate, and no noticeable
238 */
239 /* quality difference in the decoded speech. */
240 /* integer quant, nbits */
241 /* *** Read/write: variables for debugging, not needed for LPC algorithm
242 */
243 
244 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
245 */
246 /* Debug listing detail level, Line count on listing page */
247 
248 /* nframe is not needed for an embedded LPC10 at all. */
249 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
250 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
251 /* an application, I would recommend removing the call to ERROR in RCCHK,
252 */
253 /* and remove ERROR and nunsfm completely. */
254 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
255 */
256 /* sread.f. When LPC10 is embedded into an application, one might want */
257 /* to cause it to be incremented in a routine that takes the output of */
258 /* SYNTHS and sends it to an audio device. It could be optionally */
259 /* displayed, for those that might want to know what it is. */
260 /* maxosp is never initialized to 0 in SETUP, although it probably should
261 */
262 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
263 /* would be of much interest to an application in which LPC10 is */
264 /* embedded. */
265 /* listl and lincnt are not needed for an embedded LPC10 at all. */
266 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
267 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
268 /* common /contrl/ quant, nbits */
269 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
270 /* Parameters/constants */
271 /* These arrays are not Fortran PARAMETER's, but they are defined */
272 /* by DATA statements below, and their contents are never altered.
273 */
274 /* Local variables that need not be saved */
275  /* Parameter adjustments */
276  --irc;
277  --rc;
278  --voice;
279 
280  /* Function Body */
281 /* Scale RMS and RC's to integers */
282  *irms = (integer)*rms;
283  i__1 = contrl_1.order;
284  for (i__ = 1; i__ <= i__1; ++i__) {
285  irc[i__] = (integer)(rc[i__] * 32768.f);
286  }
287 /* IF(LISTL.GE.3)WRITE(FDEBUG,800)VOICE,PITCH,IRMS,(IRC(I),I=1,ORDER) */
288 /* 800 FORMAT(1X,/,' <<ENCODE IN>>',T32,2I3,I6,I5,T50,10I8) */
289 /* Encode pitch and voicing */
290  if (voice[1] != 0 && voice[2] != 0) {
291  *ipitch = entau[*pitch - 1];
292  } else {
293  if (contrl_1.corrp) {
294  *ipitch = 0;
295  if (voice[1] != voice[2]) {
296  *ipitch = 127;
297  }
298  } else {
299  *ipitch = (voice[1] << 1) + voice[2];
300  }
301  }
302 /* Encode RMS by binary table search */
303  j = 32;
304  idel = 16;
305  *irms = min(*irms,1023);
306  while(idel > 0) {
307  if (*irms > rmst[j - 1]) {
308  j -= idel;
309  }
310  if (*irms < rmst[j - 1]) {
311  j += idel;
312  }
313  idel /= 2;
314  }
315  if (*irms > rmst[j - 1]) {
316  --j;
317  }
318  *irms = 31 - j / 2;
319 /* Encode RC(1) and (2) as log-area-ratios */
320  for (i__ = 1; i__ <= 2; ++i__) {
321  i2 = irc[i__];
322  mrk = 0;
323  if (i2 < 0) {
324  i2 = -i2;
325  mrk = 1;
326  }
327  i2 /= 512;
328  i2 = min(i2,63);
329  i2 = entab6[i2];
330  if (mrk != 0) {
331  i2 = -i2;
332  }
333  irc[i__] = i2;
334  }
335 /* Encode RC(3) - (10) linearly, remove bias then scale */
336  i__1 = contrl_1.order;
337  for (i__ = 3; i__ <= i__1; ++i__) {
338  i2 = irc[i__] / 2;
339  i2 = (integer)((i2 + enadd[contrl_1.order + 1 - i__ - 1]) * enscl[
340  contrl_1.order + 1 - i__ - 1]);
341 /* Computing MIN */
342  i__2 = max(i2,-127);
343  i2 = min(i__2,127);
344  nbit = enbits[contrl_1.order + 1 - i__ - 1];
345  i3 = 0;
346  if (i2 < 0) {
347  i3 = -1;
348  }
349  i2 /= pow_ii(&c__2, &nbit);
350  if (i3 == -1) {
351  --i2;
352  }
353  irc[i__] = i2;
354  }
355 /* Protect the most significant bits of the most */
356 /* important parameters during non-voiced frames. */
357 /* RC(1) - RC(4) are protected using 20 parity bits */
358 /* replacing RC(5) - RC(10). */
359  if (contrl_1.corrp) {
360  if (*ipitch == 0 || *ipitch == 127) {
361  irc[5] = enctab[(irc[1] & 30) / 2];
362  irc[6] = enctab[(irc[2] & 30) / 2];
363  irc[7] = enctab[(irc[3] & 30) / 2];
364  irc[8] = enctab[(*irms & 30) / 2];
365  irc[9] = enctab[(irc[4] & 30) / 2] / 2;
366  irc[10] = enctab[(irc[4] & 30) / 2] & 1;
367  }
368  }
369 /* IF(LISTL.GE.3)WRITE(FDEBUG,801)VOICE,IPITCH,IRMS,(IRC(J),J=1,ORDER) */
370 /* 801 FORMAT(1X,'<<ENCODE OUT>>',T32,2I3,I6,I5,T50,10I8) */
371  return 0;
372 } /* encode_ */
#define contrl_1
Definition: encode.c:41
static integer c__2
Definition: encode.c:45
integer pow_ii(integer *ap, integer *bp)
Definition: f2clib.c:30
float real
Definition: lpc10.h:79
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
#define max(a, b)
Definition: f2c.h:198

◆ energy_()

int energy_ ( integer len,
real speech,
real rms 
)

Definition at line 78 of file energy.c.

References len().

Referenced by analys_().

79 {
80  /* System generated locals */
81  integer i__1;
82 
83  /* Builtin functions */
84  double sqrt(doublereal);
85 
86  /* Local variables */
87  integer i__;
88 
89 /* Arguments */
90 /* Local variables that need not be saved */
91  /* Parameter adjustments */
92  --speech;
93 
94  /* Function Body */
95  *rms = 0.f;
96  i__1 = *len;
97  for (i__ = 1; i__ <= i__1; ++i__) {
98  *rms += speech[i__] * speech[i__];
99  }
100  *rms = (real)sqrt(*rms / *len);
101  return 0;
102 } /* energy_ */
double doublereal
Definition: f2c.h:50
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ ham84_()

int ham84_ ( integer input,
integer output,
integer errcnt 
)

Definition at line 85 of file ham84.c.

References gsm_state::j.

Referenced by decode_().

86 {
87  /* Initialized data */
88 
89  static integer dactab[128] = { 16,0,0,3,0,5,14,7,0,9,14,11,14,13,30,14,0,
90  9,2,7,4,7,7,23,9,25,10,9,12,9,14,7,0,5,2,11,5,21,6,5,8,11,11,27,
91  12,5,14,11,2,1,18,2,12,5,2,7,12,9,2,11,28,12,12,15,0,3,3,19,4,13,
92  6,3,8,13,10,3,13,29,14,13,4,1,10,3,20,4,4,7,10,9,26,10,4,13,10,15,
93  8,1,6,3,6,5,22,6,24,8,8,11,8,13,6,15,1,17,2,1,4,1,6,15,8,1,10,15,
94  12,15,15,31 };
95 
96  integer i__, j, parity;
97 
98 /* Arguments */
99 /* Parameters/constants */
100 /* Local variables that need not be saved */
101 /* Determine parity of input word */
102  parity = *input & 255;
103  parity ^= parity / 16;
104  parity ^= parity / 4;
105  parity ^= parity / 2;
106  parity &= 1;
107  i__ = dactab[*input & 127];
108  *output = i__ & 15;
109  j = i__ & 16;
110  if (j != 0) {
111 /* No errors detected in seven bits */
112  if (parity != 0) {
113  ++(*errcnt);
114  }
115  } else {
116 /* One or two errors detected */
117  ++(*errcnt);
118  if (parity == 0) {
119 /* Two errors detected */
120  ++(*errcnt);
121  *output = -1;
122  }
123  }
124  return 0;
125 } /* ham84_ */
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1584
INT32 integer
Definition: lpc10.h:80

◆ hp100_()

int hp100_ ( real speech,
integer start,
integer end,
struct lpc10_encoder_state st 
)

Definition at line 113 of file hp100.c.

References end, lpc10_encoder_state::z11, lpc10_encoder_state::z12, lpc10_encoder_state::z21, and lpc10_encoder_state::z22.

Referenced by prepro_().

115 {
116  /* Temporary local copies of variables in lpc10_encoder_state.
117  I've only created these because it might cause the loop below
118  to execute a bit faster to access local variables, rather than
119  variables in the lpc10_encoder_state structure. It is just a
120  guess that it will be faster. */
121 
122  real z11;
123  real z21;
124  real z12;
125  real z22;
126 
127  /* System generated locals */
128  integer i__1;
129 
130  /* Local variables */
131  integer i__;
132  real si, err;
133 
134 /* Arguments */
135 /* Local variables that need not be saved */
136 /* Local state */
137  /* Parameter adjustments */
138  if (speech) {
139  --speech;
140  }
141 
142  /* Function Body */
143 
144  z11 = st->z11;
145  z21 = st->z21;
146  z12 = st->z12;
147  z22 = st->z22;
148 
149  i__1 = *end;
150  for (i__ = *start; i__ <= i__1; ++i__) {
151  si = speech[i__];
152  err = si + z11 * 1.859076f - z21 * .8648249f;
153  si = err - z11 * 2.f + z21;
154  z21 = z11;
155  z11 = err;
156  err = si + z12 * 1.935715f - z22 * .9417004f;
157  si = err - z12 * 2.f + z22;
158  z22 = z12;
159  z12 = err;
160  speech[i__] = si * .902428f;
161  }
162 
163  st->z11 = z11;
164  st->z21 = z21;
165  st->z12 = z12;
166  st->z22 = z22;
167 
168  return 0;
169 } /* hp100_ */
char * end
Definition: eagi_proxy.c:73
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ i_nint()

integer i_nint ( real x)

Definition at line 80 of file f2clib.c.

Referenced by placea_(), r_sign(), voicin_(), and vparms_().

82 {
83 return( (integer)((*x)>=0 ?
84  floor(*x + .5) : -floor(.5 - *x)) );
85 }
INT32 integer
Definition: lpc10.h:80

◆ inithp100_()

int inithp100_ ( void  )

◆ initlpcdec_()

int initlpcdec_ ( void  )

◆ initlpcenc_()

int initlpcenc_ ( void  )

◆ invert_()

int invert_ ( integer order,
real phi,
real psi,
real rc 
)

Definition at line 93 of file invert.c.

References abs, max, min, and order.

Referenced by analys_().

94 {
95  /* System generated locals */
96  unsigned i__2;
97  integer phi_dim1, phi_offset, i__1, i__3;
98  real r__1, r__2;
99 
100  /* Local variables */
101  real save;
102  integer i__, j, k;
103  real v[100] /* was [10][10] */;
104 
105 /* Arguments */
106 /* $Log$
107  * Revision 1.15 2004/06/26 03:50:14 markster
108  * Merge source cleanups (bug #1911)
109  *
110  * Revision 1.14 2003/02/12 13:59:15 matteo
111  * mer feb 12 14:56:57 CET 2003
112  *
113  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
114  * mer feb 12 14:56:57 CET 2003
115  *
116  * Revision 1.2 2000/01/05 08:20:39 markster
117  * Some OSS fixes and a few lpc changes to make it actually work
118  *
119  * Revision 1.1 1996/08/19 22:32:00 jaf
120  * Initial revision
121  * */
122 /* Revision 1.3 1996/03/29 22:03:47 jaf */
123 /* Removed definitions for any constants that were no longer used. */
124 
125 /* Revision 1.2 1996/03/26 19:34:33 jaf */
126 /* Added comments indicating which constants are not needed in an */
127 /* application that uses the LPC-10 coder. */
128 
129 /* Revision 1.1 1996/02/07 14:43:51 jaf */
130 /* Initial revision */
131 
132 /* LPC Configuration parameters: */
133 /* Frame size, Prediction order, Pitch period */
134 /* Parameters/constants */
135 /* Local variables that need not be saved */
136 /* Decompose PHI into V * D * V' where V is a triangular matrix whose */
137 /* main diagonal elements are all 1, V' is the transpose of V, and */
138 /* D is a vector. Here D(n) is stored in location V(n,n). */
139  /* Parameter adjustments */
140  --rc;
141  --psi;
142  phi_dim1 = *order;
143  phi_offset = phi_dim1 + 1;
144  phi -= phi_offset;
145 
146  /* Function Body */
147  i__1 = *order;
148  for (j = 1; j <= i__1; ++j) {
149  i__2 = *order;
150  for (i__ = j; i__ <= i__2; ++i__) {
151  v[i__ + j * 10 - 11] = phi[i__ + j * phi_dim1];
152  }
153  i__2 = j - 1;
154  for (k = 1; k <= i__2; ++k) {
155  save = v[j + k * 10 - 11] * v[k + k * 10 - 11];
156  i__3 = *order;
157  for (i__ = j; i__ <= i__3; ++i__) {
158  v[i__ + j * 10 - 11] -= v[i__ + k * 10 - 11] * save;
159  }
160  }
161 /* Compute intermediate results, which are similar to RC's */
162  if ((r__1 = v[j + j * 10 - 11], abs(r__1)) < 1e-10f) {
163  goto L100;
164  }
165  rc[j] = psi[j];
166  i__2 = j - 1;
167  for (k = 1; k <= i__2; ++k) {
168  rc[j] -= rc[k] * v[j + k * 10 - 11];
169  }
170  v[j + j * 10 - 11] = 1.f / v[j + j * 10 - 11];
171  rc[j] *= v[j + j * 10 - 11];
172 /* Computing MAX */
173 /* Computing MIN */
174  r__2 = rc[j];
175  r__1 = min(r__2,.999f);
176  rc[j] = max(r__1,-.999f);
177  }
178  return 0;
179 /* Zero out higher order RC's if algorithm terminated early */
180 L100:
181  i__1 = *order;
182  for (i__ = j; i__ <= i__1; ++i__) {
183  rc[i__] = 0.f;
184  }
185 /* Back substitute for PC's (if needed) */
186 /* 110 DO J = ORDER,1,-1 */
187 /* PC(J) = RC(J) */
188 /* DO I = 1,J-1 */
189 /* PC(J) = PC(J) - PC(I)*V(J,I) */
190 /* END DO */
191 /* END DO */
192  return 0;
193 } /* invert_ */
integer order
Definition: analys.c:66
float real
Definition: lpc10.h:79
#define abs(x)
Definition: f2c.h:195
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
#define max(a, b)
Definition: f2c.h:198

◆ irc2pc_()

int irc2pc_ ( real rc,
real pc,
integer order,
real gprime,
real g2pass 
)

Definition at line 82 of file irc2pc.c.

References order.

Referenced by synths_().

84 {
85  /* System generated locals */
86  integer i__1, i__2;
87 
88  /* Builtin functions */
89  double sqrt(doublereal);
90 
91  /* Local variables */
92  real temp[10];
93  integer i__, j;
94 
95 /* Arguments */
96 /* $Log$
97  * Revision 1.15 2004/06/26 03:50:14 markster
98  * Merge source cleanups (bug #1911)
99  *
100  * Revision 1.14 2003/02/12 13:59:15 matteo
101  * mer feb 12 14:56:57 CET 2003
102  *
103  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
104  * mer feb 12 14:56:57 CET 2003
105  *
106  * Revision 1.2 2000/01/05 08:20:39 markster
107  * Some OSS fixes and a few lpc changes to make it actually work
108  *
109  * Revision 1.1 1996/08/19 22:31:56 jaf
110  * Initial revision
111  * */
112 /* Revision 1.3 1996/03/29 22:03:47 jaf */
113 /* Removed definitions for any constants that were no longer used. */
114 
115 /* Revision 1.2 1996/03/26 19:34:33 jaf */
116 /* Added comments indicating which constants are not needed in an */
117 /* application that uses the LPC-10 coder. */
118 
119 /* Revision 1.1 1996/02/07 14:43:51 jaf */
120 /* Initial revision */
121 
122 /* LPC Configuration parameters: */
123 /* Frame size, Prediction order, Pitch period */
124 /* Local variables that need not be saved */
125  /* Parameter adjustments */
126  --pc;
127  --rc;
128 
129  /* Function Body */
130  *g2pass = 1.f;
131  i__1 = *order;
132  for (i__ = 1; i__ <= i__1; ++i__) {
133  *g2pass *= 1.f - rc[i__] * rc[i__];
134  }
135  *g2pass = *gprime * (real)sqrt(*g2pass);
136  pc[1] = rc[1];
137  i__1 = *order;
138  for (i__ = 2; i__ <= i__1; ++i__) {
139  i__2 = i__ - 1;
140  for (j = 1; j <= i__2; ++j) {
141  temp[j - 1] = pc[j] - rc[i__] * pc[i__ - j];
142  }
143  i__2 = i__ - 1;
144  for (j = 1; j <= i__2; ++j) {
145  pc[j] = temp[j - 1];
146  }
147  pc[i__] = rc[i__];
148  }
149  return 0;
150 } /* irc2pc_ */
integer order
Definition: analys.c:66
double doublereal
Definition: f2c.h:50
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ ivfilt_()

int ivfilt_ ( real lpbuf,
real ivbuf,
integer len,
integer nsamp,
real ivrc 
)

Definition at line 89 of file ivfilt.c.

References len().

Referenced by analys_().

91 {
92  /* System generated locals */
93  integer i__1;
94 
95  /* Local variables */
96  integer i__, j, k;
97  real r__[3], pc1, pc2;
98 
99 /* Arguments */
100 /* Local variables that need not be saved */
101 /* Local state */
102 /* None */
103 /* Calculate Autocorrelations */
104  /* Parameter adjustments */
105  --ivbuf;
106  --lpbuf;
107  --ivrc;
108 
109  /* Function Body */
110  for (i__ = 1; i__ <= 3; ++i__) {
111  r__[i__ - 1] = 0.f;
112  k = (i__ - 1) << 2;
113  i__1 = *len;
114  for (j = (i__ << 2) + *len - *nsamp; j <= i__1; j += 2) {
115  r__[i__ - 1] += lpbuf[j] * lpbuf[j - k];
116  }
117  }
118 /* Calculate predictor coefficients */
119  pc1 = 0.f;
120  pc2 = 0.f;
121  ivrc[1] = 0.f;
122  ivrc[2] = 0.f;
123  if (r__[0] > 1e-10f) {
124  ivrc[1] = r__[1] / r__[0];
125  ivrc[2] = (r__[2] - ivrc[1] * r__[1]) / (r__[0] - ivrc[1] * r__[1]);
126  pc1 = ivrc[1] - ivrc[1] * ivrc[2];
127  pc2 = ivrc[2];
128  }
129 /* Inverse filter LPBUF into IVBUF */
130  i__1 = *len;
131  for (i__ = *len + 1 - *nsamp; i__ <= i__1; ++i__) {
132  ivbuf[i__] = lpbuf[i__] - pc1 * lpbuf[i__ - 4] - pc2 * lpbuf[i__ - 8];
133  }
134  return 0;
135 } /* ivfilt_ */
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ lpcdec_()

int lpcdec_ ( integer bits,
real speech 
)

◆ lpcenc_()

int lpcenc_ ( real speech,
integer bits 
)

◆ lpfilt_()

int lpfilt_ ( real inbuf,
real lpbuf,
integer len,
integer nsamp 
)

Definition at line 83 of file lpfilt.c.

References inbuf(), lpc10_decoder_state::j, and len().

Referenced by analys_().

85 {
86  /* System generated locals */
87  integer i__1;
88 
89  /* Local variables */
90  integer j;
91  real t;
92 
93 /* Arguments */
94 /* Parameters/constants */
95 /* Local variables that need not be saved */
96 /* Local state */
97 /* None */
98  /* Parameter adjustments */
99  --lpbuf;
100  --inbuf;
101 
102  /* Function Body */
103  i__1 = *len;
104  for (j = *len + 1 - *nsamp; j <= i__1; ++j) {
105  t = (inbuf[j] + inbuf[j - 30]) * -.0097201988f;
106  t += (inbuf[j - 1] + inbuf[j - 29]) * -.0105179986f;
107  t += (inbuf[j - 2] + inbuf[j - 28]) * -.0083479648f;
108  t += (inbuf[j - 3] + inbuf[j - 27]) * 5.860774e-4f;
109  t += (inbuf[j - 4] + inbuf[j - 26]) * .0130892089f;
110  t += (inbuf[j - 5] + inbuf[j - 25]) * .0217052232f;
111  t += (inbuf[j - 6] + inbuf[j - 24]) * .0184161253f;
112  t += (inbuf[j - 7] + inbuf[j - 23]) * 3.39723e-4f;
113  t += (inbuf[j - 8] + inbuf[j - 22]) * -.0260797087f;
114  t += (inbuf[j - 9] + inbuf[j - 21]) * -.0455563702f;
115  t += (inbuf[j - 10] + inbuf[j - 20]) * -.040306855f;
116  t += (inbuf[j - 11] + inbuf[j - 19]) * 5.029835e-4f;
117  t += (inbuf[j - 12] + inbuf[j - 18]) * .0729262903f;
118  t += (inbuf[j - 13] + inbuf[j - 17]) * .1572008878f;
119  t += (inbuf[j - 14] + inbuf[j - 16]) * .2247288674f;
120  t += inbuf[j - 15] * .250535965f;
121  lpbuf[j] = t;
122  }
123  return 0;
124 } /* lpfilt_ */
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ median_()

integer median_ ( integer d1,
integer d2,
integer d3 
)

Definition at line 69 of file median.c.

Referenced by decode_().

70 {
71  /* System generated locals */
72  integer ret_val;
73 
74 /* Arguments */
75  ret_val = *d2;
76  if (*d2 > *d1 && *d2 > *d3) {
77  ret_val = *d1;
78  if (*d3 > *d1) {
79  ret_val = *d3;
80  }
81  } else if (*d2 < *d1 && *d2 < *d3) {
82  ret_val = *d1;
83  if (*d3 < *d1) {
84  ret_val = *d3;
85  }
86  }
87  return ret_val;
88 } /* median_ */
INT32 integer
Definition: lpc10.h:80

◆ mload_()

int mload_ ( integer order,
integer awins,
integer awinf,
real speech,
real phi,
real psi 
)

Definition at line 99 of file mload.c.

References order.

Referenced by analys_().

101 {
102  /* System generated locals */
103  integer phi_dim1, phi_offset, i__1, i__2;
104 
105  /* Local variables */
106  integer c__, i__, r__, start;
107 
108 /* Arguments */
109 /* Local variables that need not be saved */
110 /* Load first column of triangular covariance matrix PHI */
111  /* Parameter adjustments */
112  --psi;
113  phi_dim1 = *order;
114  phi_offset = phi_dim1 + 1;
115  phi -= phi_offset;
116  --speech;
117 
118  /* Function Body */
119  start = *awins + *order;
120  i__1 = *order;
121  for (r__ = 1; r__ <= i__1; ++r__) {
122  phi[r__ + phi_dim1] = 0.f;
123  i__2 = *awinf;
124  for (i__ = start; i__ <= i__2; ++i__) {
125  phi[r__ + phi_dim1] += speech[i__ - 1] * speech[i__ - r__];
126  }
127  }
128 /* Load last element of vector PSI */
129  psi[*order] = 0.f;
130  i__1 = *awinf;
131  for (i__ = start; i__ <= i__1; ++i__) {
132  psi[*order] += speech[i__] * speech[i__ - *order];
133  }
134 /* End correct to get additional columns of PHI */
135  i__1 = *order;
136  for (r__ = 2; r__ <= i__1; ++r__) {
137  i__2 = r__;
138  for (c__ = 2; c__ <= i__2; ++c__) {
139  phi[r__ + c__ * phi_dim1] = phi[r__ - 1 + (c__ - 1) * phi_dim1] -
140  speech[*awinf + 1 - r__] * speech[*awinf + 1 - c__] +
141  speech[start - r__] * speech[start - c__];
142  }
143  }
144 /* End correct to get additional elements of PSI */
145  i__1 = *order - 1;
146  for (c__ = 1; c__ <= i__1; ++c__) {
147  psi[c__] = phi[c__ + 1 + phi_dim1] - speech[start - 1] * speech[start
148  - 1 - c__] + speech[*awinf] * speech[*awinf - c__];
149  }
150 /* Copy lower triangular section into upper (why bother?) */
151 /* I'm commenting this out, since the upper triangular half of PHI
152 */
153 /* is never used by later code, unless a sufficiently high level of
154 */
155 /* tracing is turned on. */
156 /* DO R = 1,ORDER */
157 /* DO C = 1,R-1 */
158 /* PHI(C,R) = PHI(R,C) */
159 /* END DO */
160 /* END DO */
161  return 0;
162 } /* mload_ */
integer order
Definition: analys.c:66
INT32 integer
Definition: lpc10.h:80

◆ onset_()

int onset_ ( real pebuf,
integer osbuf,
integer osptr,
integer oslen,
integer sbufl,
integer sbufh,
integer lframe,
struct lpc10_encoder_state st 
)

Definition at line 129 of file onset.c.

References abs, c_b2, lpc10_encoder_state::d__, FALSE_, lpc10_encoder_state::fpc, lpc10_encoder_state::hyst, lpc10_encoder_state::l2buf, lpc10_encoder_state::l2ptr1, lpc10_encoder_state::l2ptr2, lpc10_encoder_state::l2sum1, lpc10_encoder_state::lasti, lframe, lpc10_encoder_state::n, r_sign(), and TRUE_.

Referenced by analys_().

132 {
133  /* Initialized data */
134 
135  real *n;
136  real *d__;
137  real *l2buf;
138  real *l2sum1;
139  integer *l2ptr1;
140  integer *l2ptr2;
141  logical *hyst;
142 
143  /* System generated locals */
144  integer pebuf_offset, i__1;
145  real r__1;
146 
147  /* Builtin functions */
148  double r_sign(real *, real *);
149 
150  /* Local variables */
151  integer i__;
152  integer *lasti;
153  real l2sum2;
154  real *fpc;
155 
156 /* Arguments */
157 /* $Log$
158  * Revision 1.15 2004/06/26 03:50:14 markster
159  * Merge source cleanups (bug #1911)
160  *
161  * Revision 1.14 2003/02/12 13:59:15 matteo
162  * mer feb 12 14:56:57 CET 2003
163  *
164  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
165  * mer feb 12 14:56:57 CET 2003
166  *
167  * Revision 1.2 2000/01/05 08:20:39 markster
168  * Some OSS fixes and a few lpc changes to make it actually work
169  *
170  * Revision 1.2 1996/08/20 20:37:55 jaf
171  * Removed all static local variables that were SAVE'd in the Fortran
172  * code, and put them in struct lpc10_encoder_state that is passed as an
173  * argument.
174  *
175  * Removed init function, since all initialization is now done in
176  * init_lpc10_encoder_state().
177  *
178  * Revision 1.1 1996/08/19 22:31:18 jaf
179  * Initial revision
180  * */
181 /* Revision 1.3 1996/03/29 22:03:47 jaf */
182 /* Removed definitions for any constants that were no longer used. */
183 
184 /* Revision 1.2 1996/03/26 19:34:33 jaf */
185 /* Added comments indicating which constants are not needed in an */
186 /* application that uses the LPC-10 coder. */
187 
188 /* Revision 1.1 1996/02/07 14:43:51 jaf */
189 /* Initial revision */
190 
191 /* LPC Configuration parameters: */
192 /* Frame size, Prediction order, Pitch period */
193 /* Parameters/constants */
194 /* Parameters for onset detection algorithm: */
195 /* L2 Threshold for filtered slope of FPC (function of L2WID!) */
196 /* L2LAG Lag due to both filters which compute filtered slope of FPC */
197 /* L2WID Width of the filter which computes the slope of FPC */
198 /* OSHYST The number of samples of slope(FPC) which must be below */
199 /* the threshold before a new onset may be declared. */
200 /* Local variables that need not be saved */
201 /* Local state */
202 /* Variables */
203 /* N, D Numerator and denominator of prediction filters */
204 /* FPC Current prediction coefs */
205 /* L2BUF, L2SUM1, L2SUM2 State of slope filter */
206 /* The only "significant" change I've made is to change L2SUM2 out
207 */
208 /* of the list of local variables that need to be saved, since it */
209 /* didn't need to be. */
210 /* L2SUM1 need not be, but avoiding saving it would require a small
211 */
212 /* change to the body of the code. See comments below for an */
213 /* example of how the code could be changed to avoid saving L2SUM1.
214 */
215 /* FPC and LASTI are saved from one invocation to the next, but */
216 /* they are not given initial values. This is acceptable, because
217 */
218 /* FPC will be assigned a value the first time that this function */
219 /* is called after D is initialized to 1, since the formula to */
220 /* change D will not change it to 0 in one step, and the IF (D */
221 /* .NE. 0) statement will execute its THEN part, initializing FPC.
222 */
223 
224 /* LASTI's value will not be used until HYST is .TRUE., and */
225 /* whenever HYST is changed from its initial value of .FALSE., */
226 /* LASTI is assigned a value. */
227 /* In a C version of this coder, it would be nice if all of these */
228 /* saved things, in this and all other subroutines, could be stored
229 */
230 /* in a single struct lpc10_coder_state_t, initialized with a call
231 */
232 /* to a function like lpc10_init(&lpc10_coder_state). In this way,
233 */
234 /* a program that used these functions could conveniently alternate
235 */
236 /* coding more than one distinct audio stream. */
237 
238  n = &(st->n);
239  d__ = &(st->d__);
240  fpc = &(st->fpc);
241  l2buf = &(st->l2buf[0]);
242  l2sum1 = &(st->l2sum1);
243  l2ptr1 = &(st->l2ptr1);
244  l2ptr2 = &(st->l2ptr2);
245  lasti = &(st->lasti);
246  hyst = &(st->hyst);
247 
248  /* Parameter adjustments */
249  if (osbuf) {
250  --osbuf;
251  }
252  if (pebuf) {
253  pebuf_offset = *sbufl;
254  pebuf -= pebuf_offset;
255  }
256 
257  /* Function Body */
258 
259 /* The following line subtracted a hard-coded "180" from LASTI, */
260 /* instead of using a variable like LFRAME or a constant like */
261 /* MAXFRM. I changed it to LFRAME, for "generality". */
262  if (*hyst) {
263  *lasti -= *lframe;
264  }
265  i__1 = *sbufh;
266  for (i__ = *sbufh - *lframe + 1; i__ <= i__1; ++i__) {
267 /* Compute FPC; Use old FPC on divide by zero; Clamp FPC to +/- 1.
268 */
269  *n = (pebuf[i__] * pebuf[i__ - 1] + (*n) * 63.f) / 64.f;
270 /* Computing 2nd power */
271  r__1 = pebuf[i__ - 1];
272  *d__ = (r__1 * r__1 + (*d__) * 63.f) / 64.f;
273  if ((*d__) != 0.f) {
274  if (abs(*n) > (*d__)) {
275  *fpc = (real)r_sign(&c_b2, n);
276  } else {
277  *fpc = (*n) / (*d__);
278  }
279  }
280 /* Filter FPC */
281 /* In order to allow L2SUM1 not to be saved from one invocation
282 of */
283 /* this subroutine to the next, one could change the sequence of
284  */
285 /* assignments below, up to the IF statement, to the following.
286  In */
287 /* addition, the initial value of L2PTR2 should be changed to */
288 /* L2WID/2 instead of L2WID/2+1. */
289 
290 /* L2SUM1 = L2BUF(L2PTR2) */
291 /* L2PTR2 = MOD(L2PTR2,L2WID)+1 */
292 /* L2SUM1 = L2SUM1 - L2BUF(L2PTR2) + FPC */
293 /* L2BUF(L2PTR2) = L2SUM1 */
294 
295 /* * The following lines didn't change from the original: */
296 /* L2SUM2 = L2BUF(L2PTR1) */
297 /* L2BUF(L2PTR1) = FPC */
298 /* L2PTR1 = MOD(L2PTR1,L2WID)+1 */
299 
300  l2sum2 = l2buf[*l2ptr1 - 1];
301  *l2sum1 = *l2sum1 - l2buf[*l2ptr2 - 1] + *fpc;
302  l2buf[*l2ptr2 - 1] = *l2sum1;
303  l2buf[*l2ptr1 - 1] = *fpc;
304  *l2ptr1 = *l2ptr1 % 16 + 1;
305  *l2ptr2 = *l2ptr2 % 16 + 1;
306  if ((r__1 = *l2sum1 - l2sum2, abs(r__1)) > 1.7f) {
307  if (! (*hyst)) {
308 /* Ignore if buffer full */
309  if (*osptr <= *oslen) {
310  osbuf[*osptr] = i__ - 9;
311  ++(*osptr);
312  }
313  *hyst = TRUE_;
314  }
315  *lasti = i__;
316 /* After one onset detection, at least OSHYST sample times m
317 ust go */
318 /* by before another is allowed to occur. */
319  } else if ((*hyst) && i__ - *lasti >= 10) {
320  *hyst = FALSE_;
321  }
322  }
323  return 0;
324 } /* onset_ */
#define TRUE_
Definition: f2c.h:67
integer l2ptr1
Definition: lpc10.h:112
logical hyst
Definition: lpc10.h:115
static real c_b2
Definition: onset.c:43
float real
Definition: lpc10.h:79
integer lasti
Definition: lpc10.h:114
double r_sign(real *a, real *b)
Definition: f2clib.c:64
#define abs(x)
Definition: f2c.h:195
real l2buf[16]
Definition: lpc10.h:110
integer l2ptr2
Definition: lpc10.h:113
integer lframe
Definition: analys.c:66
INT32 logical
Definition: lpc10.h:81
INT32 integer
Definition: lpc10.h:80
#define FALSE_
Definition: f2c.h:68

◆ pitsyn_()

int pitsyn_ ( integer order,
integer voice,
integer pitch,
real rms,
real rc,
integer lframe,
integer ivuv,
integer ipiti,
real rmsi,
real rci,
integer nout,
real ratio,
struct lpc10_decoder_state st 
)

Definition at line 132 of file pitsyn.c.

References FALSE_, first, lpc10_decoder_state::first_pitsyn, lpc10_decoder_state::ipito, lpc10_decoder_state::ivoico, lpc10_decoder_state::jsamp, order, lpc10_decoder_state::rco, lpc10_decoder_state::rmso, and TRUE_.

Referenced by synths_().

136 {
137  /* Initialized data */
138 
139  real *rmso;
140  logical *first;
141 
142  /* System generated locals */
143  integer rci_dim1 = 0, rci_offset, i__1, i__2;
144  real r__1;
145 
146  /* Builtin functions */
147  double log(doublereal), exp(doublereal);
148 
149  /* Local variables */
150  real alrn, alro, yarc[10], prop;
151  integer i__, j, vflag, jused, lsamp;
152  integer *jsamp;
153  real slope;
154  integer *ipito;
155  real uvpit;
156  integer ip, nl, ivoice;
157  integer *ivoico;
158  integer istart;
159  real *rco;
160  real xxy;
161 
162 /* Arguments */
163 /* $Log$
164  * Revision 1.16 2004/06/26 03:50:14 markster
165  * Merge source cleanups (bug #1911)
166  *
167  * Revision 1.15 2003/11/23 22:14:32 markster
168  * Various warning cleanups
169  *
170  * Revision 1.14 2003/02/12 13:59:15 matteo
171  * mer feb 12 14:56:57 CET 2003
172  *
173  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
174  * mer feb 12 14:56:57 CET 2003
175  *
176  * Revision 1.2 2000/01/05 08:20:39 markster
177  * Some OSS fixes and a few lpc changes to make it actually work
178  *
179  * Revision 1.2 1996/08/20 20:40:12 jaf
180  * Removed all static local variables that were SAVE'd in the Fortran
181  * code, and put them in struct lpc10_decoder_state that is passed as an
182  * argument.
183  *
184  * Removed init function, since all initialization is now done in
185  * init_lpc10_decoder_state().
186  *
187  * Revision 1.1 1996/08/19 22:31:12 jaf
188  * Initial revision
189  * */
190 /* Revision 1.3 1996/03/29 22:03:47 jaf */
191 /* Removed definitions for any constants that were no longer used. */
192 
193 /* Revision 1.2 1996/03/26 19:34:33 jaf */
194 /* Added comments indicating which constants are not needed in an */
195 /* application that uses the LPC-10 coder. */
196 
197 /* Revision 1.1 1996/02/07 14:43:51 jaf */
198 /* Initial revision */
199 
200 /* LPC Configuration parameters: */
201 /* Frame size, Prediction order, Pitch period */
202 /* Local variables that need not be saved */
203 /* LSAMP is initialized in the IF (FIRST) THEN clause, but it is */
204 /* not used the first time through, and it is given a value before
205 */
206 /* use whenever FIRST is .FALSE., so it appears unnecessary to */
207 /* assign it a value when FIRST is .TRUE. */
208 /* Local state */
209 /* FIRST - .TRUE. only on first call to PITSYN. */
210 /* IVOICO - Previous VOICE(2) value. */
211 /* IPITO - Previous PITCH value. */
212 /* RMSO - Previous RMS value. */
213 /* RCO - Previous RC values. */
214 
215 /* JSAMP - If this routine is called N times with identical values of */
216 /* LFRAME, then the total length of all pitch periods returned */
217 /* is always N*LFRAME-JSAMP, and JSAMP is always in the range 0
218 */
219 /* to MAXPIT-1 (see below for why this is so). Thus JSAMP is */
220 /* the number of samples "left over" from the previous call to */
221 /* PITSYN, that haven't been "used" in a pitch period returned */
222 /* from this subroutine. Every time this subroutine is called,
223 */
224 /* it returns pitch periods with a total length of at most */
225 /* LFRAME+JSAMP. */
226 
227 /* IVOICO, IPITO, RCO, and JSAMP need not be assigned an initial value */
228 /* with a DATA statement, because they are always initialized on the */
229 /* first call to PITSYN. */
230 
231 /* FIRST and RMSO should be initialized with DATA statements, because */
232 /* even on the first call, they are used before being initialized. */
233  /* Parameter adjustments */
234  if (rc) {
235  --rc;
236  }
237  if (rci) {
238  rci_dim1 = *order;
239  rci_offset = rci_dim1 + 1;
240  rci -= rci_offset;
241  }
242  if (voice) {
243  --voice;
244  }
245  if (ivuv) {
246  --ivuv;
247  }
248  if (ipiti) {
249  --ipiti;
250  }
251  if (rmsi) {
252  --rmsi;
253  }
254 
255  /* Function Body */
256  ivoico = &(st->ivoico);
257  ipito = &(st->ipito);
258  rmso = &(st->rmso);
259  rco = &(st->rco[0]);
260  jsamp = &(st->jsamp);
261  first = &(st->first_pitsyn);
262 
263  if (*rms < 1.f) {
264  *rms = 1.f;
265  }
266  if (*rmso < 1.f) {
267  *rmso = 1.f;
268  }
269  uvpit = 0.f;
270  *ratio = *rms / (*rmso + 8.f);
271  if (*first) {
272  lsamp = 0;
273  ivoice = voice[2];
274  if (ivoice == 0) {
275  *pitch = *lframe / 4;
276  }
277  *nout = *lframe / *pitch;
278  *jsamp = *lframe - *nout * *pitch;
279 
280 /* SYNTHS only calls this subroutine with PITCH in the range
281 20 */
282 /* to 156. LFRAME = MAXFRM = 180, so NOUT is somewhere in th
283 e */
284 /* range 1 to 9. */
285 
286 /* JSAMP is "LFRAME mod PITCH", so it is in the range 0 to */
287 /* (PITCH-1), or 0 to MAXPIT-1=155, after the first call. */
288 
289  i__1 = *nout;
290  for (i__ = 1; i__ <= i__1; ++i__) {
291  i__2 = *order;
292  for (j = 1; j <= i__2; ++j) {
293  rci[j + i__ * rci_dim1] = rc[j];
294  }
295  ivuv[i__] = ivoice;
296  ipiti[i__] = *pitch;
297  rmsi[i__] = *rms;
298  }
299  *first = FALSE_;
300  } else {
301  vflag = 0;
302  lsamp = *lframe + *jsamp;
303  slope = (*pitch - *ipito) / (real) lsamp;
304  *nout = 0;
305  jused = 0;
306  istart = 1;
307  if (voice[1] == *ivoico && voice[2] == voice[1]) {
308  if (voice[2] == 0) {
309 /* SSUV - - 0 , 0 , 0 */
310  *pitch = *lframe / 4;
311  *ipito = *pitch;
312  if (*ratio > 8.f) {
313  *rmso = *rms;
314  }
315  }
316 /* SSVC - - 1 , 1 , 1 */
317  slope = (*pitch - *ipito) / (real) lsamp;
318  ivoice = voice[2];
319  } else {
320  if (*ivoico != 1) {
321  if (*ivoico == voice[1]) {
322 /* UV2VC2 - - 0 , 0 , 1 */
323  nl = lsamp - *lframe / 4;
324  } else {
325 /* UV2VC1 - - 0 , 1 , 1 */
326  nl = lsamp - *lframe * 3 / 4;
327  }
328  ipiti[1] = nl / 2;
329  ipiti[2] = nl - ipiti[1];
330  ivuv[1] = 0;
331  ivuv[2] = 0;
332  rmsi[1] = *rmso;
333  rmsi[2] = *rmso;
334  i__1 = *order;
335  for (i__ = 1; i__ <= i__1; ++i__) {
336  rci[i__ + rci_dim1] = rco[i__ - 1];
337  rci[i__ + (rci_dim1 << 1)] = rco[i__ - 1];
338  rco[i__ - 1] = rc[i__];
339  }
340  slope = 0.f;
341  *nout = 2;
342  *ipito = *pitch;
343  jused = nl;
344  istart = nl + 1;
345  ivoice = 1;
346  } else {
347  if (*ivoico != voice[1]) {
348 /* VC2UV1 - - 1 , 0 , 0 */
349  lsamp = *lframe / 4 + *jsamp;
350  } else {
351 /* VC2UV2 - - 1 , 1 , 0 */
352  lsamp = *lframe * 3 / 4 + *jsamp;
353  }
354  i__1 = *order;
355  for (i__ = 1; i__ <= i__1; ++i__) {
356  yarc[i__ - 1] = rc[i__];
357  rc[i__] = rco[i__ - 1];
358  }
359  ivoice = 1;
360  slope = 0.f;
361  vflag = 1;
362  }
363  }
364 /* Here is the value of most variables that are used below, depending
365 on */
366 /* the values of IVOICO, VOICE(1), and VOICE(2). VOICE(1) and VOICE(2
367 ) */
368 /* are input arguments, and IVOICO is the value of VOICE(2) on the */
369 /* previous call (see notes for the IF (NOUT .NE. 0) statement near th
370 e */
371 /* end). Each of these three values is either 0 or 1. These three */
372 /* values below are given as 3-bit long strings, in the order IVOICO,
373 */
374 /* VOICE(1), and VOICE(2). It appears that the code above assumes tha
375 t */
376 /* the bit sequences 010 and 101 never occur, but I wonder whether a
377 */
378 /* large enough number of bit errors in the channel could cause such a
379  */
380 /* thing to happen, and if so, could that cause NOUT to ever go over 1
381 1? */
382 
383 /* Note that all of the 180 values in the table are really LFRAME, but
384  */
385 /* 180 has fewer characters, and it makes the table a little more */
386 /* concrete. If LFRAME is ever changed, keep this in mind. Similarly
387 , */
388 /* 135's are 3*LFRAME/4, and 45's are LFRAME/4. If LFRAME is not a */
389 /* multiple of 4, then the 135 for NL-JSAMP is actually LFRAME-LFRAME/
390 4, */
391 /* and the 45 for NL-JSAMP is actually LFRAME-3*LFRAME/4. */
392 
393 /* Note that LSAMP-JSAMP is given as the variable. This was just for
394 */
395 /* brevity, to avoid adding "+JSAMP" to all of the column entries. */
396 /* Similarly for NL-JSAMP. */
397 
398 /* Variable | 000 001 011,010 111 110 100,101 */
399 /* ------------+-------------------------------------------------- */
400 /* ISTART | 1 NL+1 NL+1 1 1 1 */
401 /* LSAMP-JSAMP | 180 180 180 180 135 45 */
402 /* IPITO | 45 PITCH PITCH oldPITCH oldPITCH oldPITCH */
403 /* SLOPE | 0 0 0 seebelow 0 0 */
404 /* JUSED | 0 NL NL 0 0 0 */
405 /* PITCH | 45 PITCH PITCH PITCH PITCH PITCH */
406 /* NL-JSAMP | -- 135 45 -- -- -- */
407 /* VFLAG | 0 0 0 0 1 1 */
408 /* NOUT | 0 2 2 0 0 0 */
409 /* IVOICE | 0 1 1 1 1 1 */
410 
411 /* while_loop | once once once once twice twice */
412 
413 /* ISTART | -- -- -- -- JUSED+1 JUSED+1 */
414 /* LSAMP-JSAMP | -- -- -- -- 180 180 */
415 /* IPITO | -- -- -- -- oldPITCH oldPITCH */
416 /* SLOPE | -- -- -- -- 0 0 */
417 /* JUSED | -- -- -- -- ?? ?? */
418 /* PITCH | -- -- -- -- PITCH PITCH */
419 /* NL-JSAMP | -- -- -- -- -- -- */
420 /* VFLAG | -- -- -- -- 0 0 */
421 /* NOUT | -- -- -- -- ?? ?? */
422 /* IVOICE | -- -- -- -- 0 0 */
423 
424 
425 /* UVPIT is always 0.0 on the first pass through the DO WHILE (.TRUE.)
426  */
427 /* loop below. */
428 
429 /* The only possible non-0 value of SLOPE (in column 111) is */
430 /* (PITCH-IPITO)/FLOAT(LSAMP) */
431 
432 /* Column 101 is identical to 100. Any good properties we can prove
433 */
434 /* for 100 will also hold for 101. Similarly for 010 and 011. */
435 
436 /* SYNTHS calls this subroutine with PITCH restricted to the range 20
437 to */
438 /* 156. IPITO is similarly restricted to this range, after the first
439 */
440 /* call. IP below is also restricted to this range, given the */
441 /* definitions of IPITO, SLOPE, UVPIT, and that I is in the range ISTA
442 RT */
443 /* to LSAMP. */
444 
445  while(TRUE_) {
446 
447 /* JUSED is the total length of all pitch periods curr
448 ently */
449 /* in the output arrays, in samples. */
450 
451 /* An invariant of the DO I = ISTART,LSAMP loop below,
452  under */
453 /* the condition that IP is always in the range 1 thro
454 ugh */
455 /* MAXPIT, is: */
456 
457 /* (I - MAXPIT) .LE. JUSED .LE. (I-1) */
458 
459 /* Note that the final value of I is LSAMP+1, so that
460 after */
461 /* the DO loop is complete, we know: */
462 
463 /* (LSAMP - MAXPIT + 1) .LE. JUSED .LE. LSAMP */
464 
465  i__1 = lsamp;
466  for (i__ = istart; i__ <= i__1; ++i__) {
467  r__1 = *ipito + slope * i__;
468  ip = (integer)(r__1 + .5f);
469  if (uvpit != 0.f) {
470  ip = (integer)uvpit;
471  }
472  if (ip <= i__ - jused) {
473  ++(*nout);
474 
475 /* The following check is no longer nece
476 ssary, now that */
477 /* we can prove that NOUT will never go
478 over 16. */
479 
480 /* IF (NOUT .GT. 16) STOP 'PITSYN: too many epochs'
481 */
482 
483  ipiti[*nout] = ip;
484  *pitch = ip;
485  ivuv[*nout] = ivoice;
486  jused += ip;
487  prop = (jused - ip / 2) / (real) lsamp;
488  i__2 = *order;
489  for (j = 1; j <= i__2; ++j) {
490  alro = (real)log((rco[j - 1] + 1) / (1 - rco[j - 1]));
491  alrn = (real)log((rc[j] + 1) / (1 - rc[j]));
492  xxy = alro + prop * (alrn - alro);
493  xxy = (real)exp(xxy);
494  rci[j + *nout * rci_dim1] = (xxy - 1) / (xxy + 1);
495  }
496  rmsi[*nout] = (real)(log(*rmso) + prop * (log(*rms) - log(*rmso)));
497  rmsi[*nout] = (real)exp(rmsi[*nout]);
498  }
499  }
500  if (vflag != 1) {
501  goto L100;
502  }
503 
504 /* I want to prove what range UVPIT must lie in after
505 the */
506 /* assignments to it below. To do this, I must determ
507 ine */
508 /* what range (LSAMP-ISTART) must lie in, after the */
509 /* assignments to ISTART and LSAMP below. */
510 
511 /* Let oldLSAMP be the value of LSAMP at this point in
512  the */
513 /* execution. This is 135+JSAMP in state 110, or 45+J
514 SAMP in */
515 /* states 100 or 101. */
516 
517 /* Given the loop invariant on JUSED above, we know th
518 at: */
519 
520 /* (oldLSAMP - MAXPIT + 1) .LE. JUSED .LE. oldLSAMP */
521 
522 /* ISTART is one more than this. */
523 
524 /* Let newLSAMP be the value assigned to LSAMP below.
525  This */
526 /* is 180+JSAMP. Thus (newLSAMP-oldLSAMP) is either 4
527 5 or */
528 /* 135, depending on the state. */
529 
530 /* Thus, the range of newLSAMP-ISTART is: */
531 
532 /* (newLSAMP-(oldLSAMP+1)) .LE. newLSAMP-ISTART */
533 /* .LE. (newLSAMP-(oldLSAMP - MAXPIT + 2)) */
534 
535 /* or: */
536 
537 /* 46 .LE. newLSAMP-ISTART .LE. 133+MAXPIT .EQ. 289 */
538 
539 /* Therefore, UVPIT is in the range 23 to 144 after th
540 e first */
541 /* assignment to UVPIT below, and after the conditiona
542 l */
543 /* assignment, it is in the range 23 to 90. */
544 
545 /* The important thing is that it is in the range 20 t
546 o 156, */
547 /* so that in the loop above, IP is always in this ran
548 ge. */
549 
550  vflag = 0;
551  istart = jused + 1;
552  lsamp = *lframe + *jsamp;
553  slope = 0.f;
554  ivoice = 0;
555  uvpit = (real) ((lsamp - istart) / 2);
556  if (uvpit > 90.f) {
557  uvpit /= 2;
558  }
559  *rmso = *rms;
560  i__1 = *order;
561  for (i__ = 1; i__ <= i__1; ++i__) {
562  rc[i__] = yarc[i__ - 1];
563  rco[i__ - 1] = yarc[i__ - 1];
564  }
565  }
566 L100:
567  *jsamp = lsamp - jused;
568  }
569 /* Given that the maximum pitch period MAXPIT .LT. LFRAME (this is
570 */
571 /* currently true on every call, since SYNTHS always sets */
572 /* LFRAME=180), NOUT will always be .GE. 1 at this point. */
573  if (*nout != 0) {
574  *ivoico = voice[2];
575  *ipito = *pitch;
576  *rmso = *rms;
577  i__1 = *order;
578  for (i__ = 1; i__ <= i__1; ++i__) {
579  rco[i__ - 1] = rc[i__];
580  }
581  }
582  return 0;
583 } /* pitsyn_ */
#define TRUE_
Definition: f2c.h:67
real rco[10]
Definition: lpc10.h:170
integer order
Definition: analys.c:66
double doublereal
Definition: f2c.h:50
float real
Definition: lpc10.h:79
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
integer ipito
Definition: lpc10.h:168
integer lframe
Definition: analys.c:66
logical first_pitsyn
Definition: lpc10.h:172
integer jsamp
Definition: lpc10.h:171
INT32 logical
Definition: lpc10.h:81
integer ivoico
Definition: lpc10.h:167
INT32 integer
Definition: lpc10.h:80
#define FALSE_
Definition: f2c.h:68

◆ placea_()

int placea_ ( integer ipitch,
integer voibuf,
integer obound,
integer af,
integer vwin,
integer awin,
integer ewin,
integer lframe,
integer maxwin 
)

Definition at line 116 of file placea.c.

References FALSE_, i_nint(), lframe, and TRUE_.

Referenced by analys_().

119 {
120  /* System generated locals */
121  real r__1;
122 
123  /* Builtin functions */
124  integer i_nint(real *);
125 
126  /* Local variables */
127  logical allv, winv;
128  integer i__, j, k, l, hrange;
129  logical ephase;
130  integer lrange;
131 
132 /* Arguments */
133 /* Local variables that need not be saved */
134  /* Parameter adjustments */
135  ewin -= 3;
136  awin -= 3;
137  vwin -= 3;
138  --voibuf;
139 
140  /* Function Body */
141  lrange = (*af - 2) * *lframe + 1;
142  hrange = *af * *lframe;
143 /* Place the Analysis window based on the voicing window */
144 /* placement, onsets, tentative voicing decision, and pitch. */
145 
146 /* Case 1: Sustained Voiced Speech */
147 /* If the five most recent voicing decisions are */
148 /* voiced, then the window is placed phase-synchronously with the */
149 /* previous window, as close to the present voicing window if possible.
150 */
151 /* If onsets bound the voicing window, then preference is given to */
152 /* a phase-synchronous placement which does not overlap these onsets. */
153 
154 /* Case 2: Voiced Transition */
155 /* If at least one voicing decision in AF is voicied, and there are no
156 */
157 /* onsets, then the window is placed as in case 1. */
158 
159 /* Case 3: Unvoiced Speech or Onsets */
160 /* If both voicing decisions in AF are unvoiced, or there are onsets, */
161 /* then the window is placed coincident with the voicing window. */
162 
163 /* Note: During phase-synchronous placement of windows, the length */
164 /* is not altered from MAXWIN, since this would defeat the purpose */
165 /* of phase-synchronous placement. */
166 /* Check for case 1 and case 2 */
167  allv = voibuf[((*af - 2) << 1) + 2] == 1;
168  allv = allv && voibuf[((*af - 1) << 1) + 1] == 1;
169  allv = allv && voibuf[((*af - 1) << 1) + 2] == 1;
170  allv = allv && voibuf[(*af << 1) + 1] == 1;
171  allv = allv && voibuf[(*af << 1) + 2] == 1;
172  winv = voibuf[(*af << 1) + 1] == 1 || voibuf[(*af << 1) + 2] == 1;
173  if (allv || (winv && *obound == 0)) {
174 /* APHASE: Phase synchronous window placement. */
175 /* Get minimum lower index of the window. */
176  i__ = (lrange + *ipitch - 1 - awin[((*af - 1) << 1) + 1]) / *ipitch;
177  i__ *= *ipitch;
178  i__ += awin[((*af - 1) << 1) + 1];
179 /* L = the actual length of this frame's analysis window. */
180  l = *maxwin;
181 /* Calculate the location where a perfectly centered window would star
182 t. */
183  k = (vwin[(*af << 1) + 1] + vwin[(*af << 1) + 2] + 1 - l) / 2;
184 /* Choose the actual location to be the pitch multiple closest to this
185 . */
186  r__1 = (real) (k - i__) / *ipitch;
187  awin[(*af << 1) + 1] = i__ + i_nint(&r__1) * *ipitch;
188  awin[(*af << 1) + 2] = awin[(*af << 1) + 1] + l - 1;
189 /* If there is an onset bounding the right of the voicing window and t
190 he */
191 /* analysis window overlaps that, then move the analysis window backwa
192 rd */
193 /* to avoid this onset. */
194  if (*obound >= 2 && awin[(*af << 1) + 2] > vwin[(*af << 1) + 2]) {
195  awin[(*af << 1) + 1] -= *ipitch;
196  awin[(*af << 1) + 2] -= *ipitch;
197  }
198 /* Similarly for the left of the voicing window. */
199  if ((*obound == 1 || *obound == 3) && awin[(*af << 1) + 1] < vwin[(*
200  af << 1) + 1]) {
201  awin[(*af << 1) + 1] += *ipitch;
202  awin[(*af << 1) + 2] += *ipitch;
203  }
204 /* If this placement puts the analysis window above HRANGE, then */
205 /* move it backward an integer number of pitch periods. */
206  while(awin[(*af << 1) + 2] > hrange) {
207  awin[(*af << 1) + 1] -= *ipitch;
208  awin[(*af << 1) + 2] -= *ipitch;
209  }
210 /* Similarly if the placement puts the analysis window below LRANGE.
211 */
212  while(awin[(*af << 1) + 1] < lrange) {
213  awin[(*af << 1) + 1] += *ipitch;
214  awin[(*af << 1) + 2] += *ipitch;
215  }
216 /* Make Energy window be phase-synchronous. */
217  ephase = TRUE_;
218 /* Case 3 */
219  } else {
220  awin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
221  awin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
222  ephase = FALSE_;
223  }
224 /* RMS is computed over an integer number of pitch periods in the analysis
225  */
226 /*window. When it is not placed phase-synchronously, it is placed as clos
227 e*/
228 /* as possible to onsets. */
229  j = (awin[(*af << 1) + 2] - awin[(*af << 1) + 1] + 1) / *ipitch * *ipitch;
230  if (j == 0 || ! winv) {
231  ewin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
232  ewin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
233  } else if (! ephase && *obound == 2) {
234  ewin[(*af << 1) + 1] = awin[(*af << 1) + 2] - j + 1;
235  ewin[(*af << 1) + 2] = awin[(*af << 1) + 2];
236  } else {
237  ewin[(*af << 1) + 1] = awin[(*af << 1) + 1];
238  ewin[(*af << 1) + 2] = awin[(*af << 1) + 1] + j - 1;
239  }
240  return 0;
241 } /* placea_ */
integer i_nint(real *x)
Definition: f2clib.c:80
#define TRUE_
Definition: f2c.h:67
float real
Definition: lpc10.h:79
integer lframe
Definition: analys.c:66
INT32 logical
Definition: lpc10.h:81
INT32 integer
Definition: lpc10.h:80
#define FALSE_
Definition: f2c.h:68

◆ placev_()

int placev_ ( integer osbuf,
integer osptr,
integer oslen,
integer obound,
integer vwin,
integer af,
integer lframe,
integer minwin,
integer maxwin,
integer dvwinl,
integer dvwinh 
)

Definition at line 112 of file placev.c.

References FALSE_, lframe, max, min, and TRUE_.

Referenced by analys_().

115 {
116  /* System generated locals */
117  integer i__1, i__2;
118 
119  /* Local variables */
120  logical crit;
121  integer i__, q, osptr1, hrange, lrange;
122 
123 /* Arguments */
124 /* Local variables that need not be saved */
125 /* Variables */
126 /* LRANGE, HRANGE Range in which window is placed */
127 /* OSPTR1 OSPTR excluding samples in 3F */
128 /* Local state */
129 /* None */
130 /* Voicing Window Placement */
131 
132 /* __________________ __________________ ______________ */
133 /* | | | */
134 /* | 1F | 2F | 3F ... */
135 /* |__________________|__________________|______________ */
136 
137 /* Previous | */
138 /* Window | */
139 /* ...________| */
140 
141 /* | | */
142 /* ------>| This window's placement range |<------ */
143 /* | | */
144 
145 /* There are three cases. Note that these are different from those */
146 /* given in the LPC-10e phase 1 report. */
147 
148 /* 1. If there are no onsets in this range, then the voicing window */
149 /* is centered in the pitch window. If such a placement is not within
150 */
151 /* the window's placement range, then the window is placed in the left-
152 */
153 /* most portion of the placement range. Its length is always MAXWIN. */
154 
155 /* 2. If the first onset is in 2F and there is sufficient room to place
156  */
157 /* the window immediately before this onset, then the window is placed
158 */
159 /* there, and its length is set to the maximum possible under these */
160 /* constraints. */
161 
162 /* "Critical Region Exception": If there is another onset in 2F */
163 /* such that a window can be placed between the two onsets, the */
164 /* window is placed there (ie, as in case 3). */
165 
166 /* 3. Otherwise, the window is placed immediately after the onset. The
167  */
168 /* window's length */
169 /* is the longest length that can fit in the range under these constraint
170 s,*/
171 /* except that the window may be shortened even further to avoid overlapp
172 ing*/
173 /* other onsets in the placement range. In any case, the window's length
174 */
175 /* is at least MINWIN. */
176 
177 /* Note that the values of MINWIN and LFRAME must be chosen such */
178 /* that case 2 = false implies case 3 = true. This means that */
179 /* MINWIN <= LFRAME/2. If this were not the case, then a fourth case */
180 /* would have to be added for when the window cannot fit either before
181 */
182 /* or after the onset. */
183 
184 /* Note also that onsets which weren't in 2F last time may be in 1F this
185  */
186 /* time, due to the filter delays in computing onsets. The result is tha
187 t*/
188 /* occasionally a voicing window will overlap that onset. The only way
189 */
190 /* to circumvent this problem is to add more delay in processing input
191 */
192 /* speech. In the trade-off between delay and window-placement, window
193 */
194 /* placement lost. */
195 /* Compute the placement range */
196  /* Parameter adjustments */
197  --osbuf;
198  vwin -= 3;
199 
200  /* Function Body */
201 /* Computing MAX */
202  i__1 = vwin[((*af - 1) << 1) + 2] + 1, i__2 = (*af - 2) * *lframe + 1;
203  lrange = max(i__1,i__2);
204  hrange = *af * *lframe;
205 /* Compute OSPTR1, so the following code only looks at relevant onsets. */
206  for (osptr1 = *osptr - 1; osptr1 >= 1; --osptr1) {
207  if (osbuf[osptr1] <= hrange) {
208  goto L90;
209  }
210  }
211 L90:
212  ++osptr1;
213 /* Check for case 1 first (fast case): */
214  if (osptr1 <= 1 || osbuf[osptr1 - 1] < lrange) {
215 /* Computing MAX */
216  i__1 = vwin[((*af - 1) << 1) + 2] + 1;
217  vwin[(*af << 1) + 1] = max(i__1,*dvwinl);
218  vwin[(*af << 1) + 2] = vwin[(*af << 1) + 1] + *maxwin - 1;
219  *obound = 0;
220  } else {
221 /* Search backward in OSBUF for first onset in range. */
222 /* This code relies on the above check being performed first. */
223  for (q = osptr1 - 1; q >= 1; --q) {
224  if (osbuf[q] < lrange) {
225  goto L100;
226  }
227  }
228 L100:
229  ++q;
230 /* Check for case 2 (placement before onset): */
231 /* Check for critical region exception: */
232  i__1 = osptr1 - 1;
233  for (i__ = q + 1; i__ <= i__1; ++i__) {
234  if (osbuf[i__] - osbuf[q] >= *minwin) {
235  crit = TRUE_;
236  goto L105;
237  }
238  }
239  crit = FALSE_;
240 L105:
241 /* Computing MAX */
242  i__1 = (*af - 1) * *lframe, i__2 = lrange + *minwin - 1;
243  if (! crit && osbuf[q] > max(i__1,i__2)) {
244  vwin[(*af << 1) + 2] = osbuf[q] - 1;
245 /* Computing MAX */
246  i__1 = lrange, i__2 = vwin[(*af << 1) + 2] - *maxwin + 1;
247  vwin[(*af << 1) + 1] = max(i__1,i__2);
248  *obound = 2;
249 /* Case 3 (placement after onset) */
250  } else {
251  vwin[(*af << 1) + 1] = osbuf[q];
252 L110:
253  ++q;
254  if (q >= osptr1) {
255  goto L120;
256  }
257  if (osbuf[q] > vwin[(*af << 1) + 1] + *maxwin) {
258  goto L120;
259  }
260  if (osbuf[q] < vwin[(*af << 1) + 1] + *minwin) {
261  goto L110;
262  }
263  vwin[(*af << 1) + 2] = osbuf[q] - 1;
264  *obound = 3;
265  return 0;
266 L120:
267 /* Computing MIN */
268  i__1 = vwin[(*af << 1) + 1] + *maxwin - 1;
269  vwin[(*af << 1) + 2] = min(i__1,hrange);
270  *obound = 1;
271  }
272  }
273  return 0;
274 } /* placev_ */
#define TRUE_
Definition: f2c.h:67
integer lframe
Definition: analys.c:66
INT32 logical
Definition: lpc10.h:81
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
#define FALSE_
Definition: f2c.h:68
#define max(a, b)
Definition: f2c.h:198

◆ pow_ii()

integer pow_ii ( integer ap,
integer bp 
)

Definition at line 30 of file f2clib.c.

References a, b, and r_sign().

Referenced by decode_(), and encode_().

32 {
33  integer pow, x, n;
34  unsigned long u;
35 
36  x = *ap;
37  n = *bp;
38 
39  if (n <= 0) {
40  if (n == 0 || x == 1)
41  return 1;
42  if (x != -1)
43  return x == 0 ? 0 : 1/x;
44  n = -n;
45  }
46  u = n;
47  for(pow = 1; ; )
48  {
49  if(u & 01)
50  pow *= x;
51  if(u >>= 1)
52  x *= x;
53  else
54  break;
55  }
56  return(pow);
57  }
INT32 integer
Definition: lpc10.h:80

◆ preemp_()

int preemp_ ( real inbuf,
real pebuf,
integer nsamp,
real coef,
real z__ 
)

Definition at line 82 of file preemp.c.

References inbuf().

Referenced by analys_().

84 {
85  /* System generated locals */
86  integer i__1;
87 
88  /* Local variables */
89  real temp;
90  integer i__;
91 
92 /* Arguments */
93 /* Local variables */
94 
95 /* None of these need to have their values saved from one */
96 /* invocation to the next. */
97 
98 /* Logically, this subroutine computes the output sequence */
99 /* pebuf(1:nsamp) defined by: */
100 
101 /* pebuf(i) = inbuf(i) - coef * inbuf(i-1) */
102 
103 /* where inbuf(0) is defined by the value of z given as input to */
104 /* this subroutine. */
105 
106 /* What is this filter's frequency response and phase response? */
107 
108 /* Why is this filter applied to the speech? */
109 
110 /* Could it be more efficient to apply multiple filters */
111 /* simultaneously, by combining them into one equivalent filter? */
112 
113 /* Are there ever cases when "factoring" one high-order filter into
114 */
115 /* multiple smaller-order filter actually reduces the number of */
116 /* arithmetic operations needed to perform them? */
117 /* When I first read this subroutine, I didn't understand why the */
118 /* variable temp was used. It seemed that the statements in the do
119 */
120 /* loop could be replaced with the following: */
121 
122 /* pebuf(i) = inbuf(i) - coef * z */
123 /* z = inbuf(i) */
124 
125 /* The reason for temp is so that even if pebuf and inbuf are the */
126 /* same arrays in memory (i.e., they are aliased), then this */
127 /* subroutine will still work correctly. I didn't realize this */
128 /* until seeing the comment after PEBUF above that says "(can be */
129 /* equal to INBUF)". */
130  /* Parameter adjustments */
131  --pebuf;
132  --inbuf;
133 
134  /* Function Body */
135  i__1 = *nsamp;
136  for (i__ = 1; i__ <= i__1; ++i__) {
137  temp = inbuf[i__] - *coef * *z__;
138  *z__ = inbuf[i__];
139  pebuf[i__] = temp;
140 /* L10: */
141  }
142  return 0;
143 } /* preemp_ */
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ prepro_()

int prepro_ ( real speech,
integer length,
struct lpc10_encoder_state st 
)

Definition at line 101 of file prepro.c.

References c__1, and hp100_().

Referenced by lpc10_encode().

103 {
104  extern /* Subroutine */ int hp100_(real *, integer *, integer *, struct lpc10_encoder_state *);
105 
106 /* Arguments */
107 /* High Pass Filter at 100 Hz */
108  /* Parameter adjustments */
109  if (speech) {
110  --speech;
111  }
112 
113  /* Function Body */
114  hp100_(&speech[1], &c__1, length, st);
115  return 0;
116 } /* prepro_ */
static integer c__1
Definition: prepro.c:45
int hp100_(real *speech, integer *start, integer *end, struct lpc10_encoder_state *st)
Definition: hp100.c:113
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80

◆ r_sign()

double r_sign ( real a,
real b 
)

Definition at line 64 of file f2clib.c.

References a, and i_nint().

Referenced by onset_(), pow_ii(), and vparms_().

66 {
67 double x;
68 x = (*a >= 0 ? *a : - *a);
69 return( *b >= 0 ? x : -x);
70 }
static struct test_val b
static struct test_val a

◆ random_()

integer random_ ( struct lpc10_decoder_state st)

Definition at line 93 of file random.c.

References lpc10_decoder_state::j, lpc10_decoder_state::k, and lpc10_decoder_state::y.

Referenced by bsynz_().

94 {
95  /* Initialized data */
96 
97  integer *j;
98  integer *k;
99  shortint *y;
100 
101  /* System generated locals */
102  integer ret_val;
103 
104 /* Parameters/constants */
105 /* Local state */
106 /* The following is a 16 bit 2's complement addition, */
107 /* with overflow checking disabled */
108 
109  j = &(st->j);
110  k = &(st->k);
111  y = &(st->y[0]);
112 
113  y[*k - 1] += y[*j - 1];
114  ret_val = y[*k - 1];
115  --(*k);
116  if (*k <= 0) {
117  *k = 5;
118  }
119  --(*j);
120  if (*j <= 0) {
121  *j = 5;
122  }
123  return ret_val;
124 } /* random_ */
shortint y[5]
Definition: lpc10.h:189
INT16 shortint
Definition: lpc10.h:82
INT32 integer
Definition: lpc10.h:80

◆ rcchk_()

int rcchk_ ( integer order,
real rc1f,
real rc2f 
)

Definition at line 82 of file rcchk.c.

References abs, and order.

Referenced by analys_().

83 {
84  /* System generated locals */
85  integer i__1;
86  real r__1;
87 
88  /* Local variables */
89  integer i__;
90 
91 /* Arguments */
92 /* Local variables that need not be saved */
93  /* Parameter adjustments */
94  --rc2f;
95  --rc1f;
96 
97  /* Function Body */
98  i__1 = *order;
99  for (i__ = 1; i__ <= i__1; ++i__) {
100  if ((r__1 = rc2f[i__], abs(r__1)) > .99f) {
101  goto L10;
102  }
103  }
104  return 0;
105 /* Note: In version embedded in other software, all calls to ERROR
106 */
107 /* should probably be removed. */
108 L10:
109 
110 /* This call to ERROR is only needed for debugging purposes. */
111 
112 /* CALL ERROR('RCCHK',2,I) */
113  i__1 = *order;
114  for (i__ = 1; i__ <= i__1; ++i__) {
115  rc2f[i__] = rc1f[i__];
116  }
117  return 0;
118 } /* rcchk_ */
integer order
Definition: analys.c:66
float real
Definition: lpc10.h:79
#define abs(x)
Definition: f2c.h:195
INT32 integer
Definition: lpc10.h:80

◆ synths_()

int synths_ ( integer voice,
integer pitch,
real rms,
real rc,
real speech,
integer k,
struct lpc10_decoder_state st 
)

Definition at line 170 of file synths.c.

References bsynz_(), buf, lpc10_decoder_state::buf, lpc10_decoder_state::buflen, c_b2, contrl_1, deemp_(), irc2pc_(), max, min, and pitsyn_().

Referenced by lpc10_decode().

172 {
173  /* Initialized data */
174 
175  real *buf;
176  integer *buflen;
177 
178  /* System generated locals */
179  integer i__1;
180  real r__1, r__2;
181 
182  /* Local variables */
183  real rmsi[16];
184  integer nout, ivuv[16], i__, j;
185  extern /* Subroutine */ int deemp_(real *, integer *, struct lpc10_decoder_state *);
186  real ratio;
187  integer ipiti[16];
188  real g2pass;
189  real pc[10];
190  extern /* Subroutine */ int pitsyn_(integer *, integer *, integer *, real
191  *, real *, integer *, integer *, integer *, real *, real *,
192  integer *, real *, struct lpc10_decoder_state *);
193  real rci[160] /* was [10][16] */;
194 
195 /* $Log$
196  * Revision 1.16 2004/06/26 03:50:14 markster
197  * Merge source cleanups (bug #1911)
198  *
199  * Revision 1.15 2003/09/27 02:45:37 markster
200  * Fix various compiler warnings (bug #322)
201  *
202  * Revision 1.2 2003/09/27 02:45:37 markster
203  * Fix various compiler warnings (bug #322)
204  *
205  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
206  * mer feb 12 14:56:57 CET 2003
207  *
208  * Revision 1.2 2000/01/05 08:20:39 markster
209  * Some OSS fixes and a few lpc changes to make it actually work
210  *
211  * Revision 1.2 1996/08/20 20:42:59 jaf
212  * Removed all static local variables that were SAVE'd in the Fortran
213  * code, and put them in struct lpc10_decoder_state that is passed as an
214  * argument.
215  *
216  * Removed init function, since all initialization is now done in
217  * init_lpc10_decoder_state().
218  *
219  * Revision 1.1 1996/08/19 22:30:33 jaf
220  * Initial revision
221  * */
222 /* Revision 1.3 1996/03/29 22:03:47 jaf */
223 /* Removed definitions for any constants that were no longer used. */
224 
225 /* Revision 1.2 1996/03/26 19:34:33 jaf */
226 /* Added comments indicating which constants are not needed in an */
227 /* application that uses the LPC-10 coder. */
228 
229 /* Revision 1.1 1996/02/07 14:43:51 jaf */
230 /* Initial revision */
231 
232 /* LPC Configuration parameters: */
233 /* Frame size, Prediction order, Pitch period */
234 /* Arguments */
235 /* $Log$
236  * Revision 1.16 2004/06/26 03:50:14 markster
237  * Merge source cleanups (bug #1911)
238  *
239  * Revision 1.15 2003/09/27 02:45:37 markster
240  * Fix various compiler warnings (bug #322)
241  *
242  * Revision 1.2 2003/09/27 02:45:37 markster
243  * Fix various compiler warnings (bug #322)
244  *
245  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
246  * mer feb 12 14:56:57 CET 2003
247  *
248  * Revision 1.2 2000/01/05 08:20:39 markster
249  * Some OSS fixes and a few lpc changes to make it actually work
250  *
251  * Revision 1.2 1996/08/20 20:42:59 jaf
252  * Removed all static local variables that were SAVE'd in the Fortran
253  * code, and put them in struct lpc10_decoder_state that is passed as an
254  * argument.
255  *
256  * Removed init function, since all initialization is now done in
257  * init_lpc10_decoder_state().
258  *
259  * Revision 1.1 1996/08/19 22:30:33 jaf
260  * Initial revision
261  * */
262 /* Revision 1.3 1996/03/29 22:05:55 jaf */
263 /* Commented out the common block variables that are not needed by the */
264 /* embedded version. */
265 
266 /* Revision 1.2 1996/03/26 19:34:50 jaf */
267 /* Added comments indicating which constants are not needed in an */
268 /* application that uses the LPC-10 coder. */
269 
270 /* Revision 1.1 1996/02/07 14:44:09 jaf */
271 /* Initial revision */
272 
273 /* LPC Processing control variables: */
274 
275 /* *** Read-only: initialized in setup */
276 
277 /* Files for Speech, Parameter, and Bitstream Input & Output, */
278 /* and message and debug outputs. */
279 
280 /* Here are the only files which use these variables: */
281 
282 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
283 
284 /* Many files which use fdebug are not listed, since it is only used in */
285 /* those other files conditionally, to print trace statements. */
286 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
287 /* LPC order, Frame size, Quantization rate, Bits per frame, */
288 /* Error correction */
289 /* Subroutine SETUP is the only place where order is assigned a value, */
290 /* and that value is 10. It could increase efficiency 1% or so to */
291 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
292 */
293 /* a variable in a COMMON block, since it is used in many places in the */
294 /* core of the coding and decoding routines. Actually, I take that back.
295 */
296 /* At least when compiling with f2c, the upper bound of DO loops is */
297 /* stored in a local variable before the DO loop begins, and then that is
298 */
299 /* compared against on each iteration. */
300 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
301 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
302 /* is used in only a few places, and never in the core coding and */
303 /* decoding routines, so it could be eliminated entirely. */
304 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
305 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
306 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
307 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
308 */
309 /* a constant or a variable, since it is only examined once per frame. */
310 /* Leaving it as a variable that is set to .TRUE. seems like a good */
311 /* idea, since it does enable some error-correction capability for */
312 /* unvoiced frames, with no change in the coding rate, and no noticeable
313 */
314 /* quality difference in the decoded speech. */
315 /* integer quant, nbits */
316 /* *** Read/write: variables for debugging, not needed for LPC algorithm
317 */
318 
319 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
320 */
321 /* Debug listing detail level, Line count on listing page */
322 
323 /* nframe is not needed for an embedded LPC10 at all. */
324 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
325 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
326 /* an application, I would recommend removing the call to ERROR in RCCHK,
327 */
328 /* and remove ERROR and nunsfm completely. */
329 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
330 */
331 /* sread.f. When LPC10 is embedded into an application, one might want */
332 /* to cause it to be incremented in a routine that takes the output of */
333 /* SYNTHS and sends it to an audio device. It could be optionally */
334 /* displayed, for those that might want to know what it is. */
335 /* maxosp is never initialized to 0 in SETUP, although it probably should
336 */
337 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
338 /* would be of much interest to an application in which LPC10 is */
339 /* embedded. */
340 /* listl and lincnt are not needed for an embedded LPC10 at all. */
341 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
342 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
343 /* common /contrl/ quant, nbits */
344 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
345 /* Parameters/constants */
346 /* Local variables that need not be saved */
347 /* Local state */
348 /* BUF is a buffer of speech samples that would have been returned
349 */
350 /* by the older version of SYNTHS, but the newer version doesn't, */
351 /* so that the newer version can always return MAXFRM samples on */
352 /* every call. This has the effect of delaying the return of */
353 /* samples for one additional frame time. */
354 
355 /* Indices 1 through BUFLEN contain samples that are left over from
356 */
357 /* the last call to SYNTHS. Given the way that PITSYN works, */
358 /* BUFLEN should always be in the range MAXFRM-MAXPIT+1 through */
359 /* MAXFRM, inclusive, after a call to SYNTHS is complete. */
360 
361 /* On the first call to SYNTHS (or the first call after */
362 /* reinitializing with the entry INITSYNTHS), BUFLEN is MAXFRM, and
363 */
364 /* a frame of silence is always returned. */
365  /* Parameter adjustments */
366  if (voice) {
367  --voice;
368  }
369  if (rc) {
370  --rc;
371  }
372  if (speech) {
373  --speech;
374  }
375 
376  /* Function Body */
377  buf = &(st->buf[0]);
378  buflen = &(st->buflen);
379 
380 /* Computing MAX */
381  i__1 = min(*pitch,156);
382  *pitch = max(i__1,20);
383  i__1 = contrl_1.order;
384  for (i__ = 1; i__ <= i__1; ++i__) {
385 /* Computing MAX */
386 /* Computing MIN */
387  r__2 = rc[i__];
388  r__1 = min(r__2,.99f);
389  rc[i__] = max(r__1,-.99f);
390  }
391  pitsyn_(&contrl_1.order, &voice[1], pitch, rms, &rc[1], &contrl_1.lframe,
392  ivuv, ipiti, rmsi, rci, &nout, &ratio, st);
393  if (nout > 0) {
394  i__1 = nout;
395  for (j = 1; j <= i__1; ++j) {
396 
397 /* Add synthesized speech for pitch period J to the en
398 d of */
399 /* BUF. */
400 
401  irc2pc_(&rci[j * 10 - 10], pc, &contrl_1.order, &c_b2, &g2pass);
402  bsynz_(pc, &ipiti[j - 1], &ivuv[j - 1], &buf[*buflen], &rmsi[j - 1]
403  , &ratio, &g2pass, st);
404  deemp_(&buf[*buflen], &ipiti[j - 1], st);
405  *buflen += ipiti[j - 1];
406  }
407 
408 /* Copy first MAXFRM samples from BUF to output array SPEECH
409 */
410 /* (scaling them), and then remove them from the beginning of
411  */
412 /* BUF. */
413 
414  for (i__ = 1; i__ <= 180; ++i__) {
415  speech[i__] = buf[i__ - 1] / 4096.f;
416  }
417  *k = 180;
418  *buflen += -180;
419  i__1 = *buflen;
420  for (i__ = 1; i__ <= i__1; ++i__) {
421  buf[i__ - 1] = buf[i__ + 179];
422  }
423  }
424  return 0;
425 } /* synths_ */
int irc2pc_(real *rc, real *pc, integer *order, real *gprime, real *g2pass)
Definition: irc2pc.c:82
integer buflen
Definition: lpc10.h:164
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int deemp_(real *x, integer *n, struct lpc10_decoder_state *st)
Definition: deemp.c:106
int bsynz_(real *coef, integer *ip, integer *iv, real *sout, real *rms, real *ratio, real *g2pass, struct lpc10_decoder_state *st)
Definition: bsynz.c:122
#define contrl_1
Definition: synths.c:59
float real
Definition: lpc10.h:79
static real c_b2
Definition: synths.c:63
real buf[360]
Definition: lpc10.h:163
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
int pitsyn_(integer *order, integer *voice, integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv, integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio, struct lpc10_decoder_state *st)
Definition: pitsyn.c:132
#define max(a, b)
Definition: f2c.h:198

◆ tbdm_()

int tbdm_ ( real speech,
integer lpita,
integer tau,
integer ltau,
real amdf,
integer minptr,
integer maxptr,
integer mintau 
)

Definition at line 94 of file tbdm.c.

References difmag_(), max, and min.

Referenced by analys_().

97 {
98  /* System generated locals */
99  integer i__1, i__2, i__3, i__4;
100 
101  /* Local variables */
102  real amdf2[6];
103  integer minp2, ltau2, maxp2, i__;
104  extern /* Subroutine */ int difmag_(real *, integer *, integer *, integer
105  *, integer *, real *, integer *, integer *);
106  integer minamd, ptr, tau2[6];
107 
108 /* Arguments */
109 /* REAL SPEECH(LPITA+TAU(LTAU)), AMDF(LTAU) */
110 /* Stupid TOAST doesn't understand expressions */
111 /* Local variables that need not be saved */
112 /* Local state */
113 /* None */
114 /* Compute full AMDF using log spaced lags, find coarse minimum */
115  /* Parameter adjustments */
116  --speech;
117  --amdf;
118  --tau;
119 
120  /* Function Body */
121  difmag_(&speech[1], lpita, &tau[1], ltau, &tau[*ltau], &amdf[1], minptr,
122  maxptr);
123  *mintau = tau[*minptr];
124  minamd = (integer)amdf[*minptr];
125 /* Build table containing all lags within +/- 3 of the AMDF minimum */
126 /* excluding all that have already been computed */
127  ltau2 = 0;
128  ptr = *minptr - 2;
129 /* Computing MAX */
130  i__1 = *mintau - 3;
131 /* Computing MIN */
132  i__3 = *mintau + 3, i__4 = tau[*ltau] - 1;
133  i__2 = min(i__3,i__4);
134  for (i__ = max(i__1,41); i__ <= i__2; ++i__) {
135  while(tau[ptr] < i__) {
136  ++ptr;
137  }
138  if (tau[ptr] != i__) {
139  ++ltau2;
140  tau2[ltau2 - 1] = i__;
141  }
142  }
143 /* Compute AMDF of the new lags, if there are any, and choose one */
144 /* if it is better than the coarse minimum */
145  if (ltau2 > 0) {
146  difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &
147  maxp2);
148  if (amdf2[minp2 - 1] < (real) minamd) {
149  *mintau = tau2[minp2 - 1];
150  minamd = (integer)amdf2[minp2 - 1];
151  }
152  }
153 /* Check one octave up, if there are any lags not yet computed */
154  if (*mintau >= 80) {
155  i__ = *mintau / 2;
156  if ((i__ & 1) == 0) {
157  ltau2 = 2;
158  tau2[0] = i__ - 1;
159  tau2[1] = i__ + 1;
160  } else {
161  ltau2 = 1;
162  tau2[0] = i__;
163  }
164  difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &
165  maxp2);
166  if (amdf2[minp2 - 1] < (real) minamd) {
167  *mintau = tau2[minp2 - 1];
168  minamd = (integer)amdf2[minp2 - 1];
169  *minptr += -20;
170  }
171  }
172 /* Force minimum of the AMDF array to the high resolution minimum */
173  amdf[*minptr] = (real) minamd;
174 /* Find maximum of AMDF within 1/2 octave of minimum */
175 /* Computing MAX */
176  i__2 = *minptr - 5;
177  *maxptr = max(i__2,1);
178 /* Computing MIN */
179  i__1 = *minptr + 5;
180  i__2 = min(i__1,*ltau);
181  for (i__ = *maxptr + 1; i__ <= i__2; ++i__) {
182  if (amdf[i__] > amdf[*maxptr]) {
183  *maxptr = i__;
184  }
185  }
186  return 0;
187 } /* tbdm_ */
float real
Definition: lpc10.h:79
int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr)
Definition: difmag.c:90
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
#define max(a, b)
Definition: f2c.h:198

◆ voicin_()

int voicin_ ( integer vwin,
real inbuf,
real lpbuf,
integer buflim,
integer half,
real minamd,
real maxamd,
integer mintau,
real ivrc,
integer obound,
integer voibuf,
integer af,
struct lpc10_encoder_state st 
)

Definition at line 258 of file voicin.c.

References lpc10_encoder_state::dither, lpc10_encoder_state::fbue, lpc10_encoder_state::fbve, i_nint(), L1, L2, lpc10_encoder_state::lbue, lpc10_encoder_state::lbve, max, lpc10_encoder_state::maxmin, min, lpc10_encoder_state::ofbue, lpc10_encoder_state::olbue, lpc10_encoder_state::sfbue, lpc10_encoder_state::slbue, lpc10_encoder_state::snr, value, lpc10_encoder_state::voice, and vparms_().

Referenced by analys_().

262 {
263  /* Initialized data */
264 
265  real *dither;
266  static real vdc[100] /* was [10][10] */ = { 0.f,1714.f,-110.f,
267  334.f,-4096.f,-654.f,3752.f,3769.f,0.f,1181.f,0.f,874.f,-97.f,
268  300.f,-4096.f,-1021.f,2451.f,2527.f,0.f,-500.f,0.f,510.f,-70.f,
269  250.f,-4096.f,-1270.f,2194.f,2491.f,0.f,-1500.f,0.f,500.f,-10.f,
270  200.f,-4096.f,-1300.f,2e3f,2e3f,0.f,-2e3f,0.f,500.f,0.f,0.f,
271  -4096.f,-1300.f,2e3f,2e3f,0.f,-2500.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
272  0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
273  0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
274  0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f };
275  static integer nvdcl = 5;
276  static real vdcl[10] = { 600.f,450.f,300.f,200.f,0.f,0.f,0.f,0.f,0.f,0.f }
277  ;
278 
279  /* System generated locals */
280  integer inbuf_offset = 0, lpbuf_offset = 0, i__1, i__2;
281  real r__1, r__2;
282 
283  /* Builtin functions */
284  integer i_nint(real *);
285  double sqrt(doublereal);
286 
287  /* Local variables */
288  real ar_b__, ar_f__;
289  integer *lbve, *lbue, *fbve, *fbue;
290  integer snrl, i__;
291  integer *ofbue, *sfbue;
292  real *voice;
293  integer *olbue, *slbue;
294  real value[9];
295  integer zc;
296  logical ot;
297  real qs;
298  real *maxmin;
299  integer vstate;
300  real rc1;
301  extern /* Subroutine */ int vparms_(integer *, real *, real *, integer *,
302  integer *, real *, integer *, integer *, integer *, integer *,
303  real *, real *, real *, real *);
304  integer fbe, lbe;
305  real *snr;
306  real snr2;
307 
308 /* Global Variables: */
309 /* Arguments */
310 /* $Log$
311  * Revision 1.16 2004/06/26 03:50:14 markster
312  * Merge source cleanups (bug #1911)
313  *
314  * Revision 1.15 2003/11/23 22:14:32 markster
315  * Various warning cleanups
316  *
317  * Revision 1.14 2003/02/12 13:59:15 matteo
318  * mer feb 12 14:56:57 CET 2003
319  *
320  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
321  * mer feb 12 14:56:57 CET 2003
322  *
323  * Revision 1.2 2000/01/05 08:20:40 markster
324  * Some OSS fixes and a few lpc changes to make it actually work
325  *
326  * Revision 1.2 1996/08/20 20:45:00 jaf
327  * Removed all static local variables that were SAVE'd in the Fortran
328  * code, and put them in struct lpc10_encoder_state that is passed as an
329  * argument.
330  *
331  * Removed init function, since all initialization is now done in
332  * init_lpc10_encoder_state().
333  *
334  * Revision 1.1 1996/08/19 22:30:14 jaf
335  * Initial revision
336  * */
337 /* Revision 1.3 1996/03/29 22:05:55 jaf */
338 /* Commented out the common block variables that are not needed by the */
339 /* embedded version. */
340 
341 /* Revision 1.2 1996/03/26 19:34:50 jaf */
342 /* Added comments indicating which constants are not needed in an */
343 /* application that uses the LPC-10 coder. */
344 
345 /* Revision 1.1 1996/02/07 14:44:09 jaf */
346 /* Initial revision */
347 
348 /* LPC Processing control variables: */
349 
350 /* *** Read-only: initialized in setup */
351 
352 /* Files for Speech, Parameter, and Bitstream Input & Output, */
353 /* and message and debug outputs. */
354 
355 /* Here are the only files which use these variables: */
356 
357 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
358 
359 /* Many files which use fdebug are not listed, since it is only used in */
360 /* those other files conditionally, to print trace statements. */
361 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
362 /* LPC order, Frame size, Quantization rate, Bits per frame, */
363 /* Error correction */
364 /* Subroutine SETUP is the only place where order is assigned a value, */
365 /* and that value is 10. It could increase efficiency 1% or so to */
366 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
367 */
368 /* a variable in a COMMON block, since it is used in many places in the */
369 /* core of the coding and decoding routines. Actually, I take that back.
370 */
371 /* At least when compiling with f2c, the upper bound of DO loops is */
372 /* stored in a local variable before the DO loop begins, and then that is
373 */
374 /* compared against on each iteration. */
375 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
376 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
377 /* is used in only a few places, and never in the core coding and */
378 /* decoding routines, so it could be eliminated entirely. */
379 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
380 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
381 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
382 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
383 */
384 /* a constant or a variable, since it is only examined once per frame. */
385 /* Leaving it as a variable that is set to .TRUE. seems like a good */
386 /* idea, since it does enable some error-correction capability for */
387 /* unvoiced frames, with no change in the coding rate, and no noticeable
388 */
389 /* quality difference in the decoded speech. */
390 /* integer quant, nbits */
391 /* *** Read/write: variables for debugging, not needed for LPC algorithm
392 */
393 
394 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
395 */
396 /* Debug listing detail level, Line count on listing page */
397 
398 /* nframe is not needed for an embedded LPC10 at all. */
399 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
400 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
401 /* an application, I would recommend removing the call to ERROR in RCCHK,
402 */
403 /* and remove ERROR and nunsfm completely. */
404 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
405 */
406 /* sread.f. When LPC10 is embedded into an application, one might want */
407 /* to cause it to be incremented in a routine that takes the output of */
408 /* SYNTHS and sends it to an audio device. It could be optionally */
409 /* displayed, for those that might want to know what it is. */
410 /* maxosp is never initialized to 0 in SETUP, although it probably should
411 */
412 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
413 /* would be of much interest to an application in which LPC10 is */
414 /* embedded. */
415 /* listl and lincnt are not needed for an embedded LPC10 at all. */
416 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
417 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
418 /* common /contrl/ quant, nbits */
419 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
420 /* Parameters/constants */
421 /* Voicing coefficient and Linear Discriminant Analysis variables:
422 */
423 /* Max number of VDC's and VDC levels */
424 /* The following are not Fortran PARAMETER's, but they are */
425 /* initialized with DATA statements, and never modified. */
426 /* Actual number of VDC's and levels */
427 /* Local variables that need not be saved */
428 /* Note: */
429 
430 /* VALUE(1) through VALUE(8) are assigned values, but VALUE(9) */
431 /* never is. Yet VALUE(9) is read in the loop that begins "DO I =
432 */
433 /* 1, 9" below. I believe that this doesn't cause any problems in
434 */
435 /* this subroutine, because all VDC(9,*) array elements are 0, and
436 */
437 /* this is what is multiplied by VALUE(9) in all cases. Still, it
438 */
439 /* would save a multiplication to change the loop to "DO I = 1, 8".
440 */
441 /* Local state */
442 /* WARNING! */
443 
444 /* VOICE, SFBUE, and SLBUE should be saved from one invocation to */
445 /* the next, but they are never given an initial value. */
446 
447 /* Does Fortran 77 specify some default initial value, like 0, or */
448 /* is it undefined? If it is undefined, then this code should be */
449 /* corrected to specify an initial value. */
450 
451 /* For VOICE, note that it is "shifted" in the statement that */
452 /* begins "IF (HALF .EQ. 1) THEN" below. Also, uninitialized */
453 /* values in the VOICE array can only affect entries in the VOIBUF
454 */
455 /* array that are for the same frame, or for an older frame. Thus
456 */
457 /* the effects of uninitialized values in VOICE cannot linger on */
458 /* for more than 2 or 3 frame times. */
459 
460 /* For SFBUE and SLBUE, the effects of uninitialized values can */
461 /* linger on for many frame times, because their previous values */
462 /* are exponentially decayed. Thus it is more important to choose
463 */
464 /* initial values for these variables. I would guess that a */
465 /* reasonable initial value for SFBUE is REF/16, the same as used */
466 /* for FBUE and OFBUE. Similarly, SLBUE can be initialized to */
467 /* REF/32, the same as for LBUE and OLBUE. */
468 
469 /* These guessed initial values should be validated by re-running */
470 /* the modified program on some audio samples. */
471 
472 /* Declare and initialize filters: */
473 
474  dither = (&st->dither);
475  snr = (&st->snr);
476  maxmin = (&st->maxmin);
477  voice = (&st->voice[0]);
478  lbve = (&st->lbve);
479  lbue = (&st->lbue);
480  fbve = (&st->fbve);
481  fbue = (&st->fbue);
482  ofbue = (&st->ofbue);
483  olbue = (&st->olbue);
484  sfbue = (&st->sfbue);
485  slbue = (&st->slbue);
486 
487  /* Parameter adjustments */
488  if (vwin) {
489  --vwin;
490  }
491  if (buflim) {
492  --buflim;
493  }
494  if (inbuf) {
495  inbuf_offset = buflim[1];
496  inbuf -= inbuf_offset;
497  }
498  if (lpbuf) {
499  lpbuf_offset = buflim[3];
500  lpbuf -= lpbuf_offset;
501  }
502  if (ivrc) {
503  --ivrc;
504  }
505  if (obound) {
506  --obound;
507  }
508  if (voibuf) {
509  --voibuf;
510  }
511 
512  /* Function Body */
513 
514 /* The following variables are saved from one invocation to the */
515 /* next, but are not initialized with DATA statements. This is */
516 /* acceptable, because FIRST is initialized ot .TRUE., and the */
517 /* first time that this subroutine is then called, they are all */
518 /* given initial values. */
519 
520 /* SNR */
521 /* LBVE, LBUE, FBVE, FBUE, OFBUE, OLBUE */
522 
523 /* MAXMIN is initialized on the first call, assuming that HALF */
524 /* .EQ. 1 on first call. This is how ANALYS calls this subroutine.
525 */
526 
527 /* Voicing Decision Parameter vector (* denotes zero coefficient): */
528 
529 /* * MAXMIN */
530 /* LBE/LBVE */
531 /* ZC */
532 /* RC1 */
533 /* QS */
534 /* IVRC2 */
535 /* aR_B */
536 /* aR_F */
537 /* * LOG(LBE/LBVE) */
538 /* Define 2-D voicing decision coefficient vector according to the voicin
539 g*/
540 /* parameter order above. Each row (VDC vector) is optimized for a speci
541 fic*/
542 /* SNR. The last element of the vector is the constant. */
543 /* E ZC RC1 Qs IVRC2 aRb aRf c */
544 
545 /* The VOICE array contains the result of the linear discriminant functio
546 n*/
547 /* (analog values). The VOIBUF array contains the hard-limited binary
548 */
549 /* voicing decisions. The VOICE and VOIBUF arrays, according to FORTRAN
550  */
551 /* memory allocation, are addressed as: */
552 
553 /* (half-frame number, future-frame number) */
554 
555 /* | Past | Present | Future1 | Future2 | */
556 /* | 1,0 | 2,0 | 1,1 | 2,1 | 1,2 | 2,2 | 1,3 | 2,3 | ---> time */
557 
558 /* Update linear discriminant function history each frame: */
559  if (*half == 1) {
560  voice[0] = voice[2];
561  voice[1] = voice[3];
562  voice[2] = voice[4];
563  voice[3] = voice[5];
564  *maxmin = *maxamd / max(*minamd,1.f);
565  }
566 /* Calculate voicing parameters twice per frame: */
567  vparms_(&vwin[1], &inbuf[inbuf_offset], &lpbuf[lpbuf_offset], &buflim[1],
568  half, dither, mintau, &zc, &lbe, &fbe, &qs, &rc1, &ar_b__, &
569  ar_f__);
570 /* Estimate signal-to-noise ratio to select the appropriate VDC vector.
571 */
572 /* The SNR is estimated as the running average of the ratio of the */
573 /* running average full-band voiced energy to the running average */
574 /* full-band unvoiced energy. SNR filter has gain of 63. */
575  r__1 = (*snr + *fbve / (real) max(*fbue,1)) * 63 / 64.f;
576  *snr = (real) i_nint(&r__1);
577  snr2 = *snr * *fbue / max(*lbue,1);
578 /* Quantize SNR to SNRL according to VDCL thresholds. */
579  snrl = 1;
580  i__1 = nvdcl - 1;
581  for (snrl = 1; snrl <= i__1; ++snrl) {
582  if (snr2 > vdcl[snrl - 1]) {
583  goto L69;
584  }
585  }
586 /* (Note: SNRL = NVDCL here) */
587 L69:
588 /* Linear discriminant voicing parameters: */
589  value[0] = *maxmin;
590  value[1] = (real) lbe / max(*lbve,1);
591  value[2] = (real) zc;
592  value[3] = rc1;
593  value[4] = qs;
594  value[5] = ivrc[2];
595  value[6] = ar_b__;
596  value[7] = ar_f__;
597 /* Evaluation of linear discriminant function: */
598  voice[*half + 3] = vdc[snrl * 10 - 1];
599  for (i__ = 1; i__ <= 8; ++i__) {
600  voice[*half + 3] += vdc[i__ + snrl * 10 - 11] * value[i__ - 1];
601  }
602 /* Classify as voiced if discriminant > 0, otherwise unvoiced */
603 /* Voicing decision for current half-frame: 1 = Voiced; 0 = Unvoiced */
604  if (voice[*half + 3] > 0.f) {
605  voibuf[*half + 6] = 1;
606  } else {
607  voibuf[*half + 6] = 0;
608  }
609 /* Skip voicing decision smoothing in first half-frame: */
610 /* Give a value to VSTATE, so that trace statements below will print
611 */
612 /* a consistent value from one call to the next when HALF .EQ. 1. */
613 /* The value of VSTATE is not used for any other purpose when this is
614 */
615 /* true. */
616  vstate = -1;
617  if (*half == 1) {
618  goto L99;
619  }
620 /* Voicing decision smoothing rules (override of linear combination): */
621 
622 /* Unvoiced half-frames: At least two in a row. */
623 /* -------------------- */
624 
625 /* Voiced half-frames: At least two in a row in one frame. */
626 /* ------------------- Otherwise at least three in a row. */
627 /* (Due to the way transition frames are encoded) */
628 
629 /* In many cases, the discriminant function determines how to smooth. */
630 /* In the following chart, the decisions marked with a * may be overridden
631 .*/
632 
633 /* Voicing override of transitions at onsets: */
634 /* If a V/UV or UV/V voicing decision transition occurs within one-half
635 */
636 /* frame of an onset bounding a voicing window, then the transition is */
637 /* moved to occur at the onset. */
638 
639 /* P 1F */
640 /* ----- ----- */
641 /* 0 0 0 0 */
642 /* 0 0 0* 1 (If there is an onset there) */
643 /* 0 0 1* 0* (Based on 2F and discriminant distance) */
644 /* 0 0 1 1 */
645 /* 0 1* 0 0 (Always) */
646 /* 0 1* 0* 1 (Based on discriminant distance) */
647 /* 0* 1 1 0* (Based on past, 2F, and discriminant distance) */
648 /* 0 1* 1 1 (If there is an onset there) */
649 /* 1 0* 0 0 (If there is an onset there) */
650 /* 1 0 0 1 */
651 /* 1 0* 1* 0 (Based on discriminant distance) */
652 /* 1 0* 1 1 (Always) */
653 /* 1 1 0 0 */
654 /* 1 1 0* 1* (Based on 2F and discriminant distance) */
655 /* 1 1 1* 0 (If there is an onset there) */
656 /* 1 1 1 1 */
657 
658 /* Determine if there is an onset transition between P and 1F. */
659 /* OT (Onset Transition) is true if there is an onset between */
660 /* P and 1F but not after 1F. */
661  ot = ((obound[1] & 2) != 0 || obound[2] == 1) && (obound[3] & 1) == 0;
662 /* Multi-way dispatch on voicing decision history: */
663  vstate = (voibuf[3] << 3) + (voibuf[4] << 2) + (voibuf[5] << 1) + voibuf[
664  6];
665  switch (vstate + 1) {
666  case 1: goto L99;
667  case 2: goto L1;
668  case 3: goto L2;
669  case 4: goto L99;
670  case 5: goto L4;
671  case 6: goto L5;
672  case 7: goto L6;
673  case 8: goto L7;
674  case 9: goto L8;
675  case 10: goto L99;
676  case 11: goto L10;
677  case 12: goto L11;
678  case 13: goto L99;
679  case 14: goto L13;
680  case 15: goto L14;
681  case 16: goto L99;
682  }
683 L1:
684  if (ot && voibuf[7] == 1) {
685  voibuf[5] = 1;
686  }
687  goto L99;
688 L2:
689  if (voibuf[7] == 0 || voice[2] < -voice[3]) {
690  voibuf[5] = 0;
691  } else {
692  voibuf[6] = 1;
693  }
694  goto L99;
695 L4:
696  voibuf[4] = 0;
697  goto L99;
698 L5:
699  if (voice[1] < -voice[2]) {
700  voibuf[4] = 0;
701  } else {
702  voibuf[5] = 1;
703  }
704  goto L99;
705 /* VOIBUF(2,0) must be 0 */
706 L6:
707  if (voibuf[1] == 1 || voibuf[7] == 1 || voice[3] > voice[0]) {
708  voibuf[6] = 1;
709  } else {
710  voibuf[3] = 1;
711  }
712  goto L99;
713 L7:
714  if (ot) {
715  voibuf[4] = 0;
716  }
717  goto L99;
718 L8:
719  if (ot) {
720  voibuf[4] = 1;
721  }
722  goto L99;
723 L10:
724  if (voice[2] < -voice[1]) {
725  voibuf[5] = 0;
726  } else {
727  voibuf[4] = 1;
728  }
729  goto L99;
730 L11:
731  voibuf[4] = 1;
732  goto L99;
733 L13:
734  if (voibuf[7] == 0 && voice[3] < -voice[2]) {
735  voibuf[6] = 0;
736  } else {
737  voibuf[5] = 1;
738  }
739  goto L99;
740 L14:
741  if (ot && voibuf[7] == 0) {
742  voibuf[5] = 0;
743  }
744 /* GOTO 99 */
745 L99:
746 /* Now update parameters: */
747 /* ---------------------- */
748 
749 /* During unvoiced half-frames, update the low band and full band unvoice
750 d*/
751 /* energy estimates (LBUE and FBUE) and also the zero crossing */
752 /* threshold (DITHER). (The input to the unvoiced energy filters is */
753 /* restricted to be less than 10dB above the previous inputs of the */
754 /* filters.) */
755 /* During voiced half-frames, update the low-pass (LBVE) and all-pass */
756 /* (FBVE) voiced energy estimates. */
757  if (voibuf[*half + 6] == 0) {
758 /* Computing MIN */
759  i__1 = fbe, i__2 = *ofbue * 3;
760  r__1 = (*sfbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
761  *sfbue = i_nint(&r__1);
762  *fbue = *sfbue / 8;
763  *ofbue = fbe;
764 /* Computing MIN */
765  i__1 = lbe, i__2 = *olbue * 3;
766  r__1 = (*slbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
767  *slbue = i_nint(&r__1);
768  *lbue = *slbue / 8;
769  *olbue = lbe;
770  } else {
771  r__1 = (*lbve * 63 + lbe) / 64.f;
772  *lbve = i_nint(&r__1);
773  r__1 = (*fbve * 63 + fbe) / 64.f;
774  *fbve = i_nint(&r__1);
775  }
776 /* Set dither threshold to yield proper zero crossing rates in the */
777 /* presence of low frequency noise and low level signal input. */
778 /* NOTE: The divisor is a function of REF, the expected energies. */
779 /* Computing MIN */
780 /* Computing MAX */
781  r__2 = (real)(sqrt((real) (*lbue * *lbve)) * 64 / 3000);
782  r__1 = max(r__2,1.f);
783  *dither = min(r__1,20.f);
784 /* Voicing decisions are returned in VOIBUF. */
785  return 0;
786 } /* voicin_ */
integer i_nint(real *x)
Definition: f2clib.c:80
integer fbve
Definition: lpc10.h:122
integer fbue
Definition: lpc10.h:122
integer olbue
Definition: lpc10.h:124
integer lbve
Definition: lpc10.h:122
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
int value
Definition: syslog.c:37
integer slbue
Definition: lpc10.h:124
int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__)
Definition: vparms.c:134
integer sfbue
Definition: lpc10.h:123
Definition: isdn_lib.h:241
Definition: isdn_lib.h:240
double doublereal
Definition: f2c.h:50
float real
Definition: lpc10.h:79
integer lbue
Definition: lpc10.h:122
real voice[6]
Definition: lpc10.h:121
integer ofbue
Definition: lpc10.h:123
INT32 logical
Definition: lpc10.h:81
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
#define max(a, b)
Definition: f2c.h:198

◆ vparms_()

int vparms_ ( integer vwin,
real inbuf,
real lpbuf,
integer buflim,
integer half,
real dither,
integer mintau,
integer zc,
integer lbe,
integer fbe,
real qs,
real rc1,
real ar_b__,
real ar_f__ 
)

Definition at line 134 of file vparms.c.

References abs, c_b2, i_nint(), max, min, r_sign(), and stop.

Referenced by voicin_().

138 {
139  /* System generated locals */
140  integer inbuf_offset, lpbuf_offset, i__1;
141  real r__1, r__2;
142 
143  /* Builtin functions */
144  double r_sign(real *, real *);
145  integer i_nint(real *);
146 
147  /* Local variables */
148  integer vlen, stop, i__;
149  real e_pre__;
150  integer start;
151  real ap_rms__, e_0__, oldsgn, lp_rms__, e_b__, e_f__, r_b__, r_f__, e0ap;
152 
153 /* Arguments */
154 /* Local variables that need not be saved */
155 /* Calculate zero crossings (ZC) and several energy and correlation */
156 /* measures on low band and full band speech. Each measure is taken */
157 /* over either the first or the second half of the voicing window, */
158 /* depending on the variable HALF. */
159  /* Parameter adjustments */
160  --vwin;
161  --buflim;
162  lpbuf_offset = buflim[3];
163  lpbuf -= lpbuf_offset;
164  inbuf_offset = buflim[1];
165  inbuf -= inbuf_offset;
166 
167  /* Function Body */
168  lp_rms__ = 0.f;
169  ap_rms__ = 0.f;
170  e_pre__ = 0.f;
171  e0ap = 0.f;
172  *rc1 = 0.f;
173  e_0__ = 0.f;
174  e_b__ = 0.f;
175  e_f__ = 0.f;
176  r_f__ = 0.f;
177  r_b__ = 0.f;
178  *zc = 0;
179  vlen = vwin[2] - vwin[1] + 1;
180  start = vwin[1] + (*half - 1) * vlen / 2 + 1;
181  stop = start + vlen / 2 - 1;
182 
183 /* I'll use the symbol HVL in the table below to represent the value */
184 /* VLEN/2. Note that if VLEN is odd, then HVL should be rounded down, */
185 /* i.e., HVL = (VLEN-1)/2. */
186 
187 /* HALF START STOP */
188 
189 /* 1 VWIN(1)+1 VWIN(1)+HVL */
190 /* 2 VWIN(1)+HVL+1 VWIN(1)+2*HVL */
191 
192 /* Note that if VLEN is even and HALF is 2, then STOP will be */
193 /* VWIN(1)+VLEN = VWIN(2)+1. That could be bad, if that index of INBUF */
194 /* is undefined. */
195 
196  r__1 = inbuf[start - 1] - *dither;
197  oldsgn = (real)r_sign(&c_b2, &r__1);
198  i__1 = stop;
199  for (i__ = start; i__ <= i__1; ++i__) {
200  lp_rms__ += (r__1 = lpbuf[i__], abs(r__1));
201  ap_rms__ += (r__1 = inbuf[i__], abs(r__1));
202  e_pre__ += (r__1 = inbuf[i__] - inbuf[i__ - 1], abs(r__1));
203 /* Computing 2nd power */
204  r__1 = inbuf[i__];
205  e0ap += r__1 * r__1;
206  *rc1 += inbuf[i__] * inbuf[i__ - 1];
207 /* Computing 2nd power */
208  r__1 = lpbuf[i__];
209  e_0__ += r__1 * r__1;
210 /* Computing 2nd power */
211  r__1 = lpbuf[i__ - *mintau];
212  e_b__ += r__1 * r__1;
213 /* Computing 2nd power */
214  r__1 = lpbuf[i__ + *mintau];
215  e_f__ += r__1 * r__1;
216  r_f__ += lpbuf[i__] * lpbuf[i__ + *mintau];
217  r_b__ += lpbuf[i__] * lpbuf[i__ - *mintau];
218  r__1 = inbuf[i__] + *dither;
219  if (r_sign(&c_b2, &r__1) != oldsgn) {
220  ++(*zc);
221  oldsgn = -oldsgn;
222  }
223  *dither = -(*dither);
224  }
225 /* Normalized short-term autocovariance coefficient at unit sample delay
226  */
227  *rc1 /= max(e0ap,1.f);
228 /* Ratio of the energy of the first difference signal (6 dB/oct preemphas
229 is)*/
230 /* to the energy of the full band signal */
231 /* Computing MAX */
232  r__1 = ap_rms__ * 2.f;
233  *qs = e_pre__ / max(r__1,1.f);
234 /* aR_b is the product of the forward and reverse prediction gains, */
235 /* looking backward in time (the causal case). */
236  *ar_b__ = r_b__ / max(e_b__,1.f) * (r_b__ / max(e_0__,1.f));
237 /* aR_f is the same as aR_b, but looking forward in time (non causal case
238 ).*/
239  *ar_f__ = r_f__ / max(e_f__,1.f) * (r_f__ / max(e_0__,1.f));
240 /* Normalize ZC, LBE, and FBE to old fixed window length of 180. */
241 /* (The fraction 90/VLEN has a range of .58 to 1) */
242  r__2 = (real) (*zc << 1);
243  r__1 = r__2 * (90.f / vlen);
244  *zc = i_nint(&r__1);
245 /* Computing MIN */
246  r__1 = lp_rms__ / 4 * (90.f / vlen);
247  i__1 = i_nint(&r__1);
248  *lbe = min(i__1,32767);
249 /* Computing MIN */
250  r__1 = ap_rms__ / 4 * (90.f / vlen);
251  i__1 = i_nint(&r__1);
252  *fbe = min(i__1,32767);
253  return 0;
254 } /* vparms_ */
integer i_nint(real *x)
Definition: f2clib.c:80
unsigned int stop
Definition: app_meetme.c:1096
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
float real
Definition: lpc10.h:79
double r_sign(real *a, real *b)
Definition: f2clib.c:64
#define abs(x)
Definition: f2c.h:195
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
static real c_b2
Definition: vparms.c:35
#define max(a, b)
Definition: f2c.h:198