-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipe.c
92 lines (76 loc) · 2.67 KB
/
pipe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <gst/gst.h>
#include <glib.h>
#include "debug.h"
GstElement *pipeline, *effect, *effect, *conv1, *conv2, *source, *sink;
void start_pipeline(int effect_num)
{
GMainLoop *loop;
/* Initialization */
gst_init (0, NULL);
loop = g_main_loop_new (NULL, FALSE);
/* Create constant gstreamer elements (we wont change these ever)*/
DBG("[pipe]:\tCreating pipeline elements\n");
pipeline = gst_pipeline_new ("filter-pipeline");
source = gst_element_factory_make ("alsasrc", "audio-source");
conv1 = gst_element_factory_make ("audioconvert", "converter src");
conv2 = gst_element_factory_make ("audioconvert", "converter sink");
sink = gst_element_factory_make ("alsasink", "audio-sink");
if (!pipeline || !source || !conv1 || !conv2 || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return;
}
/* Create effects elements */
DBG("[pipe]:\tSetting up default filter parameters\n");
switch( effect_num )
{
case 0:
effect = gst_element_factory_make("audioconvert", "pass-thru");
break;
case 1:
effect = gst_element_factory_make ("audiocheblimit", "cheb-LPF");
g_object_set (G_OBJECT (effect), "mode", 0, NULL);
g_object_set (G_OBJECT (effect), "cutoff", (float)1000, NULL);
break;
case 2:
effect = gst_element_factory_make ("audiochebband", "cheb-BPF");
g_object_set (G_OBJECT (effect), "upper-frequency", (float)1050, NULL);
g_object_set (G_OBJECT (effect), "lower-frequency", (float)950, NULL);
break;
}
/* audio-source -> converter -> cheb filter -> converter -> alsa-output */
DBG("[pipe]:\tBuilding the pipeline\n");
gst_bin_add_many (GST_BIN (pipeline),
source, conv1, effect, conv2, sink, NULL);
gst_element_link_many (source, conv1, effect, conv2, sink, NULL);
DBG("[pipe]:\tNow playing\n");
gst_element_set_state (pipeline, GST_STATE_PLAYING);
}
void stop_pipeline(){
DBG("[pipe]:\tStopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
}
void restart_pipeline(int effect_num){
stop_pipeline();
start_pipeline(effect_num);
}
void configure_LPF(float cutoff){
DBG("[pipe]:\tSetting LP cutoff to %f\n", cutoff);
g_object_set (G_OBJECT (effect), "cutoff", cutoff, NULL);
}
void configure_BPF(float center, float bandwidth){
float upper, lower;
upper = center+bandwidth/2;
if( upper < 0 )
upper = 0;
else if( upper > 100000 )
upper = 100000;
lower = center-bandwidth/2;
if( lower < 0 )
lower = 0;
else if( lower > 100000 )
lower = 100000;
DBG("[pipe]:\tSetting BP upper to %f, lower to %f\n", upper, lower);
g_object_set (G_OBJECT (effect), "upper-frequency", upper, NULL);
g_object_set (G_OBJECT (effect), "lower-frequency", lower, NULL);
}