diff options
-rw-r--r-- | include/xas/vox.h | 6 | ||||
-rw-r--r-- | src/vox.c | 22 |
2 files changed, 26 insertions, 2 deletions
diff --git a/include/xas/vox.h b/include/xas/vox.h index 9d63bba..b3ea0ed 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -8,6 +8,8 @@ #include <xas/object.h> #include <xas/audio.h> +#define XAS_VOX_DEFAULT_GAIN 1.0f + #define XAS_VOX_SETTINGS_TMP_PATH "/tmp/xas-vox.XXXXXX" #define XAS_VOX_SETTINGS_TMP_PATHLEN 64 @@ -22,6 +24,8 @@ typedef struct _xas_vox { xas_audio_format format; size_t buffer_size; + float gain; + const char *text2wave_path; int argn; char **args; @@ -51,6 +55,8 @@ xas_vox *xas_vox_new(xas_audio_format format, void xas_vox_destroy(xas_vox *vox); +void xas_vox_set_gain(xas_vox *vox, float gain); + int xas_vox_set_voice(xas_vox *vox, const char *voice); int xas_vox_set_parameter(xas_vox *vox, @@ -213,6 +213,12 @@ static ssize_t vox_fill(xas_vox *vox, if (readlen == 0) { vox_stop(vox); + } else if (vox->gain != 1.0f) { + xas_audio_apply_gain(vox->format, + samples, + vox->gain, + 0, + readlen); } readcount = readlen / vox->format.sample_size; @@ -264,6 +270,12 @@ static void tmpfile_close(xas_vox *vox) { vox->tmpfh = NULL; } +static int set_gain(xas_vox *vox, float gain) { + xas_vox_set_gain(vox, gain); + + return 0; +} + xas_vox *xas_vox_new_args(xas_audio_format format, size_t buffer_size, const char *text2wave_path, @@ -275,8 +287,9 @@ xas_vox *xas_vox_new_args(xas_audio_format format, goto error_malloc_vox; } - vox->obj.start = (xas_object_start_callback)xas_vox_generate; - vox->obj.stop = (xas_object_stop_callback)xas_vox_stop; + vox->obj.start = (xas_object_start_callback)xas_vox_generate; + vox->obj.stop = (xas_object_stop_callback)xas_vox_stop; + vox->obj.set_gain = (xas_object_set_gain_callback)set_gain; vox->text2wave_path = text2wave_path; @@ -285,6 +298,7 @@ xas_vox *xas_vox_new_args(xas_audio_format format, vox->format.sample_rate = format.sample_rate; vox->buffer_size = buffer_size; + vox->gain = XAS_VOX_DEFAULT_GAIN; vox->state = XAS_VOX_IDLE; vox->pid = -1; vox->stdin = -1; @@ -322,6 +336,10 @@ void xas_vox_destroy(xas_vox *vox) { free(vox); } +void xas_vox_set_gain(xas_vox *vox, float gain) { + vox->gain = gain; +} + int xas_vox_set_voice(xas_vox *vox, const char *voice) { if (tmpfile_open(vox) < 0) { goto error_tmpfile_open; |