Exemple #1
0
/**
 * Initializes the similarity measure
 */
void kern_distance_config()
{
    const char *str;

    /* Distance measure */
    config_lookup_string(&cfg, "measures.kern_distance.dist", &str);
    dist = measure_match(str);
    func[dist].measure_config();

    /* Substitution type */
    config_lookup_string(&cfg, "measures.kern_distance.type", &str);
    if (!strcasecmp(str, "linear")) {
        subst = DS_LINEAR;
    } else if (!strcasecmp(str, "poly")) {
        subst = DS_POLY;
    } else if (!strcasecmp(str, "neg")) {
        subst = DS_NEG;
    } else if (!strcasecmp(str, "rbf")) {
        subst = DS_RBF;
    } else {
        warning("Unknown substitution type '%s'. Using 'linear'.", str);
        subst = DS_LINEAR;
    }

    /* Parameters */
    config_lookup_float(&cfg, "measures.kern_distance.fgamma", &fgamma);
    config_lookup_float(&cfg, "measures.kern_distance.degree", &degree);

    /* Normalization */
    config_lookup_string(&cfg, "measures.kern_distance.norm", &str);
    norm = knorm_get(str);

}
static void init(void)
{
  int i;
  double bpm;
  double decay;
  int samp_rate;
  int min_burst;
  int burst_increase;
  int min_gain;
  int gain_increase;
  int detune;

  config_init(&cfg);
  if(!config_read_file(&cfg, CONFIG_FILE))
  {
    fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
            config_error_line(&cfg), config_error_text(&cfg));
    config_destroy(&cfg);
    exit(EXIT_FAILURE);
  }

  if(!config_lookup_float(&cfg, "bpm", &bpm))
    config_die("bpm");
  if(!config_lookup_float(&cfg, "subdiv", &subdiv))
    config_die("subdiv");
  if(!config_lookup_int(&cfg, "samp_rate", &samp_rate))
    config_die("samp_rate");
  if(!config_lookup_int(&cfg, "min_burst", &min_burst))
    config_die("min_burst");
  if(!config_lookup_int(&cfg, "burst_increase", &burst_increase))
    config_die("burst_increase");
  if(!config_lookup_float(&cfg, "decay", &decay))
    config_die("decay");
  if(!config_lookup_int(&cfg, "min_gain", &min_gain))
    config_die("min_gain");
  if(!config_lookup_int(&cfg, "gain_increase", &gain_increase))
    config_die("gain_increase");
  if(!config_lookup_int(&cfg, "detune", &detune))
    config_die("detune");

  note_length = (float)samp_rate * 60 * subdiv / bpm;
  system_init();
  agent_count = system_get_agent_count();

  synths = calloc(agent_count, sizeof(Synth *));
  for(i = 0; i < agent_count; i ++) {
    float pan = ((float)i / 20) * ((i % 2) * 2 - 1) + .5;
    synths[i] = synth_create(samp_rate, min_burst + i * burst_increase,
                             decay, pan, min_gain + gain_increase * i, detune);
  }
}
Exemple #3
0
/**
 * Initializes the similarity measure
 */
void dist_osa_config()
{
    const char *str;

    /* Costs */
    config_lookup_float(&cfg, "measures.dist_osa.cost_ins", &cost_ins);
    config_lookup_float(&cfg, "measures.dist_osa.cost_del", &cost_del);
    config_lookup_float(&cfg, "measures.dist_osa.cost_sub", &cost_sub);
    config_lookup_float(&cfg, "measures.dist_osa.cost_tra", &cost_tra);

    /* Normalization */
    config_lookup_string(&cfg, "measures.dist_osa.norm", &str);
    n = lnorm_get(str);
}
Exemple #4
0
/**
 * Cluster feature vectors using linkage clustering. The function uses
 * the feature vectors for computing a linkage clustering
 * @param fa Array of prototypes
 * @param r Run of clustering
 * @return clustering structure
 */
cluster_t *cluster_linkage(farray_t *fa, int r)
{
    assert(fa);
    double dmin;
    const char *mode;

    /* Get cluster configuration */
    config_lookup_float(&cfg, "cluster.min_dist", (double *) &dmin);
    config_lookup_string(&cfg, "cluster.link_mode", &mode);

    /* Allocate cluster structure */
    cluster_t *c = cluster_create(fa->len, r);

    /* Allocate distances */
    double *dist = malloc(sizeof(double) * tria_size(fa->len));
    if (!dist) {
        error("Could not allocate distance matrix.");
        return NULL;
    }

    /* Compute distances */
    farray_dist_tria(fa, dist);

    if (verbose > 0)
        printf("Clustering (%s linkage) with minimum distance %4.2f.\n",
               mode, dmin);

    /* Run clustering */
    cluster_murtagh(c, dist, dmin, mode[0]);

    free(dist);
    return c;
}
Exemple #5
0
/**
 * Initialize malheur tool
 * @param argc Number of arguments
 * @param argv Argument values
 */
static void malheur_init(int argc, char **argv)
{
    int lookup;
    double shared;

    /* Load configuration */
    load_config(argc, argv);

    /* Parse options */
    parse_options(argc, argv);

    /* Prepare malheur files */
    snprintf(mcfg.reject_file, MAX_PATH_LEN, "%s/%s", malheur_dir, REJECT_FILE);
    snprintf(mcfg.config_file, MAX_PATH_LEN,"%s/%s", malheur_dir, CONFIG_FILE);
    snprintf(mcfg.proto_file, MAX_PATH_LEN, "%s/%s", malheur_dir, PROTO_FILE);
    snprintf(mcfg.state_file, MAX_PATH_LEN, "%s/%s", malheur_dir, STATE_FILE);

    /* Init feature lookup table */
    config_lookup_int(&cfg, "features.lookup_table", &lookup);
    config_lookup_float(&cfg, "cluster.shared_ngrams", &shared);
    if (lookup || shared > 0.0) {
        ftable_init();
    }
    
    /* Reset current state */
    if (reset) {
        unlink(mcfg.reject_file);
        unlink(mcfg.proto_file);
        unlink(mcfg.state_file);
    }

    memset(&mstate, 0, sizeof(mstate));
}
Exemple #6
0
struct scenario_parameters read_scenario_parameters(char *scenario_file) {
  // configuration variable
  config_t cfg;
  config_init(&cfg);

  // string pointing to scenario file
  char scenario[100];
  strcpy(scenario, "scenarios/");
  strcat(scenario, scenario_file);

  // Read the file. If there is an error, report it and exit.
  if (!config_read_file(&cfg, scenario)) {
    printf("Error reading %s on line %i\n", scenario, config_error_line(&cfg));
    printf("%s\n", config_error_text(&cfg));
    config_destroy(&cfg);
    exit(1);
  }

  // Read scenario parameters
  struct scenario_parameters sp;
  int tmpI;
  double tmpD;

  config_lookup_int(&cfg, "num_nodes", &tmpI);
  sp.num_nodes = tmpI;
  config_lookup_float(&cfg, "run_time", &tmpD);
  sp.runTime = (time_t)tmpD;
  config_destroy(&cfg);

  return sp;
} // End readScConfigFile()
int readCfgState (void) {
	config_t cfg;
	config_init(&cfg);

	/* Read the file. If there is an error, report it and exit. */
	if (!config_read_file(&cfg, config_state_path)) {
		printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
		config_destroy(&cfg);
		return -1;
	}

	/*  */
	if (!config_lookup_int(&cfg, "tempState", &tempState)) printf("\nNo 'tempState' setting in configuration file.");
	if (!config_lookup_int(&cfg, "humState", &humState)) printf("\nNo 'humState' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay1o", &relay1o)) printf("\nNo 'relay1o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay2o", &relay2o)) printf("\nNo 'relay2o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay3o", &relay3o)) printf("\nNo 'relay3o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay4o", &relay4o)) printf("\nNo 'relay4o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay5o", &relay5o)) printf("\nNo 'relay5o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay6o", &relay6o)) printf("\nNo 'relay6o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay7o", &relay7o)) printf("\nNo 'relay7o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "relay8o", &relay8o)) printf("\nNo 'relay8o' setting in configuration file.");
	if (!config_lookup_int(&cfg, "RHeatTS", &RHeatTS)) printf("\nNo 'RHeatTS' setting in configuration file.");
	if (!config_lookup_int(&cfg, "RHumTS", &RHumTS)) printf("\nNo 'RHumTS' setting in configuration file.");
	if (!config_lookup_int(&cfg, "RHepaTS", &RHepaTS)) printf("\nNo 'RHepaTS' setting in configuration file.");
	if (!config_lookup_int(&cfg, "RFanTS", &RFanTS)) printf("\nNo 'RFanTS' setting in configuration file.");
	if (!config_lookup_float(&cfg, "wfactor", &wfactor)) printf("\nNo 'wfactor' setting in configuration file.");


	config_destroy(&cfg);
	return 0;
}
Exemple #8
0
static int
system_frequency_handler(const config_t *c, const char *p, ConfigVar *v)
{
    double value = 0.0;
    int result =  config_lookup_float(c, p, (double *) &value);
    set_system_frequency_sf((psOSCdSystem *) v->variable, value);
    return result;
}
Exemple #9
0
/**
 * Internal post-processing of feature vectors.
 * @param fv feature vector
 */
void fvec_postprocess(fvec_t *fv)
{
    const char *cfg_str;
    double flt1, flt2;

    /* Compute embedding and normalization */
    config_lookup_string(&cfg, "features.vect_embed", &cfg_str);
    fvec_embed(fv, cfg_str);
    config_lookup_string(&cfg, "features.vect_norm", &cfg_str);
    fvec_norm(fv, cfg_str);

    /* Apply thresholding */
    config_lookup_float(&cfg, "features.thres_low", &flt1);
    config_lookup_float(&cfg, "features.thres_high", &flt2);
    if (flt1 != 0.0 || flt2 != 0.0) {
        fvec_thres(fv, flt1, flt2);
    }
}
Exemple #10
0
double _cfg_float(cfg_t *cfg, const char *name, double *val, u4_t flags)
{
	double num;
	if (!config_lookup_float(&cfg->config, name, &num)) {
		if (config_error_line(&cfg->config)) cfg_error(&cfg->config, "cfg_float");
		if (!(flags & CFG_REQUIRED)) return 0;
		lprintf("%s: required parameter not found: %s\n", cfg->filename, name);
		panic("cfg_float");
	}
	if (flags & CFG_PRINT) lprintf("%s: %s = %f\n", cfg->filename, name, num);
	if (val) *val = num;
	return num;
}
int main(int argc, char *argv[])
{
  FILE *fp;
  int fd, offset, length, i, j;
  time_t t;
  struct tm *gmt;
  volatile void *cfg, *sts;
  volatile uint64_t *fifo[8];
  volatile uint8_t *rst, *sel;
  volatile uint16_t *cntr;
  int32_t type = 2;
  uint64_t *buffer;
  config_t config;
  config_setting_t *setting, *element;
  char date[12];
  char name[64];
  char zeros[15] = "000000_0000.c2";
  double dialfreq;
  double corr;
  double freq[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
  int chan[8] = {1, 1, 1, 1, 1, 1, 1, 1};
  uint8_t value = 0;

  if(argc != 2)
  {
    fprintf(stderr, "Usage: write-c2-files config_file.cfg\n");
    return EXIT_FAILURE;
  }

  config_init(&config);

  if(!config_read_file(&config, argv[1]))
  {
    fprintf(stderr, "Error on line %d in configuration file.\n", config_error_line(&config));
    return EXIT_FAILURE;
  }

  if(!config_lookup_float(&config, "corr", &corr))
  {
    fprintf(stderr, "No 'corr' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(corr < -100.0 || corr > 100.0)
  {
    fprintf(stderr, "Wrong 'corr' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  setting = config_lookup(&config, "bands");
  if(setting == NULL)
  {
    fprintf(stderr, "No 'bands' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  length = config_setting_length(setting);

  if(length > 8)
  {
    fprintf(stderr, "More than 8 bands in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(length < 1)
  {
    fprintf(stderr, "Less than 1 band in configuration file.\n");
    return EXIT_FAILURE;
  }

  for(i = 0; i < length; ++i)
  {
    element = config_setting_get_elem(setting, i);

    if(!config_setting_lookup_float(element, "freq", &freq[i]))
    {
      fprintf(stderr, "No 'freq' setting in element %d.\n", i);
      return EXIT_FAILURE;
    }

    if(!config_setting_lookup_int(element, "chan", &chan[i]))
    {
      fprintf(stderr, "No 'chan' setting in element %d.\n", i);
      return EXIT_FAILURE;
    }

    if(chan[i] < 1 || chan[i] > 2)
    {
      fprintf(stderr, "Wrong 'chan' setting in element %d.\n", i);
      return EXIT_FAILURE;
    }

    value |= (chan[i] - 1) << i;
  }

  t = time(NULL);
  if((gmt = gmtime(&t)) == NULL)
  {
    fprintf(stderr, "Cannot convert time.\n");
    return EXIT_FAILURE;
  }

  if((fd = open("/dev/mem", O_RDWR)) < 0)
  {
    fprintf(stderr, "Cannot open /dev/mem.\n");
    return EXIT_FAILURE;
  }

  sts = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40000000);
  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40001000);

  for(i = 0; i < 8; ++i)
  {
    fifo[i] = mmap(NULL, 8*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40002000 + i * 0x1000);
    *(uint32_t *)(cfg + 8 + i * 4) = (uint32_t)floor((1.0 + 1.0e-6 * corr) * freq[i] / 125.0 * (1<<30) + 0.5);
  }

  rst = (uint8_t *)(cfg + 0);
  sel = (uint8_t *)(cfg + 4);
  cntr = (uint16_t *)(sts + 12);

  *sel = value;

  *rst |= 1;
  *rst &= ~1;

  offset = 0;
  buffer = malloc(45000 * 8 * 8);
  memset(buffer, 0, 45000 * 8 * 8);

  while(offset < 42000)
  {
    while(*cntr < 500) usleep(300000);

    for(i = 0; i < 250; ++i)
    {
      for(j = 0; j < 8; ++j)
      {
        buffer[j * 45000 + offset + i] = *fifo[j];
      }
    }

    offset += 250;
  }

  for(i = 0; i < length; ++i)
  {
    dialfreq = freq[i] - 0.0015;
    strftime(date, 12, "%y%m%d_%H%M", gmt);
    sprintf(name, "wspr_%d_%d_%d_%s.c2", i, (uint32_t)(dialfreq * 1.0e6), chan[i], date);
    if((fp = fopen(name, "wb")) == NULL)
    {
      fprintf(stderr, "Cannot open output file %s.\n", name);
      return EXIT_FAILURE;
    }
    fwrite(zeros, 1, 14, fp);
    fwrite(&type, 1, 4, fp);
    fwrite(&dialfreq, 1, 8, fp);
    fwrite(&buffer[i * 45000], 1, 45000 * 8, fp);
    fclose(fp);
  }

  return EXIT_SUCCESS;
}
Exemple #12
0
/**
 * Print shared n-grams for each cluster
 * @param c Clustering structure
 * @param fa Array of feature vectors
 * @param file Output file
 */
void export_shared_ngrams(cluster_t *c, farray_t *fa, const char *file)
{
    assert(c && fa && file);
    int i, j, k;
    double shared;
    FILE *f;
    char *name = NULL;

    config_lookup_float(&cfg, "cluster.shared_ngrams", &shared);
    if (shared <= 0.0)
        return;

    if (verbose > 0)
        printf("Exporting shared n-grams with minimum ratio %4.2f.\n",
               shared);

    if (!(f = fopen(file, "a"))) {
        error("Could not create file '%s'.", file);
        return;
    }

    /* Print incremental header */
    fprintf(f, "# ---\n# Shared n-grams for %s\n", fa->src);
    fprintf(f, "# Minimum ratio of shared n-grams: %4.2f (%2.0f%%)\n",
            shared, shared * 100);
    fprintf(f, "# ---\n# <cluster> <ratio> <hash> <ngram>\n");

    /* Compute shared n-grams per cluster */
    for (i = 0; i < c->num; i++) {
        fvec_t *s = fvec_zero();

        for (j = 0, k = 0; j < c->len; j++) {
            if (c->cluster[j] != i)
                continue;

            /* Clone and binarize */
            fvec_t *x = fvec_clone(fa->x[j]);
            fvec_bin(x);

            if (k == 0)
                name = cluster_get_name(c, j);

            /* Merge n-grams in cluster */
            fvec_t *y = fvec_add(s, x);
            fvec_destroy(s);
            fvec_destroy(x);
            s = y;
            k++;
        }

        /* Check for empty cluster */
        if (k == 0)
            continue;

        fvec_div(s, k);

        /* Output shared n-grams */
        for (j = 0; j < s->len; j++) {
            if (s->val[j] < shared)
                continue;

            fprintf(f, "%s %6.4f %.16llx ", name, s->val[j],
                    (long long unsigned int) s->dim[j]);

            /* Lookup feature */
            fentry_t *fe = ftable_get(s->dim[j]);
            if (!fe)
                error("Oops. Feature not in lookup table.");

            /* Print feature */
            fprintf(f, "\"");
            for (k = 0; k < fe->len; k++) {
                if (isprint(fe->data[k]) || fe->data[k] == '%')
                    fprintf(f, "%c", fe->data[k]);
                else
                    fprintf(f, "%%%.2x", fe->data[k]);
            }
            fprintf(f, "\"\n");
        }
        fvec_destroy(s);
    }

    fclose(f);
}
int main(int argc, char *argv[])
{
  int fd, i;
  void *cfg, *mux;
  uint8_t *rst;
  uint32_t *fifo;
  unsigned char symbols[162];
  char *message, *hashtab;
  config_t config;
  double freq, corr, dphi;
  int chan;

  hashtab = malloc(sizeof(char) * 32768 * 13);
  memset(hashtab, 0, sizeof(char) * 32768 * 13);

  if(argc != 2)
  {
    fprintf(stderr, "Usage: transmit-wspr-message config_file.cfg\n");
    return EXIT_FAILURE;
  }

  config_init(&config);

  if(!config_read_file(&config, argv[1]))
  {
    fprintf(stderr, "Error on line %d in configuration file.\n", config_error_line(&config));
    return EXIT_FAILURE;
  }

  if(!config_lookup_float(&config, "freq", &freq))
  {
    fprintf(stderr, "No 'freq' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(freq < 0.1 || freq > 60.0)
  {
    fprintf(stderr, "Wrong 'freq' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(!config_lookup_float(&config, "corr", &corr))
  {
    fprintf(stderr, "No 'corr' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(corr < -100.0 || corr > 100.0)
  {
    fprintf(stderr, "Wrong 'corr' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(!config_lookup_int(&config, "chan", &chan))
  {
    fprintf(stderr, "No 'chan' setting in configuration file.\n", i);
    return EXIT_FAILURE;
  }

  if(chan < 1 || chan > 2)
  {
    fprintf(stderr, "Wrong 'chan' setting in configuration file.\n", i);
    return EXIT_FAILURE;
  }

  if(!config_lookup_string(&config, "message", &message))
  {
    fprintf(stderr, "No 'message' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if(strlen(message) > 22)
  {
    fprintf(stderr, "Wrong 'message' setting in configuration file.\n");
    return EXIT_FAILURE;
  }

  if((fd = open("/dev/mem", O_RDWR)) < 0)
  {
    perror("open");
    return EXIT_FAILURE;
  }

  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40001000);
  fifo = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x4000B000);
  mux = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x4000C000);

  if(chan == 1)
  {
    *(uint32_t *)(mux + 64) = 0;
    *(uint32_t *)(mux + 68) = 1;
  }
  else
  {
    *(uint32_t *)(mux + 64) = 1;
    *(uint32_t *)(mux + 68) = 0;
  }

  *(uint32_t *)mux = 2;

  rst = (uint8_t *)(cfg + 1);

  *rst &= ~1;
  *rst |= 1;

  get_wspr_channel_symbols(message, hashtab, symbols);

  for(i = 0; i < 162; ++i)
  {
    dphi = (freq * 1.0e6 + ((double)symbols[i] - 1.5) * 375.0 / 256.0) / 125.0e6;
    *fifo = (uint32_t)floor((1.0 + 1.0e-6 * corr) * dphi * (1<<30) + 0.5);
  }

  return EXIT_SUCCESS;
}
Exemple #14
0
void parse_general_audio_options(void) {
  /* this must be called after the output device has been initialised, so that the default values
   * are set before any options are chosen */
  int value;
  double dvalue;
  if (config.cfg != NULL) {

    /* Get the desired buffer size setting (deprecated). */
    if (config_lookup_int(config.cfg, "general.audio_backend_buffer_desired_length", &value)) {
      if ((value < 0) || (value > 66150)) {
        inform("The setting general.audio_backend_buffer_desired_length is deprecated. "
               "Use alsa.audio_backend_buffer_desired_length_in_seconds instead.");
        die("Invalid audio_backend_buffer_desired_length value: \"%d\". It "
            "should be between 0 and "
            "66150, default is %d",
            value, (int)(config.audio_backend_buffer_desired_length * 44100));
      } else {
        inform("The setting general.audio_backend_buffer_desired_length is deprecated. "
               "Use general.audio_backend_buffer_desired_length_in_seconds instead.");
        config.audio_backend_buffer_desired_length = 1.0 * value / 44100;
      }
    }

    /* Get the desired buffer size setting in seconds. */
    if (config_lookup_float(config.cfg, "general.audio_backend_buffer_desired_length_in_seconds",
                            &dvalue)) {
      if ((dvalue < 0) || (dvalue > 1.5)) {
        die("Invalid audio_backend_buffer_desired_length_in_seconds value: \"%f\". It "
            "should be between 0 and "
            "1.5, default is %.3f seconds",
            dvalue, config.audio_backend_buffer_desired_length);
      } else {
        config.audio_backend_buffer_desired_length = dvalue;
      }
    }

    /* Get the latency offset (deprecated). */
    if (config_lookup_int(config.cfg, "general.audio_backend_latency_offset", &value)) {
      if ((value < -66150) || (value > 66150)) {
        inform("The setting general.audio_backend_latency_offset is deprecated. "
               "Use general.audio_backend_latency_offset_in_seconds instead.");
        die("Invalid  audio_backend_latency_offset value: \"%d\". It "
            "should be between -66150 and +66150, default is 0",
            value);
      } else {
        inform("The setting general.audio_backend_latency_offset is deprecated. "
               "Use general.audio_backend_latency_offset_in_seconds instead.");
        config.audio_backend_latency_offset = 1.0 * value / 44100;
      }
    }

    /* Get the latency offset in seconds. */
    if (config_lookup_float(config.cfg, "general.audio_backend_latency_offset_in_seconds",
                            &dvalue)) {
      if ((dvalue < -1.0) || (dvalue > 1.5)) {
        die("Invalid audio_backend_latency_offset_in_seconds \"%f\". It "
            "should be between -1.0 and +1.5, default is 0 seconds",
            dvalue);
      } else {
        config.audio_backend_latency_offset = dvalue;
      }
    }

    /* Get the desired length of the silent lead-in. */
    if (config_lookup_float(config.cfg, "general.audio_backend_silent_lead_in_time", &dvalue)) {
      if ((dvalue < 0.0) || (dvalue > 4)) {
        die("Invalid audio_backend_silent_lead_in_time \"%f\". It "
            "must be between 0.0 and 4.0 seconds. Omit setting to use the default value",
            dvalue);
      } else {
        config.audio_backend_silent_lead_in_time = dvalue;
      }
    }
  }
}
Exemple #15
0
SET_settings
SET_Settings (char *fname)
{
  config_t cfg, *cf;
  const config_setting_t *lists;
  int count, n, ires;
  double dres;
  const char *sol;
  cf = &cfg;
  config_init (cf);
  if (!config_read_file (cf, fname))
    {
      config_destroy (cf);
      fprintf(stderr,"Initial configuration file %s not found!\n",fname);
      abort();
      return (NULL);
    }
  SET_settings p = checkedMalloc (sizeof(*p));
  p->minstep = 0;
  p->zchyst = 0;
  p->derdelta = 0;
  p->it = 0;
  p->ft = 0;
  p->dt = 0;
  p->dqmin = NULL;
  p->dqrel = NULL;
  p->symdiff = 1;
  p->lps = 1;
  p->nodesize = 0;
  p->order = 1;
  p->solver = SD_QSS3;
  p->nDQMin = 0;
  p->nDQRel = 0;
  p->pm = SD_MetisCut;
  if (config_lookup_float (cf, "minstep", &dres))
    {
      if (dres == 0)
	{
	  p->minstep = MIN_STEP;
	}
      else
	{
	  p->minstep = dres;
	}
    }
  if (config_lookup_float (cf, "dt", &dres))
      {
        p->dt = dres;
      }
  if (config_lookup_float (cf, "zchyst", &dres))
    {
      if (dres == 0)
	{
	  p->zchyst = ZC_HYST;
	}
      else
	{
	  p->zchyst = dres;
	}
    }
  if (config_lookup_float (cf, "derdelta", &dres))
    {
      if (dres == 0)
	{
	  p->derdelta = DER_DELTA;
	}
      else
	{
	  p->derdelta = dres;
	}
    }
  if (config_lookup_float (cf, "it", &dres))
    {
      p->it = dres;
    }
  if (config_lookup_float (cf, "ft", &dres))
    {
      p->ft = dres;
    }
  if (config_lookup_int (cf, "symdiff", &ires))
    {
      p->symdiff = ires;
    }
  if (config_lookup_int (cf, "lps", &ires))
    {
      if (ires == 0)
	{
	  p->lps = LPS;
	}
      else
	{
	  p->lps = ires;
	}
    }
  if (config_lookup_int (cf, "nodesize", &ires))
    {
      if (ires == 0)
	{
	  p->nodesize = NODE_SIZE;
	}
      else
	{
	  p->nodesize = ires;
	}
    }
  if (config_lookup_string (cf, "sol", &sol))
    {
      p->solver = _getSolver (sol);
      p->order = _getOrder (p->solver);
    }
  if (config_lookup_string (cf, "partitionMethod", &sol))
    {
      p->pm = _getPartitionMethod (sol);
    }
  lists = config_lookup (cf, "dqmin");
  count = config_setting_length (lists);
  p->dqmin = checkedMalloc (count * sizeof(double));
  for (n = 0; n < count; n++)
    {
      p->dqmin[n] = config_setting_get_float_elem (lists, n);
    }
  p->nDQMin = count;
  lists = config_lookup (cf, "dqrel");
  count = config_setting_length (lists);
  p->dqrel = checkedMalloc (count * sizeof(double));
  for (n = 0; n < count; n++)
    {
      p->dqrel[n] = config_setting_get_float_elem (lists, n);
    }
  p->nDQRel = count;
  config_destroy (cf);
  return ((p));
}
Exemple #16
0
MainDialog::MainDialog(QString userConfigFile) {
  ui = new Ui::MainDialog;
  ui->setupUi(this);

  if(userConfigFile.isEmpty()) {
    userConfigFile_ = qgetenv("XDG_CONFIG_HOME");
    if(userConfigFile_.isEmpty()) {
      userConfigFile_ = QDir::homePath();
      userConfigFile_ += "/.config";
    }
    // QDir configDir = QDir(userConfigFile);
    // if(!configDir.exists())
    userConfigFile_ += "/compton.conf";
  }
  else
    userConfigFile_ = userConfigFile;

  config_init(&config_);
  if(config_read_file(&config_, userConfigFile_.toLocal8Bit().constData()) == CONFIG_FALSE) {
    // loading user config file failed
    // try our default example
    qDebug() << "load fail, try " << COMPTON_CONF_DATA_DIR << "/compton.conf.example";
    config_read_file(&config_, COMPTON_CONF_DATA_DIR "/compton.conf.example");
  }

  // set up signal handlers and initial values of the controls
  connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(onDialogButtonClicked(QAbstractButton*)));
  connect(ui->aboutButton, SIGNAL(clicked(bool)), SLOT(onAboutButtonClicked()));
  connect(ui->shadow_color, SIGNAL(clicked(bool)), SLOT(onColorButtonClicked()));
  double color;
  shadowColor_.setRedF(config_lookup_float(&config_, "shadow-red", &color) == CONFIG_TRUE ?  color : 0.0);
  shadowColor_.setGreenF(config_lookup_float(&config_, "shadow-green", &color) == CONFIG_TRUE ? color : 0.0);
  shadowColor_.setBlueF(config_lookup_float(&config_, "shadow-blue", &color) == CONFIG_TRUE ? color : 0.0);
  updateShadowColorButton();

  // objectNames are kept the same as config file key names.
  Q_FOREACH(QWidget* child, findChildren<QWidget*>()) {
    if(!child->isWidgetType() || child->objectName().isEmpty())
      continue;
    // objectName uses _ while config file keys uses - as separator.
    QByteArray keyName = child->objectName().replace('_', '-').toLatin1(); // generate config key from objectName.
    if(child->inherits("QCheckBox")) {
      int val = -1;
      if(config_lookup_bool(&config_, keyName.constData(), &val) == CONFIG_TRUE)
	static_cast<QCheckBox*>(child)->setChecked((bool)val);
      connect(child, SIGNAL(toggled(bool)), SLOT(onButtonToggled(bool)));
    }
    else if(child->inherits("QDoubleSpinBox")) {
      double val;
      if(config_lookup_float(&config_, keyName.constData(), &val) == CONFIG_TRUE)
	static_cast<QDoubleSpinBox*>(child)->setValue(val);
      connect(child, SIGNAL(valueChanged(double)), SLOT(onSpinValueChanged(double)));
    }
    else if(child->inherits("QSpinBox")) {
      int val;
      if(config_lookup_int(&config_, keyName.constData(), &val) == CONFIG_TRUE)
	static_cast<QSpinBox*>(child)->setValue(val);
      connect(child, SIGNAL(valueChanged(int)), SLOT(onSpinValueChanged(int)));
    }
  }
}