From 0cdfdf8c867ac5582968e32a869d1ce3833aabb8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 1 Feb 2022 14:28:35 -0500 Subject: Add examples/open.c --- examples/Makefile | 2 +- examples/open.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/open.c diff --git a/examples/Makefile b/examples/Makefile index 52755fd..20adaea 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -7,7 +7,7 @@ INCLUDE_PATH = ../include CFLAGS += -I$(INCLUDE_PATH) LDFLAGS += -L../src -lxas -lm -EXAMPLES = test +EXAMPLES = test open all: $(EXAMPLES) diff --git a/examples/open.c b/examples/open.c new file mode 100644 index 0000000..45cd2e5 --- /dev/null +++ b/examples/open.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include + +#include + +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_file_open(argv[1], O_RDONLY)) == NULL) { + goto error_riff_file_open; + } + + 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_file_open: + return EX_OSERR; +} -- cgit v1.2.3