3 * Revision 1.1 1996/08/19 22:30:04 jaf
9 /* -- translated by f2c (version 19951025).
10 You must link the resulting object file with the libraries:
11 -lf2c -lm (in that order)
16 extern 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__
);
18 /* Table of constant values */
20 static real c_b2
= 1.f
;
22 /* ********************************************************************* */
24 /* VPARMS Version 50 */
27 * Revision 1.1 1996/08/19 22:30:04 jaf
30 /* Revision 1.6 1996/03/29 18:01:16 jaf */
31 /* Added some more comments about the range of INBUF and LPBUF that can */
32 /* be read. Note that it is possible for index VWIN(2)+1 to be read from */
33 /* INBUF, which might be outside of its defined range, although that will */
34 /* require more careful checking. */
36 /* Revision 1.5 1996/03/19 00:02:02 jaf */
37 /* I just noticed that the argument DITHER is modified inside of this */
38 /* subroutine. Comments were added explaining the possible final values. */
40 /* Revision 1.4 1996/03/18 22:22:59 jaf */
41 /* Finishing the job I said I did with the last check-in comments. */
43 /* Revision 1.3 1996/03/18 22:22:17 jaf */
44 /* Just added a few comments about which array indices of the arguments */
45 /* are used, and mentioning that this subroutine has no local state. */
47 /* Revision 1.2 1996/03/13 15:02:58 jaf */
48 /* Comments added explaining that none of the local variables of this */
49 /* subroutine need to be saved from one invocation to the next. */
51 /* Revision 1.1 1996/02/07 14:50:42 jaf */
52 /* Initial revision */
55 /* ********************************************************************* */
57 /* Calculate voicing parameters: */
60 /* VWIN - Voicing window limits */
61 /* Indices 1 through 2 read. */
62 /* INBUF - Input speech buffer */
63 /* Indices START-1 through STOP read, */
64 /* where START and STOP are defined in the code (only written once).
66 /* Note that STOP can be as large as VWIN(2)+1 ! */
67 /* LPBUF - Low pass filtered speech */
68 /* Indices START-MINTAU through STOP+MINTAU read, */
69 /* where START and STOP are defined in the code (only written once).
71 /* BUFLIM - Array bounds for INBUF and LPBUF */
72 /* Indices 1 through 4 read. */
73 /* HALF - Half frame (1 or 2) */
74 /* MINTAU - Lag corresponding to minimum AMDF value (pitch estimate) */
76 /* DITHER - Zero crossing threshold */
77 /* The resulting value might be the negation of the input */
78 /* value. It might always be the same as the input value, */
79 /* if the DO loop below always executes an even number of times. */
80 /* Output: (all of them are written on every call) */
81 /* ZC - Zero crossing rate */
82 /* LBE - Low band energy (sum of magnitudes - SM) */
83 /* FBE - Full band energy (SM) */
84 /* QS - Ratio of 6 dB/oct preemphasized energy to full band energy */
85 /* RC1 - First reflection coefficient */
86 /* AR_B - Product of the causal forward and reverse pitch */
87 /* prediction gains */
88 /* AR_F - Product of the noncausal forward and reverse pitch */
89 /* prediction gains */
91 /* OLDSGN - Previous sign of dithered signal */
92 /* VLEN - Length of voicing window */
93 /* START - Lower address of current half of voicing window */
94 /* STOP - Upper address of current half of voicing window */
95 /* E_0 - Energy of LPF speech (sum of squares - SS) */
96 /* E_B - Energy of LPF speech backward one pitch period (SS) */
97 /* E_F - Energy of LPF speech forward one pitch period (SS) */
98 /* R_B - Autocovariance of LPF speech backward one pitch period */
99 /* R_F - Autocovariance of LPF speech forward one pitch period */
100 /* LP_RMS - Energy of LPF speech (sum of magnitudes - SM) */
101 /* AP_RMS - Energy of all-pass speech (SM) */
102 /* E_PRE - Energy of 6dB preemphasized speech (SM) */
103 /* E0AP - Energy of all-pass speech (SS) */
105 /* This subroutine has no local state. */
107 /* Subroutine */ int vparms_(integer
*vwin
, real
*inbuf
, real
*lpbuf
, integer
108 *buflim
, integer
*half
, real
*dither
, integer
*mintau
, integer
*zc
,
109 integer
*lbe
, integer
*fbe
, real
*qs
, real
*rc1
, real
*ar_b__
, real
*
112 /* System generated locals */
113 integer inbuf_offset
, lpbuf_offset
, i__1
;
116 /* Builtin functions */
117 double r_sign(real
*, real
*);
118 integer
i_nint(real
*);
120 /* Local variables */
121 integer vlen
, stop
, i__
;
124 real ap_rms__
, e_0__
, oldsgn
, lp_rms__
, e_b__
, e_f__
, r_b__
, r_f__
, e0ap
;
127 /* Local variables that need not be saved */
128 /* Calculate zero crossings (ZC) and several energy and correlation */
129 /* measures on low band and full band speech. Each measure is taken */
130 /* over either the first or the second half of the voicing window, */
131 /* depending on the variable HALF. */
132 /* Parameter adjustments */
135 lpbuf_offset
= buflim
[3];
136 lpbuf
-= lpbuf_offset
;
137 inbuf_offset
= buflim
[1];
138 inbuf
-= inbuf_offset
;
152 vlen
= vwin
[2] - vwin
[1] + 1;
153 start
= vwin
[1] + (*half
- 1) * vlen
/ 2 + 1;
154 stop
= start
+ vlen
/ 2 - 1;
156 /* I'll use the symbol HVL in the table below to represent the value */
157 /* VLEN/2. Note that if VLEN is odd, then HVL should be rounded down, */
158 /* i.e., HVL = (VLEN-1)/2. */
160 /* HALF START STOP */
162 /* 1 VWIN(1)+1 VWIN(1)+HVL */
163 /* 2 VWIN(1)+HVL+1 VWIN(1)+2*HVL */
165 /* Note that if VLEN is even and HALF is 2, then STOP will be */
166 /* VWIN(1)+VLEN = VWIN(2)+1. That could be bad, if that index of INBUF */
169 r__1
= inbuf
[start
- 1] - *dither
;
170 oldsgn
= r_sign(&c_b2
, &r__1
);
172 for (i__
= start
; i__
<= i__1
; ++i__
) {
173 lp_rms__
+= (r__1
= lpbuf
[i__
], abs(r__1
));
174 ap_rms__
+= (r__1
= inbuf
[i__
], abs(r__1
));
175 e_pre__
+= (r__1
= inbuf
[i__
] - inbuf
[i__
- 1], abs(r__1
));
176 /* Computing 2nd power */
179 *rc1
+= inbuf
[i__
] * inbuf
[i__
- 1];
180 /* Computing 2nd power */
182 e_0__
+= r__1
* r__1
;
183 /* Computing 2nd power */
184 r__1
= lpbuf
[i__
- *mintau
];
185 e_b__
+= r__1
* r__1
;
186 /* Computing 2nd power */
187 r__1
= lpbuf
[i__
+ *mintau
];
188 e_f__
+= r__1
* r__1
;
189 r_f__
+= lpbuf
[i__
] * lpbuf
[i__
+ *mintau
];
190 r_b__
+= lpbuf
[i__
] * lpbuf
[i__
- *mintau
];
191 r__1
= inbuf
[i__
] + *dither
;
192 if (r_sign(&c_b2
, &r__1
) != oldsgn
) {
196 *dither
= -(*dither
);
198 /* Normalized short-term autocovariance coefficient at unit sample delay
200 *rc1
/= max(e0ap
,1.f
);
201 /* Ratio of the energy of the first difference signal (6 dB/oct preemphas
203 /* to the energy of the full band signal */
205 r__1
= ap_rms__
* 2.f
;
206 *qs
= e_pre__
/ max(r__1
,1.f
);
207 /* aR_b is the product of the forward and reverse prediction gains, */
208 /* looking backward in time (the causal case). */
209 *ar_b__
= r_b__
/ max(e_b__
,1.f
) * (r_b__
/ max(e_0__
,1.f
));
210 /* aR_f is the same as aR_b, but looking forward in time (non causal case
212 *ar_f__
= r_f__
/ max(e_f__
,1.f
) * (r_f__
/ max(e_0__
,1.f
));
213 /* Normalize ZC, LBE, and FBE to old fixed window length of 180. */
214 /* (The fraction 90/VLEN has a range of .58 to 1) */
215 r__2
= (real
) (*zc
<< 1);
216 r__1
= r__2
* (90.f
/ vlen
);
219 r__1
= lp_rms__
/ 4 * (90.f
/ vlen
);
220 i__1
= i_nint(&r__1
);
221 *lbe
= min(i__1
,32767);
223 r__1
= ap_rms__
/ 4 * (90.f
/ vlen
);
224 i__1
= i_nint(&r__1
);
225 *fbe
= min(i__1
,32767);