diff options
author | XANTRONIX Development | 2022-03-13 19:47:25 -0400 |
---|---|---|
committer | XANTRONIX Development | 2022-03-13 19:47:25 -0400 |
commit | 5e36a3241c8b0cee8b9cfd072e8b80add88e2487 (patch) | |
tree | 89501a0c4ce6f3dae3b2ca4e52b9e70aa0fce411 | |
parent | 7eeb8f6219b4680d09cce0e08e4e507f2e22882a (diff) | |
download | xas-5e36a3241c8b0cee8b9cfd072e8b80add88e2487.tar.gz xas-5e36a3241c8b0cee8b9cfd072e8b80add88e2487.tar.bz2 xas-5e36a3241c8b0cee8b9cfd072e8b80add88e2487.zip |
Instantiate vox stream only upon generation
-rw-r--r-- | include/xas/drone.h | 11 | ||||
-rw-r--r-- | src/drone.c | 39 |
2 files changed, 17 insertions, 33 deletions
diff --git a/include/xas/drone.h b/include/xas/drone.h index d7dc4c0..9a7249b 100644 --- a/include/xas/drone.h +++ b/include/xas/drone.h @@ -11,9 +11,6 @@ #define XAS_DRONE_VOX_BUFFER_SIZE 735 #define XAS_DRONE_VOX_TEXT2WAVE_PATH "/usr/bin/text2wave" -#define XAS_DRONE_VOX_DEFAULT_SPEED 1.0f -#define XAS_DRONE_VOX_DEFAULT_VOICE "voice_cmu_us_slt_cg" - #define XAS_DRONE_CHAMBER_BASS_FREQUENCY 20 /* Hz */ #define XAS_DRONE_CHAMBER_BASS_TYPE XAS_SYNTH_SQUARE @@ -27,10 +24,6 @@ typedef struct _xas_drone { typedef struct _xas_drone_vox { xas_drone *drone; xas_vox *obj; - xas_audio_stream *source; - - const char *voice; - float speed; } xas_drone_vox; typedef struct _xas_drone_chamber_interval { @@ -83,9 +76,9 @@ xas_drone_vox *xas_drone_vox_new(xas_drone *drone); void xas_drone_vox_destroy(xas_drone_vox *vox); -void xas_drone_vox_set_voice(xas_drone_vox *vox, const char *voice); +int xas_drone_vox_set_voice(xas_drone_vox *vox, const char *voice); -void xas_drone_vox_set_speed(xas_drone_vox *vox, float speed); +int xas_drone_vox_set_speed(xas_drone_vox *vox, float speed); int xas_drone_vox_vsayf(xas_drone_vox *vox, const char *format, diff --git a/src/drone.c b/src/drone.c index e4a0cb7..3c611e4 100644 --- a/src/drone.c +++ b/src/drone.c @@ -115,19 +115,10 @@ xas_drone_vox *xas_drone_vox_new(xas_drone *drone) { goto error_vox_new; } - if ((vox->source = xas_vox_stream_new(vox->obj)) == NULL) { - goto error_vox_stream_new; - } - vox->drone = drone; - vox->voice = XAS_DRONE_VOX_DEFAULT_VOICE; - vox->speed = XAS_DRONE_VOX_DEFAULT_SPEED; return vox; -error_vox_stream_new: - xas_vox_destroy(vox->obj); - error_vox_new: free(vox); @@ -136,17 +127,18 @@ error_malloc_vox: } void xas_drone_vox_destroy(xas_drone_vox *vox) { - xas_audio_stream_destroy(vox->source); xas_vox_destroy(vox->obj); free(vox); } -void xas_drone_vox_set_voice(xas_drone_vox *vox, const char *voice) { - vox->voice = voice; +int xas_drone_vox_set_voice(xas_drone_vox *vox, const char *voice) { + return xas_vox_set_voice(vox->obj, voice); } -void xas_drone_vox_set_speed(xas_drone_vox *vox, float speed) { - vox->speed = speed; +int xas_drone_vox_set_speed(xas_drone_vox *vox, float speed) { + return xas_vox_set_parameter_float(vox->obj, + "Duration_Stretch", + 1.0f / speed); } int xas_drone_vox_say(xas_drone_vox *vox, const char *text) { @@ -173,14 +165,10 @@ int xas_drone_vox_sayf(xas_drone_vox *vox, const char *format, ...) { } int xas_drone_vox_save(xas_drone_vox *vox, size_t sample_index) { - if (vox->voice && xas_vox_set_voice(vox->obj, vox->voice) < 0) { - goto error_vox_set_voice; - } + xas_audio_stream *source; - if (xas_vox_set_parameter_float(vox->obj, - "Duration_Stretch", - 1.0f / vox->speed) < 0) { - goto error_vox_set_parameter_float; + if ((source = xas_vox_stream_new(vox->obj)) == NULL) { + goto error_vox_stream_new; } if (xas_vox_generate(vox->obj) < 0) { @@ -188,18 +176,21 @@ int xas_drone_vox_save(xas_drone_vox *vox, size_t sample_index) { } if (xas_bank_record(vox->drone->bank, - vox->source, + source, sample_index, vox->drone->bank->entry_size) < 0) { goto error_bank_record; } + xas_audio_stream_destroy(source); + return 0; error_bank_record: error_vox_generate: -error_vox_set_parameter_float: -error_vox_set_voice: + xas_audio_stream_destroy(source); + +error_vox_stream_new: return -1; } |