1 /*
2 
3  * Revision 1.1  1996/08/19  22:30:04  jaf
4  * Initial revision
5  *
6 
7 */
8 
9 /*  -- translated by f2c (version 19951025).
10    You must link the resulting object file with the libraries:
11 	-lf2c -lm   (in that order)
12 */
13 
14 #include "f2c.h"
15 
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__);
17 
18 /* Table of constant values */
19 
20 static real c_b2 = 1.f;
21 
22 /* ********************************************************************* */
23 
24 /* 	VPARMS Version 50 */
25 
26 /*
27  * Revision 1.1  1996/08/19  22:30:04  jaf
28  * Initial revision
29  * */
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. */
35 
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. */
39 
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. */
42 
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. */
46 
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. */
50 
51 /* Revision 1.1  1996/02/07 14:50:42  jaf */
52 /* Initial revision */
53 
54 
55 /* ********************************************************************* */
56 
57 /*  Calculate voicing parameters: */
58 
59 /* Input: */
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).
65 */
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).
70 */
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) */
75 /* Input/Output: */
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 */
90 /* Internal: */
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) */
104 
105 /* This subroutine has no local state. */
106 
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__)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 *
110 	ar_f__)
111 {
112     /* System generated locals */
113     integer inbuf_offset, lpbuf_offset, i__1;
114     real r__1, r__2;
115 
116     /* Builtin functions */
117     double r_sign(real *, real *);
118     integer i_nint(real *);
119 
120     /* Local variables */
121     integer vlen, stop, i__;
122     real e_pre__;
123     integer start;
124     real ap_rms__, e_0__, oldsgn, lp_rms__, e_b__, e_f__, r_b__, r_f__, e0ap;
125 
126 /*       Arguments */
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 */
133     --vwin;
134     --buflim;
135     lpbuf_offset = buflim[3];
136     lpbuf -= lpbuf_offset;
137     inbuf_offset = buflim[1];
138     inbuf -= inbuf_offset;
139 
140     /* Function Body */
141     lp_rms__ = 0.f;
142     ap_rms__ = 0.f;
143     e_pre__ = 0.f;
144     e0ap = 0.f;
145     *rc1 = 0.f;
146     e_0__ = 0.f;
147     e_b__ = 0.f;
148     e_f__ = 0.f;
149     r_f__ = 0.f;
150     r_b__ = 0.f;
151     *zc = 0;
152     vlen = vwin[2] - vwin[1] + 1;
153     start = vwin[1] + (*half - 1) * vlen / 2 + 1;
154     stop = start + vlen / 2 - 1;
155 
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. */
159 
160 /* HALF  START          STOP */
161 
162 /* 1     VWIN(1)+1      VWIN(1)+HVL */
163 /* 2     VWIN(1)+HVL+1  VWIN(1)+2*HVL */
164 
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 */
167 /* is undefined. */
168 
169     r__1 = inbuf[start - 1] - *dither;
170     oldsgn = r_sign(&c_b2, &r__1);
171     i__1 = stop;
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 */
177 	r__1 = inbuf[i__];
178 	e0ap += r__1 * r__1;
179 	*rc1 += inbuf[i__] * inbuf[i__ - 1];
180 /* Computing 2nd power */
181 	r__1 = lpbuf[i__];
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) {
193 	    ++(*zc);
194 	    oldsgn = -oldsgn;
195 	}
196 	*dither = -(*dither);
197     }
198 /*   Normalized short-term autocovariance coefficient at unit sample delay
199  */
200     *rc1 /= max(e0ap,1.f);
201 /*  Ratio of the energy of the first difference signal (6 dB/oct preemphas
202 is)*/
203 /*   to the energy of the full band signal */
204 /* Computing MAX */
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
211 ).*/
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);
217     *zc = i_nint(&r__1);
218 /* Computing MIN */
219     r__1 = lp_rms__ / 4 * (90.f / vlen);
220     i__1 = i_nint(&r__1);
221     *lbe = min(i__1,32767);
222 /* Computing MIN */
223     r__1 = ap_rms__ / 4 * (90.f / vlen);
224     i__1 = i_nint(&r__1);
225     *fbe = min(i__1,32767);
226     return 0;
227 } /* vparms_ */
228 
229