4 Revision 1.16 2004/06/26 03:50:14 markster
5 Merge source cleanups (bug #1911)
7 Revision 1.15 2003/11/23 22:14:32 markster
8 Various warning cleanups
10 Revision 1.14 2003/02/12 13:59:15 matteo
11 mer feb 12 14:56:57 CET 2003
13 Revision 1.1.1.1 2003/02/12 13:59:15 matteo
14 mer feb 12 14:56:57 CET 2003
16 Revision 1.2 2000/01/05 08:20:39 markster
17 Some OSS fixes and a few lpc changes to make it actually work
19 * Revision 1.2 1996/08/20 20:40:12 jaf
20 * Removed all static local variables that were SAVE'd in the Fortran
21 * code, and put them in struct lpc10_decoder_state that is passed as an
24 * Removed init function, since all initialization is now done in
25 * init_lpc10_decoder_state().
27 * Revision 1.1 1996/08/19 22:31:12 jaf
33 /* -- translated by f2c (version 19951025).
34 You must link the resulting object file with the libraries:
35 -lf2c -lm (in that order)
40 #ifdef P_R_O_T_O_T_Y_P_E_S
41 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
);
44 /* ***************************************************************** */
46 /* PITSYN Version 53 */
49 * Revision 1.16 2004/06/26 03:50:14 markster
50 * Merge source cleanups (bug #1911)
52 * Revision 1.15 2003/11/23 22:14:32 markster
53 * Various warning cleanups
55 * Revision 1.14 2003/02/12 13:59:15 matteo
56 * mer feb 12 14:56:57 CET 2003
58 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
59 * mer feb 12 14:56:57 CET 2003
61 * Revision 1.2 2000/01/05 08:20:39 markster
62 * Some OSS fixes and a few lpc changes to make it actually work
64 * Revision 1.2 1996/08/20 20:40:12 jaf
65 * Removed all static local variables that were SAVE'd in the Fortran
66 * code, and put them in struct lpc10_decoder_state that is passed as an
69 * Removed init function, since all initialization is now done in
70 * init_lpc10_decoder_state().
72 * Revision 1.1 1996/08/19 22:31:12 jaf
75 /* Revision 1.2 1996/03/25 18:49:07 jaf */
76 /* Added commments about which indices of array arguments are read or */
79 /* Rearranged local variable declarations to indicate which need to be */
80 /* saved from one invocation to the next. Added entry INITPITSYN to */
81 /* reinitialize local state variables, if desired. */
83 /* Added lots of comments about proving that the maximum number of pitch */
84 /* periods (NOUT) that can be returned is 16. The call to STOP that */
85 /* could happen if NOUT got too large was removed as a result. */
87 /* Also proved that the total number of samples returned from N calls, */
88 /* each with identical values of LFRAME, will always be in the range */
89 /* N*LFRAME-MAXPIT+1 to N*LFRAME. */
91 /* Revision 1.1 1996/02/07 14:48:18 jaf */
92 /* Initial revision */
95 /* ***************************************************************** */
97 /* Synthesize a single pitch epoch */
100 /* ORDER - Synthesis order (number of RC's) */
101 /* VOICE - Half frame voicing decisions */
102 /* Indices 1 through 2 read. */
103 /* LFRAME - Length of speech buffer */
106 /* This value should be in the range MINPIT (20) to MAXPIT */
107 /* (156), inclusive. */
108 /* PITCH can be modified under some conditions. */
109 /* RMS - Energy (can be modified) */
110 /* RMS is changed to 1 if the value passed in is less than 1. */
111 /* RC - Reflection coefficients */
112 /* Indices 1 through ORDER can be temporarily overwritten with */
113 /* RCO, and then replaced with original values, under some */
116 /* IVUV - Pitch epoch voicing decisions */
117 /* Indices (I) of IVUV, IPITI, and RMSI are written, */
118 /* and indices (J,I) of RCI are written, */
119 /* where I ranges from 1 to NOUT, and J ranges from 1 to ORDER. */
120 /* IPITI - Pitch epoch length */
121 /* RMSI - Pitch epoch energy */
122 /* RCI - Pitch epoch RC's */
123 /* NOUT - Number of pitch periods in this frame */
124 /* This is at least 0, at least 1 if MAXPIT .LT. LFRAME (this */
125 /* is currently true on every call), and can never be more than */
126 /* (LFRAME+MAXPIT-1)/PITCH, which is currently 16 with */
127 /* LFRAME=180, MAXPIT=156, and PITCH .GE. 20, as SYNTHS */
128 /* guarantees when it calls this subroutine. */
129 /* RATIO - Previous to present energy ratio */
130 /* Always assigned a value. */
132 /* Subroutine */ int pitsyn_(integer
*order
, integer
*voice
,
133 integer
*pitch
, real
*rms
, real
*rc
, integer
*lframe
, integer
*ivuv
,
134 integer
*ipiti
, real
*rmsi
, real
*rci
, integer
*nout
, real
*ratio
,
135 struct lpc10_decoder_state
*st
)
137 /* Initialized data */
142 /* System generated locals */
143 integer rci_dim1
= 0, rci_offset
, i__1
, i__2
;
146 /* Builtin functions */
147 double log(doublereal
), exp(doublereal
);
149 /* Local variables */
150 real alrn
, alro
, yarc
[10], prop
;
151 integer i__
, j
, vflag
, jused
, lsamp
;
156 integer ip
, nl
, ivoice
;
164 * Revision 1.16 2004/06/26 03:50:14 markster
165 * Merge source cleanups (bug #1911)
167 * Revision 1.15 2003/11/23 22:14:32 markster
168 * Various warning cleanups
170 * Revision 1.14 2003/02/12 13:59:15 matteo
171 * mer feb 12 14:56:57 CET 2003
173 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
174 * mer feb 12 14:56:57 CET 2003
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
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
184 * Removed init function, since all initialization is now done in
185 * init_lpc10_decoder_state().
187 * Revision 1.1 1996/08/19 22:31:12 jaf
190 /* Revision 1.3 1996/03/29 22:03:47 jaf */
191 /* Removed definitions for any constants that were no longer used. */
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. */
197 /* Revision 1.1 1996/02/07 14:43:51 jaf */
198 /* Initial revision */
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
206 /* use whenever FIRST is .FALSE., so it appears unnecessary to */
207 /* assign it a value when FIRST is .TRUE. */
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. */
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
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,
224 /* it returns pitch periods with a total length of at most */
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. */
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 */
239 rci_offset
= rci_dim1
+ 1;
256 ivoico
= &(st
->ivoico
);
257 ipito
= &(st
->ipito
);
260 jsamp
= &(st
->jsamp
);
261 first
= &(st
->first_pitsyn
);
270 *ratio
= *rms
/ (*rmso
+ 8.f
);
275 *pitch
= *lframe
/ 4;
277 *nout
= *lframe
/ *pitch
;
278 *jsamp
= *lframe
- *nout
* *pitch
;
280 /* SYNTHS only calls this subroutine with PITCH in the range
282 /* to 156. LFRAME = MAXFRM = 180, so NOUT is somewhere in th
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. */
290 for (i__
= 1; i__
<= i__1
; ++i__
) {
292 for (j
= 1; j
<= i__2
; ++j
) {
293 rci
[j
+ i__
* rci_dim1
] = rc
[j
];
302 lsamp
= *lframe
+ *jsamp
;
303 slope
= (*pitch
- *ipito
) / (real
) lsamp
;
307 if (voice
[1] == *ivoico
&& voice
[2] == voice
[1]) {
309 /* SSUV - - 0 , 0 , 0 */
310 *pitch
= *lframe
/ 4;
316 /* SSVC - - 1 , 1 , 1 */
317 slope
= (*pitch
- *ipito
) / (real
) lsamp
;
321 if (*ivoico
== voice
[1]) {
322 /* UV2VC2 - - 0 , 0 , 1 */
323 nl
= lsamp
- *lframe
/ 4;
325 /* UV2VC1 - - 0 , 1 , 1 */
326 nl
= lsamp
- *lframe
* 3 / 4;
329 ipiti
[2] = nl
- ipiti
[1];
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__
];
347 if (*ivoico
!= voice
[1]) {
348 /* VC2UV1 - - 1 , 0 , 0 */
349 lsamp
= *lframe
/ 4 + *jsamp
;
351 /* VC2UV2 - - 1 , 1 , 0 */
352 lsamp
= *lframe
* 3 / 4 + *jsamp
;
355 for (i__
= 1; i__
<= i__1
; ++i__
) {
356 yarc
[i__
- 1] = rc
[i__
];
357 rc
[i__
] = rco
[i__
- 1];
364 /* Here is the value of most variables that are used below, depending
366 /* the values of IVOICO, VOICE(1), and VOICE(2). VOICE(1) and VOICE(2
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
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,
374 /* VOICE(1), and VOICE(2). It appears that the code above assumes tha
376 /* the bit sequences 010 and 101 never occur, but I wonder whether a
378 /* large enough number of bit errors in the channel could cause such a
380 /* thing to happen, and if so, could that cause NOUT to ever go over 1
383 /* Note that all of the 180 values in the table are really LFRAME, but
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
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/
391 /* and the 45 for NL-JSAMP is actually LFRAME-3*LFRAME/4. */
393 /* Note that LSAMP-JSAMP is given as the variable. This was just for
395 /* brevity, to avoid adding "+JSAMP" to all of the column entries. */
396 /* Similarly for NL-JSAMP. */
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 */
411 /* while_loop | once once once once twice twice */
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 */
425 /* UVPIT is always 0.0 on the first pass through the DO WHILE (.TRUE.)
429 /* The only possible non-0 value of SLOPE (in column 111) is */
430 /* (PITCH-IPITO)/FLOAT(LSAMP) */
432 /* Column 101 is identical to 100. Any good properties we can prove
434 /* for 100 will also hold for 101. Similarly for 010 and 011. */
436 /* SYNTHS calls this subroutine with PITCH restricted to the range 20
438 /* 156. IPITO is similarly restricted to this range, after the first
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
447 /* JUSED is the total length of all pitch periods curr
449 /* in the output arrays, in samples. */
451 /* An invariant of the DO I = ISTART,LSAMP loop below,
453 /* the condition that IP is always in the range 1 thro
457 /* (I - MAXPIT) .LE. JUSED .LE. (I-1) */
459 /* Note that the final value of I is LSAMP+1, so that
461 /* the DO loop is complete, we know: */
463 /* (LSAMP - MAXPIT + 1) .LE. JUSED .LE. LSAMP */
466 for (i__
= istart
; i__
<= i__1
; ++i__
) {
467 r__1
= *ipito
+ slope
* i__
;
468 ip
= (integer
)(r__1
+ .5f
);
472 if (ip
<= i__
- jused
) {
475 /* The following check is no longer nece
477 /* we can prove that NOUT will never go
480 /* IF (NOUT .GT. 16) STOP 'PITSYN: too many epochs'
485 ivuv
[*nout
] = ivoice
;
487 prop
= (jused
- ip
/ 2) / (real
) lsamp
;
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);
496 rmsi
[*nout
] = (real
)(log(*rmso
) + prop
* (log(*rms
) - log(*rmso
)));
497 rmsi
[*nout
] = (real
)exp(rmsi
[*nout
]);
504 /* I want to prove what range UVPIT must lie in after
506 /* assignments to it below. To do this, I must determ
508 /* what range (LSAMP-ISTART) must lie in, after the */
509 /* assignments to ISTART and LSAMP below. */
511 /* Let oldLSAMP be the value of LSAMP at this point in
513 /* execution. This is 135+JSAMP in state 110, or 45+J
515 /* states 100 or 101. */
517 /* Given the loop invariant on JUSED above, we know th
520 /* (oldLSAMP - MAXPIT + 1) .LE. JUSED .LE. oldLSAMP */
522 /* ISTART is one more than this. */
524 /* Let newLSAMP be the value assigned to LSAMP below.
526 /* is 180+JSAMP. Thus (newLSAMP-oldLSAMP) is either 4
528 /* 135, depending on the state. */
530 /* Thus, the range of newLSAMP-ISTART is: */
532 /* (newLSAMP-(oldLSAMP+1)) .LE. newLSAMP-ISTART */
533 /* .LE. (newLSAMP-(oldLSAMP - MAXPIT + 2)) */
537 /* 46 .LE. newLSAMP-ISTART .LE. 133+MAXPIT .EQ. 289 */
539 /* Therefore, UVPIT is in the range 23 to 144 after th
541 /* assignment to UVPIT below, and after the conditiona
543 /* assignment, it is in the range 23 to 90. */
545 /* The important thing is that it is in the range 20 t
547 /* so that in the loop above, IP is always in this ran
552 lsamp
= *lframe
+ *jsamp
;
555 uvpit
= (real
) ((lsamp
- istart
) / 2);
561 for (i__
= 1; i__
<= i__1
; ++i__
) {
562 rc
[i__
] = yarc
[i__
- 1];
563 rco
[i__
- 1] = yarc
[i__
- 1];
567 *jsamp
= lsamp
- jused
;
569 /* Given that the maximum pitch period MAXPIT .LT. LFRAME (this is
571 /* currently true on every call, since SYNTHS always sets */
572 /* LFRAME=180), NOUT will always be .GE. 1 at this point. */
578 for (i__
= 1; i__
<= i__1
; ++i__
) {
579 rco
[i__
- 1] = rc
[i__
];