Home | History | Annotate | Download | only in include
      1 /*---------------------------------------------------------------------------*
      2  *  fpi_tgt.h  *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 /*
     21  *
     22  *
     23  */
     24 
     25 #ifndef __fpi_tgt_h
     26 #define __fpi_tgt_h
     27 
     28 #ifdef SET_RCSID
     29 static const char fpi_tgt_h[] = "$Id: fpi_tgt.h,v 1.1.10.3 2007/08/31 17:44:53 dahan Exp $";
     30 #endif
     31 
     32 
     33 
     34 
     35 #include <stdlib.h>
     36 #include <string.h>
     37 
     38 #include "creccons.h"   /* CREC Public Constants    */
     39 
     40 #include "hmm_type.h"
     41 #include "specnorm.h"
     42 #include "voicing.h"
     43 
     44 #define QUICK 0
     45 
     46 /***********************************
     47  * MACROs for Pointer Manipulation *
     48  ***********************************/
     49 
     50 #if QUICK
     51 #define NEXT_FRAME_POINTER(PKT,X)   (((X) + (PKT)->frameSize) & (PKT)->stackMask)
     52 #define PREV_FRAME_POINTER(PKT,X)   (((X) - (PKT)->frameSize) & (PKT)->stackMask)
     53 #define FIX_FRAME_POINTER(PKT,X)    ((X) & (PKT)->stackMask)
     54 #define POINTER_GAP(PKT, LEAD, LAG) ((((LEAD) - (LAG)) & (PKT)->stackMask)/(PKT)->frameSize)
     55 #define CHECK_BOUND(PKT, X)         ((X) < (PKT)->frameStack ? NULL : (X) > (PKT)->lastFrameInStack ? NULL : (X))
     56 #else
     57 #define NEXT_FRAME_POINTER(PKT,X)   ((X) >= (PKT)->lastFrameInStack ? (PKT)->frameStack : (X) + (PKT)->frameSize)
     58 #define PREV_FRAME_POINTER(PKT,X)   ((X) <= (PKT)->frameStack ? (PKT)->lastFrameInStack : (X) - (PKT)->frameSize)
     59 #define FIX_FRAME_POINTER(PKT,X)    ((X) < (PKT)->frameStack ? (X) + (PKT)->featuresInStack \
     60                                      : (X) > (PKT)->lastFrameInStack ? (X) - (PKT)->featuresInStack : (X))
     61 #define POINTER_GAP(PKT, LEAD, LAG) ((LEAD) >= (LAG) ? ((LEAD) - (LAG))/(PKT)->frameSize : ((PKT)->featuresInStack + (LEAD) - (LAG))/(PKT)->frameSize)
     62 #define CHECK_BOUND(PKT, X)         ((X) < (PKT)->frameStack ? NULL : (X) > (PKT)->lastFrameInStack ? NULL : (X))
     63 #endif
     64 
     65 #ifdef DEBUGSEM
     66 volatile int releaseCalled = 0;
     67 volatile int waitCalled = 0;
     68 #endif
     69 
     70 /************************************************************************
     71  * Structures                                                           *
     72  ************************************************************************/
     73 
     74 /****************
     75  * Frame Buffer *
     76  ****************/
     77 
     78 typedef struct
     79 {
     80   volatile int  isCollecting;      /* Frame buffer is collecting */
     81   featdata*     frameStack;        /* Pointer to Frame Stack          */
     82   int           frameSize;         /* How many data items per frame?  */
     83   int           uttDim;            /* How many spectral parameters?   */
     84   int           frameStackSize;    /* How many frames in the Stack?   */
     85   unsigned long stackMask;      /* Mask to fit stack size  */
     86   int           featuresInStack;   /* How many features in the Stack? */
     87   featdata*     lastFrameInStack;  /* Pointer to last frame           */
     88   int           haveVoiced;      /* whether voice stack is valid */
     89   volatile int  voicingDetected;   /* Voicing present in this buffer  */
     90   volatile int  utt_ended;         /* end of utterance flag           */
     91   volatile int  quietFrames;      /* consecutive quiet frames to end */
     92   volatile int  uttTimeout;      /* Voicing present in this buffer  */
     93   int           holdOffPeriod;     /* Copy of 'holdOff' argument      */
     94   int           holdOff;           /* countdown of 'holdOffPeriod     */
     95 
     96   featdata* volatile pushp;        /* Ptr to frame being written      */
     97   featdata* volatile pullp;        /* Ptr to next frame to be read    */
     98   featdata* volatile pushBlkp;     /* pushp blocker                   */
     99 
    100   int    blockLen;      /* Blocking enabled to this length */
    101   volatile int  pushBlocked;       /* Set if pushp ever gets blocked  */
    102   unsigned long blockTime;         /* Last time frame was blocked     */
    103   unsigned long pushTime;          /* Time of FEP frame               */
    104   unsigned long pullTime;          /* Time of REC frame               */
    105   unsigned long startTime;         /* Time of first frame of this utt */
    106   unsigned long stopTime;          /* Time of first frame of this utt */
    107 
    108   volatile featdata  maxC0;      /* Maximum C0 tracked  */
    109   volatile featdata  minC0;      /* Minimum C0 tracked  */
    110 }
    111 fepFramePkt;
    112 
    113 /************************************************************************
    114  * Prototypes                                                           *
    115  ************************************************************************/
    116 
    117 /*************************
    118  * Both FEP and REC units
    119  *************************/
    120 void      startFrameCollection(fepFramePkt* frmPkt);
    121 int          stopFrameCollection(fepFramePkt* frmPkt);
    122 
    123 /*************************
    124  * For FEP unit Only (?) *
    125  *************************/
    126 
    127 fepFramePkt* createFrameBuffer(int fCnt, int dimen, int blockLen, int doVoice);
    128 int          resizeFrameBuffer(fepFramePkt *frmPkt, int fCnt);
    129 int          clearFrameBuffer(fepFramePkt* frmPkt);
    130 int          destroyFrameBuffer(fepFramePkt* frmPkt);
    131 int          pushSingleFEPframe(fepFramePkt* frmPkt, featdata* parPtr, int voiceData);
    132 void      clearEndOfUtterance(fepFramePkt* frmPkt);
    133 void      setupEndOfUtterance(fepFramePkt* frmPkt, long timeout, long holdOff);
    134 
    135 /*************************
    136  * For REC unit Only (?) *
    137  *************************/
    138 
    139 int         setRECframePtr(fepFramePkt* frmPkt, int fCnt, int mode);
    140 featdata*   currentRECframePtr(fepFramePkt* frmPkt);
    141 featdata*   currentFEPframePtr(fepFramePkt* frmPkt);
    142 int         incRECframePtr(fepFramePkt* frmPkt);
    143 int         decRECframePtr(fepFramePkt* frmPkt);
    144 int         framesInBuffer(fepFramePkt* frmPkt);
    145 featdata    getVoicingCode(fepFramePkt *frmPkt, featdata *frmptr);
    146 void     setVoicingCode(fepFramePkt *frmPkt, featdata *frmptr, featdata vcode);
    147 unsigned long getRECframeTime(fepFramePkt* frmPkt);
    148 unsigned long getFEPframeTime(fepFramePkt* frmPkt);
    149 featdata    getCurrentC0(fepFramePkt* frmPkt);
    150 featdata    getMaximumC0(fepFramePkt* frmPkt);
    151 featdata    getMinimumC0(fepFramePkt* frmPkt);
    152 featdata    get_c0_peak_over_range(fepFramePkt *frmPkt, int start, int end);
    153 
    154 void        clearC0Entries(fepFramePkt* frmPkt);
    155 void     releaseBlockedFramesInBuffer(fepFramePkt* frmPkt);
    156 
    157 void    get_channel_statistics(fepFramePkt *frmPkt, int start, int end,
    158                                spect_dist_info** spec, int num, int relative_to_pullp);
    159 int     get_background_statistics(fepFramePkt *frmPkt, int start, int end,
    160                                   spect_dist_info** spec, int num, int relative_to_pullp);
    161 int     rec_frame_voicing_status(fepFramePkt *frmPkt);
    162 void    utterance_detection_fixup(fepFramePkt *frmPkt, featdata **last_pushp,
    163                                   int voice_duration, int quite_duration,
    164                                   int unsure_duration);
    165 
    166 #endif
    167