diff options
| -rw-r--r-- | examples/say.c | 4 | ||||
| -rw-r--r-- | include/xas/bank.h | 11 | ||||
| -rw-r--r-- | include/xas/object.h | 19 | ||||
| -rw-r--r-- | include/xas/synth.h | 3 | ||||
| -rw-r--r-- | include/xas/vox.h | 7 | ||||
| -rw-r--r-- | src/bank.c | 18 | ||||
| -rw-r--r-- | src/object.c | 9 | ||||
| -rw-r--r-- | src/synth.c | 15 | ||||
| -rw-r--r-- | src/vox.c | 19 | 
9 files changed, 86 insertions, 19 deletions
| diff --git a/examples/say.c b/examples/say.c index fa16242..c89a245 100644 --- a/examples/say.c +++ b/examples/say.c @@ -154,12 +154,14 @@ int main(int argc, char **argv) {          goto error_bank_record;      } +    xas_bank_player_select(player, 0, 1.0); +      for (i=0; i<duration_frames; i++) {          void *buf;          ssize_t readlen;          if (i >= 300 && !xas_bank_player_playing(player)) { -            xas_bank_player_start(player, 0, 1.0); +            xas_bank_player_start(player);          }          if ((readlen = xas_audio_stream_read(mixer->output, diff --git a/include/xas/bank.h b/include/xas/bank.h index 33be492..cd1511e 100644 --- a/include/xas/bank.h +++ b/include/xas/bank.h @@ -3,6 +3,7 @@  #include <sys/types.h> +#include <xas/object.h>  #include <xas/audio.h>  enum xas_bank_player_status { @@ -22,6 +23,8 @@ typedef struct _xas_bank {  } xas_bank;  typedef struct _xas_bank_player { +    xas_object obj; +      xas_bank *bank;      enum xas_bank_player_status status; @@ -50,9 +53,11 @@ xas_bank_player *xas_bank_player_new(xas_bank *bank);  void xas_bank_player_destroy(xas_bank_player *player); -int xas_bank_player_start(xas_bank_player *player, -                            size_t entry, -                            float gain); +int xas_bank_player_select(xas_bank_player *player, +                             size_t entry, +                             float gain); + +int xas_bank_player_start(xas_bank_player *player);  int xas_bank_player_stop(xas_bank_player *player); diff --git a/include/xas/object.h b/include/xas/object.h new file mode 100644 index 0000000..b8b713b --- /dev/null +++ b/include/xas/object.h @@ -0,0 +1,19 @@ +#ifndef _XAS_OBJECT_H +#define _XAS_OBJECT_H + +typedef struct _xas_object xas_object; + +typedef int (*xas_object_start_callback)(xas_object *object); + +typedef int (*xas_object_stop_callback)(xas_object *object); + +struct _xas_object { +    xas_object_start_callback start; +    xas_object_stop_callback  stop; +}; + +int xas_object_start(xas_object *object); + +int xas_object_stop(xas_object *object); + +#endif /* _XAS_OBJECT_H */ diff --git a/include/xas/synth.h b/include/xas/synth.h index 53f3343..61f50bc 100644 --- a/include/xas/synth.h +++ b/include/xas/synth.h @@ -4,6 +4,7 @@  #include <stdint.h>  #include <sys/types.h> +#include <xas/object.h>  #include <xas/audio.h>  #define XAS_SYNTH_DEFAULT_FREQUENCY 2600 /* Hz */ @@ -25,6 +26,8 @@ typedef struct _xas_synth xas_synth;  typedef int16_t (*xas_synth_sample_callback)(xas_synth *synth);  struct _xas_synth { +    xas_object obj; +      enum xas_synth_type  type;      enum xas_synth_state state; diff --git a/include/xas/vox.h b/include/xas/vox.h index 5a1cacf..9d63bba 100644 --- a/include/xas/vox.h +++ b/include/xas/vox.h @@ -5,6 +5,7 @@  #include <stdarg.h>  #include <sys/types.h> +#include <xas/object.h>  #include <xas/audio.h>  #define XAS_VOX_SETTINGS_TMP_PATH    "/tmp/xas-vox.XXXXXX" @@ -16,6 +17,8 @@ enum xas_vox_state {  };  typedef struct _xas_vox { +    xas_object obj; +      xas_audio_format format;      size_t buffer_size; @@ -66,12 +69,12 @@ int xas_vox_set_parameter_int(xas_vox *vox,                                  const char *name,                                  int value); +int xas_vox_generate(xas_vox *vox); +  int xas_vox_stop(xas_vox *vox);  int xas_vox_active(xas_vox *vox); -int xas_vox_generate(xas_vox *vox); -  int xas_vox_vsayf(xas_vox *vox, const char *message, va_list args);  int xas_vox_sayf(xas_vox *vox, const char *message, ...); @@ -125,6 +125,9 @@ xas_bank_player *xas_bank_player_new(xas_bank *bank) {          goto error_malloc_player;      } +    player->obj.start = (xas_object_start_callback)xas_bank_player_start; +    player->obj.stop  = (xas_object_stop_callback)xas_bank_player_stop; +      player->bank   = bank;      player->status = XAS_BANK_PLAYER_STOPPED;      player->gain   = 0.0f; @@ -141,16 +144,21 @@ void xas_bank_player_destroy(xas_bank_player *player) {      free(player);  } -int xas_bank_player_start(xas_bank_player *player, -                            size_t entry, -                            float gain) { +int xas_bank_player_select(xas_bank_player *player, +                             size_t entry, +                             float gain) { +    player->entry = entry; +    player->gain  = gain; + +    return 0; +} + +int xas_bank_player_start(xas_bank_player *player) {      if (player->status == XAS_BANK_PLAYER_PLAYING) {          return 0;      }      player->status = XAS_BANK_PLAYER_PLAYING; -    player->gain   = gain; -    player->entry  = entry;      player->index  = 0;      return 0; diff --git a/src/object.c b/src/object.c new file mode 100644 index 0000000..55ea4af --- /dev/null +++ b/src/object.c @@ -0,0 +1,9 @@ +#include <xas/object.h> + +int xas_object_start(xas_object *object) { +    object->start(object); +} + +int xas_object_stop(xas_object *object) { +    object->stop(object); +} diff --git a/src/synth.c b/src/synth.c index 86990e8..fddd2a0 100644 --- a/src/synth.c +++ b/src/synth.c @@ -99,6 +99,18 @@ static ssize_t synth_fill(xas_synth *synth,      return count;  } +static int synth_start(xas_synth *synth) { +    xas_synth_start(synth); + +    return 0; +} + +static int synth_stop(xas_synth *synth) { +    xas_synth_stop(synth); + +    return 0; +} +  xas_synth *xas_synth_new(xas_audio_format format,                               size_t buffer_size,                               enum xas_synth_type type) { @@ -108,6 +120,9 @@ xas_synth *xas_synth_new(xas_audio_format format,          goto error_malloc_synth;      } +    synth->obj.start = (xas_object_start_callback)synth_start; +    synth->obj.stop  = (xas_object_stop_callback)synth_stop; +      synth->type      = type;      synth->state     = XAS_SYNTH_IDLE;      synth->phase     = 0.0f; @@ -275,6 +275,9 @@ xas_vox *xas_vox_new_args(xas_audio_format format,          goto error_malloc_vox;      } +    vox->obj.start = (xas_object_start_callback)xas_vox_generate; +    vox->obj.stop  = (xas_object_stop_callback)xas_vox_stop; +      vox->text2wave_path = text2wave_path;      vox->format.channels    = XAS_AUDIO_MONO; @@ -394,14 +397,6 @@ int xas_vox_set_parameter_int(xas_vox *vox,      return set_parameter_va(vox, name, "%d", value);  } -int xas_vox_stop(xas_vox *vox) { -    if (vox->state == XAS_VOX_ACTIVE) { -        return vox_stop(vox); -    } - -    return 0; -} -  int xas_vox_active(xas_vox *vox) {      return vox->state == XAS_VOX_ACTIVE;  } @@ -435,6 +430,14 @@ error_riff_open_fd:      return -1;  } +int xas_vox_stop(xas_vox *vox) { +    if (vox->state == XAS_VOX_ACTIVE) { +        return vox_stop(vox); +    } + +    return 0; +} +  int xas_vox_vsayf(xas_vox *vox, const char *format, va_list args) {      if (vox->state == XAS_VOX_IDLE && vox_start(vox) < 0) {          goto error_vox_start; | 
 
    