Exemplo n.º 1
0
void cmd_loop(char *args)
{
    char timebuf[SMABUF];
    char restbuf[MAXSIZ];
    long timel;
    int resp;

    if (!*args || !strcmp(args, "-")) {
        cmd_listloop(args);

        return;
    }

    if (*args == '-') {
        resp = remove_loop(args + 1);

        if (resp == true) {
            msg("-- loop: %s remove.", args + 1);
        } else if (resp == 0) {
            msg("-- loop: %s not found.", args + 1);
        }

        return;
    }

    split(args, timebuf, restbuf);
    timel = atoi(timebuf);

    if ((timel == 0) && (*args == '0')) {
        msg("-- loop: please input an integer greater than 0");

        return;
    }

    if (timel <= 0) {
        msg("-- loop: time value must be greater than 0 seconds.");

        return;
    }

    resp = add_loop(restbuf, timel, true);

    if (resp == ERROR) {
        msg("-- loop: could not malloc the memory. loop not added.");
    } else if (resp >= 0) {
        msg("-- loop(#%d): added %s with delay %d seconds", resp, restbuf, timel);
        sprintf(restbuf, "#%d", resp);
        add_assign("pid", restbuf);
    }
}
Exemplo n.º 2
0
void simulatort::loop_detection(tracet &trace)
{
  // walk down the trace, look for potential loops
  
  std::cout << "Loop Detection" << std::endl;

  for(tracet::iterator f_it=trace.begin();
      f_it!=trace.end();
      f_it++)
  {
    trace_stept &from_step=*f_it;
    
    // get successor states
    queuet queue;
    compute_successor_states(from_step.state, false, queue);
    
    bool match_found=false;
    
    // compare the successors with what we have on the trace
    // this is quadratic in trace.size()
    for(queuet::statest::const_iterator
        q_it=queue.states.begin();
        q_it!=queue.states.end() && !match_found;
        q_it++)
    {
      const statet &new_state=*q_it;
      
      if(!new_state.is_backwards_jump())
        continue;

      #if 0
      std::cout << "COMPARE " << queue.size() << "\n";
      #endif

      // first compare PCs
      for(tracet::iterator t_it=trace.begin();
          t_it!=f_it && !match_found;
          t_it++)
      {
        const trace_stept &to_step=*t_it;
        
        if(to_step.compare_PCs(new_state))
        {
          #if 0
          std::cout << "PC MATCH\n";
          #endif
          
          std::map<vart, bool> values;
          
          // this should be restricted to the active variables
          for(unsigned v=0; v<to_step.global_values.size(); v++)
            values[vart(v)]=to_step.global_values[v];

          for(unsigned t=0; t<new_state.data().threads.size(); t++)
            for(unsigned v=0; v<new_state.data().threads[t].locals.size(); v++)
            {
              unsigned v2=to_step.global_values.size()+v;
              values[vart(v2, t)]=to_step.threads[t].local_values[v];
            }
            
          // now see if data can be made to match
          // use data from trace for old state
          if(match(formula_container, new_state, values))
          {
            // oh, yes! a match!
            match_found=true;

            // avoid duplicates for now
            if(f_it->loop_from.empty() && f_it->loop_to.empty() &&
               t_it->loop_from.empty() && t_it->loop_to.empty())
              add_loop(f_it, t_it);
            
            #if 0
            std::cout << "MATCH\n";
            #endif
          }
        }
      }
    }
  }
}
Exemplo n.º 3
0
static int parse_config(int argc, char *argv[], snd_output_t *output,
			int cmdline)
{
	struct option long_option[] =
	{
		{"help", 0, NULL, 'h'},
		{"config", 1, NULL, 'g'},
		{"daemonize", 0, NULL, 'd'},
		{"pdevice", 1, NULL, 'P'},
		{"cdevice", 1, NULL, 'C'},
		{"pctl", 1, NULL, 'X'},
		{"cctl", 1, NULL, 'Y'},
		{"latency", 1, NULL, 'l'},
		{"tlatency", 1, NULL, 't'},
		{"format", 1, NULL, 'f'},
		{"channels", 1, NULL, 'c'},
		{"rate", 1, NULL, 'r'},
		{"buffer", 1, NULL, 'B'},
		{"period", 1, NULL, 'E'},
		{"seconds", 1, NULL, 's'},
		{"nblock", 0, NULL, 'b'},
		{"effect", 0, NULL, 'e'},
		{"verbose", 0, NULL, 'v'},
		{"resample", 0, NULL, 'n'},
		{"samplerate", 1, NULL, 'A'},
		{"sync", 1, NULL, 'S'},
		{"slave", 1, NULL, 'a'},
		{"thread", 1, NULL, 'T'},
		{"mixer", 1, NULL, 'm'},
		{"ossmixer", 1, NULL, 'O'},
		{"workaround", 1, NULL, 'w'},
		{"xrun", 0, NULL, 'U'},
		{NULL, 0, NULL, 0},
	};
	int err, morehelp;
	char *arg_config = NULL;
	char *arg_pdevice = NULL;
	char *arg_cdevice = NULL;
	char *arg_pctl = NULL;
	char *arg_cctl = NULL;
	unsigned int arg_latency_req = 0;
	unsigned int arg_latency_reqtime = 10000;
	snd_pcm_format_t arg_format = SND_PCM_FORMAT_S16_LE;
	unsigned int arg_channels = 2;
	unsigned int arg_rate = 48000;
	snd_pcm_uframes_t arg_buffer_size = 0;
	snd_pcm_uframes_t arg_period_size = 0;
	unsigned long arg_loop_time = ~0UL;
	int arg_nblock = 0;
	int arg_effect = 0;
	int arg_resample = 0;
	int arg_samplerate = SRC_SINC_FASTEST + 1;
	int arg_sync = SYNC_TYPE_AUTO;
	int arg_slave = SLAVE_TYPE_AUTO;
	int arg_thread = 0;
	struct loopback *loop = NULL;
	char *arg_mixers[MAX_MIXERS];
	int arg_mixers_count = 0;
	char *arg_ossmixers[MAX_MIXERS];
	int arg_ossmixers_count = 0;
	int arg_xrun = arg_default_xrun;
	int arg_wake = arg_default_wake;

	morehelp = 0;
	while (1) {
		int c;
		if ((c = getopt_long(argc, argv,
				"hdg:P:C:X:Y:l:t:F:f:c:r:s:benvA:S:a:m:T:O:w:UW:",
				long_option, NULL)) < 0)
			break;
		switch (c) {
		case 'h':
			morehelp++;
			break;
		case 'g':
			arg_config = strdup(optarg);
			break;
		case 'd':
			daemonize = 1;
			use_syslog = 1;
			openlog("alsaloop", LOG_NDELAY|LOG_PID, LOG_DAEMON);
			break;
		case 'P':
			arg_pdevice = strdup(optarg);
			break;
		case 'C':
			arg_cdevice = strdup(optarg);
			break;
		case 'X':
			arg_pctl = strdup(optarg);
			break;
		case 'Y':
			arg_cctl = strdup(optarg);
			break;
		case 'l':
			err = atoi(optarg);
			arg_latency_req = err >= 4 ? err : 4;
			break;
		case 't':
			err = atoi(optarg);
			arg_latency_reqtime = err >= 500 ? err : 500;
			break;
		case 'f':
			arg_format = snd_pcm_format_value(optarg);
			if (arg_format == SND_PCM_FORMAT_UNKNOWN) {
				logit(LOG_WARNING, "Unknown format, setting to default S16_LE\n");
				arg_format = SND_PCM_FORMAT_S16_LE;
			}
			break;
		case 'c':
			err = atoi(optarg);
			arg_channels = err >= 1 && err < 1024 ? err : 1;
			break;
		case 'r':
			err = atoi(optarg);
			arg_rate = err >= 4000 && err < 200000 ? err : 44100;
			break;
		case 'B':
			err = atoi(optarg);
			arg_buffer_size = err >= 32 && err < 200000 ? err : 0;
			break;
		case 'E':
			err = atoi(optarg);
			arg_period_size = err >= 32 && err < 200000 ? err : 0;
			break;
		case 's':
			err = atoi(optarg);
			arg_loop_time = err >= 1 && err <= 100000 ? err : 30;
			break;
		case 'b':
			arg_nblock = 1;
			break;
		case 'e':
			arg_effect = 1;
			break;
		case 'n':
			arg_resample = 1;
			break;
		case 'A':
			if (strcasecmp(optarg, "sincbest") == 0)
				arg_samplerate = SRC_SINC_BEST_QUALITY;
			else if (strcasecmp(optarg, "sincmedium") == 0)
				arg_samplerate = SRC_SINC_MEDIUM_QUALITY;
			else if (strcasecmp(optarg, "sincfastest") == 0)
				arg_samplerate = SRC_SINC_FASTEST;
			else if (strcasecmp(optarg, "zerohold") == 0)
				arg_samplerate = SRC_ZERO_ORDER_HOLD;
			else if (strcasecmp(optarg, "linear") == 0)
				arg_samplerate = SRC_LINEAR;
			else
				arg_samplerate = atoi(optarg);
			if (arg_samplerate < 0 || arg_samplerate > SRC_LINEAR)
				arg_sync = SRC_SINC_FASTEST;
			arg_samplerate += 1;
			break;
		case 'S':
			if (strcasecmp(optarg, "samplerate") == 0)
				arg_sync = SYNC_TYPE_SAMPLERATE;
			else if (optarg[0] == 'n')
				arg_sync = SYNC_TYPE_NONE;
			else if (optarg[0] == 's')
				arg_sync = SYNC_TYPE_SIMPLE;
			else if (optarg[0] == 'c')
				arg_sync = SYNC_TYPE_CAPTRATESHIFT;
			else if (optarg[0] == 'p')
				arg_sync = SYNC_TYPE_PLAYRATESHIFT;
			else if (optarg[0] == 'r')
				arg_sync = SYNC_TYPE_SAMPLERATE;
			else
				arg_sync = atoi(optarg);
			if (arg_sync < 0 || arg_sync > SYNC_TYPE_LAST)
				arg_sync = SYNC_TYPE_AUTO;
			break;
		case 'a':
			if (optarg[0] == 'a')
				arg_slave = SLAVE_TYPE_AUTO;
			else if (strcasecmp(optarg, "on") == 0)
				arg_slave = SLAVE_TYPE_ON;
			else if (strcasecmp(optarg, "off") == 0)
				arg_slave = SLAVE_TYPE_OFF;
			else
				arg_slave = atoi(optarg);
			if (arg_slave < 0 || arg_slave > SLAVE_TYPE_LAST)
				arg_slave = SLAVE_TYPE_AUTO;
			break;
		case 'T':
			arg_thread = atoi(optarg);
			if (arg_thread < 0)
				arg_thread = 10000000 + loopbacks_count;
			break;
		case 'm':
			if (arg_mixers_count >= MAX_MIXERS) {
				logit(LOG_CRIT, "Maximum redirected mixer controls reached (max %i)\n", (int)MAX_MIXERS);
				return EXIT_FAILURE;
			}
			arg_mixers[arg_mixers_count++] = optarg;
			break;
		case 'O':
			if (arg_ossmixers_count >= MAX_MIXERS) {
				logit(LOG_CRIT, "Maximum redirected mixer controls reached (max %i)\n", (int)MAX_MIXERS);
				return EXIT_FAILURE;
			}
			arg_ossmixers[arg_ossmixers_count++] = optarg;
			break;
		case 'v':
			verbose++;
			break;
		case 'w':
			if (strcasecmp(optarg, "serialopen") == 0)
				workarounds |= WORKAROUND_SERIALOPEN;
			break;
		case 'U':
			arg_xrun = 1;
			if (cmdline)
				arg_default_xrun = 1;
			break;
		case 'W':
			arg_wake = atoi(optarg);
			if (cmdline)
				arg_default_wake = arg_wake;
			break;
		}
	}

	if (morehelp) {
		help();
		return EXIT_SUCCESS;
	}
	if (arg_config == NULL) {
		struct loopback_handle *play;
		struct loopback_handle *capt;
		err = create_loopback_handle(&play, arg_pdevice, arg_pctl, "playback");
		if (err < 0) {
			logit(LOG_CRIT, "Unable to create playback handle.\n");
			return EXIT_FAILURE;
		}
		err = create_loopback_handle(&capt, arg_cdevice, arg_cctl, "capture");
		if (err < 0) {
			logit(LOG_CRIT, "Unable to create capture handle.\n");
			return EXIT_FAILURE;
		}
		err = create_loopback(&loop, play, capt, output);
		if (err < 0) {
			logit(LOG_CRIT, "Unable to create loopback handle.\n");
			return EXIT_FAILURE;
		}
		play->format = capt->format = arg_format;
		play->rate = play->rate_req = capt->rate = capt->rate_req = arg_rate;
		play->channels = capt->channels = arg_channels;
		play->buffer_size_req = capt->buffer_size_req = arg_buffer_size;
		play->period_size_req = capt->period_size_req = arg_period_size;
		play->resample = capt->resample = arg_resample;
		play->nblock = capt->nblock = arg_nblock ? 1 : 0;
		loop->latency_req = arg_latency_req;
		loop->latency_reqtime = arg_latency_reqtime;
		loop->sync = arg_sync;
		loop->slave = arg_slave;
		loop->thread = arg_thread;
		loop->xrun = arg_xrun;
		loop->wake = arg_wake;
		err = add_mixers(loop, arg_mixers, arg_mixers_count);
		if (err < 0) {
			logit(LOG_CRIT, "Unable to add mixer controls.\n");
			return EXIT_FAILURE;
		}
		err = add_oss_mixers(loop, arg_ossmixers, arg_ossmixers_count);
		if (err < 0) {
			logit(LOG_CRIT, "Unable to add ossmixer controls.\n");
			return EXIT_FAILURE;
		}
#ifdef USE_SAMPLERATE
		loop->src_enable = arg_samplerate > 0;
		if (loop->src_enable)
			loop->src_converter_type = arg_samplerate - 1;
#else
		if (arg_samplerate > 0) {
			logit(LOG_CRIT, "No libsamplerate support.\n");
			return EXIT_FAILURE;
		}
#endif
		set_loop_time(loop, arg_loop_time);
		add_loop(loop);
		return 0;
	}

	return parse_config_file(arg_config, output);
}