From ea5c729f69a9c6c2fb88caa48e37f6f548532b9b Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 1 Mar 2022 23:43:57 -0500 Subject: good cats renaming stuff,,, --- examples/Makefile | 2 +- examples/script.c | 125 ------------------------------------------------ examples/seq.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 126 deletions(-) delete mode 100644 examples/script.c create mode 100644 examples/seq.c (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index b167416..756fa89 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 script +EXAMPLES = test open say spatial seq all: $(EXAMPLES) diff --git a/examples/script.c b/examples/script.c deleted file mode 100644 index f9faccc..0000000 --- a/examples/script.c +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include -#include -#include -#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 output.wav\n", argv[0]); - - exit(EX_USAGE); -} - -int main(int argc, char **argv) { - xas_spatial_scene *scene; - xas_script *script; - - xas_spatial_object *synth_l, - *synth_r, - *voice; - - xas_audio_stream *output, - *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 } - }; - - 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 ((script = xas_script_new(scene, buffer_size)) == NULL) { - goto error_script_new; - } - - if ((voice = xas_spatial_scene_add_vox(scene, - (xas_spatial_coord){ 0.0, 0.0, -20.0 }, - "/usr/bin/text2wave")) == NULL) { - goto error_spatial_scene_add_vox; - } - - if ((synth_l = xas_spatial_scene_add_synth(scene, - (xas_spatial_coord){ -20.0, 0.0, 0.0 }, - XAS_SYNTH_SINE)) == NULL) { - goto error_spatial_scene_add_synth_l; - } - - if ((synth_r = xas_spatial_scene_add_synth(scene, - (xas_spatial_coord){ 20.0, 0.0, 0.0 }, - XAS_SYNTH_SINE)) == NULL) { - goto error_spatial_scene_add_synth_r; - } - - if ((output = xas_spatial_scene_stream_new(scene, - buffer_size)) == NULL) { - goto error_spatial_scene_stream_new; - } - - xas_vox_set_parameter_float(voice->ctx, "Duration_Stretch", 1.3); - - xas_script_add_set_frequency(script, synth_l, (struct timeval){ 0, 0 }, 220); - xas_script_add_event_on( script, synth_l, (struct timeval){ 0, 0 }); - xas_script_add_event_off(script, synth_l, (struct timeval){ 60, 0 }); - - xas_script_destroy(script); - xas_spatial_scene_destroy(scene); - xas_audio_stream_destroy(wave); - - return EX_OK; - -error_spatial_scene_stream_new: -error_spatial_scene_add_synth_r: -error_spatial_scene_add_synth_l: -error_spatial_scene_add_vox: - xas_script_destroy(script); - -error_script_new: - xas_spatial_scene_destroy(scene); - -error_spatial_scene_new: - xas_audio_stream_destroy(wave); - -error_riff_new_file: - return EX_OSERR; -} diff --git a/examples/seq.c b/examples/seq.c new file mode 100644 index 0000000..3c0293a --- /dev/null +++ b/examples/seq.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#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 output.wav\n", argv[0]); + + exit(EX_USAGE); +} + +int main(int argc, char **argv) { + xas_spatial_scene *scene; + xas_seq *seq; + + xas_spatial_object *synth_l, + *synth_r, + *voice; + + xas_audio_stream *output, + *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 } + }; + + 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 ((voice = xas_spatial_scene_add_vox(scene, + (xas_spatial_coord){ 0.0, 0.0, -20.0 }, + "/usr/bin/text2wave")) == NULL) { + goto error_spatial_scene_add_vox; + } + + if ((synth_l = xas_spatial_scene_add_synth(scene, + (xas_spatial_coord){ -20.0, 0.0, 0.0 }, + XAS_SYNTH_SINE)) == NULL) { + goto error_spatial_scene_add_synth_l; + } + + if ((synth_r = xas_spatial_scene_add_synth(scene, + (xas_spatial_coord){ 20.0, 0.0, 0.0 }, + XAS_SYNTH_SINE)) == NULL) { + goto error_spatial_scene_add_synth_r; + } + + if ((output = xas_spatial_scene_stream_new(scene, + buffer_size)) == NULL) { + goto error_spatial_scene_stream_new; + } + + xas_vox_set_parameter_float(voice->ctx, "Duration_Stretch", 1.3); + + xas_seq_add_set_frequency(seq, synth_l, (struct timeval){ 0, 0 }, 220); + xas_seq_add_set_frequency(seq, synth_r, (struct timeval){ 0, 0 }, 420); + xas_seq_add_event_on( seq, synth_l, (struct timeval){ 0, 0 }); + xas_seq_add_event_on( seq, synth_r, (struct timeval){ 0, 0 }); + + xas_seq_add_set_position(seq, + synth_l, + (struct timeval){ 15, 0 }, + (xas_spatial_coord){ -10.0, 0.0, 0.0 }); + + xas_seq_add_phrase(seq, + voice, + (struct timeval){ 10, 0 }, + "I will eat your soul."); + + xas_seq_add_event_off(seq, synth_l, (struct timeval){ 60, 0 }); + + xas_seq_play(seq, wave); + + xas_seq_destroy(seq); + xas_spatial_scene_destroy(scene); + xas_audio_stream_destroy(wave); + + return EX_OK; + +error_spatial_scene_stream_new: +error_spatial_scene_add_synth_r: +error_spatial_scene_add_synth_l: +error_spatial_scene_add_vox: + 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; +} -- cgit v1.2.3