コード例 #1
0
int low_first_t::dom_finish_vtx (
    vtx_t u,
    const subsystem_t &subsystem,
    const std::vector<Flux::Jobspec::Resource> &resources,
    const f_resource_graph_t &g, scoring_api_t &dfu)
{
    int64_t score = MATCH_MET;
    int64_t overall;
    // this comparator overrides default and prefer the lower id
    fold::less comp;

    for (auto &resource : resources) {
        if (resource.type != g[u].type)
            continue;

        // jobspec resource type matches with the visiting vertex
        for (auto &c_resource : resource.with) {
            // test children resource count requirements
            const std::string &c_type = c_resource.type;
            unsigned int qc = dfu.qualified_count (subsystem, c_type);
            unsigned int count = calc_count (c_resource, qc);
            if (count == 0) {
                score = MATCH_UNMET;
                break;
            }
            dfu.choose_accum_best_k (subsystem, c_type, count, comp);
        }
    }

    // low id first policy (just a demo policy)
    overall = (score == MATCH_MET)? (score + g[u].id + 1) : score;
    dfu.set_overall_score (overall);
    decr ();
    return (score == MATCH_MET)? 0 : -1;
}
コード例 #2
0
int high_first_t::dom_finish_graph (
    const subsystem_t &subsystem,
    const std::vector<Flux::Jobspec::Resource> &resources,
    const f_resource_graph_t &g, scoring_api_t &dfu)
{
    int64_t score = MATCH_MET;
    for (auto &resource : resources) {
        const std::string &type = resource.type;
        unsigned int qc = dfu.qualified_count (subsystem, type);
        unsigned int count = calc_count (resource, qc);
        if (count == 0) {
            score = MATCH_UNMET;
            break;
        }
        dfu.choose_accum_best_k (subsystem, type, count);
    }
    dfu.set_overall_score (score);
    return (score == MATCH_MET)? 0 : -1;
}
コード例 #3
0
ファイル: alsa_player.c プロジェクト: 5hanth/dhvani-tts
void
alsa_play(FILE *wave_file){
	int ofs = 0;
	size_t dta = 0;
	ssize_t dtawave = 0;

	pbrec_count = LLONG_MAX;
	fdcount = 0;
 	if ((fd = open64(wave_file, O_RDONLY, 0)) == -1) {
		/* just return. It okey		 */
		return;
	}
 	/* should be raw data */
	init_raw_data();
	pbrec_count = calc_count();
	playback_go(fd, dta, pbrec_count, FORMAT_RAW, wave_file);
	if (fd != 0){
		close(fd);
		remove(wave_file);/*Played, so delete the file*/
	}	
}
コード例 #4
0
ファイル: play.c プロジェクト: hishamhm/protosampler
static void playback(char *name)
{
	int ofs;
	size_t dta;
	ssize_t dtawave;

	pbrec_count = LLONG_MAX;
	fdcount = 0;
	if (!name || !strcmp(name, "-"))
		return;
	if ((fd = open64(name, O_RDONLY, 0)) == -1) {
		perror(name);
		exit(EXIT_FAILURE);
	}
	// read bytes for WAVE-header
	if ((dtawave = test_wavefile(fd, audiobuf, dta)) >= 0) {
		pbrec_count = calc_count();
		printf("will play %s", name);
		playback_go(fd, dtawave, pbrec_count, name);
	}
	if (fd != 0)
		close(fd);
}
コード例 #5
0
ファイル: arecord.c プロジェクト: JordanBlocher/record
static void capture(char *orig_name)
{
	int tostdout=0;		/* boolean which describes output stream */
	int filecount=0;	/* number of files written */
	char *name = orig_name;	/* current filename */
	char namebuf[PATH_MAX+1];
	off64_t count, rest;		/* number of bytes to capture */

	/* get number of bytes to capture */
	count = calc_count();
	if (count == 0)
		count = LLONG_MAX;
	/* WAVE-file should be even (I'm not sure), but wasting one byte
	   isn't a problem (this can only be in 8 bit mono) */
	if (count < LLONG_MAX)
		count += count % 2;
	else
		count -= count % 2;

    printf("arecord: Recording audio to: %s\n", name);
	/* setup sound hardware */
	set_params();

	/* write to stdout? */
	if (!name || !strcmp(name, "-")) {
		fd = fileno(stdout);
		name = "stdout";
		tostdout=1;
		if (count > fmt_rec_table[file_type].max_filesize)
			count = fmt_rec_table[file_type].max_filesize;
	}

	do {
		/* open a file to write */
		if(!tostdout) {
			/* upon the second file we start the numbering scheme */
			if (filecount) {
				filecount = new_capture_file(orig_name, namebuf,
							     sizeof(namebuf),
							     filecount);
				name = namebuf;
			}

			/* open a new file */
			remove(name);
			if ((fd = open64(name, O_WRONLY | O_CREAT, 0644)) == -1) {
				perror(name);
				exit(EXIT_FAILURE);
			}
			filecount++;
		}

		rest = count;
		if (rest > fmt_rec_table[file_type].max_filesize)
			rest = fmt_rec_table[file_type].max_filesize;

		/* setup sample header */
		if (fmt_rec_table[file_type].start)
			fmt_rec_table[file_type].start(fd, rest);

		/* capture */
		fdcount = 0;
		while (rest > 0 && capture_stop == 0) {
			size_t c = (rest <= (off64_t)chunk_bytes) ?
				(size_t)rest : chunk_bytes;
			size_t f = c * 8 / bits_per_frame;
			if (pcm_read(audiobuf, f) != f)
				break;
			if (write(fd, audiobuf, c) != c) {
				perror(name);
				exit(EXIT_FAILURE);
			}
			count -= c;
			rest -= c;
			fdcount += c;
		}

		/* finish sample container */
		if (fmt_rec_table[file_type].end && !tostdout) {
			fmt_rec_table[file_type].end(fd);
			fd = -1;
		}

		/* repeat the loop when format is raw without timelimit or
		 * requested counts of data are recorded
		 */
	} while ( ((file_type == FORMAT_RAW && !timelimit) || count > 0) &&
        capture_stop == 0);
    printf("arecord: Stopping capturing audio.\n");
}
コード例 #6
0
/* playing raw data, this proc handels WAVE files and
   .VOCs (as one block) */
static int
do_play (int fd, int loaded, u_long count, int rtype, char *name)
{
  int l, real_l;
  u_long c;
  char one_chn = 0;
  char to_8 = 0;
  int tmps;

  sync_dsp ();
  tmps = samplesize;
  ioctl (audio, SNDCTL_DSP_SETFMT, &tmps);
  if (tmps != samplesize)
    {
      fprintf (stderr, "Unable to set %d bit sample size", samplesize);
      if (samplesize == 16)
	{
	  samplesize = 8;
	  ioctl (audio, SNDCTL_DSP_SETFMT, &samplesize);
	  if (samplesize != 8)
	    {
	      fprintf (stderr, "Unable to set 8 bit sample size!\n");
	      return -1;
	    }
	  fprintf (stderr, "; playing 8 bit\n");
	  to_8 = 1;
	}
      else
	{
	  fprintf (stderr, "\n");
	  return -1;
	}
    }
#ifdef OSS_VERSION
  if (ioctl (audio, SNDCTL_DSP_STEREO, &dsp_stereo) < 0)
    {
#else
  if (dsp_stereo != ioctl (audio, SNDCTL_DSP_STEREO, dsp_stereo))
    {
#endif
      fprintf (stderr, "Can't play in Stereo; playing only one channel\n");
      dsp_stereo = MODE_MONO;
      one_chn = 1;
    }
  if (set_dsp_speed (&dsp_speed) < 0)
    return -1;

  abuf_size = 512;

  while (count)
    {
      c = count;

      if (c > abuf_size)
	c = abuf_size;

      if ((l = read (fd, (char *) audiobuf + loaded, c - loaded)) > 0)
	{
	  l += loaded;
	  loaded = 0;		/* correct the count; ugly but ... */
	  real_l = (one_chn
		    || to_8) ? one_channel (audiobuf, l, one_chn, to_8) : l;

	  /* change byte order if necessary */
	  if (convert && (samplesize == 16))
	    {
	      long i;

	      for (i = 0; i < real_l; i += 2)
		*((short *) (audiobuf + i)) =
		  htons (*((short *) (audiobuf + i)));
	    }

	  if (write (audio, (char *) audiobuf, real_l) != real_l)
	    {
	      perror (AUDIO);
	      return -1;
	    }
	  count -= l;
	}
      else
	{
	  if (l == -1)
	    {
	      perror (name);
	      return -1;
	    }
	  count = 0;		/* Stop */
	}
    }				/* while (count) */

  return 0;
}

/*
  let's play)
*/
static int
player (char *name)
{
  int fd, ofs;

  if (!name)
    {
      fd = 0;
      name = "stdin";
    }
  else if ((fd = open (name, O_RDONLY, 0)) == -1)
    {
      perror (name);
      return -1;
    }
  /* Read the smallest header first, then the
     missing bytes for the next, etc. */

  /* read SND-header */
  read (fd, (char *) audiobuf, sizeof (SndHeader));
  if (test_sndfile (audiobuf, fd) >= 0)
    {
      if (do_play (fd, 0, count, SND_FMT, name) < 0)
	return -1;
    }

  else
    {
      /* read VOC-Header */
      read (fd, (char *) audiobuf + sizeof (SndHeader),
	    sizeof (VocHeader) - sizeof (SndHeader));
      if ((ofs = test_vocfile (audiobuf)) >= 0)
	{
	  if (vplay (fd, ofs, name) < 0)
	    return -1;
	}

      else
	{
	  /* read bytes for WAVE-header */
	  read (fd, (char *) audiobuf + sizeof (VocHeader),
		sizeof (WaveHeader) - sizeof (VocHeader));
	  if (test_wavefile (audiobuf) >= 0)
	    {
	      if (do_play (fd, 0, count, WAVE_FMT, name) < 0)
		return -1;
	    }
	  else
	    {
	      /* should be raw data */
	      init_raw_data ();
	      count = calc_count ();
	      if (do_play (fd, sizeof (WaveHeader), count, RAW_DATA, name) <
		  0)
		return -1;
	    }
	}
    }
  if (fd != 0)
    close (fd);
  return 0;
}