README.osx wasn't easily readable in Finder. Revert back to
[sox.git] / lpc10 / placea.c
blob95471ded9452a549df30cb6961238187097af3f1
1 /*
3 $Log: placea.c,v $
4 Revision 1.2 2007/04/18 14:00:38 rrt
5 Remove $Log tokens and associated log messages (in many files, several
6 copies of every log message were being written) and lots of warnings.
8 Revision 1.1 2007/04/16 21:57:47 rrt
9 LPC-10 support, documentation still to come; I wanted to land the code
10 before 14.0.0 went into test, and I'll be busy tomorrow.
12 Not highly tested either, but it's just a format, doesn't interfere
13 with anything else, and I'll get on that case before we go stable.
15 * Revision 1.1 1996/08/19 22:31:07 jaf
16 * Initial revision
21 /* -- translated by f2c (version 19951025).
22 You must link the resulting object file with the libraries:
23 -lf2c -lm (in that order)
26 #include "f2c.h"
28 extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);
30 /* *********************************************************************** */
32 /* PLACEA Version 48 */
34 /* Revision 1.1 1996/08/19 22:31:07 jaf
35 * Initial revision
36 * */
37 /* Revision 1.5 1996/03/19 20:41:55 jaf */
38 /* Added some conditions satisfied by the output values in EWIN. */
40 /* Revision 1.4 1996/03/19 20:24:17 jaf */
41 /* Added some conditions satisfied by the output values in AWIN. */
43 /* Revision 1.3 1996/03/18 21:40:04 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. */
47 /* Revision 1.2 1996/03/13 16:43:09 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. */
51 /* Revision 1.1 1996/02/07 14:48:31 jaf */
52 /* Initial revision */
55 /* *********************************************************************** */
56 /* Input: */
57 /* IPITCH */
58 /* VOIBUF */
59 /* Indices (2,AF-2), (1,AF-1), (2,AF-1), (1,AF), and (2,AF) read.*/
60 /* All other indices untouched. */
61 /* OBOUND */
62 /* AF */
63 /* VWIN */
64 /* Indices (1,AF) and (2,AF) read. */
65 /* All other indices untouched. */
66 /* LFRAME */
67 /* MAXWIN */
68 /* Input/Output: */
69 /* AWIN */
70 /* Index (1,AF-1) read. */
71 /* Indices (1,AF) and (2,AF) written, and then read. */
72 /* All other indices untouched. */
73 /* In all cases (except possibly one), the final values will */
74 /* satisfy the condition: AWIN(2,AF)-AWIN(1,AF)+1 = MAXWIN. */
75 /* In that other case, */
76 /* AWIN(1,AF)=VWIN(1,AF) and AWIN(2,AF)=VWIN(2,AF). */
77 /* Output: */
78 /* EWIN */
79 /* Indices (1,AF) and (2,AF) written. */
80 /* All other indices untouched. */
81 /* In all cases, the final values will satisfy the condition: */
82 /* AWIN(1,AF) .LE. EWIN(1,AF) .LE. EWIN(2,AF) .LE. AWIN(2,AF) */
83 /* In other words, the energy window is a sub-window of */
84 /* the analysis window. */
86 /* This subroutine has no local state. */
88 /* Subroutine */ int placea_(integer *ipitch, integer *voibuf, integer *
89 obound, integer *af, integer *vwin, integer *awin, integer *ewin,
90 integer *lframe, integer *maxwin)
92 /* System generated locals */
93 real r__1;
95 /* Builtin functions */
96 integer i_nint(real *);
98 /* Local variables */
99 logical allv, winv;
100 integer i__, j, k, l, hrange;
101 logical ephase;
102 integer lrange;
104 /* Arguments */
105 /* Local variables that need not be saved */
106 /* Parameter adjustments */
107 ewin -= 3;
108 awin -= 3;
109 vwin -= 3;
110 --voibuf;
112 /* Function Body */
113 lrange = (*af - 2) * *lframe + 1;
114 hrange = *af * *lframe;
115 /* Place the Analysis window based on the voicing window */
116 /* placement, onsets, tentative voicing decision, and pitch. */
118 /* Case 1: Sustained Voiced Speech */
119 /* If the five most recent voicing decisions are */
120 /* voiced, then the window is placed phase-synchronously with the */
121 /* previous window, as close to the present voicing window if possible.
123 /* If onsets bound the voicing window, then preference is given to */
124 /* a phase-synchronous placement which does not overlap these onsets. */
126 /* Case 2: Voiced Transition */
127 /* If at least one voicing decision in AF is voicied, and there are no
129 /* onsets, then the window is placed as in case 1. */
131 /* Case 3: Unvoiced Speech or Onsets */
132 /* If both voicing decisions in AF are unvoiced, or there are onsets, */
133 /* then the window is placed coincident with the voicing window. */
135 /* Note: During phase-synchronous placement of windows, the length */
136 /* is not altered from MAXWIN, since this would defeat the purpose */
137 /* of phase-synchronous placement. */
138 /* Check for case 1 and case 2 */
139 allv = voibuf[((*af - 2) << 1) + 2] == 1;
140 allv = allv && voibuf[((*af - 1) << 1) + 1] == 1;
141 allv = allv && voibuf[((*af - 1) << 1) + 2] == 1;
142 allv = allv && voibuf[(*af << 1) + 1] == 1;
143 allv = allv && voibuf[(*af << 1) + 2] == 1;
144 winv = voibuf[(*af << 1) + 1] == 1 || voibuf[(*af << 1) + 2] == 1;
145 if (allv || (winv && *obound == 0)) {
146 /* APHASE: Phase synchronous window placement. */
147 /* Get minimum lower index of the window. */
148 i__ = (lrange + *ipitch - 1 - awin[((*af - 1) << 1) + 1]) / *ipitch;
149 i__ *= *ipitch;
150 i__ += awin[((*af - 1) << 1) + 1];
151 /* L = the actual length of this frame's analysis window. */
152 l = *maxwin;
153 /* Calculate the location where a perfectly centered window would star
154 t. */
155 k = (vwin[(*af << 1) + 1] + vwin[(*af << 1) + 2] + 1 - l) / 2;
156 /* Choose the actual location to be the pitch multiple closest to this
157 . */
158 r__1 = (real) (k - i__) / *ipitch;
159 awin[(*af << 1) + 1] = i__ + i_nint(&r__1) * *ipitch;
160 awin[(*af << 1) + 2] = awin[(*af << 1) + 1] + l - 1;
161 /* If there is an onset bounding the right of the voicing window and t
162 he */
163 /* analysis window overlaps that, then move the analysis window backwa
164 rd */
165 /* to avoid this onset. */
166 if (*obound >= 2 && awin[(*af << 1) + 2] > vwin[(*af << 1) + 2]) {
167 awin[(*af << 1) + 1] -= *ipitch;
168 awin[(*af << 1) + 2] -= *ipitch;
170 /* Similarly for the left of the voicing window. */
171 if ((*obound == 1 || *obound == 3) && awin[(*af << 1) + 1] < vwin[(*
172 af << 1) + 1]) {
173 awin[(*af << 1) + 1] += *ipitch;
174 awin[(*af << 1) + 2] += *ipitch;
176 /* If this placement puts the analysis window above HRANGE, then */
177 /* move it backward an integer number of pitch periods. */
178 while(awin[(*af << 1) + 2] > hrange) {
179 awin[(*af << 1) + 1] -= *ipitch;
180 awin[(*af << 1) + 2] -= *ipitch;
182 /* Similarly if the placement puts the analysis window below LRANGE.
184 while(awin[(*af << 1) + 1] < lrange) {
185 awin[(*af << 1) + 1] += *ipitch;
186 awin[(*af << 1) + 2] += *ipitch;
188 /* Make Energy window be phase-synchronous. */
189 ephase = TRUE_;
190 /* Case 3 */
191 } else {
192 awin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
193 awin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
194 ephase = FALSE_;
196 /* RMS is computed over an integer number of pitch periods in the analysis
198 /*window. When it is not placed phase-synchronously, it is placed as clos
200 /* as possible to onsets. */
201 j = (awin[(*af << 1) + 2] - awin[(*af << 1) + 1] + 1) / *ipitch * *ipitch;
202 if (j == 0 || ! winv) {
203 ewin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
204 ewin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
205 } else if (! ephase && *obound == 2) {
206 ewin[(*af << 1) + 1] = awin[(*af << 1) + 2] - j + 1;
207 ewin[(*af << 1) + 2] = awin[(*af << 1) + 2];
208 } else {
209 ewin[(*af << 1) + 1] = awin[(*af << 1) + 1];
210 ewin[(*af << 1) + 2] = awin[(*af << 1) + 1] + j - 1;
212 return 0;
213 } /* placea_ */