2005-08-02 21:35:34 +00:00
|
|
|
/*
|
|
|
|
* audio-example.c
|
2005-10-15 15:53:59 +00:00
|
|
|
*
|
2005-08-02 21:35:34 +00:00
|
|
|
* Build a pipeline with testaudiosource->alsasink
|
|
|
|
* and sweep frequency and volume
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2005-10-26 18:57:43 +00:00
|
|
|
#include <gst/controller/gstcontroller.h>
|
2005-08-02 21:35:34 +00:00
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc, gchar ** argv)
|
|
|
|
{
|
|
|
|
gint res = 1;
|
|
|
|
GstElement *src, *sink;
|
2005-08-29 19:59:52 +00:00
|
|
|
GstElement *bin;
|
2005-08-02 21:35:34 +00:00
|
|
|
GstController *ctrl;
|
2005-08-29 19:59:52 +00:00
|
|
|
GstClock *clock;
|
|
|
|
GstClockID clock_id;
|
|
|
|
GstClockReturn wait_ret;
|
2005-08-02 21:35:34 +00:00
|
|
|
GValue vol = { 0, };
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
gst_controller_init (&argc, &argv);
|
|
|
|
|
2005-12-12 14:46:06 +00:00
|
|
|
/* build pipeline */
|
2005-08-29 19:59:52 +00:00
|
|
|
bin = gst_pipeline_new ("pipeline");
|
|
|
|
clock = gst_pipeline_get_clock (GST_PIPELINE (bin));
|
2005-10-26 18:57:43 +00:00
|
|
|
src = gst_element_factory_make ("audiotestsrc", "gen_audio");
|
2005-08-02 21:35:34 +00:00
|
|
|
sink = gst_element_factory_make ("alsasink", "play_audio");
|
2005-08-29 19:59:52 +00:00
|
|
|
gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
|
|
|
|
if (!gst_element_link (src, sink)) {
|
|
|
|
GST_WARNING ("can't link elements");
|
|
|
|
goto Error;
|
|
|
|
}
|
2005-12-12 14:46:06 +00:00
|
|
|
|
|
|
|
/* square wave
|
|
|
|
g_object_set (G_OBJECT(src), "wave", 1, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* add a controller to the source */
|
2005-08-29 19:59:52 +00:00
|
|
|
if (!(ctrl = gst_controller_new (G_OBJECT (src), "freq", "volume", NULL))) {
|
|
|
|
GST_WARNING ("can't control source element");
|
2005-08-02 21:35:34 +00:00
|
|
|
goto Error;
|
|
|
|
}
|
2005-12-12 14:46:06 +00:00
|
|
|
|
|
|
|
/* set interpolation */
|
2005-08-02 21:35:34 +00:00
|
|
|
gst_controller_set_interpolation_mode (ctrl, "volume",
|
|
|
|
GST_INTERPOLATE_LINEAR);
|
2005-08-29 19:59:52 +00:00
|
|
|
gst_controller_set_interpolation_mode (ctrl, "freq", GST_INTERPOLATE_LINEAR);
|
2005-08-02 21:35:34 +00:00
|
|
|
|
2005-12-12 14:46:06 +00:00
|
|
|
/* set control values */
|
2005-08-02 21:35:34 +00:00
|
|
|
g_value_init (&vol, G_TYPE_DOUBLE);
|
|
|
|
g_value_set_double (&vol, 0.0);
|
|
|
|
gst_controller_set (ctrl, "volume", 0 * GST_SECOND, &vol);
|
|
|
|
g_value_set_double (&vol, 1.0);
|
2005-08-29 19:59:52 +00:00
|
|
|
gst_controller_set (ctrl, "volume", 5 * GST_SECOND, &vol);
|
2005-12-12 14:46:06 +00:00
|
|
|
g_value_set_double (&vol, 220.0);
|
2005-08-29 19:59:52 +00:00
|
|
|
gst_controller_set (ctrl, "freq", 0 * GST_SECOND, &vol);
|
|
|
|
g_value_set_double (&vol, 3520.0);
|
|
|
|
gst_controller_set (ctrl, "freq", 3 * GST_SECOND, &vol);
|
2005-12-12 14:46:06 +00:00
|
|
|
g_value_set_double (&vol, 440.0);
|
2005-08-29 19:59:52 +00:00
|
|
|
gst_controller_set (ctrl, "freq", 6 * GST_SECOND, &vol);
|
2005-08-02 21:35:34 +00:00
|
|
|
|
2005-08-29 19:59:52 +00:00
|
|
|
clock_id =
|
|
|
|
gst_clock_new_single_shot_id (clock,
|
|
|
|
gst_clock_get_time (clock) + (7 * GST_SECOND));
|
2005-08-02 21:35:34 +00:00
|
|
|
|
2005-12-12 14:46:06 +00:00
|
|
|
/* run for 7 seconds */
|
2005-08-29 19:59:52 +00:00
|
|
|
if (gst_element_set_state (bin, GST_STATE_PLAYING)) {
|
|
|
|
if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK) {
|
|
|
|
GST_WARNING ("clock_id_wait returned: %d", wait_ret);
|
|
|
|
}
|
|
|
|
gst_element_set_state (bin, GST_STATE_NULL);
|
|
|
|
}
|
2005-12-12 14:46:06 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
2005-08-02 21:35:34 +00:00
|
|
|
g_object_unref (G_OBJECT (ctrl));
|
2005-12-12 14:46:06 +00:00
|
|
|
gst_object_unref (G_OBJECT (clock));
|
|
|
|
gst_object_unref (G_OBJECT (bin));
|
2005-08-02 21:35:34 +00:00
|
|
|
res = 0;
|
|
|
|
Error:
|
|
|
|
return (res);
|
|
|
|
}
|