Home | History | Annotate | Download | only in ca
      1 /*---------------------------------------------------------------------------*
      2  *  acc_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 #include "simapi.h"
     32 #include "portable.h"
     33 
     34 #ifdef SET_RCSID
     35 static const char *rcsid = 0 ? (const char *) &rcsid :
     36                            "$Id: acc_basi.c,v 1.4.6.11 2008/03/07 19:46:45 dahan Exp $";
     37 #endif
     38 
     39 CA_Acoustic *CA_AllocateAcoustic(void)
     40 {
     41   CA_Acoustic *hAcoust = NULL;
     42 
     43   TRY_CA_EXCEPT;
     44 
     45   hAcoust = (CA_Acoustic *) CALLOC_CLR(1,
     46             sizeof(CA_Acoustic), "ca.hAcoust");
     47   hAcoust->is_loaded = False;
     48   hAcoust->pattern_setup_count = 0;
     49   hAcoust->ca_rtti = CA_ACOUSTIC_SIGNATURE;
     50   BEG_CATCH_CA_EXCEPT;
     51   END_CATCH_CA_EXCEPT(hAcoust);
     52   return (hAcoust);
     53 }
     54 
     55 
     56 void CA_FreeAcoustic(CA_Acoustic *hAcoust)
     57 {
     58   TRY_CA_EXCEPT
     59 
     60   ASSERT(hAcoust);
     61   FREE((char *) hAcoust);
     62   return;
     63 
     64   BEG_CATCH_CA_EXCEPT
     65   END_CATCH_CA_EXCEPT(hAcoust)
     66 }
     67 
     68 int CA_LoadAcousticSub(CA_Acoustic *hAcoust, char *subname, CA_AcoustInputParams *hAcoustInp)
     69 {
     70 //#ifndef _RTT
     71 //  int     load_genome = 0;
     72 //#endif
     73 
     74   if (hAcoustInp == 0)
     75   {
     76     /* SpeechWorks image format! */
     77     hAcoust->swimodel = load_swimodel(subname);
     78     if (hAcoust->swimodel == NULL)
     79     {
     80         // failed to load, load_swimodel will have printed an error to the log
     81         return 0;
     82     }
     83     hAcoust->is_loaded = ESR_TRUE;
     84     return 1;
     85   }
     86   else
     87   {
     88     SERVICE_ERROR(FEATURE_NOT_SUPPORTED);
     89     return 0;
     90   }
     91 }
     92 
     93 void CA_UnloadAcoustic(CA_Acoustic *hAcoust)
     94 {
     95   TRY_CA_EXCEPT
     96   ASSERT(hAcoust);
     97 
     98   if (hAcoust->is_loaded == False)
     99     SERVICE_ERROR(ACOUSTIC_NOT_LOADED);
    100   if (hAcoust->swimodel)
    101   {
    102     free_swimodel(hAcoust->swimodel);
    103     hAcoust->swimodel = 0;
    104     hAcoust->is_loaded = False;
    105     return;
    106   }
    107 	else
    108 		SERVICE_ERROR(ACOUSTIC_NOT_LOADED);
    109   return;
    110 
    111   BEG_CATCH_CA_EXCEPT
    112   END_CATCH_CA_EXCEPT(hAcoust)
    113 }
    114