From 8723f399b2e63693d0e90a1b0af87be865069e22 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 28 Feb 2022 13:12:34 -0500 Subject: Allow setting vox gain --- src/vox.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vox.c b/src/vox.c index cd31aa0..9f6382e 100644 --- a/src/vox.c +++ b/src/vox.c @@ -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; -- cgit v1.2.3