diff options
author | XANTRONIX Development | 2022-02-01 14:28:35 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-02-01 14:28:35 -0500 |
commit | 0cdfdf8c867ac5582968e32a869d1ce3833aabb8 (patch) | |
tree | b3fe40a97e8612f648cf1ff4b0b663a252aa948c /examples | |
parent | 2c1fae9184f6fc55e5f55be331c67990d6a1bde1 (diff) | |
download | xas-0cdfdf8c867ac5582968e32a869d1ce3833aabb8.tar.gz xas-0cdfdf8c867ac5582968e32a869d1ce3833aabb8.tar.bz2 xas-0cdfdf8c867ac5582968e32a869d1ce3833aabb8.zip |
Add examples/open.c
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile | 2 | ||||
-rw-r--r-- | examples/open.c | 50 |
2 files changed, 51 insertions, 1 deletions
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 <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_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; +} |