summaryrefslogtreecommitdiffstats
path: root/examples/open.c
blob: 4bf036b929e3d707e938240160d6b83881087862 (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
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sysexits.h>
#include <fcntl.h>
#include <math.h>

#include <xas/riff.h>

static void usage(int argc, char **argv, const char *message, ...) {
    va_list args;

    va_start(args, message);

    if (message) {
        vfprintf(stderr, message, args);
        fputc('\n', stderr);
    }

    va_end(args);

    fprintf(stderr, "usage: %s file.wav\n", argv[0]);

    exit(EX_USAGE);
}

int main(int argc, char **argv) {
    xas_audio_stream *wave;

    if (argc != 2) {
        usage(argc, argv, "No input file provided");
    }

    if ((wave = xas_riff_open_file(argv[1], O_RDONLY)) == NULL) {
        goto error_riff_open_file;
    }

    printf("channels %zu sample rate %zu sample size %zu\n",
           wave->channels,
           wave->sample_rate,
           wave->sample_size);

    xas_audio_stream_destroy(wave);

    return EX_OK;

error_riff_open_file:
    return EX_OSERR;
}