diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vox.c | 58 |
1 files changed, 53 insertions, 5 deletions
@@ -1,3 +1,4 @@ +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -87,6 +88,12 @@ static int vox_start(xas_vox *vox) { (void)vox_stop(vox); } + if (vox->tmpfh) { + if (fflush(vox->tmpfh) < 0) { + goto error_fflush; + } + } + if (pipe(pipe_stdin) < 0) { goto error_pipe_stdin; } @@ -168,6 +175,7 @@ error_pipe_stdout: (void)close(pipe_stdin[0]); error_pipe_stdin: +error_fflush: return -1; } @@ -276,6 +284,7 @@ xas_vox *xas_vox_new_args(xas_audio_format format, memset(vox->tmpfile, '\0', sizeof(vox->tmpfile)); vox->tmpfd = -1; + vox->tmpfh = NULL; return vox; @@ -317,26 +326,65 @@ error_tmpfile_open: return -1; } -int xas_vox_set_parameter(xas_vox *vox, +static int set_parameter_va(xas_vox *vox, const char *name, - const char *value) { + const char *format, + ...) { + va_list args; + if (tmpfile_open(vox) < 0) { goto error_tmpfile_open; } - if (fprintf(vox->tmpfh, "(Parameter.set '%s %s)\n", - name, - value) < 0) { + va_start(args, format); + + if (fprintf(vox->tmpfh, "(Parameter.set '%s ", name) < 0) { + goto error_fprintf; + } + + if (vfprintf(vox->tmpfh, format, args) < 0) { + goto error_fprintf; + } + + if (fprintf(vox->tmpfh, ")\n") < 0) { goto error_fprintf; } + va_end(args); + return 0; error_fprintf: + va_end(args); + error_tmpfile_open: return -1; } +int xas_vox_set_parameter(xas_vox *vox, + const char *name, + const char *value) { + return set_parameter_va(vox, name, "%s", value); +} + +int xas_vox_set_parameter_str(xas_vox *vox, + const char *name, + const char *value) { + return set_parameter_va(vox, name, "\"%s\"", value); +} + +int xas_vox_set_parameter_float(xas_vox *vox, + const char *name, + float value) { + return set_parameter_va(vox, name, "%f", value); +} + +int xas_vox_set_parameter_int(xas_vox *vox, + const char *name, + int value) { + return set_parameter_va(vox, name, "%d", value); +} + int xas_vox_stop(xas_vox *vox) { if (vox->state == XAS_VOX_ACTIVE) { return vox_stop(vox); |