ivfilt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.2 2000/01/05 08:20:39 markster
  12. Some OSS fixes and a few lpc changes to make it actually work
  13. * Revision 1.1 1996/08/19 22:31:53 jaf
  14. * Initial revision
  15. *
  16. */
  17. /* -- translated by f2c (version 19951025).
  18. You must link the resulting object file with the libraries:
  19. -lf2c -lm (in that order)
  20. */
  21. #include "f2c.h"
  22. #ifdef P_R_O_T_O_T_Y_P_E_S
  23. extern int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *nsamp, real *ivrc);
  24. #endif
  25. /* ********************************************************************* */
  26. /* IVFILT Version 48 */
  27. /* $Log$
  28. * Revision 1.16 2004/06/26 03:50:14 markster
  29. * Merge source cleanups (bug #1911)
  30. *
  31. * Revision 1.15 2003/09/19 01:20:22 markster
  32. * Code cleanups (bug #66)
  33. *
  34. * Revision 1.2 2003/09/19 01:20:22 markster
  35. * Code cleanups (bug #66)
  36. *
  37. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  38. * mer feb 12 14:56:57 CET 2003
  39. *
  40. * Revision 1.2 2000/01/05 08:20:39 markster
  41. * Some OSS fixes and a few lpc changes to make it actually work
  42. *
  43. * Revision 1.1 1996/08/19 22:31:53 jaf
  44. * Initial revision
  45. * */
  46. /* Revision 1.3 1996/03/15 21:36:29 jaf */
  47. /* Just added a few comments about which array indices of the arguments */
  48. /* are used, and mentioning that this subroutine has no local state. */
  49. /* Revision 1.2 1996/03/13 00:01:00 jaf */
  50. /* Comments added explaining that none of the local variables of this */
  51. /* subroutine need to be saved from one invocation to the next. */
  52. /* Revision 1.1 1996/02/07 14:47:34 jaf */
  53. /* Initial revision */
  54. /* ********************************************************************* */
  55. /* 2nd order inverse filter, speech is decimated 4:1 */
  56. /* Input: */
  57. /* LEN - Length of speech buffers */
  58. /* NSAMP - Number of samples to filter */
  59. /* LPBUF - Low pass filtered speech buffer */
  60. /* Indices LEN-NSAMP-7 through LEN read. */
  61. /* Output: */
  62. /* IVBUF - Inverse filtered speech buffer */
  63. /* Indices LEN-NSAMP+1 through LEN written. */
  64. /* IVRC - Inverse filter reflection coefficients (for voicing) */
  65. /* Indices 1 and 2 both written (also read, but only after writing).
  66. */
  67. /* This subroutine has no local state. */
  68. /* Subroutine */ int ivfilt_(real *lpbuf, real *ivbuf, integer *len, integer *
  69. nsamp, real *ivrc)
  70. {
  71. /* System generated locals */
  72. integer i__1;
  73. /* Local variables */
  74. integer i__, j, k;
  75. real r__[3], pc1, pc2;
  76. /* Arguments */
  77. /* Local variables that need not be saved */
  78. /* Local state */
  79. /* None */
  80. /* Calculate Autocorrelations */
  81. /* Parameter adjustments */
  82. --ivbuf;
  83. --lpbuf;
  84. --ivrc;
  85. /* Function Body */
  86. for (i__ = 1; i__ <= 3; ++i__) {
  87. r__[i__ - 1] = 0.f;
  88. k = (i__ - 1) << 2;
  89. i__1 = *len;
  90. for (j = (i__ << 2) + *len - *nsamp; j <= i__1; j += 2) {
  91. r__[i__ - 1] += lpbuf[j] * lpbuf[j - k];
  92. }
  93. }
  94. /* Calculate predictor coefficients */
  95. pc1 = 0.f;
  96. pc2 = 0.f;
  97. ivrc[1] = 0.f;
  98. ivrc[2] = 0.f;
  99. if (r__[0] > 1e-10f) {
  100. ivrc[1] = r__[1] / r__[0];
  101. ivrc[2] = (r__[2] - ivrc[1] * r__[1]) / (r__[0] - ivrc[1] * r__[1]);
  102. pc1 = ivrc[1] - ivrc[1] * ivrc[2];
  103. pc2 = ivrc[2];
  104. }
  105. /* Inverse filter LPBUF into IVBUF */
  106. i__1 = *len;
  107. for (i__ = *len + 1 - *nsamp; i__ <= i__1; ++i__) {
  108. ivbuf[i__] = lpbuf[i__] - pc1 * lpbuf[i__ - 4] - pc2 * lpbuf[i__ - 8];
  109. }
  110. return 0;
  111. } /* ivfilt_ */