placea.c 8.7 KB

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