Exemplo n.º 1
0
/** 
 * Read and parse an HTK Config file, and set the specified option values.
 * 
 * @param HTKconffile [in] HTK Config file path name
 * @param para [out] MFCC parameter to set
 *
 * @return TRUE on success, FALSE on failure.
 */
boolean
htk_config_file_parse(char *HTKconffile, Value *para)
{
  FILE *fp;
  char buf[512];
  char *p, *d, *a;
  float srate;
  boolean skipped;

  jlog("Stat: para: parsing HTK Config file: %s\n", HTKconffile);
  
  /* convert the content into argument list c_argv[1..c_argc-1] */
  /* c_argv[0] will be the original conffile name */
  if ((fp = fopen(HTKconffile, "r")) == NULL) {
    jlog("Error: para: failed to open HTK Config file: %s\n", HTKconffile);
    return FALSE;
  }

  srate = 0.0;

  while (getl_fp(buf, 512, fp) != NULL) {
    p = buf;
    if (*p == 35) { /* skip comment line */
      continue;
    }

    /* parse the input line to get directive and argument */
    while (*p != '\0' && ISTOKEN(*p)) p++;
    if (*p == '\0') continue;
    d = p;
    while (*p != '\0' && (!ISTOKEN(*p)) && *p != '=') p++;
    if (*p == '\0') continue;
    *p = '\0'; p++;
    while (*p != '\0' && ((ISTOKEN(*p)) || *p == '=')) p++;
    if (*p == '\0') continue;
    a = p;
    while (*p != '\0' && (!ISTOKEN(*p))) p++;
    *p = '\0';

    /* process arguments */
    skipped = FALSE;
    if (strmatch(d, "SOURCERATE")) { /* -smpPeriod */
      srate = atof(a);
    } else if (strmatch(d, "TARGETRATE")) { /* -fshift */
      para->frameshift = atof(a);
    } else if (strmatch(d, "WINDOWSIZE")) { /* -fsize */
      para->framesize = atof(a);
    } else if (strmatch(d, "ZMEANSOURCE")) { /* -zmeansource */
      para->zmeanframe = (a[0] == 'T') ? TRUE : FALSE;
    } else if (strmatch(d, "USEPOWER")) { /* -usepower */
      para->usepower = (a[0] == 'T') ? TRUE : FALSE;
    } else if (strmatch(d, "PREEMCOEF")) { /* -preemph */
      para->preEmph = atof(a);
    } else if (strmatch(d, "USEHAMMING")) { /* (fixed to T) */
      if (a[0] != 'T') {
	jlog("Error: para: USEHAMMING should be T\n", HTKconffile);
	return FALSE;
      }
    } else if (strmatch(d, "NUMCHANS")) { /* -fbank */
      para->fbank_num = atoi(a);
    } else if (strmatch(d, "CEPLIFTER")) { /* -ceplif */
      para->lifter = atoi(a);
    } else if (strmatch(d, "DELTAWINDOW")) { /* -delwin */
      para->delWin = atoi(a);
    } else if (strmatch(d, "ACCWINDOW")) { /* -accwin */
      para->accWin = atoi(a);
    } else if (strmatch(d, "LOFREQ")) { /* -lofreq */
      para->lopass = atof(a);
    } else if (strmatch(d, "HIFREQ")) { /* -hifreq */
      para->hipass = atof(a);
    } else if (strmatch(d, "RAWENERGY")) { /* -rawe */
      para->raw_e = (a[0] == 'T') ? TRUE : FALSE;
    } else if (strmatch(d, "ENORMALISE")) { /* -enormal */
      para->enormal = (a[0] == 'T') ? TRUE : FALSE;
    } else if (strmatch(d, "ESCALE")) { /* -escale */
      para->escale = atof(a);
    } else if (strmatch(d, "SILFLOOR")) { /* -silfloor */
      para->silFloor = atof(a);
    } else if (strmatch(d, "WARPFREQ")) { /* -vtln (1) */
      para->vtln_alpha = atof(a);
    } else if (strmatch(d, "WARPLCUTOFF")) { /* -vtln (2) */
      para->vtln_lower = atof(a);
    } else if (strmatch(d, "WARPUCUTOFF")) { /* -vtln (3) */
      para->vtln_upper = atof(a);
    } else if (strmatch(d, "TARGETKIND")) {
      jlog("Warning: para: TARGETKIND skipped (will be determined by AM header)\n");
      skipped = TRUE;
    } else if (strmatch(d, "NUMCEPS")) {
      jlog("Warning: para: NUMCEPS skipped (will be determined by AM header)\n");
      skipped = TRUE;
    } else {
      jlog("Warning: para: \"%s\" ignored (not supported, or irrelevant)\n", d);
      skipped = TRUE;
    }
    if (!skipped) {
      jlog("Stat: para: %s=%s\n", d, a);
    }
  }

  if (srate == 0.0) {
    jlog("Warning: no SOURCERATE found\n");
    jlog("Warning: assume source waveform sample rate to 625 (16kHz)\n");
    srate = 625;
  }

  para->smp_period = srate;
  para->smp_freq = period2freq(para->smp_period);
  para->frameshift /= srate;
  para->framesize /= srate;

  if (fclose(fp) == -1) {
    jlog("Error: para: failed to close file\n");
    return FALSE;
  }

  para->loaded = 1;

  return TRUE;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------*/

static bool settings_needs_saving(void)
{
    return(rb->memcmp(&settings, &hdd_settings, sizeof(settings)));
}

/*---------------------------------------------------------------------*/

static void tuner_settings_reset(void)
{
    settings = (struct tuner_settings) {
        .volume_threshold = VOLUME_THRESHOLD,
        .record_gain = rb->global_settings->rec_mic_gain,
        .sample_size = BUFFER_SIZE,
        .lowest_freq = period2freq(BUFFER_SIZE / 4),
        .yin_threshold = DEFAULT_YIN_THRESHOLD,
        .freq_A = DEFAULT_FREQ_A,
        .use_sharps = true,
        .display_hz = false,
        .key_transposition = DEFAULT_KEY_TRANSPOSITION,
    };
}

/*---------------------------------------------------------------------*/

static void load_settings(void)
{
    int fd = rb->open(SETTINGS_FILENAME, O_RDONLY);
    if(fd < 0){ /* file doesn't exist */
        /* Initializes the settings with default values at least */