Ejemplo n.º 1
0
int vorbis_open(const char *file) {
	FILE *fp;
	vorbis_info *info;
	
	if (!file || !*file)
		return 0;

	if (!(fp = fopen(file, "rb")))
		return 0;

	if (ov_open(fp, &track, NULL, 0)) {
		fclose(fp);
		return 0;
	}

	parse_comments(ov_comment(&track, -1));
	
	info = ov_info(&track, -1);
	
	sample_rate = info->rate;
	channels = info->channels;
	duration = ov_time_total(&track, -1);
	bitrate = ov_bitrate(&track, -1);

	return 1;
}
Ejemplo n.º 2
0
Archivo: input.c Proyecto: N-Thomas/sat
/*******************************************************************************************
 * NAME :             input_parse
 *
 * DESCRIPTION :      Parses the input from a file of the cnf sat form.
 *
 * INPUTS :
 *      PARAMETERS :   
 *          FILE              *fp     file
 *          INPUT             *input  input
 *
 * OUTPUTS :
 *      RETURN : 1 on success, -1 on failure/error
 */
int input_parser(FILE *fp, INPUT *input)
{
  int i, file_size, *nbvar, *nbclauses, **data, *clause_lengths, *pos_val_sums, *neg_val_sums;
  char *line;

  // Finding the size of the file in bytes.
  file_size = get_file_size(fp);

  // Pass over comments.
  line = parse_comments(fp, file_size);

  nbvar = malloc(sizeof(int)); // ndicates variables will be from [-1, -nbvar] and [1, nbvar].
  CHECK_PTR(nbvar);
  *nbvar = 0;

  nbclauses = malloc(sizeof(int)); // indicates the number of rows (clauses), indicated by the number of zeros.
  CHECK_PTR(nbclauses);
  *nbclauses = 0;

  if (parse_cnf_header(line, nbvar, nbclauses) != 1) { return -1; }

  data = malloc(sizeof(int*) * (*nbclauses));
  CHECK_PTR(data);

  clause_lengths = malloc(sizeof(int) * (*nbclauses));
  CHECK_PTR(clause_lengths);

  pos_val_sums = malloc(sizeof(int) * ((*nbvar)));
  CHECK_PTR(pos_val_sums);

  neg_val_sums = malloc(sizeof(int) * ((*nbvar)));
  CHECK_PTR(neg_val_sums);

  // Load array with 0s.
  for (i = 0; i < *nbvar; i++)
  {
    pos_val_sums[i] = 0;
    neg_val_sums[i] = 0;
  }

  // Loops over all clauses. 
  if (parse_clauses(fp, file_size, data, nbclauses, clause_lengths, pos_val_sums, neg_val_sums) != 1) { return -1; }  

  // Load values into structs.
  input->data           = data;
  input->nbclauses      = *nbclauses; 
  input->nbvars         = *nbvar;
  input->clause_lengths = clause_lengths;
  input->pos_val_sums   = pos_val_sums;
  input->neg_val_sums   = neg_val_sums;

  free(nbvar);
  free(nbclauses);

  return 1;
}