summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-26 23:36:50 -0500
committerXANTRONIX Development2022-02-26 23:36:50 -0500
commitab9f3166f07a43fd739262530575f30432d7782a (patch)
tree260c6a10b3d7fbb35bc092f4fdefd4e2699d3e4f
parent51806621006a9d54d368c7c033e59b2a3818f5ae (diff)
downloadxas-ab9f3166f07a43fd739262530575f30432d7782a.tar.gz
xas-ab9f3166f07a43fd739262530575f30432d7782a.tar.bz2
xas-ab9f3166f07a43fd739262530575f30432d7782a.zip
Switch to enum type for vox state
-rw-r--r--include/xas/vox.h8
-rw-r--r--src/vox.c16
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,
diff --git a/src/vox.c b/src/vox.c
index 697ff95..caa3a26 100644
--- a/src/vox.c
+++ b/src/vox.c
@@ -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;
}