Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-08-19 16:23:20 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-08-19 17:32:29 (GMT)
commit8ecc6d10a7f88577362ff486a95d393a2fc44fdf (patch)
tree6b1f8fcf28461f1a9b610fe8e7845992f47cf42f
parent7075e8b9ad881368046e49b3de7516dbd9645bc2 (diff)
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.
-rw-r--r--src/espeak.c27
-rw-r--r--src/espeak.h1
-rw-r--r--src/gstespeak.c1
3 files changed, 20 insertions, 9 deletions
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 <gst/gst.h>
#include <espeak/speak_lib.h>
-#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_) {