toaruos/apps/play.c

49 lines
1.0 KiB
C
Raw Normal View History

/**
* @brief play - Play back PCM samples
2018-08-15 04:07:33 +03:00
*
* This needs very specifically-formatted PCM data to function
* properly - 16-bit, signed, stereo, little endian, and 48KHz.
*
* TODO This should be fixed up to play back WAV files properly.
* We have a sample rate convert in the out-of-repo playmp3
*
* @copyright
* 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-2018 K. Lange
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;
}