4
Revision 1.1.1.1 2001/11/19 19:50:16 smorlat
7
Revision 1.1.1.1 2001/08/08 21:29:08 simon
10
* Revision 1.2 1996/08/20 20:40:12 jaf
11
* Removed all static local variables that were SAVE'd in the Fortran
12
* code, and put them in struct lpc10_decoder_state that is passed as an
15
* Removed init function, since all initialization is now done in
16
* init_lpc10_decoder_state().
18
* Revision 1.1 1996/08/19 22:31:12 jaf
24
#ifdef P_R_O_T_O_T_Y_P_E_S
25
extern 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);
28
/* -- translated by f2c (version 19951025).
29
You must link the resulting object file with the libraries:
30
-lf2c -lm (in that order)
35
/* ***************************************************************** */
37
/* PITSYN Version 53 */
40
/* Revision 1.1.1.1 2001/11/19 19:50:16 smorlat
43
/* Revision 1.1.1.1 2001/08/08 21:29:08 simon
46
* Revision 1.2 1996/08/20 20:40:12 jaf
47
* Removed all static local variables that were SAVE'd in the Fortran
48
* code, and put them in struct lpc10_decoder_state that is passed as an
51
* Removed init function, since all initialization is now done in
52
* init_lpc10_decoder_state().
54
* Revision 1.1 1996/08/19 22:31:12 jaf
57
/* Revision 1.2 1996/03/25 18:49:07 jaf */
58
/* Added commments about which indices of array arguments are read or */
61
/* Rearranged local variable declarations to indicate which need to be */
62
/* saved from one invocation to the next. Added entry INITPITSYN to */
63
/* reinitialize local state variables, if desired. */
65
/* Added lots of comments about proving that the maximum number of pitch */
66
/* periods (NOUT) that can be returned is 16. The call to STOP that */
67
/* could happen if NOUT got too large was removed as a result. */
69
/* Also proved that the total number of samples returned from N calls, */
70
/* each with identical values of LFRAME, will always be in the range */
71
/* N*LFRAME-MAXPIT+1 to N*LFRAME. */
73
/* Revision 1.1 1996/02/07 14:48:18 jaf */
74
/* Initial revision */
77
/* ***************************************************************** */
79
/* Synthesize a single pitch epoch */
82
/* ORDER - Synthesis order (number of RC's) */
83
/* VOICE - Half frame voicing decisions */
84
/* Indices 1 through 2 read. */
85
/* LFRAME - Length of speech buffer */
88
/* This value should be in the range MINPIT (20) to MAXPIT */
89
/* (156), inclusive. */
90
/* PITCH can be modified under some conditions. */
91
/* RMS - Energy (can be modified) */
92
/* RMS is changed to 1 if the value passed in is less than 1. */
93
/* RC - Reflection coefficients */
94
/* Indices 1 through ORDER can be temporarily overwritten with */
95
/* RCO, and then replaced with original values, under some */
98
/* IVUV - Pitch epoch voicing decisions */
99
/* Indices (I) of IVUV, IPITI, and RMSI are written, */
100
/* and indices (J,I) of RCI are written, */
101
/* where I ranges from 1 to NOUT, and J ranges from 1 to ORDER. */
102
/* IPITI - Pitch epoch length */
103
/* RMSI - Pitch epoch energy */
104
/* RCI - Pitch epoch RC's */
105
/* NOUT - Number of pitch periods in this frame */
106
/* This is at least 0, at least 1 if MAXPIT .LT. LFRAME (this */
107
/* is currently true on every call), and can never be more than */
108
/* (LFRAME+MAXPIT-1)/PITCH, which is currently 16 with */
109
/* LFRAME=180, MAXPIT=156, and PITCH .GE. 20, as SYNTHS */
110
/* guarantees when it calls this subroutine. */
111
/* RATIO - Previous to present energy ratio */
112
/* Always assigned a value. */
114
/* Subroutine */ int pitsyn_(integer *order, integer *voice,
115
integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv,
116
integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio,
117
struct lpc10_decoder_state *st)
119
/* Initialized data */
124
/* System generated locals */
125
integer rci_dim1, rci_offset, i__1, i__2;
128
/* Builtin functions */
129
double log(doublereal), exp(doublereal);
131
/* Local variables */
132
real alrn, alro, yarc[10], prop;
133
integer i__, j, vflag, jused, lsamp;
138
integer ip, nl, ivoice;
145
/* $Log: pitsyn.c,v $
146
/* Revision 1.1.1.1 2001/11/19 19:50:16 smorlat
149
/* Revision 1.1.1.1 2001/08/08 21:29:08 simon
152
* Revision 1.2 1996/08/20 20:40:12 jaf
153
* Removed all static local variables that were SAVE'd in the Fortran
154
* code, and put them in struct lpc10_decoder_state that is passed as an
157
* Removed init function, since all initialization is now done in
158
* init_lpc10_decoder_state().
160
* Revision 1.1 1996/08/19 22:31:12 jaf
163
/* Revision 1.3 1996/03/29 22:03:47 jaf */
164
/* Removed definitions for any constants that were no longer used. */
166
/* Revision 1.2 1996/03/26 19:34:33 jaf */
167
/* Added comments indicating which constants are not needed in an */
168
/* application that uses the LPC-10 coder. */
170
/* Revision 1.1 1996/02/07 14:43:51 jaf */
171
/* Initial revision */
173
/* LPC Configuration parameters: */
174
/* Frame size, Prediction order, Pitch period */
175
/* Local variables that need not be saved */
176
/* LSAMP is initialized in the IF (FIRST) THEN clause, but it is */
177
/* not used the first time through, and it is given a value before
179
/* use whenever FIRST is .FALSE., so it appears unnecessary to */
180
/* assign it a value when FIRST is .TRUE. */
182
/* FIRST - .TRUE. only on first call to PITSYN. */
183
/* IVOICO - Previous VOICE(2) value. */
184
/* IPITO - Previous PITCH value. */
185
/* RMSO - Previous RMS value. */
186
/* RCO - Previous RC values. */
188
/* JSAMP - If this routine is called N times with identical values of */
189
/* LFRAME, then the total length of all pitch periods returned */
190
/* is always N*LFRAME-JSAMP, and JSAMP is always in the range 0
192
/* to MAXPIT-1 (see below for why this is so). Thus JSAMP is */
193
/* the number of samples "left over" from the previous call to */
194
/* PITSYN, that haven't been "used" in a pitch period returned */
195
/* from this subroutine. Every time this subroutine is called,
197
/* it returns pitch periods with a total length of at most */
200
/* IVOICO, IPITO, RCO, and JSAMP need not be assigned an initial value */
201
/* with a DATA statement, because they are always initialized on the */
202
/* first call to PITSYN. */
204
/* FIRST and RMSO should be initialized with DATA statements, because */
205
/* even on the first call, they are used before being initialized. */
206
/* Parameter adjustments */
212
rci_offset = rci_dim1 + 1;
229
ivoico = &(st->ivoico);
230
ipito = &(st->ipito);
233
jsamp = &(st->jsamp);
234
first = &(st->first_pitsyn);
243
*ratio = *rms / (*rmso + 8.f);
248
*pitch = *lframe / 4;
250
*nout = *lframe / *pitch;
251
*jsamp = *lframe - *nout * *pitch;
253
/* SYNTHS only calls this subroutine with PITCH in the range
255
/* to 156. LFRAME = MAXFRM = 180, so NOUT is somewhere in th
259
/* JSAMP is "LFRAME mod PITCH", so it is in the range 0 to */
260
/* (PITCH-1), or 0 to MAXPIT-1=155, after the first call. */
263
for (i__ = 1; i__ <= i__1; ++i__) {
265
for (j = 1; j <= i__2; ++j) {
266
rci[j + i__ * rci_dim1] = rc[j];
275
lsamp = *lframe + *jsamp;
276
slope = (*pitch - *ipito) / (real) lsamp;
280
if (voice[1] == *ivoico && voice[2] == voice[1]) {
282
/* SSUV - - 0 , 0 , 0 */
283
*pitch = *lframe / 4;
289
/* SSVC - - 1 , 1 , 1 */
290
slope = (*pitch - *ipito) / (real) lsamp;
294
if (*ivoico == voice[1]) {
295
/* UV2VC2 - - 0 , 0 , 1 */
296
nl = lsamp - *lframe / 4;
298
/* UV2VC1 - - 0 , 1 , 1 */
299
nl = lsamp - *lframe * 3 / 4;
302
ipiti[2] = nl - ipiti[1];
308
for (i__ = 1; i__ <= i__1; ++i__) {
309
rci[i__ + rci_dim1] = rco[i__ - 1];
310
rci[i__ + (rci_dim1 << 1)] = rco[i__ - 1];
311
rco[i__ - 1] = rc[i__];
320
if (*ivoico != voice[1]) {
321
/* VC2UV1 - - 1 , 0 , 0 */
322
lsamp = *lframe / 4 + *jsamp;
324
/* VC2UV2 - - 1 , 1 , 0 */
325
lsamp = *lframe * 3 / 4 + *jsamp;
328
for (i__ = 1; i__ <= i__1; ++i__) {
329
yarc[i__ - 1] = rc[i__];
330
rc[i__] = rco[i__ - 1];
337
/* Here is the value of most variables that are used below, depending
339
/* the values of IVOICO, VOICE(1), and VOICE(2). VOICE(1) and VOICE(2
341
/* are input arguments, and IVOICO is the value of VOICE(2) on the */
342
/* previous call (see notes for the IF (NOUT .NE. 0) statement near th
344
/* end). Each of these three values is either 0 or 1. These three */
345
/* values below are given as 3-bit long strings, in the order IVOICO,
347
/* VOICE(1), and VOICE(2). It appears that the code above assumes tha
349
/* the bit sequences 010 and 101 never occur, but I wonder whether a
351
/* large enough number of bit errors in the channel could cause such a
353
/* thing to happen, and if so, could that cause NOUT to ever go over 1
356
/* Note that all of the 180 values in the table are really LFRAME, but
358
/* 180 has fewer characters, and it makes the table a little more */
359
/* concrete. If LFRAME is ever changed, keep this in mind. Similarly
361
/* 135's are 3*LFRAME/4, and 45's are LFRAME/4. If LFRAME is not a */
362
/* multiple of 4, then the 135 for NL-JSAMP is actually LFRAME-LFRAME/
364
/* and the 45 for NL-JSAMP is actually LFRAME-3*LFRAME/4. */
366
/* Note that LSAMP-JSAMP is given as the variable. This was just for
368
/* brevity, to avoid adding "+JSAMP" to all of the column entries. */
369
/* Similarly for NL-JSAMP. */
371
/* Variable | 000 001 011,010 111 110 100,101 */
372
/* ------------+-------------------------------------------------- */
373
/* ISTART | 1 NL+1 NL+1 1 1 1 */
374
/* LSAMP-JSAMP | 180 180 180 180 135 45 */
375
/* IPITO | 45 PITCH PITCH oldPITCH oldPITCH oldPITCH */
376
/* SLOPE | 0 0 0 seebelow 0 0 */
377
/* JUSED | 0 NL NL 0 0 0 */
378
/* PITCH | 45 PITCH PITCH PITCH PITCH PITCH */
379
/* NL-JSAMP | -- 135 45 -- -- -- */
380
/* VFLAG | 0 0 0 0 1 1 */
381
/* NOUT | 0 2 2 0 0 0 */
382
/* IVOICE | 0 1 1 1 1 1 */
384
/* while_loop | once once once once twice twice */
386
/* ISTART | -- -- -- -- JUSED+1 JUSED+1 */
387
/* LSAMP-JSAMP | -- -- -- -- 180 180 */
388
/* IPITO | -- -- -- -- oldPITCH oldPITCH */
389
/* SLOPE | -- -- -- -- 0 0 */
390
/* JUSED | -- -- -- -- ?? ?? */
391
/* PITCH | -- -- -- -- PITCH PITCH */
392
/* NL-JSAMP | -- -- -- -- -- -- */
393
/* VFLAG | -- -- -- -- 0 0 */
394
/* NOUT | -- -- -- -- ?? ?? */
395
/* IVOICE | -- -- -- -- 0 0 */
398
/* UVPIT is always 0.0 on the first pass through the DO WHILE (.TRUE.)
402
/* The only possible non-0 value of SLOPE (in column 111) is */
403
/* (PITCH-IPITO)/FLOAT(LSAMP) */
405
/* Column 101 is identical to 100. Any good properties we can prove
407
/* for 100 will also hold for 101. Similarly for 010 and 011. */
409
/* SYNTHS calls this subroutine with PITCH restricted to the range 20
411
/* 156. IPITO is similarly restricted to this range, after the first
413
/* call. IP below is also restricted to this range, given the */
414
/* definitions of IPITO, SLOPE, UVPIT, and that I is in the range ISTA
420
/* JUSED is the total length of all pitch periods curr
422
/* in the output arrays, in samples. */
424
/* An invariant of the DO I = ISTART,LSAMP loop below,
426
/* the condition that IP is always in the range 1 thro
430
/* (I - MAXPIT) .LE. JUSED .LE. (I-1) */
432
/* Note that the final value of I is LSAMP+1, so that
434
/* the DO loop is complete, we know: */
436
/* (LSAMP - MAXPIT + 1) .LE. JUSED .LE. LSAMP */
439
for (i__ = istart; i__ <= i__1; ++i__) {
440
r__1 = *ipito + slope * i__;
445
if (ip <= i__ - jused) {
448
/* The following check is no longer nece
450
/* we can prove that NOUT will never go
453
/* IF (NOUT .GT. 16) STOP 'PITSYN: too many epochs'
458
ivuv[*nout] = ivoice;
460
prop = (jused - ip / 2) / (real) lsamp;
462
for (j = 1; j <= i__2; ++j) {
463
alro = log((rco[j - 1] + 1) / (1 - rco[j - 1]));
464
alrn = log((rc[j] + 1) / (1 - rc[j]));
465
xxy = alro + prop * (alrn - alro);
467
rci[j + *nout * rci_dim1] = (xxy - 1) / (xxy + 1);
469
rmsi[*nout] = log(*rmso) + prop * (log(*rms) - log(*rmso));
470
rmsi[*nout] = exp(rmsi[*nout]);
477
/* I want to prove what range UVPIT must lie in after
479
/* assignments to it below. To do this, I must determ
481
/* what range (LSAMP-ISTART) must lie in, after the */
482
/* assignments to ISTART and LSAMP below. */
484
/* Let oldLSAMP be the value of LSAMP at this point in
486
/* execution. This is 135+JSAMP in state 110, or 45+J
488
/* states 100 or 101. */
490
/* Given the loop invariant on JUSED above, we know th
493
/* (oldLSAMP - MAXPIT + 1) .LE. JUSED .LE. oldLSAMP */
495
/* ISTART is one more than this. */
497
/* Let newLSAMP be the value assigned to LSAMP below.
499
/* is 180+JSAMP. Thus (newLSAMP-oldLSAMP) is either 4
501
/* 135, depending on the state. */
503
/* Thus, the range of newLSAMP-ISTART is: */
505
/* (newLSAMP-(oldLSAMP+1)) .LE. newLSAMP-ISTART */
506
/* .LE. (newLSAMP-(oldLSAMP - MAXPIT + 2)) */
510
/* 46 .LE. newLSAMP-ISTART .LE. 133+MAXPIT .EQ. 289 */
512
/* Therefore, UVPIT is in the range 23 to 144 after th
514
/* assignment to UVPIT below, and after the conditiona
516
/* assignment, it is in the range 23 to 90. */
518
/* The important thing is that it is in the range 20 t
520
/* so that in the loop above, IP is always in this ran
525
lsamp = *lframe + *jsamp;
528
uvpit = (real) ((lsamp - istart) / 2);
534
for (i__ = 1; i__ <= i__1; ++i__) {
535
rc[i__] = yarc[i__ - 1];
536
rco[i__ - 1] = yarc[i__ - 1];
540
*jsamp = lsamp - jused;
542
/* Given that the maximum pitch period MAXPIT .LT. LFRAME (this is
544
/* currently true on every call, since SYNTHS always sets */
545
/* LFRAME=180), NOUT will always be .GE. 1 at this point. */
551
for (i__ = 1; i__ <= i__1; ++i__) {
552
rco[i__ - 1] = rc[i__];