toaruos/userspace/extra/play.c

39 lines
715 B
C
Raw Normal View History

2015-05-14 19:25:48 +03:00
/* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2015 Kevin Lange
*/
#include <stdio.h>
2016-09-04 14:22:20 +03:00
#include <string.h>
2015-05-14 19:25:48 +03:00
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int main(int argc, char * argv[]) {
int spkr = open("/dev/dsp", O_WRONLY);
2016-09-04 14:22:20 +03:00
int song;
if (!strcmp(argv[1], "-")) {
song = STDIN_FILENO;
} else {
song = open(argv[1], O_RDONLY);
}
2015-05-14 19:25:48 +03:00
if (spkr == -1) {
fprintf(stderr, "no dsp\n");
return 1;
}
if (song == -1) {
fprintf(stderr, "audio file not found\n");
return 2;
}
char buf[0x1000];
2016-09-04 14:22:20 +03:00
int r;
while (r = read(song, buf, sizeof(buf))) {
write(spkr, buf, r);
2015-05-14 19:25:48 +03:00
}
return 0;
}