summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile2
-rw-r--r--examples/open.c50
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;
+}