1 /* GStreamer
2  *
3  * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 /* compile with :
22  * gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10 gstreamer-controller-0.10) pitch.c -o pitch
23  */
24 
25 #include <string.h>
26 #include <unistd.h>
27 #include <gst/gst.h>
28 #include <gst/controller/gsttimedvaluecontrolsource.h>
29 #include <gst/controller/gstinterpolationcontrolsource.h>
30 #include <gst/controller/gstdirectcontrolbinding.h>
31 
32 int
main(int argc,char ** argv)33 main (int argc, char **argv)
34 {
35   GMainLoop *loop;
36   gint i;
37 
38   GstElement *audiotestsrc;
39   GstElement *audioconvert1, *audioconvert2;
40   GstElement *pitch;
41   GstElement *sink;
42   GstElement *pipeline;
43   GstControlSource *cs;
44   GstTimedValueControlSource *tvcs;
45 
46   if (argc != 2) {
47     g_printerr ("Usage: %s <audiosink>\n", argv[0]);
48     return 1;
49   }
50 
51   /* initialize GStreamer */
52   gst_init (&argc, &argv);
53 
54   loop = g_main_loop_new (NULL, FALSE);
55 
56   pipeline = gst_pipeline_new ("audio-player");
57   audiotestsrc = gst_element_factory_make ("audiotestsrc", "audiotestsrc");
58   g_assert (audiotestsrc != NULL);
59   audioconvert1 = gst_element_factory_make ("audioconvert", "audioconvert1");
60   g_assert (audioconvert1 != NULL);
61   audioconvert2 = gst_element_factory_make ("audioconvert", "audioconvert2");
62   g_assert (audioconvert2 != NULL);
63   pitch = gst_element_factory_make ("pitch", "pitch");
64   g_assert (pitch != NULL);
65   sink = gst_element_factory_make (argv[1], "sink");
66   g_assert (sink != NULL);
67 
68   gst_bin_add_many (GST_BIN (pipeline),
69       audiotestsrc, audioconvert1, pitch, audioconvert2, sink, NULL);
70   gst_element_link_many (audiotestsrc, audioconvert1, pitch, audioconvert2,
71       sink, NULL);
72 
73   /* set up a controller */
74   cs = gst_interpolation_control_source_new ();
75   g_object_set (cs, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
76 
77   gst_object_add_control_binding (GST_OBJECT (pitch),
78       gst_direct_control_binding_new (GST_OBJECT (pitch), "pitch", cs));
79   tvcs = (GstTimedValueControlSource *) cs;
80 
81   for (i = 0; i < 100; ++i) {
82     if (i % 2)
83       gst_timed_value_control_source_set (tvcs, i * GST_SECOND, 0.5);
84     else
85       gst_timed_value_control_source_set (tvcs, i * GST_SECOND, 1.5);
86   }
87 
88   gst_element_set_state (pipeline, GST_STATE_PLAYING);
89   g_print ("Running\n");
90   g_main_loop_run (loop);
91 
92   /* clean up nicely */
93   gst_object_unref (cs);
94   g_print ("Returned, stopping playback\n");
95   gst_element_set_state (pipeline, GST_STATE_NULL);
96   g_print ("Deleting pipeline\n");
97   gst_object_unref (GST_OBJECT (pipeline));
98 
99   return 0;
100 }
101