mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-22 07:08:23 +00:00
freq slider now uses smooth log dparam. sounds real smooth now
Original commit message from CVS: freq slider now uses smooth log dparam. sounds real smooth now
This commit is contained in:
parent
c4630dfcee
commit
fa71b53ffa
1 changed files with 38 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gst/gst.h>
|
||||
#include <sys/soundcard.h>
|
||||
|
@ -13,6 +14,20 @@ static gint quit_live(GtkWidget *window, GdkEventAny *e, gpointer data) {
|
|||
// gtk_object_set(GTK_OBJECT(element),"volume",adj->value,NULL);
|
||||
//}
|
||||
|
||||
static void dynparm_log_value_changed(GtkAdjustment *adj,GstDParam *dparam) {
|
||||
GValue **point;
|
||||
g_return_if_fail(dparam != NULL);
|
||||
g_return_if_fail(GST_IS_DPARAM (dparam));
|
||||
|
||||
point = GST_DPARAM_GET_POINT(dparam, 0LL);
|
||||
|
||||
GST_DPARAM_LOCK(dparam);
|
||||
g_print("setting value from %f to %f\n", g_value_get_float(point[0]), (gfloat)exp(adj->value));
|
||||
g_value_set_float(point[0], (gfloat)exp(adj->value));
|
||||
GST_DPARAM_READY_FOR_UPDATE(dparam) = TRUE;
|
||||
GST_DPARAM_UNLOCK(dparam);
|
||||
}
|
||||
|
||||
static void dynparm_value_changed(GtkAdjustment *adj,GstDParam *dparam) {
|
||||
GValue **point;
|
||||
g_return_if_fail(dparam != NULL);
|
||||
|
@ -42,7 +57,7 @@ int main(int argc,char *argv[]) {
|
|||
GstDParam *freq;
|
||||
GstDParamSpec *spec;
|
||||
|
||||
GValue **vol_vals;
|
||||
GValue **vals;
|
||||
|
||||
gtk_init(&argc,&argv);
|
||||
gst_init(&argc,&argv);
|
||||
|
@ -59,18 +74,30 @@ int main(int argc,char *argv[]) {
|
|||
g_object_set(G_OBJECT(sinesrc),"buffersize",64,NULL);
|
||||
|
||||
dpman = GST_ELEMENT_DPARAM_MANAGER(sinesrc);
|
||||
|
||||
freq = gst_dparam_new(G_TYPE_FLOAT);
|
||||
//volume = gst_dparam_new(G_TYPE_FLOAT);
|
||||
|
||||
freq = gst_dparam_smooth_new(G_TYPE_FLOAT);
|
||||
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_smooth_new(G_TYPE_FLOAT);
|
||||
vol_vals = GST_DPARAM_GET_POINT(volume, 0LL);
|
||||
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(vol_vals[1], 0.2);
|
||||
g_value_set_float(vol_vals[2], 10000000.0);
|
||||
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;
|
||||
|
@ -94,9 +121,9 @@ int main(int argc,char *argv[]) {
|
|||
gtk_box_pack_start(GTK_BOX(hbox),volume_slider,TRUE,TRUE,0);
|
||||
|
||||
spec = gst_dpman_get_dparam_spec (dpman, "freq");
|
||||
freq_adj = (GtkAdjustment*)gtk_adjustment_new(g_value_get_float(spec->default_val),
|
||||
g_value_get_float(spec->min_val),
|
||||
g_value_get_float(spec->max_val), 0.1, 0.01, 0.01);
|
||||
freq_adj = (GtkAdjustment*)gtk_adjustment_new((gfloat)log(g_value_get_float(spec->default_val)),
|
||||
(gfloat)log(g_value_get_float(spec->min_val)),
|
||||
(gfloat)log(g_value_get_float(spec->max_val)), 0.1, 0.01, 0.01);
|
||||
freq_slider = gtk_vscale_new(freq_adj);
|
||||
gtk_box_pack_start(GTK_BOX(hbox),freq_slider,TRUE,TRUE,0);
|
||||
|
||||
|
@ -108,7 +135,7 @@ int main(int argc,char *argv[]) {
|
|||
volume);
|
||||
|
||||
g_signal_connect(freq_adj,"value-changed",
|
||||
GTK_SIGNAL_FUNC(dynparm_value_changed),
|
||||
GTK_SIGNAL_FUNC(dynparm_log_value_changed),
|
||||
freq);
|
||||
gtk_adjustment_value_changed(volume_adj);
|
||||
gtk_adjustment_value_changed(freq_adj);
|
||||
|
|
Loading…
Reference in a new issue