Asterisk - The Open Source Telephony Project GIT-master-a358458
placea.c
Go to the documentation of this file.
1/*
2
3$Log$
4Revision 1.16 2004/06/26 03:50:14 markster
5Merge source cleanups (bug #1911)
6
7Revision 1.15 2003/09/19 01:20:22 markster
8Code cleanups (bug #66)
9
10Revision 1.2 2003/09/19 01:20:22 markster
11Code cleanups (bug #66)
12
13Revision 1.1.1.1 2003/02/12 13:59:15 matteo
14mer feb 12 14:56:57 CET 2003
15
16Revision 1.3 2001/04/12 21:27:53 markh
17app_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.
18
19Revision 1.2 2000/01/05 08:20:39 markster
20Some OSS fixes and a few lpc changes to make it actually work
21
22 * Revision 1.1 1996/08/19 22:31:07 jaf
23 * Initial revision
24 *
25
26*/
27
28/* -- translated by f2c (version 19951025).
29 You must link the resulting object file with the libraries:
30 -lf2c -lm (in that order)
31*/
32
33#include "f2c.h"
34
35#ifdef P_R_O_T_O_T_Y_P_E_S
36extern int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin);
37#endif
38
39/* *********************************************************************** */
40
41/* PLACEA Version 48 */
42
43/* $Log$
44 * Revision 1.16 2004/06/26 03:50:14 markster
45 * Merge source cleanups (bug #1911)
46 *
47 * Revision 1.15 2003/09/19 01:20:22 markster
48 * Code cleanups (bug #66)
49 *
50 * Revision 1.2 2003/09/19 01:20:22 markster
51 * Code cleanups (bug #66)
52 *
53 * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
54 * mer feb 12 14:56:57 CET 2003
55 *
56 * Revision 1.3 2001/04/12 21:27:53 markh
57 * 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.
58 *
59 * Revision 1.2 2000/01/05 08:20:39 markster
60 * Some OSS fixes and a few lpc changes to make it actually work
61 *
62 * Revision 1.1 1996/08/19 22:31:07 jaf
63 * Initial revision
64 * */
65/* Revision 1.5 1996/03/19 20:41:55 jaf */
66/* Added some conditions satisfied by the output values in EWIN. */
67
68/* Revision 1.4 1996/03/19 20:24:17 jaf */
69/* Added some conditions satisfied by the output values in AWIN. */
70
71/* Revision 1.3 1996/03/18 21:40:04 jaf */
72/* Just added a few comments about which array indices of the arguments */
73/* are used, and mentioning that this subroutine has no local state. */
74
75/* Revision 1.2 1996/03/13 16:43:09 jaf */
76/* Comments added explaining that none of the local variables of this */
77/* subroutine need to be saved from one invocation to the next. */
78
79/* Revision 1.1 1996/02/07 14:48:31 jaf */
80/* Initial revision */
81
82
83/* *********************************************************************** */
84/* Input: */
85/* IPITCH */
86/* VOIBUF */
87/* Indices (2,AF-2), (1,AF-1), (2,AF-1), (1,AF), and (2,AF) read.*/
88/* All other indices untouched. */
89/* OBOUND */
90/* AF */
91/* VWIN */
92/* Indices (1,AF) and (2,AF) read. */
93/* All other indices untouched. */
94/* LFRAME */
95/* MAXWIN */
96/* Input/Output: */
97/* AWIN */
98/* Index (1,AF-1) read. */
99/* Indices (1,AF) and (2,AF) written, and then read. */
100/* All other indices untouched. */
101/* In all cases (except possibly one), the final values will */
102/* satisfy the condition: AWIN(2,AF)-AWIN(1,AF)+1 = MAXWIN. */
103/* In that other case, */
104/* AWIN(1,AF)=VWIN(1,AF) and AWIN(2,AF)=VWIN(2,AF). */
105/* Output: */
106/* EWIN */
107/* Indices (1,AF) and (2,AF) written. */
108/* All other indices untouched. */
109/* In all cases, the final values will satisfy the condition: */
110/* AWIN(1,AF) .LE. EWIN(1,AF) .LE. EWIN(2,AF) .LE. AWIN(2,AF) */
111/* In other words, the energy window is a sub-window of */
112/* the analysis window. */
113
114/* This subroutine has no local state. */
115
116/* Subroutine */ int placea_(integer *ipitch, integer *voibuf, integer *
117 obound, integer *af, integer *vwin, integer *awin, integer *ewin,
118 integer *lframe, integer *maxwin)
119{
120 /* System generated locals */
121 real r__1;
122
123 /* Builtin functions */
125
126 /* Local variables */
127 logical allv, winv;
128 integer i__, j, k, l, hrange;
129 logical ephase;
130 integer lrange;
131
132/* Arguments */
133/* Local variables that need not be saved */
134 /* Parameter adjustments */
135 ewin -= 3;
136 awin -= 3;
137 vwin -= 3;
138 --voibuf;
139
140 /* Function Body */
141 lrange = (*af - 2) * *lframe + 1;
142 hrange = *af * *lframe;
143/* Place the Analysis window based on the voicing window */
144/* placement, onsets, tentative voicing decision, and pitch. */
145
146/* Case 1: Sustained Voiced Speech */
147/* If the five most recent voicing decisions are */
148/* voiced, then the window is placed phase-synchronously with the */
149/* previous window, as close to the present voicing window if possible.
150*/
151/* If onsets bound the voicing window, then preference is given to */
152/* a phase-synchronous placement which does not overlap these onsets. */
153
154/* Case 2: Voiced Transition */
155/* If at least one voicing decision in AF is voiced, and there are no
156*/
157/* onsets, then the window is placed as in case 1. */
158
159/* Case 3: Unvoiced Speech or Onsets */
160/* If both voicing decisions in AF are unvoiced, or there are onsets, */
161/* then the window is placed coincident with the voicing window. */
162
163/* Note: During phase-synchronous placement of windows, the length */
164/* is not altered from MAXWIN, since this would defeat the purpose */
165/* of phase-synchronous placement. */
166/* Check for case 1 and case 2 */
167 allv = voibuf[((*af - 2) << 1) + 2] == 1;
168 allv = allv && voibuf[((*af - 1) << 1) + 1] == 1;
169 allv = allv && voibuf[((*af - 1) << 1) + 2] == 1;
170 allv = allv && voibuf[(*af << 1) + 1] == 1;
171 allv = allv && voibuf[(*af << 1) + 2] == 1;
172 winv = voibuf[(*af << 1) + 1] == 1 || voibuf[(*af << 1) + 2] == 1;
173 if (allv || (winv && *obound == 0)) {
174/* APHASE: Phase synchronous window placement. */
175/* Get minimum lower index of the window. */
176 i__ = (lrange + *ipitch - 1 - awin[((*af - 1) << 1) + 1]) / *ipitch;
177 i__ *= *ipitch;
178 i__ += awin[((*af - 1) << 1) + 1];
179/* L = the actual length of this frame's analysis window. */
180 l = *maxwin;
181/* Calculate the location where a perfectly centered window would star
182t. */
183 k = (vwin[(*af << 1) + 1] + vwin[(*af << 1) + 2] + 1 - l) / 2;
184/* Choose the actual location to be the pitch multiple closest to this
185. */
186 r__1 = (real) (k - i__) / *ipitch;
187 awin[(*af << 1) + 1] = i__ + i_nint(&r__1) * *ipitch;
188 awin[(*af << 1) + 2] = awin[(*af << 1) + 1] + l - 1;
189/* If there is an onset bounding the right of the voicing window and t
190he */
191/* analysis window overlaps that, then move the analysis window backwa
192rd */
193/* to avoid this onset. */
194 if (*obound >= 2 && awin[(*af << 1) + 2] > vwin[(*af << 1) + 2]) {
195 awin[(*af << 1) + 1] -= *ipitch;
196 awin[(*af << 1) + 2] -= *ipitch;
197 }
198/* Similarly for the left of the voicing window. */
199 if ((*obound == 1 || *obound == 3) && awin[(*af << 1) + 1] < vwin[(*
200 af << 1) + 1]) {
201 awin[(*af << 1) + 1] += *ipitch;
202 awin[(*af << 1) + 2] += *ipitch;
203 }
204/* If this placement puts the analysis window above HRANGE, then */
205/* move it backward an integer number of pitch periods. */
206 while(awin[(*af << 1) + 2] > hrange) {
207 awin[(*af << 1) + 1] -= *ipitch;
208 awin[(*af << 1) + 2] -= *ipitch;
209 }
210/* Similarly if the placement puts the analysis window below LRANGE.
211*/
212 while(awin[(*af << 1) + 1] < lrange) {
213 awin[(*af << 1) + 1] += *ipitch;
214 awin[(*af << 1) + 2] += *ipitch;
215 }
216/* Make Energy window be phase-synchronous. */
217 ephase = TRUE_;
218/* Case 3 */
219 } else {
220 awin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
221 awin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
222 ephase = FALSE_;
223 }
224/* RMS is computed over an integer number of pitch periods in the analysis
225 */
226/*window. When it is not placed phase-synchronously, it is placed as clos
227e*/
228/* as possible to onsets. */
229 j = (awin[(*af << 1) + 2] - awin[(*af << 1) + 1] + 1) / *ipitch * *ipitch;
230 if (j == 0 || ! winv) {
231 ewin[(*af << 1) + 1] = vwin[(*af << 1) + 1];
232 ewin[(*af << 1) + 2] = vwin[(*af << 1) + 2];
233 } else if (! ephase && *obound == 2) {
234 ewin[(*af << 1) + 1] = awin[(*af << 1) + 2] - j + 1;
235 ewin[(*af << 1) + 2] = awin[(*af << 1) + 2];
236 } else {
237 ewin[(*af << 1) + 1] = awin[(*af << 1) + 1];
238 ewin[(*af << 1) + 2] = awin[(*af << 1) + 1] + j - 1;
239 }
240 return 0;
241} /* placea_ */
integer lframe
Definition: analys.c:66
integer i_nint(real *x)
Definition: f2clib.c:80
#define TRUE_
Definition: f2c.h:67
#define FALSE_
Definition: f2c.h:68
float real
Definition: lpc10.h:79
INT32 integer
Definition: lpc10.h:80
INT32 logical
Definition: lpc10.h:81
int placea_(integer *ipitch, integer *voibuf, integer *obound, integer *af, integer *vwin, integer *awin, integer *ewin, integer *lframe, integer *maxwin)
Definition: placea.c:116