summaryrefslogtreecommitdiffstats
path: root/examples/script.c
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-01 09:47:24 -0500
committerXANTRONIX Development2022-03-01 09:47:24 -0500
commit25dfe9a0dd859ddd6b8ab1353ffbb14f727ab983 (patch)
tree0e3fd8071b300c487555fc8fb747493fd79d77c3 /examples/script.c
parent297dd2f36cfc5d4f53ee7a6528e0064d913f8b75 (diff)
downloadxas-25dfe9a0dd859ddd6b8ab1353ffbb14f727ab983.tar.gz
xas-25dfe9a0dd859ddd6b8ab1353ffbb14f727ab983.tar.bz2
xas-25dfe9a0dd859ddd6b8ab1353ffbb14f727ab983.zip
Begin work on examples/script.c scene script demo
Diffstat (limited to 'examples/script.c')
-rw-r--r--examples/script.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/examples/script.c b/examples/script.c
new file mode 100644
index 0000000..f9faccc
--- /dev/null
+++ b/examples/script.c
@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sysexits.h>
+#include <fcntl.h>
+#include <math.h>
+
+#include <xas/vox.h>
+#include <xas/audio.h>
+#include <xas/riff.h>
+#include <xas/spatial.h>
+#include <xas/script.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_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;
+}