Properly play a holdtime message if the announce-holdtime option is
[asterisk-bristuff.git] / codecs / lpc10 / placev.c
blob56e72c4b8efa79959140848dc45b123327a75365
1 /*
3 $Log$
4 Revision 1.15 2004/06/26 03:50:14 markster
5 Merge source cleanups (bug #1911)
7 Revision 1.14 2003/02/12 13:59:15 matteo
8 mer feb 12 14:56:57 CET 2003
10 Revision 1.1.1.1 2003/02/12 13:59:15 matteo
11 mer feb 12 14:56:57 CET 2003
13 Revision 1.3 2001/04/12 21:27:53 markh
14 app_record now supports wildcards of sort so your output file is not overwritten every time it's run. File.h got a documentation update on the ast_fileexists to include the return call. Watch out for the placea.c placev.c code, it's updates have not been tested yet. Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.
16 Revision 1.2 2000/01/05 08:20:39 markster
17 Some OSS fixes and a few lpc changes to make it actually work
19 * Revision 1.1 1996/08/19 22:31:02 jaf
20 * Initial revision
25 /* -- translated by f2c (version 19951025).
26 You must link the resulting object file with the libraries:
27 -lf2c -lm (in that order)
30 #include "f2c.h"
32 #ifdef P_R_O_T_O_T_Y_P_E_S
33 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);
34 #endif
36 /* ****************************************************************** */
38 /* PLACEV Version 48 */
40 /* $Log$
41 * Revision 1.15 2004/06/26 03:50:14 markster
42 * Merge source cleanups (bug #1911)
44 * Revision 1.14 2003/02/12 13:59:15 matteo
45 * mer feb 12 14:56:57 CET 2003
47 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
48 * mer feb 12 14:56:57 CET 2003
50 * Revision 1.3 2001/04/12 21:27:53 markh
51 * app_record now supports wildcards of sort so your output file is not overwritten every time it's run. File.h got a documentation update on the ast_fileexists to include the return call. Watch out for the placea.c placev.c code, it's updates have not been tested yet. Just a few parenthesis to make it compile nicer on newer gcc versions with all the -W flags set.
53 * Revision 1.2 2000/01/05 08:20:39 markster
54 * Some OSS fixes and a few lpc changes to make it actually work
56 * Revision 1.1 1996/08/19 22:31:02 jaf
57 * Initial revision
58 * */
59 /* Revision 1.6 1996/03/19 20:42:19 jaf */
60 /* Added some conditions satisfied by the output values in VWIN. */
62 /* Revision 1.5 1996/03/19 18:37:56 jaf */
63 /* Strengthened the specification of which indices of VWIN are read and */
64 /* written. */
66 /* Revision 1.4 1996/03/15 16:38:33 jaf */
67 /* One tiny comment added. */
69 /* Revision 1.3 1996/03/15 16:36:13 jaf */
70 /* Added comments giving In/Out status of arguments. */
72 /* Revision 1.2 1996/03/12 23:56:01 jaf */
73 /* Comments added explaining that none of the local variables of this */
74 /* subroutine need to be saved from one invocation to the next. */
76 /* Revision 1.1 1996/02/07 14:48:39 jaf */
77 /* Initial revision */
80 /* ****************************************************************** */
82 /* Input: */
83 /* OSBUF Buffer which holds sorted indexes of onsets */
84 /* I believe that only indices 1 through OSPTR-1 can be read. */
85 /* OSLEN */
86 /* OSPTR Free pointer into OSBUF */
87 /* AF */
88 /* LFRAME */
89 /* MINWIN */
90 /* MAXWIN */
91 /* DVWINL */
92 /* DVWINH (This argument is never used. Should it be?) */
93 /* Input/Output: */
94 /* VWIN Buffer of Voicing Window Positions (Modified) */
95 /* Index (2,AF-1) is read. */
96 /* Indices (1,AF) and (2,AF) are written, */
97 /* and then possibly read. */
98 /* All other indices are unused. */
99 /* In all cases, the final values will satsify the condition:*/
100 /* VWIN(2,AF)-VWIN(1,AF)+1 .LE. MAXWIN */
101 /* I'm not certain yet, but they may also satisfy: */
102 /* MINWIN .LE. VWIN(2,AF)-VWIN(1,AF)+1 */
103 /* Output: */
104 /* OBOUND This variable is set by this procedure and used */
105 /* in placing analysis windows (PLACEA). Bit 1 */
106 /* indicates whether an onset bounds the left side */
107 /* of the voicing window, and bit 2 indicates whether */
108 /* an onset bounds the right side of the voicing window. */
110 /* This subroutine has no local state. */
112 /* Subroutine */ int placev_(integer *osbuf, integer *osptr, integer *oslen,
113 integer *obound, integer *vwin, integer *af, integer *lframe, integer
114 *minwin, integer *maxwin, integer *dvwinl, integer *dvwinh)
116 /* System generated locals */
117 integer i__1, i__2;
119 /* Local variables */
120 logical crit;
121 integer i__, q, osptr1, hrange, lrange;
123 /* Arguments */
124 /* Local variables that need not be saved */
125 /* Variables */
126 /* LRANGE, HRANGE Range in which window is placed */
127 /* OSPTR1 OSPTR excluding samples in 3F */
128 /* Local state */
129 /* None */
130 /* Voicing Window Placement */
132 /* __________________ __________________ ______________ */
133 /* | | | */
134 /* | 1F | 2F | 3F ... */
135 /* |__________________|__________________|______________ */
137 /* Previous | */
138 /* Window | */
139 /* ...________| */
141 /* | | */
142 /* ------>| This window's placement range |<------ */
143 /* | | */
145 /* There are three cases. Note that these are different from those */
146 /* given in the LPC-10e phase 1 report. */
148 /* 1. If there are no onsets in this range, then the voicing window */
149 /* is centered in the pitch window. If such a placement is not within
151 /* the window's placement range, then the window is placed in the left-
153 /* most portion of the placement range. Its length is always MAXWIN. */
155 /* 2. If the first onset is in 2F and there is sufficient room to place
157 /* the window immediately before this onset, then the window is placed
159 /* there, and its length is set to the maximum possible under these */
160 /* constraints. */
162 /* "Critical Region Exception": If there is another onset in 2F */
163 /* such that a window can be placed between the two onsets, the */
164 /* window is placed there (ie, as in case 3). */
166 /* 3. Otherwise, the window is placed immediately after the onset. The
168 /* window's length */
169 /* is the longest length that can fit in the range under these constraint
170 s,*/
171 /* except that the window may be shortened even further to avoid overlapp
172 ing*/
173 /* other onsets in the placement range. In any case, the window's length
175 /* is at least MINWIN. */
177 /* Note that the values of MINWIN and LFRAME must be chosen such */
178 /* that case 2 = false implies case 3 = true. This means that */
179 /* MINWIN <= LFRAME/2. If this were not the case, then a fourth case */
180 /* would have to be added for when the window cannot fit either before
182 /* or after the onset. */
184 /* Note also that onsets which weren't in 2F last time may be in 1F this
186 /* time, due to the filter delays in computing onsets. The result is tha
188 /* occasionally a voicing window will overlap that onset. The only way
190 /* to circumvent this problem is to add more delay in processing input
192 /* speech. In the trade-off between delay and window-placement, window
194 /* placement lost. */
195 /* Compute the placement range */
196 /* Parameter adjustments */
197 --osbuf;
198 vwin -= 3;
200 /* Function Body */
201 /* Computing MAX */
202 i__1 = vwin[((*af - 1) << 1) + 2] + 1, i__2 = (*af - 2) * *lframe + 1;
203 lrange = max(i__1,i__2);
204 hrange = *af * *lframe;
205 /* Compute OSPTR1, so the following code only looks at relevant onsets. */
206 for (osptr1 = *osptr - 1; osptr1 >= 1; --osptr1) {
207 if (osbuf[osptr1] <= hrange) {
208 goto L90;
211 L90:
212 ++osptr1;
213 /* Check for case 1 first (fast case): */
214 if (osptr1 <= 1 || osbuf[osptr1 - 1] < lrange) {
215 /* Computing MAX */
216 i__1 = vwin[((*af - 1) << 1) + 2] + 1;
217 vwin[(*af << 1) + 1] = max(i__1,*dvwinl);
218 vwin[(*af << 1) + 2] = vwin[(*af << 1) + 1] + *maxwin - 1;
219 *obound = 0;
220 } else {
221 /* Search backward in OSBUF for first onset in range. */
222 /* This code relies on the above check being performed first. */
223 for (q = osptr1 - 1; q >= 1; --q) {
224 if (osbuf[q] < lrange) {
225 goto L100;
228 L100:
229 ++q;
230 /* Check for case 2 (placement before onset): */
231 /* Check for critical region exception: */
232 i__1 = osptr1 - 1;
233 for (i__ = q + 1; i__ <= i__1; ++i__) {
234 if (osbuf[i__] - osbuf[q] >= *minwin) {
235 crit = TRUE_;
236 goto L105;
239 crit = FALSE_;
240 L105:
241 /* Computing MAX */
242 i__1 = (*af - 1) * *lframe, i__2 = lrange + *minwin - 1;
243 if (! crit && osbuf[q] > max(i__1,i__2)) {
244 vwin[(*af << 1) + 2] = osbuf[q] - 1;
245 /* Computing MAX */
246 i__1 = lrange, i__2 = vwin[(*af << 1) + 2] - *maxwin + 1;
247 vwin[(*af << 1) + 1] = max(i__1,i__2);
248 *obound = 2;
249 /* Case 3 (placement after onset) */
250 } else {
251 vwin[(*af << 1) + 1] = osbuf[q];
252 L110:
253 ++q;
254 if (q >= osptr1) {
255 goto L120;
257 if (osbuf[q] > vwin[(*af << 1) + 1] + *maxwin) {
258 goto L120;
260 if (osbuf[q] < vwin[(*af << 1) + 1] + *minwin) {
261 goto L110;
263 vwin[(*af << 1) + 2] = osbuf[q] - 1;
264 *obound = 3;
265 return 0;
266 L120:
267 /* Computing MIN */
268 i__1 = vwin[(*af << 1) + 1] + *maxwin - 1;
269 vwin[(*af << 1) + 2] = min(i__1,hrange);
270 *obound = 1;
273 return 0;
274 } /* placev_ */