summaryrefslogtreecommitdiffstats
path: root/src/vox.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vox.c')
-rw-r--r--src/vox.c79
1 files changed, 38 insertions, 41 deletions
diff --git a/src/vox.c b/src/vox.c
index 502d79b..047200a 100644
--- a/src/vox.c
+++ b/src/vox.c
@@ -4,24 +4,24 @@
#include <xas/vox.h>
-static void voice_cleanup(xas_vox_voice *voice, xas_audio_stream *stream) {
+static void vox_cleanup(xas_vox *vox, xas_audio_stream *stream) {
int status;
- if (voice->flags & XAS_VOX_VOICE_ACTIVE) {
- if (voice->pid >= 0) {
- (void)waitpid(voice->pid, &status, 0);
+ if (vox->flags & XAS_VOX_ACTIVE) {
+ if (vox->pid >= 0) {
+ (void)waitpid(vox->pid, &status, 0);
}
- if (voice->stdout >= 0) {
- (void)close(voice->stdout);
+ if (vox->stdout >= 0) {
+ (void)close(vox->stdout);
}
}
}
-static ssize_t voice_fill(xas_vox_voice *voice,
- int16_t *samples,
- size_t count,
- xas_audio_stream *stream) {
+static ssize_t vox_fill(xas_vox *vox,
+ int16_t *samples,
+ size_t count,
+ xas_audio_stream *stream) {
size_t i;
for (i=0; i<count; i++) {
@@ -31,42 +31,39 @@ static ssize_t voice_fill(xas_vox_voice *voice,
return i;
}
-xas_audio_stream *xas_vox_new(const char *text2wave_path,
- size_t sample_size,
- size_t sample_rate,
- size_t buffer_size,
- void *ctx) {
- xas_audio_stream *stream;
- xas_vox_voice *voice;
+xas_vox *xas_vox_new(const char *text2wave_path,
+ size_t sample_size,
+ size_t sample_rate,
+ size_t buffer_size,
+ void *ctx) {
+ xas_vox *vox;
- if ((voice = malloc(sizeof(*voice))) == NULL) {
- goto error_malloc_voice;
+ if ((vox = malloc(sizeof(*vox))) == NULL) {
+ goto error_malloc_vox;
}
- voice->text2wave_path = text2wave_path;
- voice->sample_size = sample_size;
- voice->sample_rate = sample_rate;
- voice->ctx = ctx;
- voice->flags = XAS_VOX_VOICE_IDLE;
+ vox->text2wave_path = text2wave_path;
+ vox->sample_size = sample_size;
+ vox->sample_rate = sample_rate;
+ vox->buffer_size = buffer_size;
+ vox->ctx = ctx;
+ vox->flags = XAS_VOX_IDLE;
- voice->pid = -1;
- voice->stdout = -1;
+ vox->pid = -1;
+ vox->stdout = -1;
- if ((stream = xas_audio_stream_new_source((xas_audio_fill)voice_fill,
- (xas_audio_cleanup)voice_cleanup,
- voice,
- sample_size,
- sample_rate,
- XAS_AUDIO_STREAM_MONO,
- buffer_size)) == NULL) {
- goto error_audio_stream_new_source;
- }
-
- return stream;
-
-error_audio_stream_new_source:
- free(voice);
+ return vox;
-error_malloc_voice:
+error_malloc_vox:
return NULL;
}
+
+xas_audio_stream *xas_vox_stream_new(xas_vox *vox) {
+ return xas_audio_stream_new_source((xas_audio_fill)vox_fill,
+ (xas_audio_cleanup)vox_cleanup,
+ vox,
+ vox->sample_size,
+ vox->sample_rate,
+ XAS_AUDIO_STREAM_MONO,
+ vox->buffer_size);
+}