Home | History | Annotate | Download | only in ca
      1 /*---------------------------------------------------------------------------*
      2  *  utt_basi.c  *
      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 #include <stdlib.h>
     21 #include <string.h>
     22 #ifndef _RTT
     23 #include <stdio.h>
     24 #endif
     25 
     26 #ifdef unix
     27 #include <unistd.h>
     28 #endif
     29 #include <assert.h>
     30 
     31 
     32 #include "simapi.h"
     33 #include "portable.h"
     34 
     35 #include "../clib/fpi_tgt.inl"
     36 
     37 static const char utt_basi[] = "$Id: utt_basi.c,v 1.6.6.8 2007/10/15 18:06:24 dahan Exp $";
     38 
     39 
     40 CA_Utterance *CA_AllocateUtterance(void)
     41 {
     42   CA_Utterance *hUtt = NULL;
     43   TRY_CA_EXCEPT
     44 
     45   hUtt = (CA_Utterance *) CALLOC_CLR(1, sizeof(CA_Utterance), "ca.hUtt");
     46   hUtt->ca_rtti = CA_UTTERANCE_SIGNATURE;
     47   return (hUtt);
     48 
     49   BEG_CATCH_CA_EXCEPT
     50   END_CATCH_CA_EXCEPT(hUtt)
     51 }
     52 
     53 
     54 void CA_FreeUtterance(CA_Utterance *hUtt)
     55 {
     56   TRY_CA_EXCEPT
     57   ASSERT(hUtt);
     58 
     59   FREE((char *) hUtt);
     60   return;
     61 
     62   BEG_CATCH_CA_EXCEPT
     63   END_CATCH_CA_EXCEPT(hUtt)
     64 }
     65 
     66 
     67 int CA_InitUtteranceForFrontend(CA_Utterance *hUtt,
     68                                 CA_FrontendInputParams *hFrontPar)
     69 {
     70   TRY_CA_EXCEPT
     71   ASSERT(hUtt);
     72   ASSERT(hFrontPar > 0);
     73   if (hUtt->data.utt_type != 0)
     74     SERVICE_ERROR(UTTERANCE_ALREADY_INITIALISED);
     75 
     76   init_utterance(&hUtt->data, LIVE_INPUT, 3*hFrontPar->mel_dim,  /* TODO: change to proper function */
     77                  DEFAULT_BUFFER_SIZE, KEEP_FRAMES,
     78                  hFrontPar->mel_dim, 1);
     79   if (hFrontPar->do_skip_even_frames)
     80     set_voicing_durations(&hUtt->data, hFrontPar->voice_duration / 2,
     81                           hFrontPar->quiet_duration / 2,
     82                           hFrontPar->unsure_duration / 2,
     83                           hFrontPar->start_windback / 2);
     84   else
     85     set_voicing_durations(&hUtt->data, hFrontPar->voice_duration,
     86                           hFrontPar->quiet_duration,
     87                           hFrontPar->unsure_duration,
     88                           hFrontPar->start_windback);
     89   return (0);
     90 
     91   BEG_CATCH_CA_EXCEPT
     92   END_CATCH_CA_EXCEPT(hUtt)
     93 
     94 }
     95 
     96 
     97 void CA_ClearUtterance(CA_Utterance *hUtt)
     98 {
     99 
    100   TRY_CA_EXCEPT
    101   ASSERT(hUtt);
    102   if (hUtt->data.utt_type == 0)
    103   {
    104     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    105   }
    106 
    107   if (hUtt->data.utt_type == LIVE_INPUT)
    108   {
    109     free_utterance(&hUtt->data);
    110     hUtt->data.utt_type = 0;
    111   }
    112   else
    113   {
    114     SERVICE_ERROR(UTTERANCE_UNKNOWN);
    115   }
    116   return;
    117 
    118   BEG_CATCH_CA_EXCEPT
    119   END_CATCH_CA_EXCEPT(hUtt)
    120 }
    121 
    122 
    123 int CA_AdvanceUtteranceFrame(CA_Utterance *hUtt)
    124 {
    125   TRY_CA_EXCEPT
    126   int status_code;
    127 
    128   ASSERT(hUtt);
    129   if (hUtt->data.utt_type != LIVE_INPUT)
    130     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    131 
    132   status_code = advance_utterance_frame(&hUtt->data);
    133   return (status_code);
    134 
    135   BEG_CATCH_CA_EXCEPT
    136   END_CATCH_CA_EXCEPT(hUtt)
    137 }
    138 
    139 int CA_UtteranceHasVoicing(CA_Utterance *hUtt)
    140 {
    141   TRY_CA_EXCEPT
    142   ASSERT(hUtt);
    143   if (hUtt->data.utt_type != LIVE_INPUT)
    144     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    145 
    146   return (hUtt->data.gen_utt.frame->voicingDetected);
    147 
    148   BEG_CATCH_CA_EXCEPT
    149   END_CATCH_CA_EXCEPT(hUtt)
    150 }
    151 
    152 
    153 void CA_UnlockUtteranceForInput(CA_Utterance *hUtt)
    154 {
    155   TRY_CA_EXCEPT
    156   ASSERT(hUtt);
    157   if (hUtt->data.utt_type != LIVE_INPUT)
    158     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    159   ASSERT(!isFrameBufferActive(hUtt->data.gen_utt.frame));
    160   startFrameCollection(hUtt->data.gen_utt.frame);
    161   return;
    162 
    163   BEG_CATCH_CA_EXCEPT
    164   END_CATCH_CA_EXCEPT(hUtt)
    165 }
    166 
    167 
    168 void CA_LockUtteranceFromInput(CA_Utterance *hUtt)
    169 {
    170   TRY_CA_EXCEPT
    171   ASSERT(hUtt);
    172   if (hUtt->data.utt_type != LIVE_INPUT)
    173     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    174   ASSERT(isFrameBufferActive(hUtt->data.gen_utt.frame));
    175 
    176 
    177   stopFrameCollection(hUtt->data.gen_utt.frame);
    178   return;
    179 
    180   BEG_CATCH_CA_EXCEPT
    181   END_CATCH_CA_EXCEPT(hUtt)
    182 }
    183 
    184 
    185 void CA_ResetVoicing(CA_Utterance *hUtt)
    186 {
    187   TRY_CA_EXCEPT
    188   ASSERT(hUtt);
    189   if (hUtt->data.utt_type != LIVE_INPUT)
    190     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    191 
    192   clearEndOfUtterance(hUtt->data.gen_utt.frame);
    193   clearC0Entries(hUtt->data.gen_utt.frame);
    194   startFrameCollection(hUtt->data.gen_utt.frame);
    195   return;
    196 
    197   BEG_CATCH_CA_EXCEPT
    198   END_CATCH_CA_EXCEPT(hUtt)
    199 }
    200 
    201 
    202 void CA_FlushUtteranceFrames(CA_Utterance *hUtt)
    203 {
    204   TRY_CA_EXCEPT
    205   ASSERT(hUtt);
    206   if (hUtt->data.utt_type != LIVE_INPUT)
    207     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    208 
    209   setRECframePtr(hUtt->data.gen_utt.frame, 0, 0);
    210   releaseBlockedFramesInBuffer(hUtt->data.gen_utt.frame);
    211   hUtt->data.gen_utt.last_push = NULL;
    212   return;
    213 
    214   BEG_CATCH_CA_EXCEPT
    215   END_CATCH_CA_EXCEPT(hUtt)
    216 }
    217 
    218 
    219 void CA_SetEndOfUtteranceByLevelTimeout(CA_Utterance *hUtt, long timeout, long holdOff)
    220 {
    221   TRY_CA_EXCEPT
    222   ASSERT(hUtt);
    223   if (hUtt->data.utt_type != LIVE_INPUT)
    224     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    225 
    226   setupEndOfUtterance(hUtt->data.gen_utt.frame, timeout, holdOff);
    227   return;
    228 
    229   BEG_CATCH_CA_EXCEPT
    230   END_CATCH_CA_EXCEPT(hUtt)
    231 }
    232 
    233 
    234 int CA_UtteranceHasEnded(CA_Utterance *hUtt)
    235 {
    236   TRY_CA_EXCEPT
    237   ASSERT(hUtt);
    238   if (hUtt->data.utt_type != LIVE_INPUT)
    239     SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
    240 
    241   return (utterance_ended(&hUtt->data));
    242 
    243   BEG_CATCH_CA_EXCEPT
    244   END_CATCH_CA_EXCEPT(hUtt)
    245 }
    246