formats: clarify setting of reverse_bytes
[sox.git] / lpc10 / placev.c
blobda1edefce383b2b6da89b101e4938fd88679e82e
1 /*
3 * Revision 1.1 1996/08/19 22:31:02 jaf
4 * Initial revision
7 */
9 /* -- translated by f2c (version 19951025).
10 You must link the resulting object file with the libraries:
11 -lf2c -lm (in that order)
14 #include "f2c.h"
16 extern int placev_(integer *osbuf, integer *osptr, integer *oslen, integer *obound, integer *vwin, integer *af, integer *lframe, integer *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh);
18 /* ****************************************************************** */
20 /* PLACEV Version 48 */
23 * Revision 1.1 1996/08/19 22:31:02 jaf
24 * Initial revision
25 * */
26 /* Revision 1.6 1996/03/19 20:42:19 jaf */
27 /* Added some conditions satisfied by the output values in VWIN. */
29 /* Revision 1.5 1996/03/19 18:37:56 jaf */
30 /* Strengthened the specification of which indices of VWIN are read and */
31 /* written. */
33 /* Revision 1.4 1996/03/15 16:38:33 jaf */
34 /* One tiny comment added. */
36 /* Revision 1.3 1996/03/15 16:36:13 jaf */
37 /* Added comments giving In/Out status of arguments. */
39 /* Revision 1.2 1996/03/12 23:56:01 jaf */
40 /* Comments added explaining that none of the local variables of this */
41 /* subroutine need to be saved from one invocation to the next. */
43 /* Revision 1.1 1996/02/07 14:48:39 jaf */
44 /* Initial revision */
47 /* ****************************************************************** */
49 /* Input: */
50 /* OSBUF Buffer which holds sorted indexes of onsets */
51 /* I believe that only indices 1 through OSPTR-1 can be read. */
52 /* OSLEN */
53 /* OSPTR Free pointer into OSBUF */
54 /* AF */
55 /* LFRAME */
56 /* MINWIN */
57 /* MAXWIN */
58 /* DVWINL */
59 /* DVWINH (This argument is never used. Should it be?) */
60 /* Input/Output: */
61 /* VWIN Buffer of Voicing Window Positions (Modified) */
62 /* Index (2,AF-1) is read. */
63 /* Indices (1,AF) and (2,AF) are written, */
64 /* and then possibly read. */
65 /* All other indices are unused. */
66 /* In all cases, the final values will satsify the condition:*/
67 /* VWIN(2,AF)-VWIN(1,AF)+1 .LE. MAXWIN */
68 /* I'm not certain yet, but they may also satisfy: */
69 /* MINWIN .LE. VWIN(2,AF)-VWIN(1,AF)+1 */
70 /* Output: */
71 /* OBOUND This variable is set by this procedure and used */
72 /* in placing analysis windows (PLACEA). Bit 1 */
73 /* indicates whether an onset bounds the left side */
74 /* of the voicing window, and bit 2 indicates whether */
75 /* an onset bounds the right side of the voicing window. */
77 /* This subroutine has no local state. */
79 /* Subroutine */ int placev_(integer *osbuf, integer *osptr, integer *oslen,
80 integer *obound, integer *vwin, integer *af, integer *lframe, integer
81 *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh)
83 /* System generated locals */
84 integer i__1, i__2;
86 /* Local variables */
87 logical crit;
88 integer i__, q, osptr1, hrange, lrange;
90 /* Arguments */
91 /* Local variables that need not be saved */
92 /* Variables */
93 /* LRANGE, HRANGE Range in which window is placed */
94 /* OSPTR1 OSPTR excluding samples in 3F */
95 /* Local state */
96 /* None */
97 /* Voicing Window Placement */
99 /* __________________ __________________ ______________ */
100 /* | | | */
101 /* | 1F | 2F | 3F ... */
102 /* |__________________|__________________|______________ */
104 /* Previous | */
105 /* Window | */
106 /* ...________| */
108 /* | | */
109 /* ------>| This window's placement range |<------ */
110 /* | | */
112 /* There are three cases. Note that these are different from those */
113 /* given in the LPC-10e phase 1 report. */
115 /* 1. If there are no onsets in this range, then the voicing window */
116 /* is centered in the pitch window. If such a placement is not within
118 /* the window's placement range, then the window is placed in the left-
120 /* most portion of the placement range. Its length is always MAXWIN. */
122 /* 2. If the first onset is in 2F and there is sufficient room to place
124 /* the window immediately before this onset, then the window is placed
126 /* there, and its length is set to the maximum possible under these */
127 /* constraints. */
129 /* "Critical Region Exception": If there is another onset in 2F */
130 /* such that a window can be placed between the two onsets, the */
131 /* window is placed there (ie, as in case 3). */
133 /* 3. Otherwise, the window is placed immediately after the onset. The
135 /* window's length */
136 /* is the longest length that can fit in the range under these constraint
137 s,*/
138 /* except that the window may be shortened even further to avoid overlapp
139 ing*/
140 /* other onsets in the placement range. In any case, the window's length
142 /* is at least MINWIN. */
144 /* Note that the values of MINWIN and LFRAME must be chosen such */
145 /* that case 2 = false implies case 3 = true. This means that */
146 /* MINWIN <= LFRAME/2. If this were not the case, then a fourth case */
147 /* would have to be added for when the window cannot fit either before
149 /* or after the onset. */
151 /* Note also that onsets which weren't in 2F last time may be in 1F this
153 /* time, due to the filter delays in computing onsets. The result is tha
155 /* occasionally a voicing window will overlap that onset. The only way
157 /* to circumvent this problem is to add more delay in processing input
159 /* speech. In the trade-off between delay and window-placement, window
161 /* placement lost. */
162 /* Compute the placement range */
163 /* Parameter adjustments */
164 (void)oslen;
165 (void)dvwinh;
166 --osbuf;
167 vwin -= 3;
169 /* Function Body */
170 /* Computing MAX */
171 i__1 = vwin[((*af - 1) << 1) + 2] + 1, i__2 = (*af - 2) * *lframe + 1;
172 lrange = max(i__1,i__2);
173 hrange = *af * *lframe;
174 /* Compute OSPTR1, so the following code only looks at relevant onsets. */
175 for (osptr1 = *osptr - 1; osptr1 >= 1; --osptr1) {
176 if (osbuf[osptr1] <= hrange) {
177 goto L90;
180 L90:
181 ++osptr1;
182 /* Check for case 1 first (fast case): */
183 if (osptr1 <= 1 || osbuf[osptr1 - 1] < lrange) {
184 /* Computing MAX */
185 i__1 = vwin[((*af - 1) << 1) + 2] + 1;
186 vwin[(*af << 1) + 1] = max(i__1,*dvwinl);
187 vwin[(*af << 1) + 2] = vwin[(*af << 1) + 1] + *maxwin - 1;
188 *obound = 0;
189 } else {
190 /* Search backward in OSBUF for first onset in range. */
191 /* This code relies on the above check being performed first. */
192 for (q = osptr1 - 1; q >= 1; --q) {
193 if (osbuf[q] < lrange) {
194 goto L100;
197 L100:
198 ++q;
199 /* Check for case 2 (placement before onset): */
200 /* Check for critical region exception: */
201 i__1 = osptr1 - 1;
202 for (i__ = q + 1; i__ <= i__1; ++i__) {
203 if (osbuf[i__] - osbuf[q] >= *minwin) {
204 crit = TRUE_;
205 goto L105;
208 crit = FALSE_;
209 L105:
210 /* Computing MAX */
211 i__1 = (*af - 1) * *lframe, i__2 = lrange + *minwin - 1;
212 if (! crit && osbuf[q] > max(i__1,i__2)) {
213 vwin[(*af << 1) + 2] = osbuf[q] - 1;
214 /* Computing MAX */
215 i__1 = lrange, i__2 = vwin[(*af << 1) + 2] - *maxwin + 1;
216 vwin[(*af << 1) + 1] = max(i__1,i__2);
217 *obound = 2;
218 /* Case 3 (placement after onset) */
219 } else {
220 vwin[(*af << 1) + 1] = osbuf[q];
221 L110:
222 ++q;
223 if (q >= osptr1) {
224 goto L120;
226 if (osbuf[q] > vwin[(*af << 1) + 1] + *maxwin) {
227 goto L120;
229 if (osbuf[q] < vwin[(*af << 1) + 1] + *minwin) {
230 goto L110;
232 vwin[(*af << 1) + 2] = osbuf[q] - 1;
233 *obound = 3;
234 return 0;
235 L120:
236 /* Computing MIN */
237 i__1 = vwin[(*af << 1) + 1] + *maxwin - 1;
238 vwin[(*af << 1) + 2] = min(i__1,hrange);
239 *obound = 1;
242 return 0;
243 } /* placev_ */