From 06c30104580ec9c589580c695f2cfbb6cc0b8575 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 1 Feb 2022 11:49:03 -0500 Subject: Initial commit of src/vox.c --- include/xas/vox.h | 31 ++++++++++++++++++++++++ src/Makefile | 4 ++-- src/vox.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 include/xas/vox.h create mode 100644 src/vox.c diff --git a/include/xas/vox.h b/include/xas/vox.h new file mode 100644 index 0000000..6b73ae9 --- /dev/null +++ b/include/xas/vox.h @@ -0,0 +1,31 @@ +#ifndef _XAS_VOX_H +#define _XAS_VOX_H + +#include + +#include + +#define XAS_VOX_VOICE_IDLE 0 +#define XAS_VOX_VOICE_ACTIVE (1 << 0) + +typedef struct _xas_vox_voice { + const char *text2wave_path; + + size_t sample_size, + sample_rate; + + void *ctx; + + int flags; + + int pid, + stdout; +} xas_vox_voice; + +xas_audio_stream *xas_vox_new(const char *text2wave_path, + size_t sample_size, + size_t sample_rate, + size_t buffer_size, + void *ctx); + +#endif /* _XAS_VOX_H */ diff --git a/src/Makefile b/src/Makefile index a8853be..d5ddc43 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,9 +7,9 @@ CC = $(CROSS)cc CFLAGS += -I$(INCLUDE_PATH) LDFLAGS += -HEADERS = audio.h mixer.h synth.h riff.h +HEADERS = audio.h riff.h mixer.h synth.h vox.h -OBJS = audio.o mixer.o synth.o riff.o +OBJS = audio.o riff.o mixer.o synth.o vox.o VERSION_MAJOR = 0 VERSION_MINOR = 0.1 diff --git a/src/vox.c b/src/vox.c new file mode 100644 index 0000000..502d79b --- /dev/null +++ b/src/vox.c @@ -0,0 +1,72 @@ +#include +#include +#include + +#include + +static void voice_cleanup(xas_vox_voice *voice, xas_audio_stream *stream) { + int status; + + if (voice->flags & XAS_VOX_VOICE_ACTIVE) { + if (voice->pid >= 0) { + (void)waitpid(voice->pid, &status, 0); + } + + if (voice->stdout >= 0) { + (void)close(voice->stdout); + } + } +} + +static ssize_t voice_fill(xas_vox_voice *voice, + int16_t *samples, + size_t count, + xas_audio_stream *stream) { + size_t i; + + for (i=0; itext2wave_path = text2wave_path; + voice->sample_size = sample_size; + voice->sample_rate = sample_rate; + voice->ctx = ctx; + voice->flags = XAS_VOX_VOICE_IDLE; + + voice->pid = -1; + voice->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); + +error_malloc_voice: + return NULL; +} -- cgit v1.2.3