diff options
| -rw-r--r-- | include/xas/vox.h | 1 | ||||
| -rw-r--r-- | src/vox.c | 50 | 
2 files changed, 28 insertions, 23 deletions
| diff --git a/include/xas/vox.h b/include/xas/vox.h index 790cbca..7eb72d1 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -26,7 +26,6 @@ typedef struct _xas_vox {          stdout;      FILE *in; -    xas_audio_stream *output;  } xas_vox;  xas_vox *xas_vox_new(const char *text2wave_path, @@ -28,12 +28,6 @@ static int vox_stop(xas_vox *vox) {          vox->in = NULL;      } -    if (vox->output) { -        xas_audio_stream_destroy(vox->output); - -        vox->output = NULL; -    } -      if (vox->pid) {          int status; @@ -123,7 +117,7 @@ error_child:      vox->stdin  = pipe_stdin[1];      vox->stdout = pipe_stdout[0];      vox->in     = fdopen(pipe_stdin[1], "w"); -    vox->output = NULL; +    vox->flags |= XAS_VOX_ACTIVE;      return 0; @@ -147,8 +141,10 @@ static ssize_t vox_fill(xas_vox *vox,                          int16_t *samples,                          size_t count,                          xas_audio_stream *stream) { -    ssize_t readlen; -    int16_t *buf; +    ssize_t readlen, +            readcount; + +    size_t i;      if (!(vox->flags & XAS_VOX_ACTIVE)) {          memset(samples, '\0', count * vox->sample_size); @@ -156,19 +152,25 @@ static ssize_t vox_fill(xas_vox *vox,          return count;      } -    if ((readlen = xas_audio_stream_read(vox->output, -                                           (void **)&buf, -                                           count)) < 0) { -        goto error_audio_stream_read; +    if ((readlen = read(vox->stdout, +                        samples, +                        count * vox->sample_size)) < 0) { +        goto error_read;      }      if (readlen == 0) {          vox_stop(vox);      } -    return readlen; +    readcount = readlen / vox->sample_size; + +    for (i=readcount; i<count-readcount; i++) { +        samples[i] = 0; +    } + +    return count; -error_audio_stream_read: +error_read:      return -1;  } @@ -211,6 +213,7 @@ int xas_vox_stop(xas_vox *vox) {  int xas_vox_vsayf(xas_vox *vox, const char *format, va_list args) {      int ret; +    xas_audio_stream *output;      if (vox_start(vox) < 0) {          goto error_vox_start; @@ -220,27 +223,30 @@ int xas_vox_vsayf(xas_vox *vox, const char *format, va_list args) {          goto error_vfprintf;      } +    (void)fflush(vox->in); +    (void)fclose(vox->in);      (void)close(vox->stdin); -    vox->stdin = -1; -    (void)fclose(vox->in); -    vox->in = NULL; +    vox->stdin = -1; +    vox->in    = NULL; -    if ((vox->output = xas_riff_open_fd(vox->stdout)) == NULL) { +    if ((output = xas_riff_open_fd(vox->stdout)) == NULL) {          goto error_riff_open_fd;      } -    if (vox->output->sample_size != vox->sample_size -     || vox->output->sample_rate != vox->sample_rate) { +    if (output->sample_size != vox->sample_size +     || output->sample_rate != vox->sample_rate) {          errno = EINVAL;          goto error_invalid_stream;      } +    xas_audio_stream_destroy(output); +      return ret;  error_invalid_stream: -    xas_audio_stream_destroy(vox->output); +    xas_audio_stream_destroy(output);  error_riff_open_fd:  error_vfprintf: | 
 
    