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