Original commit message from CVS:
sinesrc:
- fixed timestamp calculation (again)
- renamed buffer_size to the less ambigious samples_per_buffer
demo_dparams:
- replaced clumsy g_object_set_property with g_object_set
- use volume element for volume (just for testing)
This commit is contained in:
Steve Baker 2002-05-05 15:46:05 +00:00
parent 49f02b6a0e
commit d66933e37f
3 changed files with 62 additions and 92 deletions

View file

@ -13,29 +13,22 @@ static gint quit_live(GtkWidget *window, GdkEventAny *e, gpointer data) {
}
static void dynparm_log_value_changed(GtkAdjustment *adj,GstDParam *dparam) {
GValue set_val;
gfloat value;
g_return_if_fail(dparam != NULL);
g_return_if_fail(GST_IS_DPARAM (dparam));
ZERO(set_val);
g_value_init(&set_val, G_TYPE_FLOAT);
g_value_set_float(&set_val, exp(adj->value));
value = exp(adj->value);
g_print("setting value to %f\n", g_value_get_float(&set_val));
g_object_set_property(G_OBJECT(dparam), "value_float", &set_val);
g_print("setting value to %f\n", value);
g_object_set(G_OBJECT(dparam), "value_float", value, NULL);
}
static void dynparm_value_changed(GtkAdjustment *adj,GstDParam *dparam) {
GValue set_val;
g_return_if_fail(dparam != NULL);
g_return_if_fail(GST_IS_DPARAM (dparam));
ZERO(set_val);
g_value_init(&set_val, G_TYPE_FLOAT);
g_value_set_float(&set_val, adj->value);
g_print("setting value to %f\n", adj->value);
g_object_set_property(G_OBJECT(dparam), "value_float", &set_val);
g_object_set(G_OBJECT(dparam), "value_float", (gfloat)adj->value, NULL);
}
@ -48,12 +41,11 @@ int main(int argc,char *argv[]) {
GtkWidget *volume_slider;
GtkWidget *freq_slider;
GstElement *thread, *sinesrc, *osssink;
GstElement *thread, *sinesrc, *volfilter, *osssink;
GstDParamManager *dpman;
GstDParam *volume;
GstDParam *freq;
GParamSpecFloat *spec;
GValue temp_val;
gtk_init(&argc,&argv);
gst_init(&argc,&argv);
@ -65,65 +57,14 @@ int main(int argc,char *argv[]) {
thread = gst_thread_new("live-example");
sinesrc = gst_element_factory_make("sinesrc","sine-source");
osssink = gst_element_factory_make("osssink","sound-sink");
gst_bin_add(GST_BIN(thread),sinesrc);
gst_bin_add(GST_BIN(thread),osssink);
gst_element_connect(sinesrc,osssink);
/* this breaks with current alsa oss compat lib
g_object_set(G_OBJECT(osssink),"fragment",0x00180008,NULL);*/
volfilter = gst_element_factory_make("volume","volume-filter");
gst_bin_add_many(GST_BIN(thread), sinesrc, volfilter, osssink, NULL);
gst_element_connect_many(sinesrc, volfilter, osssink, NULL);
/* this breaks with current alsa oss compat lib */
g_object_set(G_OBJECT(osssink),"fragment",0x00180008,NULL);
g_object_set(G_OBJECT(sinesrc),"buffersize",64,NULL);
dpman = gst_dpman_get_manager (sinesrc);
freq = gst_dpsmooth_new(G_TYPE_FLOAT);
g_object_set(G_OBJECT(sinesrc),"samplesperbuffer",64,NULL);
ZERO(temp_val);
g_value_init(&temp_val, G_TYPE_INT64);
g_value_set_int64(&temp_val, 2000000LL);
g_object_set_property(G_OBJECT(freq), "update_period", &temp_val);
ZERO(temp_val);
g_value_init(&temp_val, G_TYPE_FLOAT);
g_value_set_float(&temp_val, 0.693);
g_object_set_property(G_OBJECT(freq), "slope_delta_float", &temp_val);
ZERO(temp_val);
g_value_init(&temp_val, G_TYPE_INT64);
g_value_set_int64(&temp_val, 50000000LL);
g_object_set_property(G_OBJECT(freq), "slope_time", &temp_val);
/* vals = GST_DPARAM_GET_POINT(freq, 0LL);
g_value_set_float(vals[0], 10.0);
* this defines the maximum slope that this *
* param can change. This says that in 50ms *
* the value can change by a maximum of one semitone *
* (the log of one semitone is 0.693) *
g_value_set_float(vals[1], 0.693);
g_value_set_float(vals[2], 50000000.0);
* set the default update period to 0.5ms, or 2000Hz *
GST_DPARAM_DEFAULT_UPDATE_PERIOD(freq) = 2000000LL;
*/
volume = gst_dparam_new(G_TYPE_FLOAT);
/* vals = GST_DPARAM_GET_POINT(volume, 0LL);
* this defines the maximum slope that this *
* param can change. This says that in 10ms *
* the value can change by a maximum of 0.2 *
g_value_set_float(vals[1], 0.2);
g_value_set_float(vals[2], 10000000.0);
* set the default update period to 0.5ms, or 2000Hz *
GST_DPARAM_DEFAULT_UPDATE_PERIOD(volume) = 2000000LL;
*/
g_assert(gst_dpman_attach_dparam (dpman, "volume", volume));
g_assert(gst_dpman_attach_dparam (dpman, "freq", freq));
gst_dpman_set_mode(dpman, "synchronous");
/***** set up the GUI *****/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 80, 400);
@ -131,14 +72,23 @@ int main(int argc,char *argv[]) {
hbox = gtk_hbox_new(TRUE,0);
gtk_container_add(GTK_CONTAINER(window),hbox);
spec = (GParamSpecFloat*)gst_dpman_get_param_spec (dpman, "volume");
volume_adj = (GtkAdjustment*)gtk_adjustment_new(spec->default_value,
spec->minimum,
spec->maximum, 0.1, 0.01, 0.01);
volume_slider = gtk_vscale_new(volume_adj);
gtk_scale_set_digits(GTK_SCALE(volume_slider), 2);
gtk_box_pack_start(GTK_BOX(hbox),volume_slider,TRUE,TRUE,0);
/***** set up the dparams *****/
freq = gst_dpsmooth_new(G_TYPE_FLOAT);
g_object_set(G_OBJECT(freq), "update_period", 2000000LL, NULL);
/* this defines the maximum slope that this *
* param can change. This says that in 50ms *
* the value can change by a maximum of one semitone *
* (the log of one semitone is 0.693) */
g_object_set(G_OBJECT(freq), "slope_delta_float", 0.693F, NULL);
g_object_set(G_OBJECT(freq), "slope_time", 50000000LL, NULL);
dpman = gst_dpman_get_manager (sinesrc);
g_assert(gst_dpman_attach_dparam (dpman, "freq", freq));
gst_dpman_set_mode(dpman, "synchronous");
spec = (GParamSpecFloat*)gst_dpman_get_param_spec (dpman, "freq");
freq_adj = (GtkAdjustment*)gtk_adjustment_new((gfloat)log(spec->default_value),
(gfloat)log(spec->minimum),
@ -148,7 +98,28 @@ int main(int argc,char *argv[]) {
freq_slider = gtk_vscale_new(freq_adj);
gtk_scale_set_digits(GTK_SCALE(freq_slider), 2);
gtk_box_pack_start(GTK_BOX(hbox),freq_slider,TRUE,TRUE,0);
volume = gst_dpsmooth_new(G_TYPE_FLOAT);
g_object_set(G_OBJECT(volume), "update_period", 2000000LL, NULL);
/* this defines the maximum slope that this *
* param can change. This says that in 50ms *
* the value can change from 0.0 to 1.0 */
g_object_set(G_OBJECT(volume), "slope_delta_float", 1.0F, NULL);
g_object_set(G_OBJECT(volume), "slope_time", 50000000LL, NULL);
dpman = gst_dpman_get_manager (volfilter);
g_assert(gst_dpman_attach_dparam (dpman, "volume", volume));
gst_dpman_set_mode(dpman, "synchronous");
g_object_set(G_OBJECT(volfilter), "mute", FALSE, NULL);
spec = (GParamSpecFloat*)gst_dpman_get_param_spec (dpman, "volume");
volume_adj = (GtkAdjustment*)gtk_adjustment_new(spec->default_value, 0.0, 1.2, 0.1, 0.01, 0.01);
volume_slider = gtk_vscale_new(volume_adj);
gtk_scale_set_digits(GTK_SCALE(volume_slider), 2);
gtk_box_pack_start(GTK_BOX(hbox),volume_slider,TRUE,TRUE,0);
/***** set up the handlers and such *****/
/*gtk_signal_connect(volume_adj,"value-changed",GTK_SIGNAL_FUNC(volume_changed),sinesrc); */

View file

@ -50,12 +50,11 @@ enum {
ARG_FORMAT,
ARG_SAMPLERATE,
ARG_TABLESIZE,
ARG_BUFFER_SIZE,
ARG_SAMPLES_PER_BUFFER,
ARG_FREQ,
ARG_VOLUME,
};
/* FIXME: this is not core business... */
GST_PAD_TEMPLATE_FACTORY (sinesrc_src_factory,
"src",
GST_PAD_SRC,
@ -137,8 +136,8 @@ gst_sinesrc_class_init (GstSineSrcClass *klass)
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_TABLESIZE,
g_param_spec_int("tablesize","tablesize","tablesize",
G_MININT,G_MAXINT,0,G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFFER_SIZE,
g_param_spec_int("buffersize","buffersize","buffersize",
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SAMPLES_PER_BUFFER,
g_param_spec_int("samplesperbuffer","samplesperbuffer","samplesperbuffer",
0, G_MAXINT, 1024, G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FREQ,
g_param_spec_float("freq","freq","freq",
@ -172,7 +171,7 @@ gst_sinesrc_init (GstSineSrc *src)
src->table_pos = 0.0;
src->table_size = 1024;
src->buffer_size=1024;
src->samples_per_buffer=1024;
src->timestamp=0LL;
src->bufpool=NULL;
@ -217,7 +216,7 @@ gst_sinesrc_get(GstPad *pad)
src = GST_SINESRC(gst_pad_get_parent (pad));
if (src->bufpool == NULL) {
src->bufpool = gst_buffer_pool_get_default (2 * src->buffer_size, 8);
src->bufpool = gst_buffer_pool_get_default (2 * src->samples_per_buffer, 8);
}
buf = (GstBuffer *) gst_buffer_new_from_pool (src->bufpool, 0, 0);
@ -226,10 +225,10 @@ gst_sinesrc_get(GstPad *pad)
samples = (gint16*)GST_BUFFER_DATA(buf);
GST_BUFFER_DATA(buf) = (gpointer) samples;
frame_countdown = GST_DPMAN_PREPROCESS(src->dpman, src->buffer_size, src->timestamp);
frame_countdown = GST_DPMAN_PREPROCESS(src->dpman, src->samples_per_buffer, src->timestamp);
src->timestamp += src->buffer_size * 10^9 / src->samplerate;
src->timestamp += (gint64)src->samples_per_buffer * 1000000000LL / (gint64)src->samplerate;
while(GST_DPMAN_PROCESS_COUNTDOWN(src->dpman, frame_countdown, i)) {
src->table_lookup = (gint)(src->table_pos);
@ -291,8 +290,8 @@ gst_sinesrc_set_property (GObject *object, guint prop_id, const GValue *value, G
gst_sinesrc_populate_sinetable(src);
gst_sinesrc_update_table_inc(src);
break;
case ARG_BUFFER_SIZE:
src->buffer_size = g_value_get_int (value);
case ARG_SAMPLES_PER_BUFFER:
src->samples_per_buffer = g_value_get_int (value);
break;
case ARG_FREQ:
gst_dpman_bypass_dparam(src->dpman, "freq");
@ -326,8 +325,8 @@ gst_sinesrc_get_property (GObject *object, guint prop_id, GValue *value, GParamS
case ARG_TABLESIZE:
g_value_set_int (value, src->table_size);
break;
case ARG_BUFFER_SIZE:
g_value_set_int (value, src->buffer_size);
case ARG_SAMPLES_PER_BUFFER:
g_value_set_int (value, src->samples_per_buffer);
break;
case ARG_FREQ:
g_value_set_float (value, src->freq);

View file

@ -74,7 +74,7 @@ struct _GstSineSrc {
gint format;
gint samplerate;
gint buffer_size;
gint samples_per_buffer;
gulong seq;
gint64 timestamp;