From eed6ff683cf124f43a21191ffa11278d9dbd7ff3 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sat, 30 Nov 2024 17:49:02 +0100 Subject: audio/pcm: Add a proram to play audio files --- userland/pcm/pcm.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 userland/pcm/pcm.c (limited to 'userland/pcm/pcm.c') diff --git a/userland/pcm/pcm.c b/userland/pcm/pcm.c new file mode 100644 index 0000000..780bbeb --- /dev/null +++ b/userland/pcm/pcm.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + if (argc < 2) { + printf("provide command line arguments dumbass\n"); + return 1; + } + + char *filename = argv[1]; + int fd = open(filename, O_READ, 0); + if (-1 == fd) { + perror("open"); + return 1; + } + int audio_fd = open("/dev/audio", O_WRITE, 0); + if (-1 == audio_fd) { + perror("open"); + return 1; + } + + char *buffer = malloc(128000); + + for (;;) { + int rc; + if (0 == (rc = read(fd, buffer, 128000))) { + break; + } + write(audio_fd, buffer, rc); + } + + free(buffer); + close(audio_fd); + close(fd); + return 0; +} -- cgit v1.2.3