diff options
author | Anton Kling <anton@kling.gg> | 2024-11-30 17:49:02 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-11-30 17:49:37 +0100 |
commit | eed6ff683cf124f43a21191ffa11278d9dbd7ff3 (patch) | |
tree | b3621490015340a489d496bc1026ac99fb4096ad | |
parent | c1b3c95536ae7c66f7f5d522348f95440dab5ff0 (diff) |
audio/pcm: Add a proram to play audio files
-rw-r--r-- | userland/pcm/Makefile | 15 | ||||
-rw-r--r-- | userland/pcm/pcm.c | 40 |
2 files changed, 55 insertions, 0 deletions
diff --git a/userland/pcm/Makefile b/userland/pcm/Makefile new file mode 100644 index 0000000..7a558a3 --- /dev/null +++ b/userland/pcm/Makefile @@ -0,0 +1,15 @@ +CC="i686-sb-gcc" +CFLAGS=-ggdb -O0 -Wall -Wextra -pedantic +LDFLAGS= +BIN=pcm +OBJ=pcm.o +all: $(BIN) + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $< + +$(BIN): $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + +clean: + rm $(BIN) $(OBJ) 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 <assert.h> +#include <fcntl.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +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; +} |