www.pudn.com > lpc.zip > tbdm_i.c
/************************************************************
*
* TBDM Version 49
*
*************************************************************
*
* TURBO DIFMAG: Compute High Resolution Average Magnitude Difference Function
*
* Inputs:
* SPEECH - Low pass filtered speech
* LPITA - Length of speech buffer
* TAU - Table of lags
* LTAU - Number of lag values to compute
* Outputs:
* AMDF - Average Magnitude Difference for each lag in TAU
* MINPTR - Index of minimum AMDF value
* MAXPTR - Index of maximum AMDF value within +/- 1/2 octave of min
* MINTAU - Lag corresponding to minimum AMDF value
*/
#include "lpcdefs.h"
#include "ourstuff.h"
tbdm_i( speech, tau, amdf, minptr, maxptr, mintau )
int_type speech[], amdf[];
int_type *minptr, *maxptr, *mintau, tau[];
{
int_type minamd;
int_type i, ptr, ltau2, minp2, maxp2;
int_type amdf2[6];
static int_type tau2[6];
/* REAL SPEECH(LPITA+TAU(LTAU)), AMDF(LTAU), AMDF2(6)
/* Compute full AMDF using log spaced lags, find coarse minimum */
/*
for( i = PWINL; i<=PWINH-LFRAME; i++) {
printf("speech_i:%d\n",speech[i]);
}
*/
difmag_i(speech, tau, LTAU, tau[LTAU], amdf, minptr, maxptr );
/*printf("minptr_i: %d\n", *minptr);*/
*mintau = tau[*minptr];
/*printf("mintau_i: %d\n", *mintau);
getchar();*/
minamd = amdf[*minptr];
/*printf("minamd_i: %d\n", minamd);*/
/* Build table containing all lags within +/- 3 of the AMDF minimum
* excluding all that have already been computed */
ltau2 = 0;
ptr = *minptr - 2;
for(i=mmax(*mintau-3,41); i<=mmin(*mintau+3,tau[LTAU]); i++) {
while( tau[ptr] < i )
ptr++;
if( tau[ptr] !=i) {
ltau2++;
tau2[ltau2-1] = i;
}
}
/* Compute AMDF of the new lags, if there are any, and choose one
* if it is better than the coarse minimum */
if( ltau2 > 0 ) {
difmag_i(speech, &tau2[0]-1, ltau2, tau[LTAU], &amdf2[0]-1, &minp2, &maxp2);
if( amdf2[minp2-1] < minamd ) {
*mintau = tau2[minp2-1];
minamd = amdf2[minp2-1];
}
}
/* Check one octave up, if there are any lags not yet computed */
if( *mintau >= 80 ) {
i = *mintau>>2;
if( (i & 1) == 0 ) {
ltau2 = 2;
tau2[0] = i-1;
tau2[1] = i+1;
}
else {
ltau2 = 1;
tau2[0] = i;
}
difmag_i(speech, &tau2[0]-1, ltau2, tau[LTAU], &amdf2[0]-1, &minp2, &maxp2 );
if( amdf2[minp2-1] < minamd ) {
*mintau = tau2[minp2-1];
minamd = amdf2[minp2-1];
*(minptr) -= 20;
}
}
/* Force minimum of the AMDF array to the high resolution minimum */
amdf[*minptr] = minamd;
/* Find maximum of AMDF within 1/2 octave of minimum */
*maxptr = mmax(*minptr-5,1);
for(i=*maxptr+1; i<= mmin(*minptr+5,LTAU); i++) {
if( amdf[i] > amdf[*maxptr]) *maxptr = i;
}
}