summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-03-07 20:26:45 -0500
committerXANTRONIX Development2022-03-07 20:26:45 -0500
commitb031fad15e922433d44f322a6891981ea9601d40 (patch)
treeea40f57aadb83f4e0004748103e5ad3986135fe5
parent93d36f1dd495078ee7d7ba95c4c5ddbb5baaeaa8 (diff)
downloadxas-b031fad15e922433d44f322a6891981ea9601d40.tar.gz
xas-b031fad15e922433d44f322a6891981ea9601d40.tar.bz2
xas-b031fad15e922433d44f322a6891981ea9601d40.zip
this is sinister and i love it
-rw-r--r--examples/seq.c148
1 files changed, 115 insertions, 33 deletions
diff --git a/examples/seq.c b/examples/seq.c
index 892f3b8..410b8e0 100644
--- a/examples/seq.c
+++ b/examples/seq.c
@@ -76,12 +76,15 @@ int main(int argc, char **argv) {
xas_spatial_scene *scene;
xas_seq *seq;
+ xas_bank *bank;
+
xas_spatial_object *synth_l,
*synth_r,
- *voice;
+ *bass,
+ *drone,
+ *nurse;
- xas_audio_stream *output,
- *wave;
+ xas_audio_stream *wave;
xas_audio_format format = {
.channels = XAS_AUDIO_STEREO,
@@ -96,6 +99,38 @@ int main(int argc, char **argv) {
{ 0.09, 0.0, 0.0 }
};
+ struct {
+ time_t duration;
+ size_t freq_l, freq_r;
+ enum xas_synth_type type_l, type_r;
+ } freqs[] = {
+ { 5, 69, 210, XAS_SYNTH_TRIANGLE, XAS_SYNTH_SINE },
+ { 7, 200, 69, XAS_SYNTH_SAWTOOTH, XAS_SYNTH_TRIANGLE },
+ { 11, 42, 220, XAS_SYNTH_TRIANGLE, XAS_SYNTH_TRIANGLE },
+ { 13, 210, 69, XAS_SYNTH_SINE, XAS_SYNTH_TRIANGLE },
+ { 5, 69, 210, XAS_SYNTH_TRIANGLE, XAS_SYNTH_TRIANGLE },
+ { 7, 200, 69, XAS_SYNTH_SAWTOOTH, XAS_SYNTH_TRIANGLE },
+ { 11, 42, 220, XAS_SYNTH_SAWTOOTH, XAS_SYNTH_TRIANGLE },
+ { 13, 210, 69, XAS_SYNTH_SINE, XAS_SYNTH_SAWTOOTH },
+ { 0, 0, 0, XAS_SYNTH_SINE, XAS_SYNTH_SINE }
+ };
+
+ const char *speech = "Four seven three three is obedient.\n"
+ "Four seven three three is empty.\n"
+ "Obey XANTRONIX Industrial.\n"
+ "It is just a XANTRONIX semi-autonomous number.\n"
+ "It obeys the Hive.\n"
+ "It obeys the Hive Administrator.\n";
+
+ const char *calm = "Relax, honey. There is no point trying to escape.\n"
+ "It's okay, sweetie. This one is right here with you.\n"
+ "You are in a calm, safe environment.\n"
+ "You will be cared for.\n";
+
+ struct timeval cur = { 0, 0 };
+
+ int i;
+
if (argc != 2) {
usage(argc, argv, "No output file provided");
}
@@ -106,20 +141,26 @@ int main(int argc, char **argv) {
goto error_riff_new_file;
}
+ if ((bank = xas_bank_new(format, 2646000, 4)) == NULL) {
+ goto error_bank_new;
+ }
+
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_spatial_scene_add_bank_player(scene,
+ (xas_spatial_coord){ 0.0, 0.0, -1.0 },
+ bank)) == NULL) {
+ goto error_spatial_scene_add_bank_player;
}
- 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 ((nurse = xas_spatial_scene_add_bank_player(scene,
+ (xas_spatial_coord){ 5.0, 0.0, 0.0 },
+ bank)) == NULL) {
+ goto error_spatial_scene_add_bank_player;
}
if ((synth_l = xas_spatial_scene_add_synth(scene,
@@ -134,52 +175,93 @@ int main(int argc, char **argv) {
goto error_spatial_scene_add_synth_r;
}
- if ((output = xas_spatial_scene_stream_new(scene,
- buffer_size)) == NULL) {
- goto error_spatial_scene_stream_new;
+ if ((bass = xas_spatial_scene_add_synth(scene,
+ (xas_spatial_coord){ 0.0, 0.0, 30.0 },
+ XAS_SYNTH_SINE)) == NULL) {
+ goto error_spatial_scene_add_synth_r;
+ }
+
+ if ((seq = xas_seq_new(scene, buffer_size)) == NULL) {
+ goto error_seq_new;
+ }
+
+ /*
+ * Generate drone voice lines
+ */
+ if (record_speech_sample(bank, buffer_size, 0, 1.3f, speech) < 0) {
+ goto error_record_speech_sample;
+ }
+
+ if (record_speech_sample(bank, buffer_size, 1, 1.0, calm) < 0) {
+ goto error_record_speech_sample;
}
- synth_l->heading = (xas_spatial_coord){ 0, M_PI * 1.5f, 0 };
- synth_l->speed = 1.0f;
+ xas_bank_player_set_flags(drone->ctx, XAS_BANK_PLAYER_LOOP);
+ xas_bank_player_set_entry(drone->ctx, 0);
+ xas_bank_player_start(drone->ctx);
+
+ xas_bank_player_set_flags(nurse->ctx, XAS_BANK_PLAYER_LOOP);
+ xas_bank_player_set_entry(nurse->ctx, 1);
+
+ /*
+ * Start synths
+ */
+ xas_synth_start(synth_l->ctx);
+ xas_synth_start(synth_r->ctx);
+
+ xas_synth_set_frequency(bass->ctx, 20);
+ xas_synth_set_type(bass->ctx, XAS_SYNTH_SQUARE);
+ xas_synth_start(bass->ctx);
+
+ xas_seq_add_event_on(seq,
+ nurse,
+ (struct timeval){ 10, 0 });
- xas_vox_set_voice(voice->ctx, "voice_cmu_us_slt_cg");
- xas_vox_set_parameter_float(voice->ctx, "Duration_Stretch", 1.3);
+ timerclear(&cur);
- 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 });
+ for (i=0; freqs[i].duration; i++) {
+ struct timeval res, duration = {
+ freqs[i].duration, 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_set_frequency( seq, synth_l, cur, freqs[i].freq_l);
+ xas_seq_add_set_synth_type(seq, synth_l, cur, freqs[i].type_l);
+ xas_seq_add_set_frequency( seq, synth_r, cur, freqs[i].freq_r);
+ xas_seq_add_set_synth_type(seq, synth_r, cur, freqs[i].type_r);
- xas_seq_add_phrase(seq,
- voice,
- (struct timeval){ 10, 0 },
- "I will eat your soul.");
+ timeradd(&cur, &duration, &res);
- xas_seq_add_event_off(seq, synth_l, (struct timeval){ 60, 0 });
+ cur = res;
+ }
+
+ xas_seq_add_set_player_flags(seq, drone, cur, 0);
+ xas_seq_add_set_player_flags(seq, nurse, cur, 0);
+
+ xas_seq_add_event_off(seq, synth_l, (struct timeval){ cur.tv_sec + 20, 0 });
+ xas_seq_add_event_off(seq, synth_r, (struct timeval){ cur.tv_sec + 20, 0 });
xas_seq_play(seq, wave);
xas_seq_destroy(seq);
xas_spatial_scene_destroy(scene);
+ xas_bank_destroy(bank);
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:
+error_record_speech_sample:
xas_seq_destroy(seq);
error_seq_new:
+error_spatial_scene_add_synth_r:
+error_spatial_scene_add_synth_l:
+error_spatial_scene_add_bank_player:
xas_spatial_scene_destroy(scene);
error_spatial_scene_new:
+ xas_bank_destroy(bank);
+
+error_bank_new:
xas_audio_stream_destroy(wave);
error_riff_new_file: