Example #1
0
static void resample(long first, long last)
{
    begin_operation("Resampling audio data");
    resample_audio_data(&prefs, first, last);
    end_operation();
    save_sample_block_data(&prefs);
    display_times();
}
Example #2
0
int
main (int argc, char *argv[])
{
	struct itimerval itv;
	clock_t prevClock;
	int maxSigs;
	int sigCnt;
	struct sigaction sa;
	int ret;

	if (argc > 1 && strcmp (argv[1], "--help") == 0) {
		printf ("usage: %s [<secs> [<interval secs>]]\n", argv[0]);
		return 0;
	}

	sigCnt = 0;

	ret = sigemptyset (&sa.sa_mask);
	if (ret == -1) {
		perror ("sigemptyset()");
		return 1;
	}
	sa.sa_flags = 0;
	sa.sa_handler = signal_handler;
	ret = sigaction (SIGALRM, &sa, NULL);
	if (ret == -1) {
		perror ("sigaction()");
		return 1;
	}

	// set timer from cmdline
	itv.it_value.tv_sec = (argc > 1)? atol (argv[1]) : 2;
	itv.it_value.tv_usec = 0;
	itv.it_interval.tv_sec = (argc > 2)? atol (argv[2]) : 0;
	itv.it_interval.tv_usec = 0;

	maxSigs = (itv.it_interval.tv_sec == 0)? 1 : 3;
	display_times ("start:", false);

	ret = setitimer (ITIMER_REAL, &itv, NULL);
	if (ret == -1) {
		perror ("setitimer()");
		return 1;
	}

	prevClock = clock ();
	sigCnt = 0;

	for (;;) {
		while (((clock () - prevClock) * 10 / CLOCKS_PER_SEC) < 5) {
			if (gotAlarm_G) {
				gotAlarm_G = 0;
				display_times ("alarm:", true);

				++sigCnt;
				if (sigCnt >= maxSigs) {
					printf ("done\n");
					return 0;
				}
			}
		}

		prevClock = clock ();
		display_times ("main:", true);
	}
}
Example #3
0
int main(int argc, char **argv)
{
	FILE *port;
	char *filename;
	int c, i, j, tmp;
	int debugmode = 0;
	int lanes;
    float times[MAX_LANES];
	float prev_times[MAX_LANES][4];
    int prev_head = 0;\
	char *tmpbuf[10];
    
	/* parse command line options */
	if (argc == 1) {
		usage();
		return 0;
	}

	opterr = 0;
	while ((c = getopt (argc, argv, "dp:")) != -1) {
		switch (c) {
		case 'd':
			printf("Debugging mode enabled\n");
			debugmode = 1;
			break;
		case 'p':
			filename = optarg;
			break;
		case '?':
		default:
			usage();
			return 1;
		}
	}

	/* open timer */
	port = open_timer(filename, !debugmode);
	if (!port) {
		fprintf(stderr, "Eek! Unable to open timer port! Cannot continue.\n");
		fprintf(stderr, "Possible problems:\n");
		fprintf(stderr, "\tbad filename for port (if USB timer, check dmesg for port id\n");
		fprintf(stderr, "\tno write access to device (check permissions or run as root)\n");
		fprintf(stderr, "\tUSB timer not connected\n");
		return 1;
	}
	/* reset timer */
	lanes = init_timer(port);
	if (!lanes) {
		fprintf(stderr, "Eek! Cannot initialize timer! Cannot continue!\n");
		fprintf(stderr, "Make sure your timer is supported by this program.\n");
		close_timer(port);
		return 1;
	}

	memset(prev_times, 0, sizeof(float) * 3 * MAX_LANES);
    printf("Press enter to continue.\n");
    fgets(tmpbuf, 10, stdin);

	/* main loop */
	while (1) {
		printf("Begin racing when ready.\n");
		tmp = get_times(port, lanes, times, debugmode);
		printf("Run is complete. Results:\n");
		if (tmp > 0) {
			/* good race! */
            display_winner(tmp);
            printf("\n");
            // save current time, drop last time
            display_times(lanes, times);
			for (j = 0; j < lanes; j++) {
                prev_times[j][prev_head] = times[j];
			}
			printf("\nPrevious results:\n");
            i = prev_head - 1;
            if (i < 0)
                i = 3;
            while (i != prev_head) {
                for (j = 0; j < lanes; j++)
                    printf("\t%1.4f", prev_times[j][i]);
                printf("\n");
                i--;
                if (i < 0)
                    i = 3;
            }

            prev_head++;
            if (prev_head == 4)
                prev_head = 0;
		}
		if (tmp == 0) {
			printf("Null race result! Please redo this run.\n");
		}
		if (tmp < 0) {
			port = reinit_timer(port, filename, !debugmode, lanes);
			/* if this returns, we've succeeded */
		}
        printf("Press enter to continue, X to exit.\n");
		fgets(tmpbuf, 10, stdin);
        if (strchr(tmpbuf, 'x') || strchr(tmpbuf, 'X'))
			break;
		rearm_timer(port, debugmode);
	}

	/* all done */
	printf("\nDone.\n");
	close_timer(port);
	return 0;
}