CA_Recog *CA_AllocateRecognition()
{
  CA_Recog *hRecog = NULL;

#ifdef SREC_ENGINE_VERBOSE_LOGGING
  PLogMessage("in CA_AllocateRecognition\n");
#endif

  TRY_CA_EXCEPT


  /* CREC_SET_SIGNATURE must be 'tied' to the
   * actual creation of the recog_info structure.
   * Any methods which take 'recog_info' as an argument,
   * even 'destroy_recognition()' will test the signature!
   */
  hRecog = (CA_Recog *) CALLOC_CLR(1, sizeof(CA_Recog), "ca.hRecog");

  hRecog->setup_count = 0;
  hRecog->is_running = False;
  hRecog->is_configured = False;
  hRecog->is_resultBlocked = False;
  hRecog->ca_rtti = CA_RECOGNIZER_SIGNATURE;

  hRecog->recm = (multi_srec*)CALLOC_CLR(1, sizeof(multi_srec), "ca.hRecog.srec");
  return (hRecog);

  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hRecog)
}
srec_word_lattice *allocate_word_lattice(frameID max_frames)
{
  srec_word_lattice *wl;

  wl = (srec_word_lattice*) CALLOC_CLR(1, sizeof(srec_word_lattice), "search.word_lattice.base");
  wl->max_frames = max_frames;
  wl->words_for_frame = (wtokenID*) CALLOC_CLR(max_frames, sizeof(wtokenID), "search.word_lattice.words");

  wl->whether_sorted = (asr_int16_t*)CALLOC_CLR(max_frames,  sizeof(asr_int16_t), "search.word_lattice.sflag");

  return wl;
}
norm_info *create_channel_normalization()
{
  norm_info *channorm;
  
  channorm = (norm_info *) CALLOC_CLR(1, sizeof(norm_info), "clib.channorm");
  return (channorm);
}
static void create_cepstrum_offsets(preprocessed *prep)
{
  ASSERT(prep);
  prep->chan_offset = (imeldata *) CALLOC_CLR(prep->dim,
                      sizeof(imeldata), "srec.chan_offset");
  return;
}
CA_Acoustic *CA_AllocateAcoustic(void)
{
  CA_Acoustic *hAcoust = NULL;
  
  TRY_CA_EXCEPT;
  
  hAcoust = (CA_Acoustic *) CALLOC_CLR(1,
            sizeof(CA_Acoustic), "ca.hAcoust");
  hAcoust->is_loaded = False;
  hAcoust->pattern_setup_count = 0;
  hAcoust->ca_rtti = CA_ACOUSTIC_SIGNATURE;
  BEG_CATCH_CA_EXCEPT;
  END_CATCH_CA_EXCEPT(hAcoust);
  return (hAcoust);
}
Exemple #6
0
static void allocate_recognition1(srec *rec,
                                  int viterbi_prune_thresh,  /*score-based pruning threshold - only keep paths within this delta of best cost*/
                                  int max_hmm_tokens,
                                  int max_fsmnode_tokens,
                                  int max_word_tokens,
                                  int max_altword_tokens,
                                  int num_wordends_per_frame,
                                  int max_frames,
                                  int max_model_states)
{
#ifdef SREC_ENGINE_VERBOSE_LOGGING
    PLogMessage("allocating recognition arrays2 prune %d max_hmm_tokens %d max_fsmnode_tokens %d max_word_tokens %d max_altword_tokens %d max_wordends_per_frame %d\n",
                viterbi_prune_thresh,
                max_hmm_tokens,
                max_fsmnode_tokens,
                max_word_tokens,
                max_altword_tokens,
                num_wordends_per_frame);
#endif
    rec->current_model_scores = (costdata*) CALLOC_CLR(max_model_states, sizeof(costdata), "search.srec.current_model_scores"); /*FIX - either get NUM_MODELS from acoustic models, or check this someplace to make sure we have enough room*/
    rec->num_model_slots_allocated = (modelID)max_model_states;

    rec->fsmarc_token_array_size = (stokenID)max_hmm_tokens;

    rec->fsmarc_token_array = (fsmarc_token*) CALLOC_CLR(rec->fsmarc_token_array_size , sizeof(fsmarc_token), "search.srec.fsmarc_token_array");
    rec->max_new_states = (stokenID)max_hmm_tokens;

    rec->word_token_array = (word_token*) CALLOC_CLR(max_word_tokens, sizeof(word_token), "search.srec.word_token_array");
    rec->word_token_array_size = (wtokenID)max_word_tokens;
    /* todo: change this to a bit array later */
    rec->word_token_array_flags = (asr_int16_t*) CALLOC_CLR(max_word_tokens, sizeof(asr_int16_t), "search.srec.word_token_array_flags");

    rec->fsmnode_token_array = (fsmnode_token*) CALLOC_CLR(max_fsmnode_tokens, sizeof(fsmnode_token), "search.srec.fsmnode_token_array");
    rec->fsmnode_token_array_size = (ftokenID)max_fsmnode_tokens;

    rec->altword_token_array = (altword_token*) CALLOC_CLR(max_altword_tokens, sizeof(altword_token), "search.srec.altword_token_array");
    rec->altword_token_array_size = (wtokenID)max_altword_tokens;

    rec->prune_delta = (costdata)viterbi_prune_thresh;

    rec->max_frames   = (frameID)max_frames;
    rec->best_model_cost_for_frame = (costdata*)CALLOC_CLR(max_frames, sizeof(costdata), "search.srec.best_model_cost_for_frame");
    rec->word_lattice = allocate_word_lattice((frameID)max_frames);

    rec->word_priority_q = allocate_priority_q(num_wordends_per_frame);
    rec->best_fsmarc_token = MAXstokenID;

#define ASTAR_NBEST_LEN 10
    rec->astar_stack = astar_stack_make(rec, ASTAR_NBEST_LEN);
    rec->context = NULL;
}
Exemple #7
0
CA_Pattern *CA_AllocatePattern(void)
{
  TRY_CA_EXCEPT
  CA_Pattern *hPattern = NULL;

  hPattern = (CA_Pattern *) CALLOC_CLR(1,
             sizeof(CA_Pattern), "ca.hPattern");
  hPattern->is_loaded = False;
  //hPattern->setup_whole = NULL;
  //hPattern->setup_sub = NULL;
  hPattern->ca_rtti = CA_PATTERN_SIGNATURE;
  return (hPattern);

  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hPattern)
}
Exemple #8
0
CA_ConfidenceScorer* CA_AllocateConfidenceScorer(void)
{
    CA_ConfidenceScorer *hConfidenceScorer;
    hConfidenceScorer = NULL;

    TRY_CA_EXCEPT

    hConfidenceScorer = (CA_ConfidenceScorer *) CALLOC_CLR(1,
                        sizeof(CA_ConfidenceScorer), "ca.hConfidenceScorer");

    return (hConfidenceScorer);

    BEG_CATCH_CA_EXCEPT
    END_CATCH_CA_EXCEPT(hConfidenceScorer)

}
Exemple #9
0
CA_RecInputParams *CA_AllocateRecognitionParameters(void)
{
  CA_RecInputParams *hRecInp = NULL;
  TRY_CA_EXCEPT
  hRecInp = (CA_RecInputParams *) CALLOC_CLR(1,
            sizeof(CA_RecInputParams), "ca.hRecInp");

  if ( hRecInp != NULL )
    {
    hRecInp->is_loaded = False;
    hRecInp->ca_rtti = CA_RECOGNIZER_PARAMETERS_SIGNATURE;
    }
  return (hRecInp);
  BEG_CATCH_CA_EXCEPT;
  END_CATCH_CA_EXCEPT(hRecInp);

}
Exemple #10
0
CA_PatInputParams *CA_AllocatePatternParameters(void)
{
  CA_PatInputParams *hPatInp = NULL;

  TRY_CA_EXCEPT

  hPatInp = (CA_PatInputParams *) CALLOC_CLR(1,
            sizeof(CA_PatInputParams), "ca.hPatInp");

  hPatInp->is_loaded = False;
  hPatInp->ca_rtti = CA_PATTERN_PARAMETERS_SIGNATURE;

  return (hPatInp);
  BEG_CATCH_CA_EXCEPT;
  END_CATCH_CA_EXCEPT(hPatInp);

}
Exemple #11
0
CA_AcoustInputParams *CA_AllocateAcousticParameters(void)
{
  CA_AcoustInputParams *hAcoustInp = NULL;
  TRY_CA_EXCEPT

  hAcoustInp = (CA_AcoustInputParams *) CALLOC_CLR(1,
               sizeof(CA_AcoustInputParams), "ca.hAcoustInp");

  hAcoustInp->is_loaded = False;
  hAcoustInp->ca_rtti = CA_ACOUSTIC_PARAMETERS_SIGNATURE;

  BEG_CATCH_CA_EXCEPT;
  END_CATCH_CA_EXCEPT(hAcoustInp);

  return (hAcoustInp);

}
Exemple #12
0
int CA_LoadPattern(CA_Pattern *hPattern, CA_PatInputParams *hPatInput,
                   int dimen , char *multable , char *imelda)
{

  TRY_CA_EXCEPT
#ifndef _RTT
  int ii, ret_code;

  ASSERT(hPattern);
  ASSERT(hPatInput);
  if (hPattern->is_loaded == True)
    SERVICE_ERROR(PATTERN_ALREADY_LOADED);
  if (hPatInput->is_loaded == False)
    SERVICE_ERROR(PATTERN_INPUT_NOT_LOADED);

  hPattern->data.prep = (preprocessed *) CALLOC_CLR(1,
                        sizeof(preprocessed), "ca.hPattern->data.prep");

  /*  Load the Imelda transform if specified */
  if (imelda && strlen(imelda) > 0)
  {
    ret_code = init_newton_transform(hPattern->data.prep, 0, imelda, hPatInput->dimen);
    if (ret_code > 0)
      SERVICE_ERROR(PATTERN_NOT_LOADED);
  }
  else
  {
    hPattern->data.prep->use_dim = hPatInput->dimen;
    hPattern->data.prep->use_from = hPatInput->feat_start;
  }

  if (hPatInput->whole_dimen == 0)
    hPattern->data.prep->whole_dim = hPatInput->dimen;
  else
    hPattern->data.prep->whole_dim = hPatInput->whole_dimen;
  if (hPattern->data.prep->whole_dim > hPattern->data.prep->use_dim)
    SERVICE_ERROR(BAD_PARAMETER);

  hPattern->data.prep->mix_score_scale = (prdata)(128 * hPatInput->mix_score_scale + 0.5)
                                         - (prdata)0.5;
  hPattern->data.prep->uni_score_scale = (prdata)(128 * hPatInput->uni_score_scale + 0.5)
                                         - (prdata)0.5;      
  hPattern->data.prep->uni_score_offset = (prdata) hPatInput->uni_score_offset;
  hPattern->data.prep->imelda_scale = (prdata)hPatInput->imelda_scale;
  init_preprocessed(hPattern->data.prep, dimen, hPatInput->imelda_scale); /* TODO: move this to Setup */


  /* Annotation parameters */
  hPattern->data.prep->end.rel_low  = hPatInput->rel_low;
  hPattern->data.prep->end.rel_high  = hPatInput->rel_high;
  hPattern->data.prep->end.gap_period  = hPatInput->gap_period;
  hPattern->data.prep->end.click_period = hPatInput->click_period;
  hPattern->data.prep->end.breath_period = hPatInput->breath_period;
  hPattern->data.prep->end.extend_annotation = hPatInput->extend_annotation;
  hPattern->data.prep->end.min_annotation_frames = hPatInput->min_annotation_frames;
  hPattern->data.prep->end.max_annotation_frames = hPatInput->max_annotation_frames;
  hPattern->data.prep->end.min_segment_rel_c0 = hPatInput->min_segment_rel_c0;
  hPattern->data.prep->end.min_initial_quiet_frames = hPatInput->min_initial_quiet_frames;
  hPattern->data.prep->end.delete_leading_segments = hPatInput->delete_leading_segments;
  hPattern->data.prep->end.leading_segment_min_frames = hPatInput->leading_segment_min_frames;
  hPattern->data.prep->end.leading_segment_max_frames = hPatInput->leading_segment_max_frames;
  hPattern->data.prep->end.leading_segment_min_silence_gap_frames
  = hPatInput->leading_segment_min_silence_gap_frames;
  hPattern->data.prep->end.leading_segment_accept_if_not_found
  = hPatInput->leading_segment_accept_if_not_found;
#if DO_SUBTRACTED_SEGMENTATION
  hPattern->data.prep->end.snr_holdoff = hPatInput->snr_holdoff;
  hPattern->data.prep->end.min_acceptable_snr = hPatInput->min_acceptable_snr;
#endif
  hPattern->data.prep->end.param  = hPatInput->param;
  hPattern->data.prep->end.beep_size = hPatInput->beep_size;
  hPattern->data.prep->end.beep_threshold = hPatInput->beep_threshold;


  /* log-lookup table */
  create_lookup_logadd(&hPattern->data.prep->add, (float)MUL_SCALE);

  /* Build the weights conversion table */
  for (ii = 0; ii < MAX_WTS; ii++)
    hPattern->data.prep->exp_wt[ii] =
      (prdata)(WEIGHT_SCALE * exp((double)(0x01 << WT_ADJUST) *
                                  (double) - ii / (MUL_SCALE * hPattern->data.prep->add.scale)) +
               0.5) - (prdata)0.5;

  hPattern->data.prep->ref_count = 1;
  hPattern->is_loaded = True;

  return (True);
#else
  log_report("RTT not in module\n");
  SERVICE_ERROR(FEATURE_NOT_SUPPORTED);
  return (False);
#endif


  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hPattern)

}
Exemple #13
0
int allocate_recognition(multi_srec *rec,
                         int viterbi_prune_thresh,  /*score-based pruning threshold - only keep paths within this delta of best cost*/
                         int max_hmm_tokens,
                         int max_fsmnode_tokens,
                         int max_word_tokens,
                         int max_altword_tokens,
                         int num_wordends_per_frame,
                         int max_fsm_nodes,
                         int max_fsm_arcs,
                         int max_frames,
                         int max_model_states,
                         int max_searches)
{
    int i;

    if (check_parameter_range(max_fsm_nodes, 1, MAXnodeID, "max_fsm_nodes"))
        return 1;
    if (check_parameter_range(max_fsm_arcs, 1, MAXarcID, "max_fsm_arcs"))
        return 1;
    if (check_parameter_range(max_frames, 1, MAXframeID, "max_frames"))
        return 1;
    if (check_parameter_range(max_model_states, 1, MAXmodelID, "max_model_states"))
        return 1;
    if (check_parameter_range(max_hmm_tokens, 1, MAXstokenID, "max_hmm_tokens"))
        return 1;
    if (check_parameter_range(max_fsmnode_tokens, 1, MAXftokenID, "max_fsmnode_tokens"))
        return 1;
    if (check_parameter_range(viterbi_prune_thresh, 1, MAXcostdata, "viterbi_prune_thresh"))
        return 1;
    if (check_parameter_range(max_altword_tokens, 0, MAXftokenID, "max_altword_tokens"))
        return 1;
    if (check_parameter_range(max_searches, 1, 2, "max_searches"))
        return 1;

    rec->rec = (srec*)CALLOC_CLR(max_searches, sizeof(srec), "search.srec.base");
    rec->num_allocated_recs = max_searches;
    rec->num_swimodels      = 0;

    /* best_token_for_arc and best_token_for_node are shared across
       multiple searches */
    rec->best_token_for_arc = (stokenID*)CALLOC_CLR(max_fsm_arcs, sizeof(stokenID), "search.srec.best_token_for_arc");
    rec->max_fsm_arcs = (arcID)max_fsm_arcs;

    rec->best_token_for_node = (ftokenID*)CALLOC_CLR(max_fsm_nodes, sizeof(ftokenID), "search.srec.best_token_for_node");
    rec->max_fsm_nodes = (nodeID)max_fsm_nodes;

    /* cost offsets and accumulated cost offsets are pooled for all
       different searches, this saves memory and enables each search
       to know it's total scores */
    rec->cost_offset_for_frame = (costdata*)CALLOC_CLR(max_frames, sizeof(costdata), "search.srec.current_best_costs");
    rec->accumulated_cost_offset = (bigcostdata*)CALLOC_CLR(max_frames, sizeof(bigcostdata), "search.srec.accumulated_cost_offset");
    rec->max_frames = (frameID)max_frames;
    for (i = 0; i < max_frames; i++)
        rec->accumulated_cost_offset[i] = 0;

    /* now copy the shared data down to individual recogs */
    for (i = 0; i < rec->num_allocated_recs; i++)
    {
        allocate_recognition1(&rec->rec[i], viterbi_prune_thresh, max_hmm_tokens, max_fsmnode_tokens, max_word_tokens, max_altword_tokens, num_wordends_per_frame, max_frames, max_model_states);
        rec->rec[i].best_token_for_node     = rec->best_token_for_node;
        rec->rec[i].max_fsm_nodes           = rec->max_fsm_nodes;
        rec->rec[i].best_token_for_arc      = rec->best_token_for_arc;
        rec->rec[i].max_fsm_arcs            = rec->max_fsm_arcs;
        rec->rec[i].max_frames              = rec->max_frames;
        rec->rec[i].cost_offset_for_frame   = rec->cost_offset_for_frame;
        rec->rec[i].accumulated_cost_offset = rec->accumulated_cost_offset;
        rec->rec[i].id = (asr_int16_t)i;
    }
    rec->eos_status = VALID_SPEECH_NOT_YET_DETECTED;
    return 0;
}