From 8ecc6d10a7f88577362ff486a95d393a2fc44fdf Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Sun, 19 Aug 2012 16:23:20 +0000 Subject: Set gst buffer size This does not mean that plugin will return buffers of specified sizes, code needs to be redesigned to for that reason. --- diff --git a/src/espeak.c b/src/espeak.c index bc8131b..60bdd1b 100644 --- a/src/espeak.c +++ b/src/espeak.c @@ -21,7 +21,8 @@ #include #include -#define SYNC_BUFFER_SIZE 4096 +#define SYNC_BUFFER_SIZE_MS 200 +#define BYTES_PER_SAMPLE 2 #define SPIN_QUEUE_SIZE 2 #define SPIN_FRAME_SIZE 255 @@ -121,6 +122,7 @@ static GCond *process_cond = NULL; static GSList *process_queue = NULL; static gint espeak_sample_rate = 0; +static gint espeak_buffer_size = 0; static GValueArray *espeak_voices = NULL; // ----------------------------------------------------------------------------- @@ -202,7 +204,7 @@ GstBuffer *play (Econtext * self, Espin * spin, gsize size_to_play) { for (;; ++spin->events_pos) { espeak_EVENT *i = &g_array_index (spin->events, espeak_EVENT, spin->events_pos); - gsize len = i->sample * 2 - spin->sound_offset; + gsize len = i->sample * BYTES_PER_SAMPLE - spin->sound_offset; if (i->type == espeakEVENT_LIST_TERMINATED || len >= size_to_play) return len; @@ -236,7 +238,7 @@ GstBuffer *play (Econtext * self, Espin * spin, gsize size_to_play) { } if (!sample_offset) { - sample_offset = i->sample * 2; + sample_offset = i->sample * BYTES_PER_SAMPLE; } return sample_offset - spin->sound_offset; @@ -329,7 +331,7 @@ void espeak_reset (Econtext * self) { process_pop (self); GstBuffer *buf; - while ((buf = espeak_out (self, SYNC_BUFFER_SIZE)) != NULL) + while ((buf = espeak_out (self, espeak_buffer_size)) != NULL) gst_buffer_unref (buf); int i; @@ -355,7 +357,7 @@ static gint synth_cb (short *data, int numsamples, espeak_EVENT * events) { if (numsamples > 0) { g_byte_array_append (spin->sound, (const guint8 *) data, - numsamples * 2); + numsamples * BYTES_PER_SAMPLE); espeak_EVENT *i; @@ -363,7 +365,7 @@ static gint synth_cb (short *data, int numsamples, espeak_EVENT * events) { GST_DEBUG ("type=%d text_position=%d length=%d " "audio_position=%d sample=%d", i->type, i->text_position, i->length, - i->audio_position, i->sample * 2); + i->audio_position, i->sample * BYTES_PER_SAMPLE); // convert to 0-based position --i->text_position; @@ -387,7 +389,7 @@ static gint synth_cb (short *data, int numsamples, espeak_EVENT * events) { } } - GST_DEBUG ("numsamples=%d", numsamples * 2); + GST_DEBUG ("numsamples=%d", numsamples * BYTES_PER_SAMPLE); return 0; } @@ -426,7 +428,7 @@ static void synth (Econtext * self, Espin * spin) { } espeak_EVENT last_event = { espeakEVENT_LIST_TERMINATED }; - last_event.sample = spin->sound->len / 2; + last_event.sample = spin->sound->len / BYTES_PER_SAMPLE; g_array_append_val (spin->events, last_event); } @@ -434,6 +436,10 @@ gint espeak_get_sample_rate () { return espeak_sample_rate; } +gint espeak_get_buffer_size () { + return espeak_buffer_size; +} + GValueArray *espeak_get_voices () { init (); return g_value_array_copy (espeak_voices); @@ -562,7 +568,10 @@ static void init () { process_tid = g_thread_create (process, NULL, FALSE, NULL); espeak_sample_rate = espeak_Initialize (AUDIO_OUTPUT_SYNCHRONOUS, - SYNC_BUFFER_SIZE, NULL, 0); + SYNC_BUFFER_SIZE_MS, NULL, 0); + espeak_buffer_size = + (SYNC_BUFFER_SIZE_MS * espeak_sample_rate) / + 1000 / BYTES_PER_SAMPLE; espeak_SetSynthCallback (synth_cb); gsize count = 0; diff --git a/src/espeak.h b/src/espeak.h index 329466e..1dfb4f2 100644 --- a/src/espeak.h +++ b/src/espeak.h @@ -31,6 +31,7 @@ Econtext *espeak_new (GstElement *); void espeak_unref (Econtext *); gint espeak_get_sample_rate (); +gint espeak_get_buffer_size (); GValueArray *espeak_get_voices (); void espeak_set_pitch (Econtext *, gint); void espeak_set_rate (Econtext *, gint); diff --git a/src/gstespeak.c b/src/gstespeak.c index 1dd097e..b7603eb 100644 --- a/src/gstespeak.c +++ b/src/gstespeak.c @@ -153,6 +153,7 @@ static void gst_espeak_init (GstEspeak * self) { "channels", G_TYPE_INT, 1, NULL); gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME); + gst_base_src_set_blocksize (GST_BASE_SRC (self), espeak_get_buffer_size()); } static void gst_espeak_finalize (GObject * self_) { -- cgit v0.9.1