GstBus * gst_pipeline_get_bus (GstPipeline *pipeline)
guint gst_bus_add_watch (GstBus *bus, GstBusFunc func, gpointer user_data) void gst_bus_add_signal_watch (GstBus *bus)
GstMessage *gst_bus_poll (GstBus *bus, GstMessageType events, GstClockTime timeout)
g_signal_connect (bus, "message::error", G_CALLBACK (cb_message_error), NULL)
#include <gst/gst.h> #define SUPRESS_LEVEL 1.0 // 0.0 1.0 #define MONO_LEVEL 1.0 // 0.0 1.0 #define FILTER_BAND 220.0 // 0.0 441.0 #define FILTER_WIDTH 100.0 // 0.0 100.0 static GMainLoop *loop; static gboolean my_bus_callback (GstBus *bus, GstMessage *message, gpointer data) { switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR: { GError *err; gchar *debug; gst_message_parse_error (message, &err, &debug); g_print ("Error: %s\n", err->message); g_error_free (err); g_free (debug); g_main_loop_quit (loop); break; } case GST_MESSAGE_EOS: { g_print ("\n\nYou've got 100 points!\n"); g_main_loop_quit (loop); break; } default: break; } /* TRUE, , */ return TRUE; } int main (int argc, char * argv[]) { if (argc != 3) { g_printerr("Usage: %s audiofile.mp3 lyricsfile.txt\n", argv[0]); return -1; } GstElement *pipeline, *audiosrc, *parser, *decoder, *converter, *karaoke, *audiosink; GstElement *textsrc, *textsink; GstStateChangeReturn ret; GstBus *bus; guint bus_watch_id; /* */ gst_init(NULL, NULL); /* */ pipeline = gst_element_factory_make ("pipeline", "pipe"); audiosrc = gst_element_factory_make ("filesrc", "audiosrc"); parser = gst_element_factory_make ("mpegaudioparse", "parser"); decoder = gst_element_factory_make ("mad", "decoder"); converter = gst_element_factory_make ("audioconvert", "converter"); karaoke = gst_element_factory_make ("audiokaraoke", "karaoke"); audiosink = gst_element_factory_make ("autoaudiosink", "audiosink"); textsrc = gst_element_factory_make ("filesrc", "textsrc"); textsink = gst_element_factory_make ("fdsink", "textsink"); if (!pipeline || !audiosrc || !parser || !decoder || !converter || !karaoke || !audiosink || !textsrc || !textsink) { g_printerr ("Unable to create some elements\n"); return -1; } /* */ gst_bin_add_many (GST_BIN(pipeline), audiosrc, parser, decoder, converter, karaoke, audiosink, textsrc, textsink, NULL); /* */ if (gst_element_link_many (audiosrc, parser, decoder, converter, karaoke, audiosink, NULL) != TRUE) { g_printerr ("Unable to link some elements\n"); gst_object_unref(pipeline); return -1; } if (gst_element_link (textsrc, textsink) != TRUE) { g_printerr ("Unable to link text with textsink\n"); gst_object_unref(pipeline); return -1; } /* */ g_object_set (audiosrc, "location", argv[1], NULL); g_object_set (textsrc, "location", argv[2], NULL); g_object_set (karaoke, "level", SUPRESS_LEVEL, "mono-level", MONO_LEVEL, "filter-band", FILTER_BAND, "filter-width", FILTER_WIDTH, NULL); /* */ ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); if ( ret == GST_STATE_CHANGE_FAILURE ) { g_printerr ("Unable to set pipeline to the playing state\n"); gst_object_unref (pipeline); return -1; } /* */ bus = gst_element_get_bus (pipeline); bus_watch_id = gst_bus_add_watch (bus, my_bus_callback, NULL); gst_object_unref (bus); /* */ loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); /* */ gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); g_source_remove (bus_watch_id); g_main_loop_unref (loop); return 0; }
$ gcc -Wall -o karaoke karaoke.c $(pkg-config --libs --cflags gstreamer-1.0)
$ ./karaoke audiofile.mp3 lyricsfile.txt
Song | Effect |
---|---|
Tool - Parabola | Not bad cut vocals, but suppressed a lot of instrumental (especially the flageoles in solo) |
At the Drive-In - Rolodex Propaganda | The instrumental is well preserved, but the vocals are quite strong (apparently, due to its height) |
Radiohead - Jigsaw Falling into Place | It turned out pretty interesting here - the main vocal was crushed, and the backing remained |
U2 - Raised by Wolves | The guitar is kept almost perfect. |
Source: https://habr.com/ru/post/254417/
All Articles