diff options
-rw-r--r-- | include/xas/vox.h | 12 | ||||
-rw-r--r-- | src/vox.c | 58 |
2 files changed, 65 insertions, 5 deletions
diff --git a/include/xas/vox.h b/include/xas/vox.h index 7aa43e4..5a1cacf 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -54,6 +54,18 @@ int xas_vox_set_parameter(xas_vox *vox, const char *name, const char *value); +int xas_vox_set_parameter_str(xas_vox *vox, + const char *name, + const char *value); + +int xas_vox_set_parameter_float(xas_vox *vox, + const char *name, + float value); + +int xas_vox_set_parameter_int(xas_vox *vox, + const char *name, + int value); + int xas_vox_stop(xas_vox *vox); int xas_vox_active(xas_vox *vox); @@ -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); |