Exemplo n.º 1
0
int aq_soft_flush(void)
{
    int rc;

    while(head)
    {
	if(head->len < bucket_size)
	{
	    /* Add silence code */
	    memset (head->data + head->len, 0, bucket_size - head->len);
	    head->len = bucket_size;
	}
	if(aq_fill_one() == -1)
	    return RC_ERROR;
	trace_loop();
	rc = check_apply_control();
	if(RC_IS_SKIP_FILE(rc))
	{
	    play_mode->acntl(PM_REQ_DISCARD, NULL);
	    flush_buckets();
	    return rc;
	}
    }
    play_mode->acntl(PM_REQ_OUTPUT_FINISH, NULL);
    return RC_NONE;
}
Exemplo n.º 2
0
static int wait_event_time(void *p)
{
	MidiEvent *ev = (MidiEvent *)p;
	int rc, ch;

	for(;;){
		if(ev->time - (current_tick()*play_mode->rate+30)/60 < 0)
			break;
		trace_loop();
		YieldToAnyThread();
		rc = check_apply_control();
		if(RC_IS_SKIP_FILE(rc)){
			prescan = 0;
			for(ch = 0; ch < MAX_CHANNELS; ch++){
				if(note_channel[ch] != NULL){
					NADisposeNoteChannel(gNoteAllocator, note_channel[ch]);
					note_channel[ch] = NULL;
				}
				channel[ch].bank_lsb = 0;
				channel[ch].bank_msb = 0;
			}
			trace_flush();
			return rc;
		}
	}
	return RC_NONE;
}
Exemplo n.º 3
0
static int acntl(int request, void *arg)
{
    switch (request){
      case PM_REQ_GETFRAGSIZ:
	*((int *)arg) = BUFLEN;
	return 0;
        
	//case PM_REQ_GETQSIZ:
	if (total_bytes == -1)
	  return -1;
	*((int *)arg) = sizeof(globals.buffer);
	return 0;

      /*case PM_REQ_GETFILLABLE:
	if (total_bytes == -1)
	  return -1;
	if(!(dpm.encoding & PE_MONO)) i >>= 1;
	if(dpm.encoding & PE_16BIT) i >>= 1;
	*((int *)arg) = i;
	return 0;*/

      /*case PM_REQ_GETFILLED:

	i = pstatus.queue;
	if(!(dpm.encoding & PE_MONO)) i >>= 1;
	if(dpm.encoding & PE_16BIT) i >>= 1;
	*((int *)arg) = i;
	return 0;*/

    //case PM_REQ_GETSAMPLES:
          *((int *)arg) = globals.samples*2;
        /*{
            static int c=0;
            if( c%0x100000==0 ){
                ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
                        "getsamples = %d", *((int *)arg));
            
            }
        }*/

          return 0;

    case PM_REQ_DISCARD:
          AudioDeviceStop(globals.device, appIOProc);
	  init_variable();
          return 0;
	  
    case PM_REQ_PLAY_START:
	init_variable();
	return 0;
	
    case PM_REQ_FLUSH:
    case PM_REQ_OUTPUT_FINISH:
        while( globals.soundPlaying ){
	    trace_loop();
	    usleep(1000);
	}
	init_variable();
	return 0;
    
    default:
        break;
    }
    return -1;
}
Exemplo n.º 4
0
int aq_flush(int discard)
{
    int rc;
    int more_trace;

    /* to avoid infinite loop */
    double t, timeout_expect;

    aq_add_count = 0;
    init_effect();

    if(discard)
    {
	trace_flush();
	if(play_mode->acntl(PM_REQ_DISCARD, NULL) != -1)
	{
	    flush_buckets();
	    return RC_NONE;
	}
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
		  "ERROR: Can't discard audio buffer");
    }

    if(!IS_STREAM_TRACE)
    {
	play_mode->acntl(PM_REQ_FLUSH, NULL);
	play_counter = play_offset_counter = 0;
	return RC_NONE;
    }

    rc = aq_soft_flush();
    if(RC_IS_SKIP_FILE(rc))
	return rc;

    more_trace = 1;
    t = get_current_calender_time();
    timeout_expect = t + (double)aq_filled() / play_mode->rate;

    while(more_trace || aq_filled() > 0)
    {
	rc = check_apply_control();
	if(RC_IS_SKIP_FILE(rc))
	{
	    play_mode->acntl(PM_REQ_DISCARD, NULL);
	    flush_buckets();
	    return rc;
	}
	more_trace = trace_loop();

	t = get_current_calender_time();
	if(t >= timeout_expect - 0.1)
	  break;

	if(!more_trace)
	  usleep((unsigned long)((timeout_expect - t) * 1000000));
	else
	  aq_wait_ticks();
    }

    trace_flush();
    play_mode->acntl(PM_REQ_FLUSH, NULL);
    flush_buckets();
    return RC_NONE;
}
Exemplo n.º 5
0
int aq_add(int32 *samples, int32 count)
{
    int32 nbytes, i;
    char *buff;

    if(!(play_mode->flag & PF_PCM_STREAM))
	return 0;

    if(!count)
    {
	if(!aq_fill_buffer_flag)
	    return aq_fill_nonblocking();
	return 0;
    }

    aq_add_count += count;
    do_effect(samples, count);
    nbytes = general_output_convert(samples, count);
    buff = (char *)samples;

    if(device_qsize == 0)
      return play_mode->output_data(buff, nbytes);

    aq_fill_buffer_flag = (aq_add_count <= aq_start_count);

    if(!aq_fill_buffer_flag)
	if(aq_fill_nonblocking() == -1)
	    return -1;

    if(!ctl->trace_playing)
    {
	while((i = add_play_bucket(buff, nbytes)) < nbytes)
	{
	    buff += i;
	    nbytes -= i;
	    if(head && head->len == bucket_size)
	    {
		if(aq_fill_one() == -1)
		    return -1;
	    }
	    aq_fill_buffer_flag = 0;
	}
	return 0;
    }

    trace_loop();
    while((i = add_play_bucket(buff, nbytes)) < nbytes)
    {
	/* Software buffer is full.
	 * Write one bucket to audio device.
	 */
	buff += i;
	nbytes -= i;
	aq_wait_ticks();
	trace_loop();
	if(aq_fill_nonblocking() == -1)
	    return -1;
	aq_fill_buffer_flag = 0;
    }
    return 0;
}
Exemplo n.º 6
0
int
main(int argc, char *argv[])
{
#define	MAX_RCVBUF 127*1024
#define	MIN_RCVBUF  4*1024

	int ch, bsize, soc;
	char *p, *tmp_ptr, *options, *value, delim;
	const char *result;
	in_addr_t netaddr, netmask;
	int on;

	(void) setlocale(LC_ALL, "");
#if	!defined(TEXT_DOMAIN)   /* Should be defined by cc -D */
#define	TEXT_DOMAIN	"SYS_TEXT"
#endif	/* ! TEXT_DOMAIN */

	(void) textdomain(TEXT_DOMAIN);

	OMSG.rip_nets[0].n_dst = RIP_DEFAULT;
	OMSG.rip_nets[0].n_family = RIP_AF_UNSPEC;
	OMSG.rip_nets[0].n_metric = htonl(HOPCNT_INFINITY);

	if ((pgmname = argv[0]) == NULL)
		pgmname = "rtquery";
	while ((ch = getopt(argc, argv, "np1w:r:t:a:")) != -1)
		switch (ch) {
		case 'n':
			not_trace = _B_TRUE;
			nflag = _B_TRUE;
			break;

		case 'p':
			not_trace = _B_TRUE;
			pflag = _B_TRUE;
			break;

		case '1':
			ripv2 = _B_FALSE;
			break;

		case 'w':
			not_trace = _B_TRUE;
			wtime = (int)strtoul(optarg, &p, 0);
			if (*p != '\0' || wtime <= 0 || p == optarg)
				usage();
			break;

		case 'r':
			not_trace = _B_TRUE;
			if (rflag)
				usage();
			rflag = getnet(optarg, &netaddr, &netmask);
			if (rflag) {
				OMSG.rip_nets[0].n_dst = htonl(netaddr);
				OMSG.rip_nets[0].n_family = RIP_AF_INET;
				OMSG.rip_nets[0].n_mask = htonl(netmask);
			} else {
				struct hostent *hp = gethostbyname(optarg);
				if (hp == NULL) {
					(void) fprintf(stderr, "%s: %s: %s\n",
					    pgmname, optarg,
					    hstrerror(h_errno));
					exit(EXIT_FAILURE);
				}
				(void) memcpy(&OMSG.rip_nets[0].n_dst,
				    hp->h_addr,
				    sizeof (OMSG.rip_nets[0].n_dst));
				OMSG.rip_nets[0].n_family = RIP_AF_INET;
				OMSG.rip_nets[0].n_mask = INADDR_BROADCAST;
				rflag = _B_TRUE;
			}
			break;

		case 't':
			trace = _B_TRUE;
			options = optarg;
			while (*options != '\0') {
				/* messy complications to make -W -Wall happy */
				static char on_str[] = "on";
				static char more_str[] = "more";
				static char off_str[] = "off";
				static char dump_str[] = "dump";
				static char *traceopts[] = {
#define	TRACE_ON	0
					on_str,
#define	TRACE_MORE	1
					more_str,
#define	TRACE_OFF	2
					off_str,
#define	TRACE_DUMP	3
					dump_str,
					0
				};
				result = "";
				switch (getsubopt(&options, traceopts,
				    &value)) {
				case TRACE_ON:
					OMSG.rip_cmd = RIPCMD_TRACEON;
					if (value == NULL ||
					    strlen(value) > MAXPATHLEN)
					    usage();
					result = value;
					break;
				case TRACE_MORE:
					if (value != NULL)
					    usage();
					OMSG.rip_cmd = RIPCMD_TRACEON;
					break;
				case TRACE_OFF:
					if (value != NULL)
					    usage();
					OMSG.rip_cmd = RIPCMD_TRACEOFF;
					break;
				case TRACE_DUMP:
					if (value != NULL)
					    usage();
					OMSG.rip_cmd = RIPCMD_TRACEON;
					result = "dump/../table";
					break;
				default:
					usage();
				}
				(void) strlcpy((char *)OMSG.rip_tracefile,
				    result, MAXPATHLEN);
				omsg_len += strlen(result) -
				    sizeof (OMSG.ripun);
			}
			break;

		case 'a':
			not_trace = _B_TRUE;
			p = strchr(optarg, '=');
			if (p == NULL)
				usage();
			*p++ = '\0';
			if (0 == strcasecmp("passwd", optarg))
				auth_type = RIP_AUTH_PW;
			else if (0 == strcasecmp("md5_passwd", optarg))
				auth_type = RIP_AUTH_MD5;
			else
				usage();
			if (0 > parse_quote(&p, "|", &delim,
			    passwd, sizeof (passwd)))
				usage();
			if (auth_type == RIP_AUTH_MD5 &&
			    delim == '|') {
				tmp_ptr = p+1;
				keyid = strtoul(p+1, &p, 0);
				if (keyid > 255 || *p != '\0' ||
				    p == tmp_ptr)
					usage();
			} else if (delim != '\0') {
				usage();
			}
			break;

		default:
			usage();
	}
	argv += optind;
	argc -= optind;
	if (not_trace && trace)
		usage();
	if (argc == 0) {
		argc = 1;
		argv = default_argv;
	}

	soc = socket(PF_INET, SOCK_DGRAM, 0);
	if (soc < 0) {
		perror("rtquery: socket");
		exit(EXIT_FAILURE);
	}

	on = 1;
	if (setsockopt(soc, IPPROTO_IP, IP_RECVIF, &on, sizeof (on)))
		perror("rtquery: setsockopt IP_RECVIF");

	/* be prepared to receive a lot of routes */
	for (bsize = MAX_RCVBUF; ; bsize -= 1024) {
		if (setsockopt(soc, SOL_SOCKET, SO_RCVBUF,
		    &bsize, sizeof (bsize)) == 0)
			break;
		if (bsize <= MIN_RCVBUF) {
			perror("rtquery: setsockopt SO_RCVBUF");
			break;
		}
	}

	if (trace)
		trace_loop(argv, soc);
	else
		query_loop(argv, argc, soc);
	/* NOTREACHED */
	return (0);
}