diff options
author | XANTRONIX Development | 2022-03-17 23:50:30 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-17 23:50:30 -0400 |
commit | 0e7217162d12db94f84445f6649011581607e6c7 (patch) | |
tree | e2dbccf289cd45b044f8c8387b61810fc16b20a1 | |
parent | 8ce8ec1c8c2531c7b78b2bf36241fa2e7b5c1da0 (diff) | |
download | xas-0e7217162d12db94f84445f6649011581607e6c7.tar.gz xas-0e7217162d12db94f84445f6649011581607e6c7.tar.bz2 xas-0e7217162d12db94f84445f6649011581607e6c7.zip |
Initial implementation of examples/beep.c
Initial implementation of examples/beep.c to exercise drone beeping!
-rw-r--r-- | examples/Makefile | 2 | ||||
-rw-r--r-- | examples/beep.c | 124 |
2 files changed, 125 insertions, 1 deletions
diff --git a/examples/Makefile b/examples/Makefile index 1146600..72e4c3d 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -8,7 +8,7 @@ LIBNAME = xas CFLAGS += -I$(INCLUDE_PATH) LDFLAGS += -L../src -l$(LIBNAME) -lm -EXAMPLES = test open say spatial seq pod +EXAMPLES = test open say spatial seq pod beep all: $(EXAMPLES) diff --git a/examples/beep.c b/examples/beep.c new file mode 100644 index 0000000..fce565a --- /dev/null +++ b/examples/beep.c @@ -0,0 +1,124 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <sysexits.h> +#include <fcntl.h> +#include <math.h> + +#include <xas/audio.h> +#include <xas/vox.h> +#include <xas/bank.h> +#include <xas/riff.h> +#include <xas/spatial.h> +#include <xas/drone.h> +#include <xas/seq.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 output.wav\n", argv[0]); + + exit(EX_USAGE); +} + +int main(int argc, char **argv) { + xas_spatial_scene *scene; + xas_seq *seq; + + xas_audio_stream *wave; + + xas_audio_format format = { + .channels = XAS_AUDIO_STEREO, + .sample_size = XAS_AUDIO_PCM_16_BIT, + .sample_rate = 44100 + }; + + size_t buffer_size = 735; + + xas_spatial_coord speakers[2] = { + { -0.09, 0.0, 0.0 }, + { 0.09, 0.0, 0.0 } + }; + + xas_drone *drone; + + struct timeval cur = { 0, 0 }; + + int mood; + + if (argc < 2) { + usage(argc, argv, "No output file provided"); + } + + if ((wave = xas_riff_new_file(argv[1], + format, + O_WRONLY | O_CREAT | O_TRUNC)) == NULL) { + goto error_riff_new_file; + } + + if ((scene = xas_spatial_scene_new(format, + speakers[0], + speakers[1])) == NULL) { + goto error_spatial_scene_new; + } + + if ((seq = xas_seq_new(scene, buffer_size)) == NULL) { + goto error_seq_new; + } + + if ((drone = xas_drone_new(scene, + (xas_spatial_coord){ 0.0, 0.0, -1.0 }, + 2646000, + 4)) == NULL) { + goto error_drone_new; + } + + timerclear(&cur); + + for (mood=0; mood<6; mood++) { + struct timeval interval = { 0, 250000 }, + tmp; + + xas_drone_seq_beep(drone, + seq, + mood, + &cur); + + timeradd(&cur, &interval, &tmp); + + cur = tmp; + } + + xas_seq_add_stop(seq, cur); + + xas_seq_play(seq, wave); + + xas_drone_destroy(drone); + xas_seq_destroy(seq); + xas_spatial_scene_destroy(scene); + xas_audio_stream_destroy(wave); + + return EX_OK; + +error_drone_new: + xas_seq_destroy(seq); + +error_seq_new: + xas_spatial_scene_destroy(scene); + +error_spatial_scene_new: + xas_audio_stream_destroy(wave); + +error_riff_new_file: + return EX_OSERR; +} |