toaruos/apps/play.c

45 lines
927 B
C
Raw Normal View History

2018-08-15 04:07:33 +03:00
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* This file is part of ToaruOS and is released under the terms
2018-04-17 17:15:25 +03:00
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2015-2018 K. Lange
2018-08-15 04:07:33 +03:00
*
* play - Play back PCM samples
*
* This needs very specifically-formatted PCM data to function
* properly - 16-bit, signed, stereo, little endian, and 48KHz.
2018-04-17 17:15:25 +03:00
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int main(int argc, char * argv[]) {
int spkr = open("/dev/dsp", O_WRONLY);
int song;
if (!strcmp(argv[1], "-")) {
song = STDIN_FILENO;
} else {
song = open(argv[1], O_RDONLY);
}
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];
int r;
2018-04-25 08:03:29 +03:00
while ((r = read(song, buf, sizeof(buf)))) {
2018-04-17 17:15:25 +03:00
write(spkr, buf, r);
}
return 0;
}