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