static GstFlowReturn gst_flite_test_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstBuffer ** buffer) { GstFliteTestSrc *src; int n_bytes; src = GST_FLITE_TEST_SRC (basesrc); n_bytes = src->info.channels * sizeof (gint16) * src->samples_per_buffer; while (gst_adapter_available (src->adapter) < n_bytes) { GstBuffer *buf; char *text; int i; GstMapInfo map; gint16 *data; cst_wave *wave; gsize size; text = get_channel_name (src, src->channel); wave = flite_text_to_wave (text, src->voice); g_free (text); cst_wave_resample (wave, src->info.rate); GST_DEBUG ("type %s, sample_rate %d, num_samples %d, num_channels %d", wave->type, wave->sample_rate, wave->num_samples, wave->num_channels); size = src->info.channels * sizeof (gint16) * wave->num_samples; buf = gst_buffer_new_and_alloc (size); gst_buffer_map (buf, &map, GST_MAP_WRITE); data = (gint16 *) map.data; memset (data, 0, size); for (i = 0; i < wave->num_samples; i++) { data[i * src->info.channels + src->channel] = wave->samples[i]; } gst_buffer_unmap (buf, &map); src->channel++; if (src->channel == src->info.channels) { src->channel = 0; } gst_adapter_push (src->adapter, buf); } *buffer = gst_adapter_take_buffer (src->adapter, n_bytes); return GST_FLOW_OK; }
/*-------------------------------------------------------------------- * flite_synth : synthesize current text-buffer *--------------------------------------------------------------------*/ void flite_synth(t_flite *x) { cst_wave *wave; int i,vecsize; t_garray *a; t_float *vec; # ifdef FLITE_DEBUG post("flite: got message 'synth'"); # endif // -- sanity checks if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { pd_error(x,"flite: no such array '%s'", x->x_arrayname->s_name); return; } if (!x->textbuf) { pd_error(x,"flite: attempt to synthesize empty text-buffer!"); return; } # ifdef FLITE_DEBUG post("flite: flite_text_to_wave()"); # endif wave = flite_text_to_wave(x->textbuf,voice); if (!wave) { pd_error(x,"flite: synthesis failed for text '%s'", x->textbuf); return; } // -- resample # ifdef FLITE_DEBUG post("flite: cst_wave_resample()"); # endif cst_wave_resample(wave,sys_getsr()); // -- resize & write to our array # ifdef FLITE_DEBUG post("flite: garray_resize(%d)", wave->num_samples); # endif garray_resize(a, wave->num_samples); if (!garray_getfloatarray(a, &vecsize, &vec)) pd_error(x,"flite: bad template for write to array '%s'", x->x_arrayname->s_name); # ifdef FLITE_DEBUG post("flite: ->write to garray loop<-"); # endif for (i = 0; i < wave->num_samples; i++) { *vec++ = wave->samples[i]/32767.0; } // -- outlet synth-done-bang outlet_bang(x->x_obj.ob_outlet); // -- cleanup delete_wave(wave); // -- redraw garray_redraw(a); }