4 Revision 1.3 2000/01/05 08:20:40 markster
7 Revision 1.2 2000/01/05 08:20:40 markster
8 Some OSS fixes and a few lpc changes to make it actually work
10 * Revision 1.1 1996/08/19 22:30:26 jaf
16 #ifdef P_R_O_T_O_T_Y_P_E_S
17 extern int tbdm_(real *speech, integer *lpita, integer *tau, integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *mintau);
18 /*:ref: difmag_ 14 8 6 4 4 4 4 6 4 4 */
21 /* -- translated by f2c (version 19951025).
22 You must link the resulting object file with the libraries:
23 -lf2c -lm (in that order)
28 /* ********************************************************************** */
33 * Revision 1.3 2000/01/05 08:20:40 markster
34 * Version 0.1.4 from FTP
36 /* Revision 1.2 2000/01/05 08:20:40 markster
37 /* Some OSS fixes and a few lpc changes to make it actually work
39 * Revision 1.1 1996/08/19 22:30:26 jaf
42 /* Revision 1.3 1996/03/18 22:14:00 jaf */
43 /* Just added a few comments about which array indices of the arguments */
44 /* are used, and mentioning that this subroutine has no local state. */
46 /* Revision 1.2 1996/03/13 14:48:37 jaf */
47 /* Comments added explaining that none of the local variables of this */
48 /* subroutine need to be saved from one invocation to the next. */
50 /* Revision 1.1 1996/02/07 14:49:54 jaf */
51 /* Initial revision */
54 /* ********************************************************************* */
56 /*TURBO DIFMAG: Compute High Resolution Average Magnitude Difference Function
59 /* Note: There are several constants in here that appear to depend on a */
60 /* particular TAU table. That's not a problem for the LPC10 coder, but */
61 /* watch out if you change the contents of TAU in the subroutine ANALYS. */
64 /* SPEECH - Low pass filtered speech */
65 /* Indices 1 through MAX+LPITA-1 are read, where: */
66 /* MAX = (TAU(LTAU)-TAU(1))/2+1 */
67 /* (If TAU(1) .LT. 39, then larger indices could be read */
68 /* by the last call to DIFMAG below.) */
69 /* LPITA - Length of speech buffer */
70 /* TAU - Table of lags, sorted in increasing order. */
71 /* Indices 1 through LTAU read. */
72 /* LTAU - Number of lag values to compute */
74 /* AMDF - Average Magnitude Difference for each lag in TAU */
75 /* Indices 1 through LTAU written, and several might then be read.*/
76 /* MINPTR - Index of minimum AMDF value */
77 /* MAXPTR - Index of maximum AMDF value within +/- 1/2 octave of min */
78 /* MINTAU - Lag corresponding to minimum AMDF value */
80 /* This subroutine has no local state. */
82 /* Subroutine */ int tbdm_(real *speech, integer *lpita, integer *tau,
83 integer *ltau, real *amdf, integer *minptr, integer *maxptr, integer *
86 /* System generated locals */
87 integer i__1, i__2, i__3, i__4;
91 integer minp2, ltau2, maxp2, i__;
92 extern /* Subroutine */ int difmag_(real *, integer *, integer *, integer
93 *, integer *, real *, integer *, integer *);
94 integer minamd, ptr, tau2[6];
97 /* REAL SPEECH(LPITA+TAU(LTAU)), AMDF(LTAU) */
98 /* Stupid TOAST doesn't understand expressions */
99 /* Local variables that need not be saved */
102 /* Compute full AMDF using log spaced lags, find coarse minimum */
103 /* Parameter adjustments */
109 difmag_(&speech[1], lpita, &tau[1], ltau, &tau[*ltau], &amdf[1], minptr,
111 *mintau = tau[*minptr];
112 minamd = amdf[*minptr];
113 /* Build table containing all lags within +/- 3 of the AMDF minimum */
114 /* excluding all that have already been computed */
120 i__3 = *mintau + 3, i__4 = tau[*ltau] - 1;
121 i__2 = min(i__3,i__4);
122 for (i__ = max(i__1,41); i__ <= i__2; ++i__) {
123 while(tau[ptr] < i__) {
126 if (tau[ptr] != i__) {
128 tau2[ltau2 - 1] = i__;
131 /* Compute AMDF of the new lags, if there are any, and choose one */
132 /* if it is better than the coarse minimum */
134 difmag_(&speech[1], lpita, tau2, <au2, &tau[*ltau], amdf2, &minp2, &
136 if (amdf2[minp2 - 1] < (real) minamd) {
137 *mintau = tau2[minp2 - 1];
138 minamd = amdf2[minp2 - 1];
141 /* Check one octave up, if there are any lags not yet computed */
144 if ((i__ & 1) == 0) {
152 difmag_(&speech[1], lpita, tau2, <au2, &tau[*ltau], amdf2, &minp2, &
154 if (amdf2[minp2 - 1] < (real) minamd) {
155 *mintau = tau2[minp2 - 1];
156 minamd = amdf2[minp2 - 1];
160 /* Force minimum of the AMDF array to the high resolution minimum */
161 amdf[*minptr] = (real) minamd;
162 /* Find maximum of AMDF within 1/2 octave of minimum */
165 *maxptr = max(i__2,1);
168 i__2 = min(i__1,*ltau);
169 for (i__ = *maxptr + 1; i__ <= i__2; ++i__) {
170 if (amdf[i__] > amdf[*maxptr]) {