1 /*
2 
3  * Revision 1.1  1996/08/19  22:30:26  jaf
4  * Initial revision
5  *
6 
7 */
8 
9 /*  -- translated by f2c (version 19951025).
10    You must link the resulting object file with the libraries:
11 	-lf2c -lm   (in that order)
12 */
13 
14 #include "f2c.h"
15 
16 extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);
17 
18 /* ********************************************************************** */
19 
20 /* 	TBDM Version 49 */
21 
22 /*
23  * Revision 1.1  1996/08/19  22:30:26  jaf
24  * Initial revision
25  * */
26 /* Revision 1.3  1996/03/18  22:14:00  jaf */
27 /* Just added a few comments about which array indices of the arguments */
28 /* are used, and mentioning that this subroutine has no local state. */
29 
30 /* Revision 1.2  1996/03/13  14:48:37  jaf */
31 /* Comments added explaining that none of the local variables of this */
32 /* subroutine need to be saved from one invocation to the next. */
33 
34 /* Revision 1.1  1996/02/07 14:49:54  jaf */
35 /* Initial revision */
36 
37 
38 /* ********************************************************************* */
39 
40 /*TURBO DIFMAG: Compute High Resolution Average Magnitude Difference Function
41 */
42 
43 /* Note: There are several constants in here that appear to depend on a */
44 /* particular TAU table.  That's not a problem for the LPC10 coder, but */
45 /* watch out if you change the contents of TAU in the subroutine ANALYS. */
46 
47 /* Input: */
48 /*  SPEECH - Low pass filtered speech */
49 /*           Indices 1 through MAX+LPITA-1 are read, where: */
50 /*           MAX = (TAU(LTAU)-TAU(1))/2+1 */
51 /*           (If TAU(1) .LT. 39, then larger indices could be read */
52 /*           by the last call to DIFMAG below.) */
53 /*  LPITA  - Length of speech buffer */
54 /*  TAU    - Table of lags, sorted in increasing order. */
55 /*           Indices 1 through LTAU read. */
56 /*  LTAU   - Number of lag values to compute */
57 /* Output: */
58 /*  AMDF   - Average Magnitude Difference for each lag in TAU */
59 /*          Indices 1 through LTAU written, and several might then be read.*/
60 /*  MINPTR - Index of minimum AMDF value */
61 /*  MAXPTR - Index of maximum AMDF value within +/- 1/2 octave of min */
62 /*  MINTAU - Lag corresponding to minimum AMDF value */
63 
64 /* This subroutine has no local state. */
65 
tbdm_(real * speech,integer * lpita,integer * tau,integer * ltau,real * amdf,integer * minptr,integer * maxptr,integer * mintau)66 /* Subroutine */ int tbdm_(real *speech, integer *lpita, integer *tau,
67 	integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *
68 	mintau)
69 {
70     /* System generated locals */
71     integer i__1, i__2, i__3, i__4;
72 
73     /* Local variables */
74     real amdf2[6];
75     integer minp2, ltau2, maxp2, i__;
76     extern /* Subroutine */ int difmag_(real *, integer *, integer *, integer
77 	    *, integer *, real *, integer *, integer *);
78     integer minamd, ptr, tau2[6];
79 
80 /* 	Arguments */
81 /* 	REAL SPEECH(LPITA+TAU(LTAU)), AMDF(LTAU) */
82 /*   Stupid TOAST doesn't understand expressions */
83 /*       Local variables that need not be saved */
84 /*       Local state */
85 /*       None */
86 /*   Compute full AMDF using log spaced lags, find coarse minimum */
87     /* Parameter adjustments */
88     --speech;
89     --amdf;
90     --tau;
91 
92     /* Function Body */
93     difmag_(&speech[1], lpita, &tau[1], ltau, &tau[*ltau], &amdf[1], minptr,
94 	    maxptr);
95     *mintau = tau[*minptr];
96     minamd = amdf[*minptr];
97 /*   Build table containing all lags within +/- 3 of the AMDF minimum */
98 /*    excluding all that have already been computed */
99     ltau2 = 0;
100     ptr = *minptr - 2;
101 /* Computing MAX */
102     i__1 = *mintau - 3;
103 /* Computing MIN */
104     i__3 = *mintau + 3, i__4 = tau[*ltau] - 1;
105     i__2 = min(i__3,i__4);
106     for (i__ = max(i__1,41); i__ <= i__2; ++i__) {
107 	while(tau[ptr] < i__) {
108 	    ++ptr;
109 	}
110 	if (tau[ptr] != i__) {
111 	    ++ltau2;
112 	    tau2[ltau2 - 1] = i__;
113 	}
114     }
115 /*   Compute AMDF of the new lags, if there are any, and choose one */
116 /*    if it is better than the coarse minimum */
117     if (ltau2 > 0) {
118 	difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &
119 		maxp2);
120 	if (amdf2[minp2 - 1] < (real) minamd) {
121 	    *mintau = tau2[minp2 - 1];
122 	    minamd = amdf2[minp2 - 1];
123 	}
124     }
125 /*   Check one octave up, if there are any lags not yet computed */
126     if (*mintau >= 80) {
127 	i__ = *mintau / 2;
128 	if ((i__ & 1) == 0) {
129 	    ltau2 = 2;
130 	    tau2[0] = i__ - 1;
131 	    tau2[1] = i__ + 1;
132 	} else {
133 	    ltau2 = 1;
134 	    tau2[0] = i__;
135 	}
136 	difmag_(&speech[1], lpita, tau2, &ltau2, &tau[*ltau], amdf2, &minp2, &
137 		maxp2);
138 	if (amdf2[minp2 - 1] < (real) minamd) {
139 	    *mintau = tau2[minp2 - 1];
140 	    minamd = amdf2[minp2 - 1];
141 	    *minptr += -20;
142 	}
143     }
144 /*   Force minimum of the AMDF array to the high resolution minimum */
145     amdf[*minptr] = (real) minamd;
146 /*   Find maximum of AMDF within 1/2 octave of minimum */
147 /* Computing MAX */
148     i__2 = *minptr - 5;
149     *maxptr = max(i__2,1);
150 /* Computing MIN */
151     i__1 = *minptr + 5;
152     i__2 = min(i__1,*ltau);
153     for (i__ = *maxptr + 1; i__ <= i__2; ++i__) {
154 	if (amdf[i__] > amdf[*maxptr]) {
155 	    *maxptr = i__;
156 	}
157     }
158     return 0;
159 } /* tbdm_ */
160 
161