1 /* Demo Recorder for MAEMO 5
2 * Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2,
5 * or (at your option) any later version, as published by the Free
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 public class InputBin : Gst.Bin {
23 Gst.Element converter;
28 Gst.GhostPad sink_pad;
30 public InputBin(string name) {
32 construct_pipeline(SettingsStructures.RecordingSettings());
34 public InputBin.with_settings(string name, SettingsStructures.RecordingSettings settings) {
36 construct_pipeline(settings);
39 private string get_source_device(string name) {
44 return "sink.hw0.monitor";
51 private string get_source_name(string device) {
55 case "sink.hw0.monitor":
64 private void construct_pipeline(SettingsStructures.RecordingSettings settings) {
66 this.src = Gst.ElementFactory.make("pulsesrc", "capture");
67 this.src.set_property("device", get_source_device(settings.source)); //"source.hw0"); /// TODO
70 this.converter = Gst.ElementFactory.make("audioconvert", "converter");
71 this.add(this.converter);
73 this.pregain = Gst.ElementFactory.make("volume", "pregain");
74 this.pregain.set_property("volume", settings.pregain);
75 this.add(this.pregain);
77 this.dynamics = Gst.ElementFactory.make("audiodynamic", "dynamics");
78 this.add(this.dynamics);
79 this.dynamics.set_property("mode", settings.dynamics.mode); // compressor or expander
80 this.dynamics.set_property("characteristics", settings.dynamics.characteristics); // hard-knee or soft-knee
81 this.dynamics.set_property("threshold", settings.dynamics.threshold); // [0, 1]
82 this.dynamics.set_property("ratio", settings.dynamics.ratio); // >= 0
84 this.volume = Gst.ElementFactory.make("volume", "volume");
85 this.volume.set_property("volume", settings.volume);
86 this.add(this.volume);
88 this.src.link(converter);
89 this.converter.link(pregain);
90 this.pregain.link(dynamics);
91 this.dynamics.link(volume);
93 sink_pad = new Gst.GhostPad("sink", src.get_static_pad("sink"));
94 this.add_pad(sink_pad);
95 src_pad = new Gst.GhostPad("src", volume.get_static_pad("src"));
96 this.add_pad(src_pad);
99 public new Gst.PadTemplate get_pad_template(string name) {
102 return this.volume.get_pad_template("src");
104 return this.src.get_pad_template("sink");
106 return base.get_pad_template(name);
110 public void set_dynamics(string mode, string characteristics, double threshold, double ratio) {
111 this.dynamics.set_property("mode", mode); // compressor or expander
112 this.dynamics.set_property("characteristics", characteristics); // hard-knee or soft-knee
113 this.dynamics.set_property("threshold", threshold); // [0, 1]
114 this.dynamics.set_property("ratio", ratio); // >= 0
116 public void set_dynamics_mode(string mode) {
117 this.dynamics.set_property("mode", mode); // compressor or expander
119 public void set_dynamics_characteristics(string characteristics) {
120 this.dynamics.set_property("characteristics", characteristics); // hard-knee or soft-knee
122 public void set_dynamics_threshold(double threshold) {
123 this.dynamics.set_property("threshold", threshold); // [0, 1]
125 public void set_dynamics_ratio(double ratio) {
126 this.dynamics.set_property("ratio", ratio); // >= 0
129 public void set_source(string name) {
131 Gst.ClockTime time = Gst.util_get_timestamp ();
132 this.get_state (out state, null, time);
133 this.set_state(Gst.State.NULL);
134 this.src.set_property("device", get_source_device(name));
135 this.set_state(state);
137 public string get_source() {
139 this.src.get_property("device", ref val);
140 return get_source_name(val.get_string());
143 public void set_pregain(double val)
144 requires (val >= 0.0 && val <= 10.0) {
145 this.pregain.set_property("volume", val);
147 public double get_pregain()
148 ensures (result >= 0.0 && result <= 10.0) {
150 this.pregain.get_property("volume", ref val);
151 return val.get_double();
154 public void set_volume(double val)
155 requires (val >= 0.0 && val <= 10.0) {
156 this.volume.set_property("volume", val);
158 public double get_volume()
159 ensures (result >= 0.0 && result <= 10.0) {
161 this.volume.get_property("volume", ref val);
162 return val.get_double();
165 public void set_mute(bool val) {
166 this.volume.set_property("mute", val);
168 public bool get_mute() {
170 this.volume.get_property("mute", ref val);
171 return val.get_boolean();