summaryrefslogtreecommitdiff
path: root/userland/pcm/pcm.c
blob: 780bbeb46796a56ba14258bc9fd18d56c2efef36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}