www.pudn.com > lpc.zip > onset_i.c


/*******************************************************************
*
*	ONSET Version 49
*
*******************************************************************
*
*	Floating point version
*/

#include "ourstuff.h"
#include "config.ch"
#include "lpcdefs.h"
#include 

onset_i( pebuf, osbuf, osptr)
int_type pebuf[];
int_type osbuf[], *osptr;
{
/*   Detection of onsets in (or slightly preceding) the futuremost frame
*   of speech.

*   Arguments
*    PEBUF	Preemphasized speech
*    OSBUF	Buffer which holds sorted indexes of onsets (Modified)
*    OSPTR	Free pointer into OSBUF (Modified)

*   Parameters for onset detection algorithm:
*    L2		Threshold for filtered slope of FPC (function of L2WID!)
*    L2LAG	Lag due to both filters which compute filtered slope of FPC
*    L2WID	Width of the filter which computes the slope of FPC
*    OSHYST	The number of samples which of slope(FPC) which must be below
*	        the threshold before a new onset may be declared.
*   Variables
*    N, D       Numerator and denominator of prediction filters
*    FPC        Current prediction coefs
*    L2BUF, L2SUM1, L2SUM2    State of slope filter
*/

int_type l2lag=9, l2wid=16, oshyst=10;
int_type l2=6963;

static int_type n=0, d=1, fpc;
static int_type l2buf[16], l2sum1=0., l2sum2=0.;
static int_type l2ptr1=1, l2ptr2=9, lasti;
int i;
static short hyst=0;
static short first=1;


if (hyst) lasti -= 180;


for(i=SBUFH-LFRAME+1; i<=SBUFH;i++)  {

/*   Compute FPC; Use old FPC on divide by zero; Clamp FPC to +/- 1.	*/
/*
  printf("(I) %d:  %d * %d >> 6 = %d  (%d) ",
    i,pebuf[i],pebuf[i-1],pebuf[i]*pebuf[i-1]>>6,n);
  */
   n=(((long_type)pebuf[i]*(long_type)pebuf[i-1]) >> 6)
      + (((long_type)63*(long_type)n) >> 6);
   /*
  printf(" ==> %d\n",n);
  */
   d=(((long_type)pebuf[i-1]*(long_type)pebuf[i-1]) >> 6) 
      + (((long_type)63*(long_type)d) >> 6);

   if (d != 0) {
      if (((n>0)?n:-n) > d) {
         /*fpc = sign(1., n);*/
	fpc = (n<0)?-4096:4096;
      }
      else
         fpc=(n*4096)/d;
   }

   /*printf("(i) %d: %d %d n = %d  d = %d  fpc = %f\n",i,pebuf[i],pebuf[i-1],n,d,fpc/4096.);*/

/*   Filter FPC	*/
   l2sum2 = l2buf[l2ptr1-1];
   l2sum1 = l2sum1 - l2buf[l2ptr2-1] + fpc;
   l2buf[l2ptr2-1] = l2sum1;
   l2buf[l2ptr1-1] = fpc;
   l2ptr1 = (l2ptr1- l2wid*(l2ptr1/l2wid))+1;
   l2ptr2 = (l2ptr2 - l2wid*(l2ptr2/l2wid))+1;

   if (((l2sum1-l2sum2>0)?(l2sum1-l2sum2):-(l2sum1-l2sum2)) > l2) {  
      if (!hyst) { 
/*   Ignore if buffer full	*/
         if (*osptr <= OSLEN) { 
            osbuf[*osptr] = i - l2lag;
            *osptr = *osptr + 1;
         } 
         hyst = 1;
      } 
      lasti = i;
   }
   else  if (hyst && i - lasti >= oshyst) { 
      hyst = 0;
   } 

} /* end while */


}