diff options
| author | XANTRONIX Development | 2022-02-01 15:39:16 -0500 | 
|---|---|---|
| committer | XANTRONIX Development | 2022-02-01 15:39:16 -0500 | 
| commit | a048f5848e6d57098d4524cb8b97853ef8329854 (patch) | |
| tree | d59a03d2f7d877084009d417c7492f90a4630770 /src | |
| parent | 0cdfdf8c867ac5582968e32a869d1ce3833aabb8 (diff) | |
| download | xas-a048f5848e6d57098d4524cb8b97853ef8329854.tar.gz xas-a048f5848e6d57098d4524cb8b97853ef8329854.tar.bz2 xas-a048f5848e6d57098d4524cb8b97853ef8329854.zip | |
hmm...getting more refined here
Diffstat (limited to 'src')
| -rw-r--r-- | src/vox.c | 79 | 
1 files changed, 38 insertions, 41 deletions
| @@ -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); +} | 
 
    