2 * cutter.c - cut audio into pieces based on silence - thomas@apestaart.org
4 * construct a simple pipeline osssrc ! cutter ! disksink
5 * pause when necessary, change output
7 * Latest change : 03/06/2001
19 gboolean playing = TRUE;
20 gboolean cut_start_signalled = FALSE;
21 gboolean cut_stop_signalled = FALSE;
23 int id = 0; /* increment this for each new cut */
33 /* signal callbacks */
35 void cut_start (GstElement *element)
37 g_print ("\nDEBUG: main: cut start\n");
38 /* we should pause the pipeline, disconnect cutter and disksink
39 * create a new disksink to a real file, reconnect, and set to play
41 g_print ("DEBUG: cut_start: main_bin pausing\n");
42 gst_element_set_state (main_bin, GST_STATE_PAUSED);
43 g_print ("DEBUG: cut_start: main_bin paused\n");
49 ct = localtime (&seconds);
50 // sprintf (buffer, "/news/incoming/audio/cutter.%06d.wav", id);
51 sprintf (buffer, "/news/incoming/audio/cutter.%04d%02d%02d.%02d%02d%02d.wav",
52 ct->tm_year + 1900, ct->tm_mon, ct->tm_mday,
53 ct->tm_hour, ct->tm_min, ct->tm_sec);
55 g_print ("DEBUG: cut_start: setting new location to %s\n", buffer);
56 g_object_set (G_OBJECT (disksink), "location", buffer, NULL);
57 g_object_set (G_OBJECT (disksink), "type", 4, NULL);
59 gst_element_set_state (main_bin, GST_STATE_PLAYING);
61 g_print ("start_cut_signal done\n");
65 void cut_start_signal (GstElement *element)
67 g_print ("\nDEBUG: main: cut start signal\n");
68 cut_start_signalled = TRUE;
71 void cut_stop (GstElement *element)
73 g_print ("\nDEBUG: main: cut stop\n");
74 /* we should pause the pipeline, disconnect disksink, create a fake disksink,
75 * connect to pipeline, and set to play
77 g_print ("DEBUG: cut_stop: main_bin paused\n");
78 gst_element_set_state (main_bin, GST_STATE_PAUSED);
80 g_print ("DEBUG: cut_stop: setting new location\n");
81 g_object_set (G_OBJECT (disksink), "location", "/dev/null", NULL);
83 gst_element_set_state (main_bin, GST_STATE_PLAYING);
84 g_print ("stop_cut_signal done\n");
88 void cut_stop_signal (GstElement *element)
90 g_print ("\nDEBUG: main: cut stop signal\n");
91 cut_stop_signalled = TRUE;
94 int main (int argc, char *argv[])
101 //output_channel_t *channel_out;
103 GstElement *audiosrc;
105 gst_init (&argc,&argv);
109 g_print("usage: %s <filename1> <filename2> <...>\n", argv[0]);
113 /* set up input channel and main bin */
115 g_print ("creating main bin\n");
117 cutter = gst_elementfactory_make ("cutter", "cutter");
119 g_object_set (G_OBJECT (cutter),
120 "threshold_dB", -40.0,
125 /* create an audio src */
126 audiosrc = gst_elementfactory_make ("osssrc", "audio_src");
130 g_object_set (G_OBJECT (audiosrc), "frequency", 44100,
134 encoder = gst_elementfactory_make ("passthrough", "encoder");
135 disksink = gst_elementfactory_make ("afsink", "disk_sink");
137 g_object_set (G_OBJECT (disksink), "location", "/dev/null", NULL);
139 thread = gst_thread_new ("thread");
140 g_assert (thread != NULL);
142 /* create main bin */
143 main_bin = gst_pipeline_new ("bin");
144 g_assert (main_bin != NULL);
146 queue = gst_elementfactory_make ("queue", "queue");
148 /* add elements to bin */
149 gst_bin_add (GST_BIN (main_bin), audiosrc);
150 gst_bin_add (GST_BIN (thread), queue);
152 gst_bin_add (GST_BIN (thread), cutter);
153 gst_bin_add (GST_BIN (thread), encoder);
154 gst_bin_add (GST_BIN (thread), disksink);
156 /* connect adder and disksink */
158 gst_pad_connect (gst_element_get_pad (audiosrc, "src"),
159 gst_element_get_pad (queue, "sink"));
161 gst_pad_connect (gst_element_get_pad (queue, "src"),
162 gst_element_get_pad (cutter, "sink"));
163 gst_pad_connect (gst_element_get_pad (cutter, "src"),
164 gst_element_get_pad (encoder, "sink"));
165 gst_pad_connect (gst_element_get_pad (encoder, "src"),
166 gst_element_get_pad (disksink, "sink"));
168 gst_bin_add (GST_BIN (main_bin), thread);
170 /* set signal handlers */
171 g_print ("setting signal handlers\n");
172 g_signal_connectc (G_OBJECT(cutter), "cut_start",
173 (GCallback)cut_start_signal, NULL, FALSE);
174 g_signal_connectc (G_OBJECT(cutter), "cut_stop",
175 (GCallback)cut_stop_signal, NULL, FALSE);
178 g_print ("setting to play\n");
179 gst_element_set_state (main_bin, GST_STATE_PLAYING);
181 g_print ("setting thread to play\n");
182 gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
187 gst_bin_iterate (GST_BIN (main_bin));
189 if (cut_start_signalled)
191 g_print ("\nDEBUG: main: cut_start_signalled true !\n");
193 cut_start_signalled = FALSE;
195 if (cut_stop_signalled)
197 g_print ("\nDEBUG: main: cut_stop_signalled true !\n");
199 cut_stop_signalled = FALSE;
202 g_print ("we're done iterating.\n");
205 gst_element_set_state (main_bin, GST_STATE_NULL);
207 gst_object_destroy (GST_OBJECT (disksink));
208 gst_object_destroy (GST_OBJECT (main_bin));