diff options
-rw-r--r-- | include/xas/vox.h | 8 | ||||
-rw-r--r-- | src/vox.c | 16 |
2 files changed, 13 insertions, 11 deletions
diff --git a/include/xas/vox.h b/include/xas/vox.h index 917eda1..641fe3a 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -7,20 +7,22 @@ #include <xas/audio.h> -#define XAS_VOX_IDLE 0 -#define XAS_VOX_ACTIVE (1 << 0) typedef struct _xas_vox { +enum xas_vox_state { + XAS_VOX_IDLE, + XAS_VOX_ACTIVE +}; xas_audio_format format; size_t buffer_size; - int flags; const char *text2wave_path; int argn; char **args; + enum xas_vox_state state; int pid, stdin, @@ -38,7 +38,7 @@ static int vox_stop(xas_vox *vox) { vox->pid = -1; } - vox->flags &= ~XAS_VOX_ACTIVE; + vox->state = XAS_VOX_IDLE; return 0; @@ -83,7 +83,7 @@ static int vox_start(xas_vox *vox) { char sample_rate[40]; - if (vox->flags & XAS_VOX_ACTIVE) { + if (vox->state == XAS_VOX_ACTIVE) { (void)vox_stop(vox); } @@ -155,7 +155,7 @@ error_child: vox->stdin = pipe_stdin[1]; vox->stdout = pipe_stdout[0]; vox->in = fdopen(pipe_stdin[1], "w"); - vox->flags |= XAS_VOX_ACTIVE; + vox->state = XAS_VOX_ACTIVE; return 0; @@ -182,7 +182,7 @@ static ssize_t vox_fill(xas_vox *vox, ssize_t readlen, readcount; - if (!(vox->flags & XAS_VOX_ACTIVE)) { + if (vox->state != XAS_VOX_ACTIVE) { xas_audio_zero(vox->format, samples, 0, count); return count; @@ -224,7 +224,7 @@ xas_vox *xas_vox_new(const char *text2wave_path, vox->format.sample_rate = format.sample_rate; vox->buffer_size = buffer_size; - vox->flags = XAS_VOX_IDLE; + vox->state = XAS_VOX_IDLE; vox->pid = -1; vox->stdin = -1; vox->stdout = -1; @@ -246,7 +246,7 @@ void xas_vox_destroy(xas_vox *vox) { } int xas_vox_stop(xas_vox *vox) { - if (vox->flags & XAS_VOX_ACTIVE) { + if (vox->state == XAS_VOX_ACTIVE) { return vox_stop(vox); } @@ -254,7 +254,7 @@ int xas_vox_stop(xas_vox *vox) { } int xas_vox_active(xas_vox *vox) { - return vox->flags & XAS_VOX_ACTIVE; + return vox->state == XAS_VOX_ACTIVE; } int xas_vox_generate(xas_vox *vox) { @@ -288,7 +288,7 @@ error_riff_open_fd: } int xas_vox_vsayf(xas_vox *vox, const char *format, va_list args) { - if (!(vox->flags & XAS_VOX_ACTIVE) && vox_start(vox) < 0) { + if (vox->state == XAS_VOX_IDLE && vox_start(vox) < 0) { goto error_vox_start; } |