Example #1
0
void convert_adjustment_to_imelda(norm_info *norm, preprocessed *prep)
{
  int      ii;
  imeldata fram[MAX_DIMEN];

  ASSERT(prep);
  ASSERT(norm);
  for (ii = 0; ii < 12; ii++)      /* TODO: fix dimension properly, and sort out rouding/type */
    fram[ii] = (imeldata) norm->adjust[ii]; /* TODO: review types */
  for (; ii < prep->dim; ii++)
    fram[ii] = 0;

  linear_transform_frame(prep, fram, False);

  for (ii = 0; ii < prep->dim; ii++)
    norm->imelda_adjust[ii] = fram[ii];
#if DEBUG
  log_report("NORM AUX: ");
  for (ii = 0; ii < norm->dim; ii++)
    log_report("%d ", (int)norm->imelda_adjust[ii]);
  log_report("\n");
#endif
  norm->adj_valid = True;
  return;
}
Example #2
0
void cepstrum_params(front_channel *channel, front_wave *waveobj,
                     front_freq *freqobj, front_cep *cepobj)
{
#if SPEC_CORRECT
  /*  2.30 Apply a spectrum correction */
  if (cepobj->mel_loop)
    mel_spectrum_correction(freqobj->filterbank, cepobj->mel_loop, channel->num_freq);
#endif
  /*  2.33 Calculate log dB energy values */
    mel_loglookup_with_offset(cepobj, channel);
#if DEBUG
  log_report("Filterbank output: ");
  write_scaled_frames(freqobj->nf, 1, channel->filterbank, D_FIXED, 1 / (float)LOG_SCALE);
#endif

  /*  2.34 Cosine transformation */
  icostrans(cepobj->cs, channel->filterbank, channel->cep,
            channel->num_freq, cepobj->mel_dim);

#if DEBUG
  log_report("Cepstrum coefficients: ");
  write_scaled_frames((cepobj->mel_dim + 1), 1, channel->cep, D_FIXED, (float)1 / (0x01 << (LOG_SCALE_SHIFT + COSINE_TABLE_SHIFT)));
#endif
  return;
}
Example #3
0
void init_preprocessed(preprocessed *prep, int dimen, float imelda_scale)
/*
**  To setup the preprocessed structure
*/
{

  ASSERT(prep);
  ASSERT(dimen > 0);
  prep->dim = dimen;
  prep->seq = (imeldata *) CALLOC(prep->dim, sizeof(imeldata),
                                        "srec.prep->seq");
  prep->seq_unnorm = (imeldata *) CALLOC(prep->dim, sizeof(imeldata),
                     "srec.prep->seq_unnorm");
  prep->last_frame = (featdata *) CALLOC(prep->dim, sizeof(featdata),
                     "srec.prep->last_frame");

  /*  Setup constants for distance calculation
  */
  /* TODO: check numbers for non-zero */
  prep->add.scale = (prdata)((2 * imelda_scale * imelda_scale) / MUL_SCALE
                             + 0.5) - (prdata)0.5;
  prep->add.inv_scale = (prdata)(((float)(0x01 << 12) * MUL_SCALE) /
                                 (2 * imelda_scale * imelda_scale) + 0.5) -
                        (prdata)0.5;
  prep->mul.multable_factor_gaussian = 1;
  prep->mul.multable_factor = (prdata)(((MUL_SCALE * (0x01 << EUCLID_SHIFT)
                                         * prep->uni_score_scale)
                                        / (2 * (imelda_scale * imelda_scale
                                                * FUDGE_FACTOR * FUDGE_FACTOR))) / 128 + 0.5)
                              - (prdata)0.5;
  prep->mul.grand_mod_cov = (prdata)((MUL_SCALE * prep->uni_score_scale *
                                      prep->whole_dim *
                                      log((imelda_scale * FUDGE_FACTOR) /
                                          (SIGMA_BIAS * root_pi_over_2))) / 128 + 0.5)
                            - (prdata)0.5 - prep->uni_score_offset;
  prep->mul.grand_mod_cov_gaussian = (prdata)(2 * imelda_scale * imelda_scale *
                                     prep->use_dim *
                                     log(imelda_scale /
                                         (SIGMA_BIAS * root_pi_over_2)) + 0.5)
                                     - (prdata)0.5;
#if DEBUG
  log_report("grand_mod_cov %.1f, grand_mod_cov_gaussian %.1f\n",
             (float)prep->mul.grand_mod_cov,
             (float)prep->mul.grand_mod_cov_gaussian);
  log_report("multable_factor %f, multable_factor_gaussian %f\n",
             (float)prep->mul.multable_factor,
             (float)prep->mul.multable_factor_gaussian);
#endif


  create_cepstrum_offsets(prep);
  return;
}
void read_cb(uv_fs_t* read_req) {
  int r = 0;
  if (read_req->result < 0) CHECK(read_req->result, "uv_fs_read callback");

  /* extracting our context from the read_req */
  context_t* context = read_req->data;

  /* 4. Report the contents of the buffer */
  /*
  log_report("%s", read_req->bufsml->base);
  log_info("%s", read_req->bufsml->base);

  free(read_req->bufsml->base);
  log_report("%s", context->iov->base);
  log_info("%s", context->iov->base);
  if I don't call log_report/log_info on context->iov, then valgrind has 0 erro!
  */
  log_report("%s", context->iov.base);
  log_info("%s", context->iov.base);

  /* 5. Close the file descriptor (synchronously) */
  uv_fs_t close_req;
  r = uv_fs_close(read_req->loop, &close_req, context->open_req->result, NULL);
  if (r < 0) CHECK(abs(r), "uv_fs_close");

  /* cleanup all requests and context */
  uv_fs_req_cleanup(context->open_req);
  uv_fs_req_cleanup(read_req);
  uv_fs_req_cleanup(&close_req);
  free(context);
}
Example #5
0
void CA_DetachCMSfromUtterance(CA_Wave *hWave, CA_Utterance *hUtt)
{
  TRY_CA_EXCEPT
  ASSERT(hWave);

  if (hWave->is_configuredForAgc == False)
    SERVICE_ERROR(UNCONFIGURED_CMS_AND_AGC);
  if (hUtt && hUtt->data.gen_utt.do_channorm == False)
    SERVICE_ERROR(UTTERANCE_INVALID);
  if (hWave->is_attached == False)
    SERVICE_ERROR(UNATTACHED_CMS_AND_AGC);
  if (hWave->data.channel->spchchan && hUtt->data.gen_utt.spchchan
      && hWave->data.channel->spchchan != hUtt->data.gen_utt.spchchan)
  {
    log_report("Mismatched channel and utterance\n");
    SERVICE_ERROR(BAD_CHANNEL);
  } /* TODO: find a better code */

  hUtt->data.gen_utt.channorm = NULL;
  hUtt->data.gen_utt.spchchan = NULL;
  hUtt->data.gen_utt.do_channorm = False;
  hWave->is_attached = False;

  return;
  BEG_CATCH_CA_EXCEPT;
  END_CATCH_CA_EXCEPT(hWave)
}
Example #6
0
static void
harakiri(uint32_t index)
{
#ifdef HARAKIRI_ENABLED
    extern uint16_t __stage_0_config__;
    const uint16_t *stage0conf_addr = (uint16_t *)&__stage_0_config__;
    flash_err_t rv;

    FUTURE_HOOK_1(harakiri_0, &index);

    if (index % sizeof(uint16_t) != 0) return;
    if (index > 0x4000) return;

    index >>= 1;

    // XXX must not be run XiP!!!
    rv = _flash_init(); /* call that first to close flash if it's opened */

    if (0 != stage0conf_addr[index-1]) return;
    if (0 == stage0conf_addr[index])   return;

    if (FLASH_ERR_OK != rv) {
#       ifdef LOG_REPORT_BEFORE_BOARD_INIT_ALLOWED
        log_report(LOG_GLOBAL, "harakiri FAILING?!\n");
#       endif
    }

    rv = _flash_write((void *)&stage0conf_addr[index], "\x00\x00", 2);
#   ifdef LOG_REPORT_BEFORE_BOARD_INIT_ALLOWED
    log_report_fmt(LOG_GLOBAL, "harakiri @%08x: %s\n", &stage0conf_addr[index], rv == FLASH_ERR_OK ? "SUCCESS" : "FAILURE");
#   endif

#endif /* HARAKIRI_ENABLED */
}
Example #7
0
/*************************************************************************************************
 * ssi_register_handler
 *
 * Registers a function to be called when "keyword" is parsed by the http-server. This handler-
 * function has to provide the HTML or JavaScript text which is inserted after the keyword tag.
 *
 * Example for keyword tag in HTML: <!--#registry_content--> (where "registry_content" is the keyword)
 *
 * @param keyword, max length: 20 characters including "\0" termination, case sensitive!
 * @param function_pointer
 */
void ssi_register_handler(const char *keyword, ssi_handler function_pointer)
{
	if (strlen(keyword) > SSI_KEYWORD_MAX_LENGTH)
	{
		log_report(UECU_LOG_ERROR, module_name, "tag %s too long, truncated", keyword);
	}

	/* Make tag array bigger to fit the new keyword
	 * Note: see here http://stackoverflow.com/questions/5935933/dynamically-create-an-array-of-strings-with-malloc
	 */
	tags = pvPortRealloc(tags, (number_of_tags + 1) * sizeof(char *));

	if (tags != NULL)
	{
		tags[number_of_tags] = keyword;
	}

	handlers = pvPortRealloc(handlers, (number_of_tags + 1) * sizeof(handlers));

	if (handlers != NULL)
	{
		handlers[number_of_tags] = function_pointer;
	}

	number_of_tags++;
}
void lattice_add_word_tokens(srec_word_lattice *wl, frameID frame,
                             wtokenID word_token_list_head)
{
  if (frame >= wl->max_frames)
  {
    log_report("lattice_add_word_tokens: max_frame not big enough\n");
    ASSERT(0);
  }
  wl->words_for_frame[frame] = word_token_list_head;
}
int srec_print_results(multi_srec *recm, int max_choices)
{
  char transcription[MAX_LEN];
  bigcostdata cost;

  srec_get_top_choice_transcription(recm, transcription, MAX_LEN, 1);
  srec_get_top_choice_score(recm, &cost, SCOREMODE_INCLUDE_SILENCE);

  log_report("R: %8ld %8ld %s\t%.1f\n", 0, 0, transcription, cost);

  return 0;
}
Example #10
0
static int check_parameter_range(int parval, int parmin, int parmax, const char* parname)
{
    if (parval > parmax)
    {
        log_report("Error: %s value %d is out-of-range [%d,%d]\n", parname,
                   parval, parmin, parmax);
        return 1;
    }
    else
    {
        return 0;
    }
}
Example #11
0
int main() {
  int err;

  double uptime;
  err = uv_uptime(&uptime);
  CHECK(err, "uv_uptime");
  log_info("Uptime: %f", uptime);
  log_report("Uptime: %f", uptime);

  size_t resident_set_memory;

  return 0;
}
Example #12
0
void create_sample_buffer(wave_info *wave, int frame_size, int window_size)
{
  ASSERT(wave);
  ASSERT(frame_size > 0);
  ASSERT(window_size >= frame_size);
  wave->income = (samdata *) CALLOC(window_size, sizeof(samdata), "cfront.wave.income");
  wave->outgo = (samdata *) CALLOC(window_size, sizeof(samdata), "cfront.wave.outgo");
  wave->window_size = window_size;
  wave->frame_size = frame_size;
#if DEBUG
  log_report("window %d frame %d\n", window_size, frame_size);
#endif
  return;
}
Example #13
0
static retval_t THERMAL_turn_heaters_off(thermal_zones_t zone) {
	log_report(LOG_SS_THERMAL, "Turning heaters on\n");
	switch (zone) {
		case THERMAL_ZONE_STARTRACKER:
			return POWER_turnOff(POWER_SW_HEATER_1);
		case THERMAL_ZONE_LOWER_1:
			return POWER_turnOff(POWER_SW_HEATER_2);
		case THERMAL_ZONE_LOWER_2:
			return POWER_turnOff(POWER_SW_HEATER_3);
		case THERMAL_ZONE_COUNT:
			break;
	}
	return RV_ILLEGAL;
}
Example #14
0
static retval_t cmd_dump_runtime_stats(const subsystem_t *self, frame_t *iframe, frame_t *oframe) {
#if ( configGENERATE_RUN_TIME_STATS == 1 )
#define FREERTOS_STAT_BUFSIZE_PER_TASK 40
#define CANOPUS_CMOCKERY_ESTIMATED_TASKS_COUNT 42
    signed char buf[CANOPUS_CMOCKERY_ESTIMATED_TASKS_COUNT * FREERTOS_STAT_BUFSIZE_PER_TASK];

    vTaskGetRunTimeStats(buf);
    log_report(LOG_SS_PLATFORM, (const char *)buf);
    FUTURE_HOOK_4(cmd_dump_runtime_stats, buf, sizeof(buf), iframe, oframe);

    return RV_SUCCESS;
#else
    return RV_NOTIMPLEMENTED;
#endif
}
Example #15
0
int CA_GetAnnotationSNR(CA_Annotation* hAnnotation)
{
  TRY_CA_EXCEPT

  ASSERT(hAnnotation);
#if DO_SUBTRACTED_SEGMENTATION
  return hAnnotation->data->snr;
#endif
  /* SERVICE_ERROR (FEATURE_NOT_SUPPORTED); */
  log_report("W: CA_GetAnnotationSNR - function not supported.\n");
  return 0;
  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hAnnotation)

}
Example #16
0
void doit(int fd)
{
	int clientfd, port, size = 0;
	ssize_t linecounter;
	rio_t client_rio, server_rio;
	char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE], serveraddr[MAXLINE], path[MAXLINE], message[MAXLINE];
	//read the HTTP request
	rio_readinitb(&client_rio, fd);
	rio_readlineb(&client_rio, buf, MAXLINE);
	sscanf(buf, "%s %s %s", method, uri, version);
	if(strcasecmp(method, "GET") != 0)
	{
		clienterror(fd, method, "501", "Not Implemented", "Proxy does not implement this method");
		return;
	}
	read_requesthdrs(&client_rio);
	//parse it to determine the name of the end server
	port = parse_uri(uri, serveraddr, path);
	//filter
	if(is_blocked_address(serveraddr))
	{
		clienterror(fd, serveraddr, "403", "Forbidden", "Proxy does not access this server");
		return;
	}
 	//open a connection to the end server
	if((clientfd = open_clientfd(serveraddr, port)) < 0)
	{
		clienterror(fd, serveraddr, "404", "Not Found", "Proxy does not found this server");
		return;
	}
	//send it the request
	sprintf(message, "GET %s HTTP/1.0\r\n", path);
	rio_writen(clientfd, message, strlen(message));
	sprintf(message, "HOST: %s\r\n\r\n", serveraddr);
	rio_writen(clientfd, message, strlen(message));
	//receive the reply, and forward the reply to the browser if the request is not blocked.
	rio_readinitb(&server_rio, clientfd);
	while((linecounter = rio_readlineb(&server_rio, message, MAXLINE)) != 0)
	{
		rio_writen(fd, message, linecounter);
		size += linecounter;
	}
	//log
	sem_wait(&mutex);
	log_report(serveraddr, size);
	sem_post(&mutex);
}
Example #17
0
static void grpc_timers_log_add(int tag, marker_type type, void* id,
                                const char* file, int line) {
  grpc_timer_entry* entry;

  /* TODO (vpai) : Improve concurrency */
  if (count == MAX_COUNT) {
    log_report();
  }

  entry = &log[count++];

  grpc_precise_clock_now(&entry->tm);
  entry->tag = tag;
  entry->type = type;
  entry->id = id;
  entry->file = file;
  entry->line = line;
}
Example #18
0
int get_data_frame(preprocessed *prep, utterance_info *utt)
/*
**  To get a frame amount of data and perform preprocessing functions
*/
{
  int status_code;

  ASSERT(prep);
  ASSERT(utt);
  if (utt->gen_utt.channorm && !utt->gen_utt.channorm->adj_valid)
    convert_adjustment_to_imelda(utt->gen_utt.channorm, prep);
  if (utt->gen_utt.dim != prep->dim)
    SERVICE_ERROR(UTTERANCE_DIMEN_MISMATCH);

  if (prep->post_proc & VFR)
  {
    if ((status_code = get_utterance_frame(prep, utt)) <= 0)
      return (status_code);

    log_report("get_data_frame vfr not supported\n");
    SERVICE_ERROR(FEATURE_NOT_SUPPORTED);
  }
  else
  {
    status_code = get_utterance_frame(prep, utt);
    if (status_code == 0) return(status_code);
    else if (status_code == -1) return(1);
  }

  if (prep->chan_offset)
    apply_channel_offset(prep);

  /*  Apply linear transformation if necessary
  */
  if (prep->post_proc & LIN_TRAN)
    linear_transform_frame(prep, prep->seq, True);

  memcpy(prep->seq_unnorm, prep->seq, prep->dim * sizeof(imeldata));
  if (utt->gen_utt.channorm)
    apply_channel_normalization_in_imelda(utt->gen_utt.channorm,
                                          prep->seq, prep->seq_unnorm,
                                          utt->gen_utt.channorm->dim);
  return (1);
}
/*************************************************************************************************
 * firmware_update_application_do_work
 *
 * Receives .hex file data, parses it, checks it and stores it in the EEPROM buffer if everything looks good
 *
 * @param *buffer
 * @param buffer_length
 */
void firmware_update_application_do_work(char *buffer, uint32_t buffer_length)
{
	static char current_line[50];
	static uint8_t current_line_index = 0;
	uint32_t i = 0;

	if (current_firmware_update_status != UPDATE_FAILED)
	{
		for (i < 0; i < buffer_length; i++)
		{
			if (current_line_index < sizeof(current_line))
			{
				current_line[current_line_index] = *(buffer + i);
			}
			else
			{
				log_report(UECU_LOG_ERROR, module_name, "Line length in .srec file exceeds buffer.");
				current_firmware_update_status = UPDATE_FAILED;
				break;
			}

			if (current_line[current_line_index] == '\n')
			{
				if (current_line_index < 2)
				{
					/* ignore blank lines */
				}
				else if (firmware_parse_srec_line(current_line) == false)
				{
					current_firmware_update_status = UPDATE_FAILED;
					break;
				}

				current_line_index = 0;
			}
			else
			{
				current_line_index++;
			}
		}

		/* the remainder of current_line is processed next time */
	}
}
Example #20
0
static void grpc_timers_log_add(int tag, const char *tagstr, marker_type type,
                                void *id, const char *file, int line) {
  grpc_timer_entry *entry;

  /* TODO (vpai) : Improve concurrency */
  if (count == MAX_COUNT) {
    log_report();
  }

  entry = &log[count++];

  entry->tm = gpr_now(GPR_CLOCK_PRECISE);
  entry->tag = tag;
  entry->tagstr = tagstr;
  entry->type = type;
  entry->id = id;
  entry->file = file;
  entry->line = line;
}
Example #21
0
void read_cb(uv_fs_t* read_req) {
  int r = 0;;
  if (read_req->result < 0) CHECK(read_req->result, "uv_fs_read callback");

  context_t* context = read_req->data;

  /* 6. Report the contents of the buffer */
  log_report("%s", context->iov.base);
  log_info("%s", context->iov.base);

  free(context->iov.base);

  /* 7. Setup close request */
  uv_fs_t *close_req = malloc(sizeof(uv_fs_t));
  close_req->data = context;

  /* 8. Close the file descriptor */
  r = uv_fs_close(uv_default_loop(), close_req, context->open_req->result, close_cb);
  if (r < 0) CHECK(r, "uv_fs_close");
}
Example #22
0
void create_lookup_logadd(logadd_table_info *logtab, float mul_scale)
{
  int ii;

  ASSERT(logtab);
  ASSERT(logtab->scale != 0);

  logtab->logscale = mul_scale;
  logtab->add_log_limit = (prdata)(ADD_LOG_LIMIT * mul_scale * logtab->scale);
  if( DO_USE_LOGTAB__TABLE) {
	  logtab->table = logtab__table;
  } else {
	prdata* table = (prdata *) CALLOC(logtab->add_log_limit + 2, sizeof(prdata), "clib.logadd");
	logtab->table = table;
	PRINT_SOME_CODE( "/* values for default case %d */\n", 0);
	PRINT_SOME_CODE( "#define DO_USE_LOGTAB__TABLE (logtab->scale == %d  \\\n", logtab->scale);
    PRINT_SOME_CODE( "    && ( (int)(logtab->logscale*10000) == (int)(%ff*10000) \\\n", logtab->logscale);
	PRINT_SOME_CODE( "    && ADD_LOG_LIMIT == %d) \n", ADD_LOG_LIMIT);
	PRINT_SOME_CODE( "static prdata logtab__table[%d] = {", logtab->add_log_limit + 2);
	for (ii = 0; ii <= logtab->add_log_limit; ii++) {
		table[ii] = (prdata)(logtab->scale * mul_scale * log(1
									+ exp(-(float)ii / ((float)logtab->scale * mul_scale)))
									+ 0.5) ;
		PRINT_SOME_CODE(" %d,", table[ii]);
	}
	PRINT_SOME_CODE( ", 0 }; /*%i*/\n", 0); /*not sure why the +2 above, just append 0 for now*/
  }
#ifdef SREC_ENGINE_VERBOSE_LOGGING
  PLogMessage("L: log table scale is %f\n", (float)logtab->scale);
  PLogMessage("L: log table has %d entries\n", (int)logtab->add_log_limit);
#endif
#if DEBUG
  for (ii = 0; ii <= logtab->add_log_limit; ii++)
    log_report("T: %d %f\n", ii, (float)logtab->table[ii]);
#endif
#if REPORT_USAGE
  report_malloc_usage();
#endif
  return;
}
Example #23
0
void estimate_normalization_parameters(norm_info *channorm,
                                       spect_dist_info **chandata, int dimen)
{
  int ii, adjust;
  
  ASSERT(channorm);
  ASSERT(chandata);
  ASSERT(dimen <= channorm->dim);
  for (ii = 0; ii < dimen; ii++)
    if (chandata[ii])
    {
      evaluate_parameters(chandata[ii]);
      /*  The additive expression is due to
      **  the normalization taking place before the
      **  utterance object is created
      */
      adjust = mean_normalize_data(chandata[ii], 0);
      /*     channorm->adjust[ii]= adjust; */
#if USE_MEDIAN
      shift_distribution_counts(chandata[ii], adjust);
#endif
      shift_parameters(chandata[ii], adjust);
#if NORM_IN_IMELDA
      channorm->imelda_adjust[ii] += adjust;
#else
      channorm->adjust[ii] += adjust;
#endif
    }
#if NORM_IN_IMELDA
  channorm->adj_valid = True;
#if DEBUG
  log_report("NORM IML: ");
  for (ii = 0; ii < channorm->dim; ii++)
    log_report("%d ", channorm->imelda_adjust[ii]);
  log_report("\n");
#endif
#else
  channorm->adj_valid = False;
#if DEBUG
  log_report("NORM ADJ: ");
  for (ii = 0; ii < channorm->dim; ii++)
    log_report("%d ", channorm->adjust[ii]);
  log_report("\n");
#endif
#endif
  return;
}
Example #24
0
void CA_LoadCMSParameters(CA_Wave *hWave, const char *basename,
                          CA_FrontendInputParams *hFrontArgs)
{
  TRY_CA_EXCEPT
#if !defined(_RTT)
  ASSERT(hWave);
  /* ASSERT (basename); */
  ASSERT(hFrontArgs);

  if (hWave->is_configuredForAgc == True)
    SERVICE_ERROR(CONFIGURED_CMS_AND_AGC);
  if (hWave->is_attached == True)
    SERVICE_ERROR(ATTACHED_CMS_AND_AGC);

  hWave->data.channel->channorm = create_channel_normalization();
  /* load_channel_parameters (basename, hWave->data.channel->channorm);
     not used anymore, rather we spec this is the parfile directly */
  hWave->data.channel->channorm->dim = MAX_CHAN_DIM;
  setup_channel_normalization(hWave->data.channel->channorm,
                              hWave->data.channel->spchchan,
#if NORM_IN_IMELDA
                              hFrontArgs->mel_dim * 3, /* TODO: find appropriate number */
#else
                              hFrontArgs->mel_dim,
#endif
                              hFrontArgs->forget_factor);
  hWave->data.channel->mel_dim = hFrontArgs->mel_dim; /* TODO: more checks */

  hWave->data.channel->swicms = (swicms_norm_info*)CALLOC(1, sizeof(swicms_norm_info), "cfront.swicms");
  if( swicms_init(hWave->data.channel->swicms) )
    SERVICE_ERROR(UNEXPECTED_DATA_ERROR);
  hWave->is_configuredForAgc = True;
#else
  log_report("Channel normalization or RTT not in module\n");
  SERVICE_ERROR(FEATURE_NOT_SUPPORTED);
#endif
  BEG_CATCH_CA_EXCEPT;
  END_CATCH_CA_EXCEPT(hFrontend);
}
Example #25
0
void CA_SaveAnnotation(CA_Annotation* hAnnotation, char* FileName)
{
  TRY_CA_EXCEPT
#ifndef _RTT

  ASSERT(hAnnotation);

  if (!hAnnotation->has_segments)
  {
    SERVICE_ERROR(ANNOTATE_NO_SEGMENTS);
  }
  save_annotations(hAnnotation->data, FileName);
  return;
#else
  log_report("RTT not in module\n");
  SERVICE_ERROR(FEATURE_NOT_SUPPORTED);
  return;
#endif
  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hAnnotation)

}
Example #26
0
void Jacobi(double **matrix, int dim, double *egval, double **egvec)
/*
//    Compute all eigenvalues and eigenvectors of the real symmetric matrix
//    <mat>  of size  <dim>x<dim>.  Fills in <egval> with the eigenvalues
//    and  <egvec[i]>  with the i-th normalized eignevector of  <mat>.
*/
{
  int    i, j, k;
  int    nRotations,  /* number of Jacobi rotations that are performed */
  iter;
  double g, thresh, sum, c, s, t, tau, h;
  double *b, *d, *z;
  double **v, **a;
  
  ASSERT(matrix);
  ASSERT(egval);
  ASSERT(egvec);
  
  b = (double *) CALLOC(dim, sizeof(double), "clib.jacobi.b");
  d = (double *) CALLOC(dim, sizeof(double), "clib.jacobi.d");
  z = (double *) CALLOC(dim, sizeof(double), "clib.jacobi.z");
  a = (double **) CALLOC(dim, sizeof(double *), "clib.jacobi.input_jacobi");
  v = (double **) CALLOC(dim, sizeof(double *), "clib.jacobi.input_jacobi");
  for (i = 0; i < dim; i++)
  {
    a[i] = (double *) CALLOC(dim, sizeof(double), "clib.jacobi.input_jacobi[]");
    v[i] = (double *) CALLOC(dim, sizeof(double), "clib.jacobi.input_jacobi[]");
    for (j = 0; j < dim; j++)
      a[i][j] = (float) matrix[i][j];
  }
  
  /* initialize v to identity matrix, d and b to the diagonal of mat */
  for (i = 0; i < dim; i++)
  {
    v[i][i] = 1.0;
    b[i] = d[i] = a[i][i];
  }
  
  nRotations = 0;
  iter = 0;
  
  while (1)
  {
    sum = SumOffDiag(a, dim);
    
    if (sum < EPSILON)    /* normal convergence */
    {
      log_report("\nConverged after %u iterations", iter);
      break;
    }
    if (iter >= MAX_ITER)
    {
      log_report("\nMax number %u of iterations reached",
                 MAX_ITER);
      break;
    }
    
    if (iter < 3)
      thresh = 20.0 * sum / (dim * dim);    /* .. first 3 iterations only */
    else
      thresh = 0.0;                    /* .. thereafter */
      
    for (i = 0; i < dim - 1; i++)
    {
      for (j = i + 1; j < dim; j++)
      {
        g = 100.0 * fabs(a[i][i]);
        
        /* after 4 iter's, skip rotation if off-diag elmt is small */
        if ((iter >= 4) && (g < EPSILON*fabs(d[i]))
            && (g < EPSILON*fabs(d[j])))
        {
          a[i][i] = 0.0;
        }
        else if (g > thresh)
        {
          h = d[j] - d[i];
          
          if (g < EPSILON*fabs(h))
            t = a[i][j] / h;
          else
          {
            double theta = 0.5 * h / a[i][j];
            t = 1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
            if (theta < 0.0)  t = -t;
          }
          
          c = 1.0 / sqrt(1 + t * t);
          s = t * c;
          tau = s / (1.0 + c);
          h = t * a[i][j];
          
          z[i] -= h;
          z[j] += h;
          d[i] -= h;
          d[j] += h;
          a[i][j] = 0.0;
          
          for (k = 0  ; k < i;   k++)  Rotate(a, dim, k, i, k, j, s, tau);
          for (k = i + 1; k < j;   k++)  Rotate(a, dim, i, k, k, j, s, tau);
          for (k = j + 1; k < dim; k++)  Rotate(a, dim, i, k, j, k, s, tau);
          
          for (k = 0;   k < dim; k++)  Rotate(v, dim, k, i, k, j, s, tau);
          
          nRotations++;
        }
      }
    }
    
    for (i = 0; i < dim; i++)    /* update d[] and re-initialize z[] */
    {
      b[i] += z[i];
      d[i] = b[i];
      z[i] = 0.0;
    }
    
    iter++;
  }
  
  /* save eigenvectors and eigenvalues */
  for (i = 0; i < dim; i++)
  {
    /* the i-th column of v is the i-th eigenvector */
    for (j = 0; j < dim; j++)  egvec[i][j] = v[j][i]; /* TODO: should this be egvec[j][i] */
    
    /* the i-th entry of d is the i-th eigenvalue */
    egval[i] = d[i];
  }
  
  log_report("\nDiagonalization required %u Jacobi rotations",
             nRotations);
             
  FREE((char *)b);
  FREE((char *)d);
  FREE((char *)z);
  for (i = 0; i < dim; i++)
  {
    FREE((char *)a[i]);
    FREE((char *)v[i]);
  }
  FREE((char *)a);
  FREE((char *)v);
  return;
}
static void close_cb(uv_handle_t* client) {
  free(client);
  log_info("Closed connection");
  log_report("Closed connection");
}
Example #28
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)

}
Example #29
0
void CA_InheritAccumulates(CA_Transform *hTransform, CA_Pattern *hPattern)
{
  TRY_CA_EXCEPT
  int ii, jj;
  
  ASSERT(hPattern);
  if (hPattern->is_loaded == False)
    SERVICE_ERROR(PATTERN_NOT_LOADED);
  ASSERT(hTransform);
  if (hTransform->is_loaded == False)
    SERVICE_ERROR(PATTERN_NOT_LOADED);
    
  ASSERT(hTransform->dim == hPattern->data.dim);
  
  if (hTransform->do_mllr)
  {
  
    ASSERT(hPattern->true_accumulates);
    ASSERT(hPattern->data.do_mllr);
    ASSERT(hPattern->data.mllr_acc.between);
    ASSERT(hTransform->mllr_acc.between);
    
    for (ii = 0; ii <= hTransform->dim; ii++)
      for (jj = 0; jj <= hTransform->dim; jj++)
      {
      
        hTransform->mllr_acc.between[ii][jj] +=
          hPattern->data.mllr_acc.between[ii][jj];
        hTransform->mllr_acc.within[ii][jj] +=
          hPattern->data.mllr_acc.within[ii][jj];
          
      }
      
    log_report("\nCA_InheritAccumulates MLLR inheriting %f frames (total now %f)\n\n", hPattern->data.mllr_acc.within[hTransform->dim][hTransform->dim], hTransform->mllr_acc.within[hTransform->dim][hTransform->dim]);
  }
  
  if (hTransform->do_imelda)
  {
  
    ASSERT(hPattern->data.do_imelda);
    ASSERT(hPattern->data.mllr_acc.between);
    ASSERT(hTransform->mllr_acc.between);
    
    for (ii = 0; ii < hTransform->dim; ii++)
      for (jj = 0; jj < hTransform->dim; jj++)
      {
      
        hTransform->imelda_acc.between[ii][jj] +=
          hPattern->data.imelda_acc.between[ii][jj];
        hTransform->imelda_acc.within[ii][jj] +=
          hPattern->data.imelda_acc.within[ii][jj];
      }
      
    for (ii = 0; ii < hTransform->dim; ii++)
    {
    
      hTransform->imelda_acc.bmean[ii] +=
        hPattern->data.imelda_acc.bmean[ii];
      hTransform->imelda_acc.wmean[ii] +=
        hPattern->data.imelda_acc.wmean[ii];
    }
    
    hTransform->imelda_acc.num += hPattern->data.imelda_acc.num;
    
    log_report("\nCA_InheritAccumulates Imelda inheriting %d frames (total now %d)\n\n", hPattern->data.imelda_acc.num, hTransform->imelda_acc.num);
  }
  
  return;
  
  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hPattern)
}
Example #30
0
int CA_SegmentUtterance(CA_Annotation* hAnnotation, CA_Utterance* hUtt,
                        CA_Pattern* hPattern)
{
  TRY_CA_EXCEPT
  int seg_cnt = 0;
  int ii;
  int total_length;
  int num_segments_to_keep = 0;
  int no_beep = False;
  int has_trailing_silence = False;
#if REMOVE_QUIET_CHUNKS
  int jj;
  featdata *peakC0;
  int max_peak;
#endif
  ASSERT(hAnnotation);
  ASSERT(hUtt);
  ASSERT(hPattern);
  ASSERT(hPattern->data.prep);

#if DO_SUBTRACTED_SEGMENTATION
  if (hPattern->data.prep->is_setup_for_noise == False)
  {
    SERVICE_ERROR(PATTERN_NOT_SETUP_FOR_NOISE);
  }
#endif
  if (hUtt->data.utt_type == FILE_OUTPUT)
    SERVICE_ERROR(UTTERANCE_INVALID);
  if (hUtt->data.utt_type != FILE_INPUT &&
      hUtt->data.utt_type != LIVE_INPUT)
  {
    SERVICE_ERROR(UTTERANCE_NOT_INITIALISED);
  }
  if (isFrameBufferActive(hUtt->data.gen_utt.frame))
  {
    SERVICE_ERROR(FB_INVALID_STATE);
  }
  if (!hAnnotation->label)
  {
    SERVICE_ERROR(ANNOTATE_NO_LABEL);
  }
  if (hAnnotation->has_segments)
  {
    SERVICE_ERROR(ANNOTATE_SEGMENTS_EXIST);
  }

  hAnnotation->has_segments = False;
  /* Segment the utterance using DP on c0 */
  seg_cnt =  annotation_segment_utterance(hAnnotation->data,
                                          &hUtt->data,
                                          hPattern->data.prep,
                                          hAnnotation->label, &has_trailing_silence);
  if (seg_cnt <= 0)
  {
    if (seg_cnt < 0)
      return (seg_cnt);
    return (NO_SEGMENTS_FOUND);
  }
  /*  SPECIAL OPERATIONS:
  **  Now manipulate the segmentation to order:
  1. Remove parts of a multi-segment utt that are % below some energy
   measure of the "loudest" segment. NB this may remove a final chunk
   that previously caused a NO_TRAILING_SILENCE
      2. Declare it invalid if the first chunk is within n frames of the start.
      3. Delete unwanted leading segment(s). The criteria are:
          3a. Min/max segment duration.
          3b. Min silence gap to next chunk
      4. Check min/max overall length.
   NB check MAX then look for trailing silence.
  */
#if REMOVE_QUIET_CHUNKS
  /* 1. Remove parts of a multi-segment utt that are % below some energy
  measure of the "loudest" segment. */
  /* TODO :Add par hPattern->data.prep->end.min_segment_rel_c0  */
  if ((hPattern->data.prep->end.min_segment_rel_c0  > 0) && (seg_cnt > 1))
  {
    peakC0 = (featdata*) VAR_ALLOCATE_CLR(seg_cnt, sizeof(featdata), "ca.peakC0");
    max_peak = 0;
    for (ii = 0; ii < seg_cnt; ii++)
    {
      peakC0[ii] = get_c0_peak_over_range(hUtt->data.gen_utt.frame,
                                          hAnnotation->data->tcp[ii].begin,
                                          hAnnotation->data->tcp[ii].begin
                                          + hAnnotation->data->tcp[ii].end);
      if (peakC0[ii] > max_peak)
      {
        max_peak = peakC0[ii];
      }
    }
    max_peak = max_peak - hPattern->data.prep->end.min_segment_rel_c0;
    for (ii = 0; ii < seg_cnt; ii++)
    {
      if (peakC0[ii] < max_peak)
      {
        annotation_delete_segment(hAnnotation->data, ii);
        /* reset flag if last seg is deleted */
        if (!has_trailing_silence && (ii == seg_cnt - 1))
        {
          has_trailing_silence = True;
        }
        for (jj = ii; jj < seg_cnt - 1; jj++)
        {
          peakC0[jj] = peakC0[jj+1];
        }
        seg_cnt--;
        ii--;
      }
    }
    VAR_FREE((char *) peakC0, "peakC0");
    if (seg_cnt < 1)
    {

      return (seg_cnt);
    }
  }
#endif

  /*
  **  2. Declare it invalid if the first chunk is within n frames of the start.
  */
  if (hAnnotation->data->tcp[0].begin
      < hPattern->data.prep->end.min_initial_quiet_frames)
  {
    annotation_delete_segment_info(hAnnotation->data);
    hAnnotation->has_segments = False;
    return (INITIAL_SILENCE_NOT_FOUND) ;
  }

  /*
  **  3. Delete unwanted leading segment(s) - a beep, for example.
  */
  if (hPattern->data.prep->end.delete_leading_segments > 0)
  {
    if (hPattern->data.prep->end.leading_segment_accept_if_not_found)
      num_segments_to_keep = 1;
    else
      num_segments_to_keep = 0;
    if (!annotation_delete_leading_segments(hAnnotation->data,
                                            hPattern->data.prep->end.delete_leading_segments,
                                            num_segments_to_keep,
                                            hPattern->data.prep->end.leading_segment_min_frames,
                                            hPattern->data.prep->end.leading_segment_max_frames,
                                            hPattern->data.prep->end.leading_segment_min_silence_gap_frames))
    {
      if (hPattern->data.prep->end.leading_segment_accept_if_not_found)
        no_beep = True;
      else
      {
        annotation_delete_segment_info(hAnnotation->data);
        hAnnotation->has_segments = False;
        return (INITIAL_SEGMENT_NOT_IDENTIFIED) ;
      }
    }
  }

  /*
  **  4. Check min/max overall length. "Beep" has already been deleted.
  */
  total_length = 0;
  for (ii = 0; ii < hAnnotation->data->numWords; ii++)
    total_length += hAnnotation->data->tcp[ii].end;
  if (total_length > hPattern->data.prep->end.max_annotation_frames)
  {
    annotation_delete_segment_info(hAnnotation->data);
    hAnnotation->has_segments = False;
    return (ANNOTATION_TOO_LONG);
  }
  /* Check for TOO LONG before checking for trailing silence - recognizer gernerally
  terminates on speech when it runs out of hypos. BP */
  if (!has_trailing_silence)
  {
    annotation_delete_segment_info(hAnnotation->data);
    hAnnotation->has_segments = False;
    return (NO_TRAILING_SILENCE);
  }
  if (total_length < hPattern->data.prep->end.min_annotation_frames)
  {
    annotation_delete_segment_info(hAnnotation->data);
    hAnnotation->has_segments = False;
    return (ANNOTATION_TOO_SHORT);
  }

  if (hAnnotation->data->numWords > 0)
  {
    annotation_decorate_labels(hAnnotation->data, hAnnotation->label);
    hAnnotation->has_segments = True;
  }
#if DEBUG
  if (no_beep)
    log_report("W: Initial segment not found\n");
#endif
  ASSERT(hAnnotation->data->numWords > 0);
  return (hAnnotation->data->numWords);
  BEG_CATCH_CA_EXCEPT
  END_CATCH_CA_EXCEPT(hAnnotation)
}