4
Revision 1.2 2000/01/05 08:20:39 markster
5
Some OSS fixes and a few lpc changes to make it actually work
7
* Revision 1.2 1996/08/20 20:40:12 jaf
8
* Removed all static local variables that were SAVE'd in the Fortran
9
* code, and put them in struct lpc10_decoder_state that is passed as an
12
* Removed init function, since all initialization is now done in
13
* init_lpc10_decoder_state().
15
* Revision 1.1 1996/08/19 22:31:12 jaf
21
#ifdef P_R_O_T_O_T_Y_P_E_S
22
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);
25
/* -- translated by f2c (version 19951025).
26
You must link the resulting object file with the libraries:
27
-lf2c -lm (in that order)
32
/* ***************************************************************** */
34
/* PITSYN Version 53 */
37
/* Revision 1.2 2000/01/05 08:20:39 markster
38
/* Some OSS fixes and a few lpc changes to make it actually work
40
* Revision 1.2 1996/08/20 20:40:12 jaf
41
* Removed all static local variables that were SAVE'd in the Fortran
42
* code, and put them in struct lpc10_decoder_state that is passed as an
45
* Removed init function, since all initialization is now done in
46
* init_lpc10_decoder_state().
48
* Revision 1.1 1996/08/19 22:31:12 jaf
51
/* Revision 1.2 1996/03/25 18:49:07 jaf */
52
/* Added commments about which indices of array arguments are read or */
55
/* Rearranged local variable declarations to indicate which need to be */
56
/* saved from one invocation to the next. Added entry INITPITSYN to */
57
/* reinitialize local state variables, if desired. */
59
/* Added lots of comments about proving that the maximum number of pitch */
60
/* periods (NOUT) that can be returned is 16. The call to STOP that */
61
/* could happen if NOUT got too large was removed as a result. */
63
/* Also proved that the total number of samples returned from N calls, */
64
/* each with identical values of LFRAME, will always be in the range */
65
/* N*LFRAME-MAXPIT+1 to N*LFRAME. */
67
/* Revision 1.1 1996/02/07 14:48:18 jaf */
68
/* Initial revision */
71
/* ***************************************************************** */
73
/* Synthesize a single pitch epoch */
76
/* ORDER - Synthesis order (number of RC's) */
77
/* VOICE - Half frame voicing decisions */
78
/* Indices 1 through 2 read. */
79
/* LFRAME - Length of speech buffer */
82
/* This value should be in the range MINPIT (20) to MAXPIT */
83
/* (156), inclusive. */
84
/* PITCH can be modified under some conditions. */
85
/* RMS - Energy (can be modified) */
86
/* RMS is changed to 1 if the value passed in is less than 1. */
87
/* RC - Reflection coefficients */
88
/* Indices 1 through ORDER can be temporarily overwritten with */
89
/* RCO, and then replaced with original values, under some */
92
/* IVUV - Pitch epoch voicing decisions */
93
/* Indices (I) of IVUV, IPITI, and RMSI are written, */
94
/* and indices (J,I) of RCI are written, */
95
/* where I ranges from 1 to NOUT, and J ranges from 1 to ORDER. */
96
/* IPITI - Pitch epoch length */
97
/* RMSI - Pitch epoch energy */
98
/* RCI - Pitch epoch RC's */
99
/* NOUT - Number of pitch periods in this frame */
100
/* This is at least 0, at least 1 if MAXPIT .LT. LFRAME (this */
101
/* is currently true on every call), and can never be more than */
102
/* (LFRAME+MAXPIT-1)/PITCH, which is currently 16 with */
103
/* LFRAME=180, MAXPIT=156, and PITCH .GE. 20, as SYNTHS */
104
/* guarantees when it calls this subroutine. */
105
/* RATIO - Previous to present energy ratio */
106
/* Always assigned a value. */
108
/* Subroutine */ int pitsyn_(integer *order, integer *voice,
109
integer *pitch, real *rms, real *rc, integer *lframe, integer *ivuv,
110
integer *ipiti, real *rmsi, real *rci, integer *nout, real *ratio,
111
struct lpc10_decoder_state *st)
113
/* Initialized data */
118
/* System generated locals */
119
integer rci_dim1, rci_offset, i__1, i__2;
122
/* Builtin functions */
123
double log(doublereal), exp(doublereal);
125
/* Local variables */
126
real alrn, alro, yarc[10], prop;
127
integer i__, j, vflag, jused, lsamp;
132
integer ip, nl, ivoice;
139
/* $Log: pitsyn.c,v $
140
/* Revision 1.2 2000/01/05 08:20:39 markster
141
/* Some OSS fixes and a few lpc changes to make it actually work
143
* Revision 1.2 1996/08/20 20:40:12 jaf
144
* Removed all static local variables that were SAVE'd in the Fortran
145
* code, and put them in struct lpc10_decoder_state that is passed as an
148
* Removed init function, since all initialization is now done in
149
* init_lpc10_decoder_state().
151
* Revision 1.1 1996/08/19 22:31:12 jaf
154
/* Revision 1.3 1996/03/29 22:03:47 jaf */
155
/* Removed definitions for any constants that were no longer used. */
157
/* Revision 1.2 1996/03/26 19:34:33 jaf */
158
/* Added comments indicating which constants are not needed in an */
159
/* application that uses the LPC-10 coder. */
161
/* Revision 1.1 1996/02/07 14:43:51 jaf */
162
/* Initial revision */
164
/* LPC Configuration parameters: */
165
/* Frame size, Prediction order, Pitch period */
166
/* Local variables that need not be saved */
167
/* LSAMP is initialized in the IF (FIRST) THEN clause, but it is */
168
/* not used the first time through, and it is given a value before
170
/* use whenever FIRST is .FALSE., so it appears unnecessary to */
171
/* assign it a value when FIRST is .TRUE. */
173
/* FIRST - .TRUE. only on first call to PITSYN. */
174
/* IVOICO - Previous VOICE(2) value. */
175
/* IPITO - Previous PITCH value. */
176
/* RMSO - Previous RMS value. */
177
/* RCO - Previous RC values. */
179
/* JSAMP - If this routine is called N times with identical values of */
180
/* LFRAME, then the total length of all pitch periods returned */
181
/* is always N*LFRAME-JSAMP, and JSAMP is always in the range 0
183
/* to MAXPIT-1 (see below for why this is so). Thus JSAMP is */
184
/* the number of samples "left over" from the previous call to */
185
/* PITSYN, that haven't been "used" in a pitch period returned */
186
/* from this subroutine. Every time this subroutine is called,
188
/* it returns pitch periods with a total length of at most */
191
/* IVOICO, IPITO, RCO, and JSAMP need not be assigned an initial value */
192
/* with a DATA statement, because they are always initialized on the */
193
/* first call to PITSYN. */
195
/* FIRST and RMSO should be initialized with DATA statements, because */
196
/* even on the first call, they are used before being initialized. */
197
/* Parameter adjustments */
203
rci_offset = rci_dim1 + 1;
220
ivoico = &(st->ivoico);
221
ipito = &(st->ipito);
224
jsamp = &(st->jsamp);
225
first = &(st->first_pitsyn);
234
*ratio = *rms / (*rmso + 8.f);
239
*pitch = *lframe / 4;
241
*nout = *lframe / *pitch;
242
*jsamp = *lframe - *nout * *pitch;
244
/* SYNTHS only calls this subroutine with PITCH in the range
246
/* to 156. LFRAME = MAXFRM = 180, so NOUT is somewhere in th
250
/* JSAMP is "LFRAME mod PITCH", so it is in the range 0 to */
251
/* (PITCH-1), or 0 to MAXPIT-1=155, after the first call. */
254
for (i__ = 1; i__ <= i__1; ++i__) {
256
for (j = 1; j <= i__2; ++j) {
257
rci[j + i__ * rci_dim1] = rc[j];
266
lsamp = *lframe + *jsamp;
267
slope = (*pitch - *ipito) / (real) lsamp;
271
if (voice[1] == *ivoico && voice[2] == voice[1]) {
273
/* SSUV - - 0 , 0 , 0 */
274
*pitch = *lframe / 4;
280
/* SSVC - - 1 , 1 , 1 */
281
slope = (*pitch - *ipito) / (real) lsamp;
285
if (*ivoico == voice[1]) {
286
/* UV2VC2 - - 0 , 0 , 1 */
287
nl = lsamp - *lframe / 4;
289
/* UV2VC1 - - 0 , 1 , 1 */
290
nl = lsamp - *lframe * 3 / 4;
293
ipiti[2] = nl - ipiti[1];
299
for (i__ = 1; i__ <= i__1; ++i__) {
300
rci[i__ + rci_dim1] = rco[i__ - 1];
301
rci[i__ + (rci_dim1 << 1)] = rco[i__ - 1];
302
rco[i__ - 1] = rc[i__];
311
if (*ivoico != voice[1]) {
312
/* VC2UV1 - - 1 , 0 , 0 */
313
lsamp = *lframe / 4 + *jsamp;
315
/* VC2UV2 - - 1 , 1 , 0 */
316
lsamp = *lframe * 3 / 4 + *jsamp;
319
for (i__ = 1; i__ <= i__1; ++i__) {
320
yarc[i__ - 1] = rc[i__];
321
rc[i__] = rco[i__ - 1];
328
/* Here is the value of most variables that are used below, depending
330
/* the values of IVOICO, VOICE(1), and VOICE(2). VOICE(1) and VOICE(2
332
/* are input arguments, and IVOICO is the value of VOICE(2) on the */
333
/* previous call (see notes for the IF (NOUT .NE. 0) statement near th
335
/* end). Each of these three values is either 0 or 1. These three */
336
/* values below are given as 3-bit long strings, in the order IVOICO,
338
/* VOICE(1), and VOICE(2). It appears that the code above assumes tha
340
/* the bit sequences 010 and 101 never occur, but I wonder whether a
342
/* large enough number of bit errors in the channel could cause such a
344
/* thing to happen, and if so, could that cause NOUT to ever go over 1
347
/* Note that all of the 180 values in the table are really LFRAME, but
349
/* 180 has fewer characters, and it makes the table a little more */
350
/* concrete. If LFRAME is ever changed, keep this in mind. Similarly
352
/* 135's are 3*LFRAME/4, and 45's are LFRAME/4. If LFRAME is not a */
353
/* multiple of 4, then the 135 for NL-JSAMP is actually LFRAME-LFRAME/
355
/* and the 45 for NL-JSAMP is actually LFRAME-3*LFRAME/4. */
357
/* Note that LSAMP-JSAMP is given as the variable. This was just for
359
/* brevity, to avoid adding "+JSAMP" to all of the column entries. */
360
/* Similarly for NL-JSAMP. */
362
/* Variable | 000 001 011,010 111 110 100,101 */
363
/* ------------+-------------------------------------------------- */
364
/* ISTART | 1 NL+1 NL+1 1 1 1 */
365
/* LSAMP-JSAMP | 180 180 180 180 135 45 */
366
/* IPITO | 45 PITCH PITCH oldPITCH oldPITCH oldPITCH */
367
/* SLOPE | 0 0 0 seebelow 0 0 */
368
/* JUSED | 0 NL NL 0 0 0 */
369
/* PITCH | 45 PITCH PITCH PITCH PITCH PITCH */
370
/* NL-JSAMP | -- 135 45 -- -- -- */
371
/* VFLAG | 0 0 0 0 1 1 */
372
/* NOUT | 0 2 2 0 0 0 */
373
/* IVOICE | 0 1 1 1 1 1 */
375
/* while_loop | once once once once twice twice */
377
/* ISTART | -- -- -- -- JUSED+1 JUSED+1 */
378
/* LSAMP-JSAMP | -- -- -- -- 180 180 */
379
/* IPITO | -- -- -- -- oldPITCH oldPITCH */
380
/* SLOPE | -- -- -- -- 0 0 */
381
/* JUSED | -- -- -- -- ?? ?? */
382
/* PITCH | -- -- -- -- PITCH PITCH */
383
/* NL-JSAMP | -- -- -- -- -- -- */
384
/* VFLAG | -- -- -- -- 0 0 */
385
/* NOUT | -- -- -- -- ?? ?? */
386
/* IVOICE | -- -- -- -- 0 0 */
389
/* UVPIT is always 0.0 on the first pass through the DO WHILE (.TRUE.)
393
/* The only possible non-0 value of SLOPE (in column 111) is */
394
/* (PITCH-IPITO)/FLOAT(LSAMP) */
396
/* Column 101 is identical to 100. Any good properties we can prove
398
/* for 100 will also hold for 101. Similarly for 010 and 011. */
400
/* SYNTHS calls this subroutine with PITCH restricted to the range 20
402
/* 156. IPITO is similarly restricted to this range, after the first
404
/* call. IP below is also restricted to this range, given the */
405
/* definitions of IPITO, SLOPE, UVPIT, and that I is in the range ISTA
411
/* JUSED is the total length of all pitch periods curr
413
/* in the output arrays, in samples. */
415
/* An invariant of the DO I = ISTART,LSAMP loop below,
417
/* the condition that IP is always in the range 1 thro
421
/* (I - MAXPIT) .LE. JUSED .LE. (I-1) */
423
/* Note that the final value of I is LSAMP+1, so that
425
/* the DO loop is complete, we know: */
427
/* (LSAMP - MAXPIT + 1) .LE. JUSED .LE. LSAMP */
430
for (i__ = istart; i__ <= i__1; ++i__) {
431
r__1 = *ipito + slope * i__;
436
if (ip <= i__ - jused) {
439
/* The following check is no longer nece
441
/* we can prove that NOUT will never go
444
/* IF (NOUT .GT. 16) STOP 'PITSYN: too many epochs'
449
ivuv[*nout] = ivoice;
451
prop = (jused - ip / 2) / (real) lsamp;
453
for (j = 1; j <= i__2; ++j) {
454
alro = log((rco[j - 1] + 1) / (1 - rco[j - 1]));
455
alrn = log((rc[j] + 1) / (1 - rc[j]));
456
xxy = alro + prop * (alrn - alro);
458
rci[j + *nout * rci_dim1] = (xxy - 1) / (xxy + 1);
460
rmsi[*nout] = log(*rmso) + prop * (log(*rms) - log(*rmso));
461
rmsi[*nout] = exp(rmsi[*nout]);
468
/* I want to prove what range UVPIT must lie in after
470
/* assignments to it below. To do this, I must determ
472
/* what range (LSAMP-ISTART) must lie in, after the */
473
/* assignments to ISTART and LSAMP below. */
475
/* Let oldLSAMP be the value of LSAMP at this point in
477
/* execution. This is 135+JSAMP in state 110, or 45+J
479
/* states 100 or 101. */
481
/* Given the loop invariant on JUSED above, we know th
484
/* (oldLSAMP - MAXPIT + 1) .LE. JUSED .LE. oldLSAMP */
486
/* ISTART is one more than this. */
488
/* Let newLSAMP be the value assigned to LSAMP below.
490
/* is 180+JSAMP. Thus (newLSAMP-oldLSAMP) is either 4
492
/* 135, depending on the state. */
494
/* Thus, the range of newLSAMP-ISTART is: */
496
/* (newLSAMP-(oldLSAMP+1)) .LE. newLSAMP-ISTART */
497
/* .LE. (newLSAMP-(oldLSAMP - MAXPIT + 2)) */
501
/* 46 .LE. newLSAMP-ISTART .LE. 133+MAXPIT .EQ. 289 */
503
/* Therefore, UVPIT is in the range 23 to 144 after th
505
/* assignment to UVPIT below, and after the conditiona
507
/* assignment, it is in the range 23 to 90. */
509
/* The important thing is that it is in the range 20 t
511
/* so that in the loop above, IP is always in this ran
516
lsamp = *lframe + *jsamp;
519
uvpit = (real) ((lsamp - istart) / 2);
525
for (i__ = 1; i__ <= i__1; ++i__) {
526
rc[i__] = yarc[i__ - 1];
527
rco[i__ - 1] = yarc[i__ - 1];
531
*jsamp = lsamp - jused;
533
/* Given that the maximum pitch period MAXPIT .LT. LFRAME (this is
535
/* currently true on every call, since SYNTHS always sets */
536
/* LFRAME=180), NOUT will always be .GE. 1 at this point. */
542
for (i__ = 1; i__ <= i__1; ++i__) {
543
rco[i__ - 1] = rc[i__];