Asterisk - The Open Source Telephony Project  18.5.0
vparms.c
Go to the documentation of this file.
1 /*
2 
3 $Log$
4 Revision 1.15 2004/06/26 03:50:14 markster
5 Merge source cleanups (bug #1911)
6 
7 Revision 1.14 2003/02/12 13:59:15 matteo
8 mer feb 12 14:56:57 CET 2003
9 
10 Revision 1.1.1.1 2003/02/12 13:59:15 matteo
11 mer feb 12 14:56:57 CET 2003
12 
13 Revision 1.2 2000/01/05 08:20:40 markster
14 Some OSS fixes and a few lpc changes to make it actually work
15 
16  * Revision 1.1 1996/08/19 22:30:04 jaf
17  * Initial revision
18  *
19 
20 */
21 
22 /* -- translated by f2c (version 19951025).
23  You must link the resulting object file with the libraries:
24  -lf2c -lm (in that order)
25 */
26 
27 #include "f2c.h"
28 
29 #ifdef P_R_O_T_O_T_Y_P_E_S
30 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__);
31 #endif
32 
33 /* Table of constant values */
34 
35 static real c_b2 = 1.f;
36 
37 /* ********************************************************************* */
38 
39 /* VPARMS Version 50 */
40 
41 /* $Log$
42  * Revision 1.15 2004/06/26 03:50:14 markster
43  * Merge source cleanups (bug #1911)
44  *
45  * Revision 1.14 2003/02/12 13:59:15 matteo
46  * mer feb 12 14:56:57 CET 2003
47  *
48  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
49  * mer feb 12 14:56:57 CET 2003
50  *
51  * Revision 1.2 2000/01/05 08:20:40 markster
52  * Some OSS fixes and a few lpc changes to make it actually work
53  *
54  * Revision 1.1 1996/08/19 22:30:04 jaf
55  * Initial revision
56  * */
57 /* Revision 1.6 1996/03/29 18:01:16 jaf */
58 /* Added some more comments about the range of INBUF and LPBUF that can */
59 /* be read. Note that it is possible for index VWIN(2)+1 to be read from */
60 /* INBUF, which might be outside of its defined range, although that will */
61 /* require more careful checking. */
62 
63 /* Revision 1.5 1996/03/19 00:02:02 jaf */
64 /* I just noticed that the argument DITHER is modified inside of this */
65 /* subroutine. Comments were added explaining the possible final values. */
66 
67 /* Revision 1.4 1996/03/18 22:22:59 jaf */
68 /* Finishing the job I said I did with the last check-in comments. */
69 
70 /* Revision 1.3 1996/03/18 22:22:17 jaf */
71 /* Just added a few comments about which array indices of the arguments */
72 /* are used, and mentioning that this subroutine has no local state. */
73 
74 /* Revision 1.2 1996/03/13 15:02:58 jaf */
75 /* Comments added explaining that none of the local variables of this */
76 /* subroutine need to be saved from one invocation to the next. */
77 
78 /* Revision 1.1 1996/02/07 14:50:42 jaf */
79 /* Initial revision */
80 
81 
82 /* ********************************************************************* */
83 
84 /* Calculate voicing parameters: */
85 
86 /* Input: */
87 /* VWIN - Voicing window limits */
88 /* Indices 1 through 2 read. */
89 /* INBUF - Input speech buffer */
90 /* Indices START-1 through STOP read, */
91 /* where START and STOP are defined in the code (only written once).
92 */
93 /* Note that STOP can be as large as VWIN(2)+1 ! */
94 /* LPBUF - Low pass filtered speech */
95 /* Indices START-MINTAU through STOP+MINTAU read, */
96 /* where START and STOP are defined in the code (only written once).
97 */
98 /* BUFLIM - Array bounds for INBUF and LPBUF */
99 /* Indices 1 through 4 read. */
100 /* HALF - Half frame (1 or 2) */
101 /* MINTAU - Lag corresponding to minimum AMDF value (pitch estimate) */
102 /* Input/Output: */
103 /* DITHER - Zero crossing threshold */
104 /* The resulting value might be the negation of the input */
105 /* value. It might always be the same as the input value, */
106 /* if the DO loop below always executes an even number of times. */
107 /* Output: (all of them are written on every call) */
108 /* ZC - Zero crossing rate */
109 /* LBE - Low band energy (sum of magnitudes - SM) */
110 /* FBE - Full band energy (SM) */
111 /* QS - Ratio of 6 dB/oct preemphasized energy to full band energy */
112 /* RC1 - First reflection coefficient */
113 /* AR_B - Product of the causal forward and reverse pitch */
114 /* prediction gains */
115 /* AR_F - Product of the noncausal forward and reverse pitch */
116 /* prediction gains */
117 /* Internal: */
118 /* OLDSGN - Previous sign of dithered signal */
119 /* VLEN - Length of voicing window */
120 /* START - Lower address of current half of voicing window */
121 /* STOP - Upper address of current half of voicing window */
122 /* E_0 - Energy of LPF speech (sum of squares - SS) */
123 /* E_B - Energy of LPF speech backward one pitch period (SS) */
124 /* E_F - Energy of LPF speech forward one pitch period (SS) */
125 /* R_B - Autocovariance of LPF speech backward one pitch period */
126 /* R_F - Autocovariance of LPF speech forward one pitch period */
127 /* LP_RMS - Energy of LPF speech (sum of magnitudes - SM) */
128 /* AP_RMS - Energy of all-pass speech (SM) */
129 /* E_PRE - Energy of 6dB preemphasized speech (SM) */
130 /* E0AP - Energy of all-pass speech (SS) */
131 
132 /* This subroutine has no local state. */
133 
134 /* Subroutine */ int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer
135  *buflim, integer *half, real *dither, integer *mintau, integer *zc,
136  integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *
137  ar_f__)
138 {
139  /* System generated locals */
140  integer inbuf_offset, lpbuf_offset, i__1;
141  real r__1, r__2;
142 
143  /* Builtin functions */
144  double r_sign(real *, real *);
145  integer i_nint(real *);
146 
147  /* Local variables */
148  integer vlen, stop, i__;
149  real e_pre__;
150  integer start;
151  real ap_rms__, e_0__, oldsgn, lp_rms__, e_b__, e_f__, r_b__, r_f__, e0ap;
152 
153 /* Arguments */
154 /* Local variables that need not be saved */
155 /* Calculate zero crossings (ZC) and several energy and correlation */
156 /* measures on low band and full band speech. Each measure is taken */
157 /* over either the first or the second half of the voicing window, */
158 /* depending on the variable HALF. */
159  /* Parameter adjustments */
160  --vwin;
161  --buflim;
162  lpbuf_offset = buflim[3];
163  lpbuf -= lpbuf_offset;
164  inbuf_offset = buflim[1];
165  inbuf -= inbuf_offset;
166 
167  /* Function Body */
168  lp_rms__ = 0.f;
169  ap_rms__ = 0.f;
170  e_pre__ = 0.f;
171  e0ap = 0.f;
172  *rc1 = 0.f;
173  e_0__ = 0.f;
174  e_b__ = 0.f;
175  e_f__ = 0.f;
176  r_f__ = 0.f;
177  r_b__ = 0.f;
178  *zc = 0;
179  vlen = vwin[2] - vwin[1] + 1;
180  start = vwin[1] + (*half - 1) * vlen / 2 + 1;
181  stop = start + vlen / 2 - 1;
182 
183 /* I'll use the symbol HVL in the table below to represent the value */
184 /* VLEN/2. Note that if VLEN is odd, then HVL should be rounded down, */
185 /* i.e., HVL = (VLEN-1)/2. */
186 
187 /* HALF START STOP */
188 
189 /* 1 VWIN(1)+1 VWIN(1)+HVL */
190 /* 2 VWIN(1)+HVL+1 VWIN(1)+2*HVL */
191 
192 /* Note that if VLEN is even and HALF is 2, then STOP will be */
193 /* VWIN(1)+VLEN = VWIN(2)+1. That could be bad, if that index of INBUF */
194 /* is undefined. */
195 
196  r__1 = inbuf[start - 1] - *dither;
197  oldsgn = (real)r_sign(&c_b2, &r__1);
198  i__1 = stop;
199  for (i__ = start; i__ <= i__1; ++i__) {
200  lp_rms__ += (r__1 = lpbuf[i__], abs(r__1));
201  ap_rms__ += (r__1 = inbuf[i__], abs(r__1));
202  e_pre__ += (r__1 = inbuf[i__] - inbuf[i__ - 1], abs(r__1));
203 /* Computing 2nd power */
204  r__1 = inbuf[i__];
205  e0ap += r__1 * r__1;
206  *rc1 += inbuf[i__] * inbuf[i__ - 1];
207 /* Computing 2nd power */
208  r__1 = lpbuf[i__];
209  e_0__ += r__1 * r__1;
210 /* Computing 2nd power */
211  r__1 = lpbuf[i__ - *mintau];
212  e_b__ += r__1 * r__1;
213 /* Computing 2nd power */
214  r__1 = lpbuf[i__ + *mintau];
215  e_f__ += r__1 * r__1;
216  r_f__ += lpbuf[i__] * lpbuf[i__ + *mintau];
217  r_b__ += lpbuf[i__] * lpbuf[i__ - *mintau];
218  r__1 = inbuf[i__] + *dither;
219  if (r_sign(&c_b2, &r__1) != oldsgn) {
220  ++(*zc);
221  oldsgn = -oldsgn;
222  }
223  *dither = -(*dither);
224  }
225 /* Normalized short-term autocovariance coefficient at unit sample delay
226  */
227  *rc1 /= max(e0ap,1.f);
228 /* Ratio of the energy of the first difference signal (6 dB/oct preemphas
229 is)*/
230 /* to the energy of the full band signal */
231 /* Computing MAX */
232  r__1 = ap_rms__ * 2.f;
233  *qs = e_pre__ / max(r__1,1.f);
234 /* aR_b is the product of the forward and reverse prediction gains, */
235 /* looking backward in time (the causal case). */
236  *ar_b__ = r_b__ / max(e_b__,1.f) * (r_b__ / max(e_0__,1.f));
237 /* aR_f is the same as aR_b, but looking forward in time (non causal case
238 ).*/
239  *ar_f__ = r_f__ / max(e_f__,1.f) * (r_f__ / max(e_0__,1.f));
240 /* Normalize ZC, LBE, and FBE to old fixed window length of 180. */
241 /* (The fraction 90/VLEN has a range of .58 to 1) */
242  r__2 = (real) (*zc << 1);
243  r__1 = r__2 * (90.f / vlen);
244  *zc = i_nint(&r__1);
245 /* Computing MIN */
246  r__1 = lp_rms__ / 4 * (90.f / vlen);
247  i__1 = i_nint(&r__1);
248  *lbe = min(i__1,32767);
249 /* Computing MIN */
250  r__1 = ap_rms__ / 4 * (90.f / vlen);
251  i__1 = i_nint(&r__1);
252  *fbe = min(i__1,32767);
253  return 0;
254 } /* vparms_ */
integer i_nint(real *x)
Definition: f2clib.c:80
unsigned int stop
Definition: app_meetme.c:1096
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
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__)
Definition: vparms.c:134
float real
Definition: lpc10.h:79
double r_sign(real *a, real *b)
Definition: f2clib.c:64
#define abs(x)
Definition: f2c.h:195
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
static real c_b2
Definition: vparms.c:35
#define max(a, b)
Definition: f2c.h:198