Exemplo n.º 1
0
/*
 * Play a file and wait for it to complete
 */
void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
  
  // see if an error occurred while playing
  sdErrorCheck();
}
Exemplo n.º 2
0
static void 
playlist(FILE *conn) 
{
	while(root->next != NULL) {
		playfile(conn, root);
		root = root->next;
	}
}
Exemplo n.º 3
0
void playcomplete(char *name) {
  uint16_t potval;
  uint32_t newsamplerate;
  
  playfile(name);
  samplerate = wave.dwSamplesPerSec;
  while (wave.isplaying) {     
	// you can do stuff here!
	delay(500);
   }
  card.close_file(f);
}
Exemplo n.º 4
0
static void replay_start(void)
{
    tty tev_vt;
    ttyrec_frame tev_tail;
    struct timeval doomsday;

    ttyrec_free(ttr);
    tev_vt=tty_init(defsx, defsy, 1);
    tev_vt->cp437=1;
    tty_printf(tev_vt, "\e[36m");
    tty_printf(tev_vt, _("Termplay v%s\n\n"),
        "\e[36;1m"PACKAGE_VERSION"\e[0;36m");
    tty_printf(tev_vt, "\e[0m");

    tr.tv_sec=tr.tv_usec=0;
    tev_done=0;
    tmax.tv_sec=tmax.tv_usec=0;
    progmax=0;
    progdiv=1000000;
    progval=-1;
    // TODO: re-enable threading
#ifdef THREADED
    pth=CreateThread(0, 0, (LPTHREAD_START_ROUTINE)playfile, (LPDWORD)0, 0, 0);
#else
//    printf("Buffering: started.\n");
    playfile(tev_vt);
//    printf("Buffering: done.\n");
    tev_done=1;
    tev_cur=ttyrec_seek(ttr, 0, 0);
    tdate=tev_cur->t;
    replay_seek();
    doomsday.tv_sec=1ULL<<(sizeof(doomsday.tv_sec)*8-1)-1;
    doomsday.tv_usec=0;
    tev_tail=ttyrec_seek(ttr, &doomsday, 0);
    tmax=tev_tail->t;
    tsub(tmax, tdate);
    if (tmax.tv_sec<100)
        progdiv=10000;
    else
        progdiv=1000000;
    selstart.tv_sec=0;
    selstart.tv_usec=0;
    selend=tmax;
    progmax=tmax.tv_sec*(1000000/progdiv)+tmax.tv_usec/progdiv;
    set_prog_max();
    set_prog();
#endif
}
Exemplo n.º 5
0
void loop() {
  if (!wave.isplaying) {
    // dump to the serial port just for grins
    ls();
    delay (1000);
    
    char * filename = file_at_index(last_played);
    if (filename == NULL) {
      last_played = 1;
    } else {
      Serial.print("Playing file");
      Serial.println(filename);
      card.reset_dir();
      playfile(filename);
      last_played++;
    }
  }
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    FILE *fp;

    if (argc < 2) {
	printf("usage: %s <filename>\n", argv[0]);
	exit(1);
    }

    fp = fopen(argv[1], "rb");
    if (fp == NULL) {
	printf("Cannot open %s.\n", argv[1]);
	exit(2);
    }

    playfile(fp);
    fclose(fp);

    return 0;
}
Exemplo n.º 7
0
FRESULT scan_files(void)
{
	FRESULT res;
	FILINFO fno;
	FIL fp;
	DIR dir;
	int j;
	char *fn;
	char path[64];

	strcpy(path, "0:");
	res = f_opendir(&dir, path);
	if (res == FR_OK) {

		for (;;) {
			res = f_readdir(&dir, &fno);
			fn = fno.fname;

			if (res || !fn[0]) { break; }
			if (fn[0] == '.' || fn[0] == '_') { continue; }

			j = strlen(fn);
			if (j < 4) continue;
			if (fn[j-4] != '.' || fn[j-3] != 'W' || fn[j-2] != 'A' || fn[j-1] != 'V') continue;

			strcpy(&path[2], fn);

			res = f_open(&fp, path, FA_OPEN_EXISTING | FA_READ);
			if (res == FR_OK) {
				playfile(&fp);
				break;
			}
		}

	} else {
	}
	return res;
}
Exemplo n.º 8
0
static void file_dirty(void)
{
	char *page;
	char fn[PATHBUFLEN];
	fn[0] = 0;
	int fd = playfile(fn);

	page = checked_mmap(NULL, PS, PROT_READ, MAP_SHARED|MAP_POPULATE, fd, 0);
	testmem("dirty file initial", page, MREAD);
	expecterr("msync expect error", msync(page, PS, MS_SYNC) < 0);
	close(fd);
	munmap_reserve(page, PS);

	fd = open(fn, O_RDONLY);
	if (fd < 0) err("reopening temp file");
	page = checked_mmap(NULL, PS, PROT_READ, MAP_SHARED|MAP_POPULATE, fd, 0);
	recover("dirty file populated", page, MREAD_OK);
	close(fd);
	munmap_reserve(page, PS);

	fd = open(fn, O_RDONLY);
	if (fd < 0) err("reopening temp file");
	page = checked_mmap(NULL, PS, PROT_READ, MAP_SHARED, fd, 0);
	recover("dirty file fault", page, MREAD_OK);
	close(fd);
	munmap_reserve(page, PS);

	fd = open(fn, O_RDWR);
	char buf[128];
	expecterr("explicit read after poison", read(fd, buf, sizeof buf) < 0);
	expecterr("explicit write after poison", write(fd, "foobar", 6) < 0);
	optionalerr("fsync expect error", fsync(fd) < 0);
	close(fd);

	/* should unlink return an error here? */
	if (unlink(fn) < 0)
		perror("unlink");
}
Exemplo n.º 9
0
int
main(int argc, char **argv)
{
	int ch;
	int example = 0;
	int gmreset = 0;
	char *file = NULL;
	FILE *f;
	const char *errstr;
	struct sigaction sa;
	struct itimerval it;

	while ((ch = getopt(argc, argv, "?d:f:glmqt:vx")) != -1) {
		switch (ch) {
		case 'f':
			file = optarg;
			break;
		case 'g':
			gmreset = 1;
			break;
		case 'm':
			showmeta = 1;
			break;
		case 'q':
			play = 0;
			break;
		case 't':
			tempo = 60 * 1000000 / 
			    strtonum(optarg, 40, 240, &errstr);
			if (errstr)
				errx(1, "tempo is %s: %s", errstr, optarg);
			break;
		case 'v':
			verbose++;
			break;
		case 'x':
			example = 1;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;
    
	hdl = mio_open(file, MIO_OUT, 0);
	if (hdl == NULL)
		errx(1, "failed to open MIDI output");
	if (gmreset)
		midireset();

	sa.sa_flags = SA_RESTART;
	sa.sa_handler = sigalrm;
	sigfillset(&sa.sa_mask);
	if (sigaction(SIGALRM, &sa, NULL) < 0)
		err(1, "sigaction");
	it.it_interval.tv_sec = it.it_value.tv_sec = 0;
	it.it_interval.tv_usec = it.it_value.tv_usec = 1000;
	if (setitimer(ITIMER_REAL, &it, NULL) < 0)
		err(1, "setitimer");

	if (example)
		playdata(sample, sizeof sample, "<Gubben Noa>");
	else if (argc == 0)
		playfile(stdin, "<stdin>");
	else
		while (argc--) {
			f = fopen(*argv, "r");
			if (f == NULL)
				err(1, "%s", *argv);
			else {
				playfile(f, *argv);
				fclose(f);
			}
			argv++;
		}

	exit(0);
}
Exemplo n.º 10
0
int 
handleclient(int conn) 
{
	char *basedir;
	char *clientdir;
	mp3entry *mp3buf;
	FILE *stream;

	if ((stream = fdopen(conn, "r+")) == NULL || !readrequest(stream)) {
		debug(1, "error while reading client request");
		fclose(stream);
		return(EXIT_FAILURE);
	}
	
	debug(1, "requested path %s", conf.path);

	GETCWD(basedir);
	if(chdir(conf.path))
		die("incorrect dir");
	GETCWD(clientdir);
	
	debug(1, "doing security checks");
	if(strncmp(basedir, clientdir, strlen(basedir) - 1)) {
		fclose(stream);
		debug(1, "basedir %s, clientdir %s", basedir, clientdir);
		die("client tried to break out of base directory");
	}
	
	debug(1, "looking for mp3 files in subdirectory %s", conf.path);
	if(!MODE_ISSET(MODE_SINGLE)) {
		getfiles(".");
	} else if(validfile(conf.filename, clientdir, &mp3buf)) { 
		addentry(&root, mp3buf);
	}
	
	if(!root)
		die("no files");
	else
		debug(1, "%d MP3 file(s) found", countentries(root));

	if(!MODE_ISSET(MODE_INDEX) && !conf.order) {
		debug(1, "shuffling mp3 files");
		shuffleentries();
	}

	if(conf.debuglevel > 2) {
		debug(1, "listing mp3 files");
		dumpentries();
	}
	
	if(MODE_ISSET(MODE_INDEX)) {
		debug(1, "entering HTTP mode");
		fprintf(stream, HTTPSERVMSG, AMPLE_VERSION);
		fflush(stream);
		createhtml(stream,(clientdir + strlen(basedir)),(strlen(clientdir) + 1));
	} else if(MODE_ISSET(MODE_SINGLE)) {
		debug(1, "entering MP3-Single mode");
		fprintf(stream, SINGLESERVMSG, AMPLE_VERSION, root->filesize);
		fflush(stream);
		playfile(stream, root);
	} else if (MODE_ISSET(MODE_METADATA)) {
		debug(1, "entering MP3-Metadata mode");
		fprintf(stream, SHOUTSERVMSG, AMPLE_VERSION, conf.servername, BYTESBETWEENMETA);
		fflush(stream);
		playlist(stream);
	} else {
		debug(1, "entering MP3-Basic mode");
		fprintf(stream, BASICSERVMSG, AMPLE_VERSION);
		fflush(stream);
		playlist(stream);
	}

	fclose(stream);
	clearlist(root);
	return(EXIT_SUCCESS);
}