difmag.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. $Log$
  3. Revision 1.15 2004/06/26 03:50:14 markster
  4. Merge source cleanups (bug #1911)
  5. Revision 1.14 2003/02/12 13:59:14 matteo
  6. mer feb 12 14:56:57 CET 2003
  7. Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  8. mer feb 12 14:56:57 CET 2003
  9. Revision 1.2 2000/01/05 08:20:39 markster
  10. Some OSS fixes and a few lpc changes to make it actually work
  11. * Revision 1.1 1996/08/19 22:32:31 jaf
  12. * Initial revision
  13. *
  14. */
  15. /* -- translated by f2c (version 19951025).
  16. You must link the resulting object file with the libraries:
  17. -lf2c -lm (in that order)
  18. */
  19. #include "f2c.h"
  20. #ifdef P_R_O_T_O_T_Y_P_E_S
  21. extern int difmag_(real *speech, integer *lpita, integer *tau, integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *maxptr);
  22. #endif
  23. /* ********************************************************************** */
  24. /* DIFMAG Version 49 */
  25. /* $Log$
  26. * Revision 1.15 2004/06/26 03:50:14 markster
  27. * Merge source cleanups (bug #1911)
  28. *
  29. * Revision 1.14 2003/02/12 13:59:14 matteo
  30. * mer feb 12 14:56:57 CET 2003
  31. *
  32. * Revision 1.1.1.1 2003/02/12 13:59:14 matteo
  33. * mer feb 12 14:56:57 CET 2003
  34. *
  35. * Revision 1.2 2000/01/05 08:20:39 markster
  36. * Some OSS fixes and a few lpc changes to make it actually work
  37. *
  38. * Revision 1.1 1996/08/19 22:32:31 jaf
  39. * Initial revision
  40. * */
  41. /* Revision 1.3 1996/03/15 23:09:39 jaf */
  42. /* Just added a few comments about which array indices of the arguments */
  43. /* are used, and mentioning that this subroutine has no local state. */
  44. /* Revision 1.2 1996/03/13 14:41:31 jaf */
  45. /* Comments added explaining that none of the local variables of this */
  46. /* subroutine need to be saved from one invocation to the next. */
  47. /* Revision 1.1 1996/02/07 14:45:04 jaf */
  48. /* Initial revision */
  49. /* ********************************************************************* */
  50. /* Compute Average Magnitude Difference Function */
  51. /* Inputs: */
  52. /* SPEECH - Low pass filtered speech */
  53. /* Indices MIN_N1 through MAX_N1+LPITA-1 are read, where */
  54. /* MIN_N1 = (MAXLAG - MAX_TAU)/2+1 MAX_TAU = max of TAU(I) for I=1,LTAU
  55. */
  56. /* MAX_N1 = (MAXLAG - MIN_TAU)/2+1 MIN_TAU = min of TAU(I) for I=1,LTAU
  57. */
  58. /* LPITA - Length of speech buffer */
  59. /* TAU - Table of lags */
  60. /* Indices 1 through LTAU read. */
  61. /* LTAU - Number of lag values to compute */
  62. /* MAXLAG - Maximum possible lag value */
  63. /* Outputs: */
  64. /* (All of these outputs are also read, but only after being written.) */
  65. /* AMDF - Average Magnitude Difference for each lag in TAU */
  66. /* Indices 1 through LTAU written */
  67. /* MINPTR - Index of minimum AMDF value */
  68. /* MAXPTR - Index of maximum AMDF value */
  69. /* This subroutine has no local state. */
  70. /* Subroutine */ int difmag_(real *speech, integer *lpita, integer *tau,
  71. integer *ltau, integer *maxlag, real *amdf, integer *minptr, integer *
  72. maxptr)
  73. {
  74. /* System generated locals */
  75. integer i__1, i__2;
  76. real r__1;
  77. /* Local variables */
  78. integer i__, j, n1, n2;
  79. real sum;
  80. /* Arguments */
  81. /* Local variables that need not be saved */
  82. /* Local state */
  83. /* None */
  84. /* Parameter adjustments */
  85. --amdf;
  86. --tau;
  87. --speech;
  88. /* Function Body */
  89. *minptr = 1;
  90. *maxptr = 1;
  91. i__1 = *ltau;
  92. for (i__ = 1; i__ <= i__1; ++i__) {
  93. n1 = (*maxlag - tau[i__]) / 2 + 1;
  94. n2 = n1 + *lpita - 1;
  95. sum = 0.f;
  96. i__2 = n2;
  97. for (j = n1; j <= i__2; j += 4) {
  98. sum += (r__1 = speech[j] - speech[j + tau[i__]], abs(r__1));
  99. }
  100. amdf[i__] = sum;
  101. if (amdf[i__] < amdf[*minptr]) {
  102. *minptr = i__;
  103. }
  104. if (amdf[i__] > amdf[*maxptr]) {
  105. *maxptr = i__;
  106. }
  107. }
  108. return 0;
  109. } /* difmag_ */